From b71e6ad00b2290e103342a2c7fe20d01865e0ba7 Mon Sep 17 00:00:00 2001 From: Jacob <93085583+cobward@users.noreply.github.com> Date: Wed, 24 Aug 2022 20:50:29 +0100 Subject: [PATCH] ethers-etherscan: derive debug, clone and copy (#1634) * ethers-etherscan: derive debug, clone and copy Derive Debug, Clone and Copy on all appropriate Structs and Enums. * Update changelog --- CHANGELOG.md | 1 + ethers-etherscan/src/account.rs | 22 ++++++++++++++-------- ethers-etherscan/src/contract.rs | 8 ++++---- ethers-etherscan/src/gas.rs | 2 +- ethers-etherscan/src/lib.rs | 2 +- ethers-etherscan/src/source_tree.rs | 4 ++-- ethers-etherscan/src/transaction.rs | 4 ++-- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff174341..65ed438c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,7 @@ - Add Arithmetic Shift Right operation for I256 [#1323](https://github.com/gakonst/ethers-rs/issues/1323) - [#1535](https://github.com/gakonst/ethers-rs/pull/1535) Add support to Aurora and Aurora testnet networks. - [#1632](https://github.com/gakonst/ethers-rs/pull/1632) Re-export `H32` from `ethabi`. +- [#1634](https://github.com/gakonst/ethers-rs/pull/1634) Derive missing `Clone`, `Copy` and `Debug` impls in ethers-etherscan. ## ethers-contract-abigen diff --git a/ethers-etherscan/src/account.rs b/ethers-etherscan/src/account.rs index 9ba5caa3..71c53ecd 100644 --- a/ethers-etherscan/src/account.rs +++ b/ethers-etherscan/src/account.rs @@ -11,7 +11,7 @@ use std::{ }; /// The raw response from the balance-related API endpoints -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AccountBalance { pub account: Address, pub balance: String, @@ -139,7 +139,7 @@ mod hex_string { /// /// Transactions from the Genesis block may contain fields that do not conform to the expected /// types. -#[derive(Debug)] +#[derive(Clone, Debug)] pub enum GenesisOption { None, Genesis, @@ -169,7 +169,7 @@ impl GenesisOption { } /// The raw response from the transaction list API endpoint -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct NormalTransaction { pub is_error: String, @@ -211,7 +211,7 @@ pub struct NormalTransaction { } /// The raw response from the internal transaction list API endpoint -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct InternalTransaction { #[serde(deserialize_with = "deserialize_stringified_block_number")] @@ -239,7 +239,7 @@ pub struct InternalTransaction { } /// The raw response from the ERC20 transfer list API endpoint -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ERC20TokenTransferEvent { #[serde(deserialize_with = "deserialize_stringified_block_number")] @@ -274,7 +274,7 @@ pub struct ERC20TokenTransferEvent { } /// The raw response from the ERC721 transfer list API endpoint -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ERC721TokenTransferEvent { #[serde(deserialize_with = "deserialize_stringified_block_number")] @@ -309,7 +309,7 @@ pub struct ERC721TokenTransferEvent { } /// The raw response from the ERC1155 transfer list API endpoint -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ERC1155TokenTransferEvent { #[serde(deserialize_with = "deserialize_stringified_block_number")] @@ -344,7 +344,7 @@ pub struct ERC1155TokenTransferEvent { } /// The raw response from the mined blocks API endpoint -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct MinedBlock { #[serde(deserialize_with = "deserialize_stringified_block_number")] @@ -354,6 +354,7 @@ pub struct MinedBlock { } /// The pre-defined block parameter for balance API endpoints +#[derive(Clone, Copy, Debug)] pub enum Tag { Earliest, Pending, @@ -377,6 +378,7 @@ impl Default for Tag { } /// The list sorting preference +#[derive(Clone, Copy, Debug)] pub enum Sort { Asc, Desc, @@ -392,6 +394,7 @@ impl Display for Sort { } /// Common optional arguments for the transaction or event list API endpoints +#[derive(Clone, Copy, Debug)] pub struct TxListParams { start_block: u64, end_block: u64, @@ -425,6 +428,7 @@ impl From for HashMap<&'static str, String> { } /// Options for querying internal transactions +#[derive(Clone, Debug)] pub enum InternalTxQueryOption { ByAddress(Address), ByTransactionHash(H256), @@ -432,6 +436,7 @@ pub enum InternalTxQueryOption { } /// Options for querying ERC20 or ERC721 token transfers +#[derive(Clone, Debug)] pub enum TokenQueryOption { ByAddress(Address), ByContract(Address), @@ -460,6 +465,7 @@ impl TokenQueryOption { } /// The pre-defined block type for retrieving mined blocks +#[derive(Copy, Clone, Debug)] pub enum BlockType { CanonicalBlocks, Uncles, diff --git a/ethers-etherscan/src/contract.rs b/ethers-etherscan/src/contract.rs index b7bb7da7..ad6f768a 100644 --- a/ethers-etherscan/src/contract.rs +++ b/ethers-etherscan/src/contract.rs @@ -139,7 +139,7 @@ impl Default for CodeFormat { } } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] #[serde(transparent)] pub struct ContractMetadata { pub items: Vec, @@ -154,12 +154,12 @@ impl IntoIterator for ContractMetadata { } } -#[derive(Deserialize)] +#[derive(Deserialize, Clone, Debug)] struct EtherscanSourceEntry { content: String, } -#[derive(Deserialize)] +#[derive(Deserialize, Clone, Debug)] struct EtherscanSourceJsonMetadata { sources: HashMap, } @@ -217,7 +217,7 @@ impl ContractMetadata { } /// Etherscan contract metadata -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct Metadata { #[serde(rename = "SourceCode")] pub source_code: String, diff --git a/ethers-etherscan/src/gas.rs b/ethers-etherscan/src/gas.rs index 988a3285..da573ffc 100644 --- a/ethers-etherscan/src/gas.rs +++ b/ethers-etherscan/src/gas.rs @@ -7,7 +7,7 @@ use ethers_core::types::U256; use crate::{Client, EtherscanError, Response, Result}; -#[derive(Deserialize)] +#[derive(Deserialize, Clone, Debug)] #[serde(rename_all = "PascalCase")] pub struct GasOracle { #[serde(deserialize_with = "deserialize_number_from_string")] diff --git a/ethers-etherscan/src/lib.rs b/ethers-etherscan/src/lib.rs index 0d38f49f..89ec0000 100644 --- a/ethers-etherscan/src/lib.rs +++ b/ethers-etherscan/src/lib.rs @@ -399,7 +399,7 @@ pub enum ResponseData { } /// The type that gets serialized as query -#[derive(Debug, Serialize)] +#[derive(Clone, Debug, Serialize)] struct Query<'a, T: Serialize> { apikey: Cow<'a, str>, module: Cow<'a, str>, diff --git a/ethers-etherscan/src/source_tree.rs b/ethers-etherscan/src/source_tree.rs index 16619621..015bb84a 100644 --- a/ethers-etherscan/src/source_tree.rs +++ b/ethers-etherscan/src/source_tree.rs @@ -4,13 +4,13 @@ use std::{ path::{Component, Path, PathBuf}, }; -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct SourceTreeEntry { pub path: PathBuf, pub contents: String, } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct SourceTree { pub entries: Vec, } diff --git a/ethers-etherscan/src/transaction.rs b/ethers-etherscan/src/transaction.rs index 39b1cc3a..c54c71da 100644 --- a/ethers-etherscan/src/transaction.rs +++ b/ethers-etherscan/src/transaction.rs @@ -4,14 +4,14 @@ use serde::Deserialize; use crate::{Client, EtherscanError, Response, Result}; -#[derive(Deserialize)] +#[derive(Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] struct ContractExecutionStatus { is_error: String, err_description: String, } -#[derive(Deserialize)] +#[derive(Deserialize, Clone, Debug)] struct TransactionReceiptStatus { status: String, }