-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export some kind of general Contract struct #513
Comments
So, I think there is a large change we can make to the struct MyContractAbi;
implement Abi for MyContractAbi {
type Function: MyContractFunction;
type Event: MyContractEvent;
}
enum MyContractFunction {
Foo {
value: U256,
owner: Address,
},
Bar,
}
enum MyContractEvent {
// same as now.
} We would then be able to create instances of type: let instance: Contract<MyContractAbi>; Some other advantages of this separation:
fn do_something_to_contract<C: Abi>(instance: Contract<C>) { /* ... */ };
fn call_some_function<C: Abi>(instance: Contract<C>, function: C::Function) { /* ... */ };
let instance: MockContract<MyContractAbi>;
let calldata = MyContractEvent::encode(MyContractFunction::Foo { value, owner }); |
Trying to make this general deployment block fetcher async fn get_deployment_block<T: Transport>(contract: ðcontract::contract::Instance<T>) -> Option<u64> {
match contract.deployment_information() {
Some(DeploymentInformation::BlockNumber(block_number)) => Some(block_number),
Some(DeploymentInformation::TransactionHash(hash)) => Some(
contract
.raw_instance()
.web3()
.block_number_from_tx_hash(hash)
.await?,
),
None => None,
}
} But when I give it a generated contract instance I get this: error[E0308]: mismatched types
--> shared/src/balancer/event_handler.rs:286:71
|
286 | let deployment_block_two_token_factory = get_deployment_block(&two_token_pool_factory).await;
| ^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Instance`, found struct `BalancerV2WeightedPool2TokensFactory`
|
= note: expected reference `&Instance<_>`
found reference `&BalancerV2WeightedPool2TokensFactory` Managed to work around it by passing the async fn get_deployment_block(
deployment_info: Option<DeploymentInformation>,
web3: &DynWeb3,
) -> Option<u64> {
match deployment_info {
Some(DeploymentInformation::BlockNumber(block_number)) => Some(block_number),
Some(DeploymentInformation::TransactionHash(hash)) => {
Some(web3.block_number_from_tx_hash(hash).await.ok()?)
}
None => None,
}
} |
Not exactly sure how to describe this, but I suppose it would be analogous to the
Contract
object what we know and love fromethers
which can be instantiated as an interface from an ABI or as an instance when also provided with an address and web3Provider.This would allow us to make generalizations for arbitrary contracts some common functionalities.
One particular place where this could come in handy is when implementing an Event Listener in place of the generic
EventRetrieving
Where
At the moment we need to implement
EventRetrieving
in a very boiler plate kind of way for each contract we want to listen to.The text was updated successfully, but these errors were encountered: