-
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.
fix: ensure contractInstance.subscriptionManager.subscribe is not thr…
…owing (#7327) * rename `LogsSubscription` at `web3-eth-contract` to `ContractLogsSubscription` * fix issue that `contractInstance.subscriptionManager.subscribe` was throwing * add a unit test
- Loading branch information
1 parent
fab66e9
commit ed85cce
Showing
8 changed files
with
153 additions
and
22 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
packages/web3-eth-contract/src/contract-subscription-manager.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,72 @@ | ||
/* | ||
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 { Web3SubscriptionConstructor, Web3SubscriptionManager } from 'web3-core'; | ||
import { EthExecutionAPI, ContractAbi, DataFormat, DEFAULT_RETURN_FORMAT } from 'web3-types'; | ||
// eslint-disable-next-line import/no-cycle | ||
import { Contract } from './contract.js'; | ||
|
||
/** | ||
* Similar to `Web3SubscriptionManager` but has a reference to the Contract that uses | ||
*/ | ||
export class ContractSubscriptionManager< | ||
API extends EthExecutionAPI, | ||
RegisteredSubs extends { | ||
[key: string]: Web3SubscriptionConstructor<API>; | ||
} = any, // = ContractSubscriptions | ||
> extends Web3SubscriptionManager<API, RegisteredSubs> { | ||
public readonly parentContract: Contract<ContractAbi>; | ||
|
||
/** | ||
* | ||
* @param - Web3SubscriptionManager | ||
* @param - parentContract | ||
* | ||
* @example | ||
* ```ts | ||
* const requestManager = new Web3RequestManager("ws://localhost:8545"); | ||
* const contract = new Contract(...) | ||
* const subscriptionManager = new Web3SubscriptionManager(requestManager, {}, contract); | ||
* ``` | ||
*/ | ||
public constructor( | ||
self: Web3SubscriptionManager<API, RegisteredSubs>, | ||
parentContract: Contract<ContractAbi>, | ||
) { | ||
super(self.requestManager, self.registeredSubscriptions); | ||
|
||
this.parentContract = parentContract; | ||
} | ||
|
||
/** | ||
* Will create a new subscription | ||
* | ||
* @param name - The subscription you want to subscribe to | ||
* @param args - Optional additional parameters, depending on the subscription type | ||
* @param returnFormat- ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) - Specifies how the return data from the call should be formatted. | ||
* | ||
* Will subscribe to a specific topic (note: name) | ||
* @returns The subscription object | ||
*/ | ||
public async subscribe<T extends keyof RegisteredSubs>( | ||
name: T, | ||
args?: ConstructorParameters<RegisteredSubs[T]>[0], | ||
returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, | ||
): Promise<InstanceType<RegisteredSubs[T]>> { | ||
return super.subscribe(name, args ?? this.parentContract.options, returnFormat); | ||
} | ||
} |
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
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
ed85cce
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
22475
ops/sec (±7.29%
)22533
ops/sec (±6.62%
)1.00
processingContractDeploy
37859
ops/sec (±7.67%
)39420
ops/sec (±7.63%
)1.04
processingContractMethodSend
16019
ops/sec (±6.80%
)16012
ops/sec (±7.57%
)1.00
processingContractMethodCall
27428
ops/sec (±6.22%
)27328
ops/sec (±7.22%
)1.00
abiEncode
42843
ops/sec (±7.53%
)42745
ops/sec (±7.84%
)1.00
abiDecode
29934
ops/sec (±7.71%
)29680
ops/sec (±8.64%
)0.99
sign
1501
ops/sec (±3.06%
)1484
ops/sec (±3.35%
)0.99
verify
368
ops/sec (±0.51%
)364
ops/sec (±0.49%
)0.99
This comment was automatically generated by workflow using github-action-benchmark.