Created
November 22, 2019 05:26
-
-
Save kumavis/db5f5d7768c857d6c7b24f5e78b2cd41 to your computer and use it in GitHub Desktop.
batch tx polyfill idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const provider = polyfillJsonRpcBatchAsBatchTx(inpageProvider) | |
function polyfillJsonRpcBatchAsBatchTx (oldProvider) { | |
const newProvider = { sendAsync } | |
return newProvider | |
function sendAsync (req, cb) { | |
if (Array.isArray(req)) { | |
const shouldBatch = req.every(req => req.method === 'eth_sendTransaction') | |
if (!shouldBatch) { | |
// procede normally | |
return oldProvider.sendAsync(req, cb) | |
} | |
// do as a batch | |
const newReq = { | |
method: 'wallet_batchTx', | |
params: req.map(entry => entry.params[0]), | |
} | |
return oldProvider.sendAsync(newReq, cb) | |
} else { | |
// procede normally | |
return oldProvider.sendAsync(req, cb) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment