feat(etherscan): erc1155 token transfer events endpoint (#1503)

Added the function `get_erc1155_transfer_events` and the corresponding struct `ERC1155TokenTransferEvent`.
This commit is contained in:
Hari 2022-07-26 17:28:09 +02:00 committed by GitHub
parent 6b713958d1
commit 3766c2b47c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 78 additions and 0 deletions

View File

@ -4,6 +4,7 @@
### Unreleased ### Unreleased
- Added `get_erc1155_token_transfer_events` function for etherscan client [#1503](https://github.com/gakonst/ethers-rs/pull/1503)
- Add support for Geth `debug_traceTransaction` [#1469](https://github.com/gakonst/ethers-rs/pull/1469) - Add support for Geth `debug_traceTransaction` [#1469](https://github.com/gakonst/ethers-rs/pull/1469)
- Use correct, new transaction type for `typool_content` RPC endpoint [#1501](https://github.com/gakonst/ethers-rs/pull/1501) - Use correct, new transaction type for `typool_content` RPC endpoint [#1501](https://github.com/gakonst/ethers-rs/pull/1501)
- Fix the default config for generated `BuildInfo` [#1458](https://github.com/gakonst/ethers-rs/pull/1458) - Fix the default config for generated `BuildInfo` [#1458](https://github.com/gakonst/ethers-rs/pull/1458)

View File

@ -203,6 +203,33 @@ pub struct ERC721TokenTransferEvent {
pub confirmations: U64, pub confirmations: U64,
} }
/// The raw response from the ERC1155 transfer list API endpoint
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ERC1155TokenTransferEvent {
pub block_number: BlockNumber,
pub time_stamp: String,
pub hash: H256,
pub nonce: U256,
pub block_hash: H256,
pub from: Address,
pub contract_address: Address,
pub to: Option<Address>,
#[serde(rename = "tokenID")]
pub token_id: String,
pub token_value: String,
pub token_name: String,
pub token_symbol: String,
pub transaction_index: U64,
pub gas: U256,
pub gas_price: Option<U256>,
pub gas_used: U256,
pub cumulative_gas_used: U256,
/// deprecated
pub input: String,
pub confirmations: U64,
}
/// The raw response from the mined blocks API endpoint /// The raw response from the mined blocks API endpoint
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
@ -532,6 +559,36 @@ impl Client {
Ok(response.result) Ok(response.result)
} }
/// Returns the list of ERC-1155 ( NFT ) tokens transferred by an address, with optional
/// filtering by token contract.
///
/// ```no_run
/// # use ethers_etherscan::{Client, account::TokenQueryOption};
/// # use ethers_core::types::Chain;
///
/// # #[tokio::main]
/// # async fn main() {
/// let client = Client::new(Chain::Mainnet, "API_KEY").unwrap();
/// let txs = client
/// .get_erc1155_token_transfer_events(
/// TokenQueryOption::ByAddressAndContract(
/// "0x216CD350a4044e7016f14936663e2880Dd2A39d7".parse().unwrap(),
/// "0x495f947276749ce646f68ac8c248420045cb7b5e".parse().unwrap(),
/// ), None).await.unwrap();
/// # }
/// ```
pub async fn get_erc1155_token_transfer_events(
&self,
event_query_option: TokenQueryOption,
params: Option<TxListParams>,
) -> Result<Vec<ERC1155TokenTransferEvent>> {
let params = event_query_option.into_params(params.unwrap_or_default());
let query = self.create_query("account", "token1155tx", params);
let response: Response<Vec<ERC1155TokenTransferEvent>> = self.get_json(&query).await?;
Ok(response.result)
}
/// Returns the list of blocks mined by an address. /// Returns the list of blocks mined by an address.
/// ///
/// ```no_run /// ```no_run
@ -708,6 +765,26 @@ mod tests {
.await .await
} }
#[tokio::test]
#[serial]
async fn get_erc1155_transfer_events_success() {
run_at_least_duration(Duration::from_millis(250), async {
let client = Client::new_from_env(Chain::Mainnet).unwrap();
let txs = client
.get_erc1155_token_transfer_events(
TokenQueryOption::ByAddressAndContract(
"0x216CD350a4044e7016f14936663e2880Dd2A39d7".parse().unwrap(),
"0x495f947276749ce646f68ac8c248420045cb7b5e".parse().unwrap(),
),
None,
)
.await;
assert!(txs.is_ok());
})
.await
}
#[tokio::test] #[tokio::test]
#[serial] #[serial]
async fn get_mined_blocks_success() { async fn get_mined_blocks_success() {