neo: Ledger.GetTransaction() can't get current transaction

I used method Ledger.GetTransaction() in the smart contract, and I expect it to return true when pre-execution, and false when I actually execution it.

Contract code

public static bool t1()
{
    return Ledger.GetTransaction(((Transaction)Runtime.ScriptContainer).Hash) == null;
}

Invokefunction(pre-execution) request

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "invokefunction",
    "params": [
        "0xd2448d18052d5732f7da35d5d31e6ef47e664508",
        "t1",
        [],
        [
            {
                "account": "0x4578060c29f4c03f1e16c84312429d991952c94c",
                "scopes": "CalledByEntry",
                "allowedcontracts": [],
                "allowedgroups": []
            }
        ]
    ]
}

response

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "script": "wh8MAnQxDBQIRWZ+9G4e09U12vcyVy0FGI1E0kFifVtS",
        "state": "HALT",
        "gasconsumed": "4718760",
        "exception": null,
        "stack": [
            {
                "type": "Boolean",
                "value": true
            }
        ],
        "tx": "ANaI8RGoAEgAAAAAAPjrEQAAAAAAlhoAAAFMyVIZmZ1CEkPIFh4/wPQpDAZ4RQEAIcIfDAJ0MQwUCEVmfvRuHtPVNdr3MlctBRiNRNJBYn1bUgFCDEBB6QBbnLMUY/Vw4MDHdRClOeYy02quh/S3f7PNq5pOud8EkCWIVq+4w39RRbbr5wCpWGhc5IiG2eQRSHFANngqKAwhAnuOhIl9zf58vffm17ad227dYyPL5zLqaN0rPUSoDoDwQVbnsyc="
    }
}

Then I sent the transaction and got the transaction log: (actually execution)

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "txid": "0x5490875a4a161f457de2de8553af13b089fd36e8092b7fe199d85c13651f5ea0",
        "executions": [
            {
                "trigger": "Application",
                "vmstate": "HALT",
                "exception": null,
                "gasconsumed": "4718760",
                "stack": [
                    {
                        "type": "Boolean",
                        "value": true
                    }
                ],
                "notifications": []
            }
        ]
    }
}

So, Ledger.GetTransaction can’t get current transaction?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 26 (13 by maintainers)

Most upvoted comments

Assuming that pre-execution requires 2GAS and the actual execution has a 20% chance of requiring 2.01GAS, I would rather add 0.01 GAS to each transaction, otherwise I would lose 2GAS because the contract execution would fail due to sufficient fees.

The wallet(Neo-cli/Neo3-GUI/NeoLine/O3/Neon) used by the user can’t add systemfee, so I can only add systemfee to the pre-execution of the contract.

You can add some GAS to system fee when you’re creating a transaction, contract itself shouldn’t even try to do estimations of this kind. And it shouldn’t differentiate between on-chain and test executions in general, otherwise what’s use of test execution? It’s not just about GAS, I’d also like to see exactly what happens when I do something with the contract, if the contract decides to change its behavior on-chain I’d say this contract is cheating me.

I think you can find the answer in your code, you were asking your transaction from the Ledger while your transaction was not in the Ledger, it was still persisting.

So, Ledger.GetTransaction can’t get current transaction?

Yes. As well as any other transaction from the same block, they’re not traceable. https://github.com/neo-project/neo/blob/a4d2eddbee049bbe3d5d9552e11181d294af929e/src/neo/SmartContract/Native/LedgerContract.cs#L54-L59 Which actually allows for some interesting optimizations.