-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contract Transactions Middleware (#7138)
* contract transactionMiddleware * transactionMiddleware setting for contract from eth * contract Tx middleware plugin * contract tx middleware tests * changelog * fix * test import fix * integration patch fix * lint fix * integration tests * middleware in fixture * unit test * lint fix * fixture fix for lint import err via symlink * unit test coverage push * up coverage
- Loading branch information
Showing
12 changed files
with
525 additions
and
10 deletions.
There are no files selected for viewing
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
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
38 changes: 38 additions & 0 deletions
38
packages/web3-eth-contract/test/fixtures/contract_transaction_middleware.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
This file is part of web3.js. | ||
web3.js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
web3.js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { TransactionMiddleware, TransactionMiddlewareData } from "web3-eth"; | ||
|
||
// Sample Transaction Middleware | ||
export class ContractTransactionMiddleware implements TransactionMiddleware { | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
public async processTransaction(transaction: TransactionMiddlewareData, | ||
_options?: { [key: string]: unknown } | undefined): | ||
|
||
Promise<TransactionMiddlewareData> { | ||
|
||
// eslint-disable-next-line prefer-const | ||
let txObj = { ...transaction }; | ||
|
||
// Add your logic here for transaction modification | ||
txObj.data = '0x123'; | ||
|
||
return Promise.resolve(txObj); | ||
} | ||
|
||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
This file is part of web3.js. | ||
web3.js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
web3.js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { TransactionMiddleware, TransactionMiddlewareData } from "web3-eth"; | ||
|
||
// Sample Transaction Middleware | ||
export class CTransactionMiddleware implements TransactionMiddleware { | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
public async processTransaction(transaction: TransactionMiddlewareData, | ||
_options?: { [key: string]: unknown } | undefined): | ||
|
||
Promise<TransactionMiddlewareData> { | ||
|
||
// eslint-disable-next-line prefer-const | ||
let txObj = { ...transaction }; | ||
|
||
// Add your logic here for transaction modification | ||
txObj.data = '0x123'; | ||
|
||
return Promise.resolve(txObj); | ||
} | ||
|
||
} |
Oops, something went wrong.
e9fc019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
processingTx
9175
ops/sec (±3.95%
)8643
ops/sec (±4.01%
)0.94
processingContractDeploy
38902
ops/sec (±6.92%
)37706
ops/sec (±7.16%
)0.97
processingContractMethodSend
15550
ops/sec (±7.85%
)15011
ops/sec (±8.43%
)0.97
processingContractMethodCall
27222
ops/sec (±8.01%
)26199
ops/sec (±7.75%
)0.96
abiEncode
43564
ops/sec (±6.49%
)40879
ops/sec (±7.43%
)0.94
abiDecode
30187
ops/sec (±7.32%
)30556
ops/sec (±6.68%
)1.01
sign
1545
ops/sec (±0.67%
)1503
ops/sec (±3.72%
)0.97
verify
367
ops/sec (±0.61%
)363
ops/sec (±0.57%
)0.99
This comment was automatically generated by workflow using github-action-benchmark.