add json rpc bindings for eth_getCode (#15)
This commit is contained in:
parent
636762d464
commit
5d92e72882
|
@ -409,7 +409,27 @@ impl<P: JsonRpcClient> Provider<P> {
|
|||
.map_err(Into::into)?)
|
||||
}
|
||||
|
||||
// TODO: get_code, get_storage_at
|
||||
// TODO: get_storage_at
|
||||
|
||||
/// Returns the deployed code at a given address
|
||||
pub async fn get_code(
|
||||
&self,
|
||||
at: impl Into<NameOrAddress>,
|
||||
block: Option<BlockNumber>,
|
||||
) -> Result<Bytes, ProviderError> {
|
||||
let at = match at.into() {
|
||||
NameOrAddress::Name(ens_name) => self.resolve_name(&ens_name).await?,
|
||||
NameOrAddress::Address(addr) => addr,
|
||||
};
|
||||
|
||||
let at = utils::serialize(&at);
|
||||
let block = utils::serialize(&block.unwrap_or(BlockNumber::Latest));
|
||||
Ok(self
|
||||
.0
|
||||
.request("eth_getCode", [at, block])
|
||||
.await
|
||||
.map_err(Into::into)?)
|
||||
}
|
||||
|
||||
////// Ethereum Naming Service
|
||||
// The Ethereum Naming Service (ENS) allows easy to remember and use names to
|
||||
|
|
|
@ -132,6 +132,9 @@ pub mod contract {
|
|||
///
|
||||
/// let block = provider.get_block(100u64).await?;
|
||||
/// println!("Got block: {}", serde_json::to_string(&block)?);
|
||||
///
|
||||
/// let code = provider.get_code("0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359", None).await?;
|
||||
/// println!("Got code: {}", serde_json::to_string(&code)?);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
|
|
Loading…
Reference in New Issue