Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Asynchronous transactions (polling based for now). #1652

Merged
merged 5 commits into from Jul 19, 2016
Merged

Conversation

gavofyork
Copy link
Contributor

@gavofyork gavofyork commented Jul 17, 2016

  • Add eth_postTransaction as an async alternative to eth_sendTransaction. Returns a Confirmation promise ID.
  • Add eth_checkTransaction, takes a single argument - a Confirmation promise ID and returns
    one of:
    • Transaction hash (signed and submitted).
    • null (still pending, call again later),
    • Zero hash (will never be signed).

- Alter eth_sendTransaction to be async, returning one of:
  - Transaction hash (signed and submitted).
  - Transaction promise ID (< 32 bytes).
  - Zero hash (will never be signed).
- Introduce new JSONRPC eth_checkTransaction.

The new API call takes a single argument - a promise ID. It returns
either:
- Transaction hash (signed and submitted).
- null (still pending, call again later),
- Zero hash (will never be signed).
@coveralls
Copy link

coveralls commented Jul 17, 2016

Coverage Status

Coverage decreased (-0.1%) to 76.264% when pulling f223199 on async_sendtx into 5ab18d1 on master.

- Restore previous semantics of sendTransaction.
- Introduce eth_postTransaction.
- Some refactoring.
@gavofyork
Copy link
Contributor Author

Additional web3.js code required to make this work:

web3._extend({
    property: 'eth',
    methods: [
        new web3._extend.Method({
            name: 'postTransaction',
            call: 'eth_postTransaction',
            params: 1,
            inputFormatter: [web3._extend.formatters.inputCallFormatter]
        })
    ]
});

web3._extend({
    property: 'eth',
    methods: [
        new web3._extend.Method({
            name: 'checkTransaction',
            call: 'eth_checkTransaction',
            params: 1
        })
    ]
});

{
    var postTransaction = web3.eth.postTransaction.bind(web3.eth);
    var sendTransaction = web3.eth.sendTransaction.bind(web3.eth);
    web3.eth.sendTransaction = function(options, f) {
        // No callback - use compatibility sync API.
        if (typeof f != "function")
            return sendTransaction(options);
        // Callback - use async API.
        var id = postTransaction(options);
        var timer_id = window.setInterval(check, 500);
        function check() {
            let r = web3.eth.checkTransaction(id);
            if (typeof r == 'string') {
                clearInterval(timer_id);
                if (r == "0x0000000000000000000000000000000000000000000000000000000000000000")
                    f("Rejected", r);
                else
                    f(null, r);
            }
        }
    }
}

@coveralls
Copy link

coveralls commented Jul 17, 2016

Coverage Status

Coverage decreased (-0.09%) to 76.288% when pulling a465d01 on async_sendtx into 5ab18d1 on master.

@coveralls
Copy link

coveralls commented Jul 17, 2016

Coverage Status

Coverage decreased (-0.1%) to 76.297% when pulling 73c9125 on async_sendtx into dd17c76 on master.

@@ -59,6 +61,7 @@ impl<C, M> EthSigningQueueClient<C, M> where C: MiningBlockChainClient, M: Miner
accounts: Arc::downgrade(accounts),
client: Arc::downgrade(client),
miner: Arc::downgrade(miner),
pending: Mutex::new(HashMap::new()),
Copy link
Collaborator

@tomusdrw tomusdrw Jul 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can leak (when check is not called), maybe TransientHashMap (the same one is used for filters) could be used here?

@tomusdrw
Copy link
Collaborator

JS code is invalid in general case - The code should be applied only if signer is enabled.

Minor things:

  1. Rejected -> { message: 'rejected' } for compatibility with Mist.
  2. If postTransaction or checkTransaction fail (for instance when node is turned off or API returns invalid params error) callback is not invoked (you need to try/catch the invocations when using sync methods)

@tomusdrw tomusdrw added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jul 18, 2016
@gavofyork
Copy link
Contributor Author

signer should always be used with UI and in any case JS code is not part of this PR.

@tomusdrw tomusdrw added A8-looksgood 🦄 Pull request is reviewed well. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Jul 18, 2016
@coveralls
Copy link

coveralls commented Jul 18, 2016

Coverage Status

Coverage decreased (-0.01%) to 76.39% when pulling 5864bcc on async_sendtx into dd17c76 on master.

@gavofyork gavofyork merged commit 3ba3dd3 into master Jul 19, 2016
@gavofyork gavofyork deleted the async_sendtx branch July 19, 2016 07:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants