Fix 'get_transactions' response. (#1632)
* Fix 'get_transactions' response. * Add some explanation to GenesisOption. * One-line-ifying * Update changelog
This commit is contained in:
parent
b302ac05be
commit
ff66008cbe
|
@ -82,6 +82,7 @@
|
||||||
- Fix handling of Websocket connection errors [#1287](https://github.com/gakonst/ethers-rs/pull/1287)
|
- Fix handling of Websocket connection errors [#1287](https://github.com/gakonst/ethers-rs/pull/1287)
|
||||||
- Add Arithmetic Shift Right operation for I256 [#1323](https://github.com/gakonst/ethers-rs/issues/1323)
|
- 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.
|
- [#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`.
|
||||||
|
|
||||||
## ethers-contract-abigen
|
## ethers-contract-abigen
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub type Selector = [u8; 4];
|
||||||
/// A transaction Hash
|
/// A transaction Hash
|
||||||
pub use ethabi::ethereum_types::H256 as TxHash;
|
pub use ethabi::ethereum_types::H256 as TxHash;
|
||||||
|
|
||||||
pub use ethabi::ethereum_types::{Address, Bloom, H160, H256, H512, H64, U128, U256, U64};
|
pub use ethabi::ethereum_types::{Address, Bloom, H160, H256, H32, H512, H64, U128, U256, U64};
|
||||||
|
|
||||||
pub mod transaction;
|
pub mod transaction;
|
||||||
pub use transaction::{
|
pub use transaction::{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{Client, EtherscanError, Query, Response, Result};
|
use crate::{Client, EtherscanError, Query, Response, Result};
|
||||||
use ethers_core::{
|
use ethers_core::{
|
||||||
abi::Address,
|
abi::Address,
|
||||||
types::{serde_helpers::*, BlockNumber, Bytes, H256, U256},
|
types::{serde_helpers::*, BlockNumber, Bytes, H256, H32, U256},
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -17,7 +17,7 @@ pub struct AccountBalance {
|
||||||
pub balance: String,
|
pub balance: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
mod jsonstring {
|
mod genesis_string {
|
||||||
use super::*;
|
use super::*;
|
||||||
use serde::{
|
use serde::{
|
||||||
de::{DeserializeOwned, Error as _},
|
de::{DeserializeOwned, Error as _},
|
||||||
|
@ -52,9 +52,9 @@ mod jsonstring {
|
||||||
{
|
{
|
||||||
let json = Cow::<'de, str>::deserialize(deserializer)?;
|
let json = Cow::<'de, str>::deserialize(deserializer)?;
|
||||||
if !json.is_empty() && !json.starts_with("GENESIS") {
|
if !json.is_empty() && !json.starts_with("GENESIS") {
|
||||||
let value =
|
serde_json::from_str(&format!("\"{}\"", &json))
|
||||||
serde_json::from_str(&format!("\"{}\"", &json)).map_err(D::Error::custom)?;
|
.map(GenesisOption::Some)
|
||||||
Ok(GenesisOption::Some(value))
|
.map_err(D::Error::custom)
|
||||||
} else if json.starts_with("GENESIS") {
|
} else if json.starts_with("GENESIS") {
|
||||||
Ok(GenesisOption::Genesis)
|
Ok(GenesisOption::Genesis)
|
||||||
} else {
|
} else {
|
||||||
|
@ -63,7 +63,82 @@ mod jsonstring {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Possible values for some field responses
|
mod json_string {
|
||||||
|
use super::*;
|
||||||
|
use serde::{
|
||||||
|
de::{DeserializeOwned, Error as _},
|
||||||
|
ser::Error as _,
|
||||||
|
Deserializer, Serializer,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn serialize<T, S>(value: &Option<T>, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
T: Serialize,
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
let json = match value {
|
||||||
|
Option::None => Cow::from(""),
|
||||||
|
Option::Some(value) => serde_json::to_string(value).map_err(S::Error::custom)?.into(),
|
||||||
|
};
|
||||||
|
serializer.serialize_str(&json)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deserialize<'de, T, D>(deserializer: D) -> std::result::Result<Option<T>, D::Error>
|
||||||
|
where
|
||||||
|
T: DeserializeOwned,
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let json = Cow::<'de, str>::deserialize(deserializer)?;
|
||||||
|
if json.is_empty() {
|
||||||
|
Ok(Option::None)
|
||||||
|
} else {
|
||||||
|
serde_json::from_str(&format!("\"{}\"", &json))
|
||||||
|
.map(Option::Some)
|
||||||
|
.map_err(D::Error::custom)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod hex_string {
|
||||||
|
use super::*;
|
||||||
|
use serde::{
|
||||||
|
de::{DeserializeOwned, Error as _},
|
||||||
|
ser::Error as _,
|
||||||
|
Deserializer, Serializer,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn serialize<T, S>(value: &Option<T>, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
T: Serialize,
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
let json = match value {
|
||||||
|
Option::None => Cow::from("0x"),
|
||||||
|
Option::Some(value) => serde_json::to_string(value).map_err(S::Error::custom)?.into(),
|
||||||
|
};
|
||||||
|
serializer.serialize_str(&json)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deserialize<'de, T, D>(deserializer: D) -> std::result::Result<Option<T>, D::Error>
|
||||||
|
where
|
||||||
|
T: DeserializeOwned,
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let json = Cow::<'de, str>::deserialize(deserializer)?;
|
||||||
|
if json.is_empty() || json == "0x" {
|
||||||
|
Ok(Option::None)
|
||||||
|
} else {
|
||||||
|
serde_json::from_str(&format!("\"{}\"", &json))
|
||||||
|
.map(Option::Some)
|
||||||
|
.map_err(D::Error::custom)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Possible values for some field responses.
|
||||||
|
///
|
||||||
|
/// Transactions from the Genesis block may contain fields that do not conform to the expected
|
||||||
|
/// types.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum GenesisOption<T> {
|
pub enum GenesisOption<T> {
|
||||||
None,
|
None,
|
||||||
|
@ -101,15 +176,15 @@ pub struct NormalTransaction {
|
||||||
#[serde(deserialize_with = "deserialize_stringified_block_number")]
|
#[serde(deserialize_with = "deserialize_stringified_block_number")]
|
||||||
pub block_number: BlockNumber,
|
pub block_number: BlockNumber,
|
||||||
pub time_stamp: String,
|
pub time_stamp: String,
|
||||||
#[serde(with = "jsonstring")]
|
#[serde(with = "genesis_string")]
|
||||||
pub hash: GenesisOption<H256>,
|
pub hash: GenesisOption<H256>,
|
||||||
#[serde(with = "jsonstring")]
|
#[serde(with = "json_string")]
|
||||||
pub nonce: GenesisOption<U256>,
|
pub nonce: Option<U256>,
|
||||||
#[serde(with = "jsonstring")]
|
#[serde(with = "json_string")]
|
||||||
pub block_hash: GenesisOption<U256>,
|
pub block_hash: Option<U256>,
|
||||||
#[serde(deserialize_with = "deserialize_stringified_u64_opt")]
|
#[serde(deserialize_with = "deserialize_stringified_u64_opt")]
|
||||||
pub transaction_index: Option<u64>,
|
pub transaction_index: Option<u64>,
|
||||||
#[serde(with = "jsonstring")]
|
#[serde(with = "genesis_string")]
|
||||||
pub from: GenesisOption<Address>,
|
pub from: GenesisOption<Address>,
|
||||||
pub to: Option<Address>,
|
pub to: Option<Address>,
|
||||||
#[serde(deserialize_with = "deserialize_stringified_numeric")]
|
#[serde(deserialize_with = "deserialize_stringified_numeric")]
|
||||||
|
@ -120,16 +195,19 @@ pub struct NormalTransaction {
|
||||||
pub gas_price: Option<U256>,
|
pub gas_price: Option<U256>,
|
||||||
#[serde(rename = "txreceipt_status")]
|
#[serde(rename = "txreceipt_status")]
|
||||||
pub tx_receipt_status: String,
|
pub tx_receipt_status: String,
|
||||||
#[serde(with = "jsonstring")]
|
pub input: Bytes,
|
||||||
pub input: GenesisOption<Bytes>,
|
#[serde(with = "json_string")]
|
||||||
#[serde(with = "jsonstring")]
|
pub contract_address: Option<Address>,
|
||||||
pub contract_address: GenesisOption<Address>,
|
|
||||||
#[serde(deserialize_with = "deserialize_stringified_numeric")]
|
#[serde(deserialize_with = "deserialize_stringified_numeric")]
|
||||||
pub gas_used: U256,
|
pub gas_used: U256,
|
||||||
#[serde(deserialize_with = "deserialize_stringified_numeric")]
|
#[serde(deserialize_with = "deserialize_stringified_numeric")]
|
||||||
pub cumulative_gas_used: U256,
|
pub cumulative_gas_used: U256,
|
||||||
#[serde(deserialize_with = "deserialize_stringified_u64")]
|
#[serde(deserialize_with = "deserialize_stringified_u64")]
|
||||||
pub confirmations: u64,
|
pub confirmations: u64,
|
||||||
|
#[serde(with = "hex_string")]
|
||||||
|
pub method_id: Option<H32>,
|
||||||
|
#[serde(with = "json_string")]
|
||||||
|
pub function_name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The raw response from the internal transaction list API endpoint
|
/// The raw response from the internal transaction list API endpoint
|
||||||
|
@ -141,13 +219,13 @@ pub struct InternalTransaction {
|
||||||
pub time_stamp: String,
|
pub time_stamp: String,
|
||||||
pub hash: H256,
|
pub hash: H256,
|
||||||
pub from: Address,
|
pub from: Address,
|
||||||
#[serde(with = "jsonstring")]
|
#[serde(with = "genesis_string")]
|
||||||
pub to: GenesisOption<Address>,
|
pub to: GenesisOption<Address>,
|
||||||
#[serde(deserialize_with = "deserialize_stringified_numeric")]
|
#[serde(deserialize_with = "deserialize_stringified_numeric")]
|
||||||
pub value: U256,
|
pub value: U256,
|
||||||
#[serde(with = "jsonstring")]
|
#[serde(with = "genesis_string")]
|
||||||
pub contract_address: GenesisOption<Address>,
|
pub contract_address: GenesisOption<Address>,
|
||||||
#[serde(with = "jsonstring")]
|
#[serde(with = "genesis_string")]
|
||||||
pub input: GenesisOption<Bytes>,
|
pub input: GenesisOption<Bytes>,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub result_type: String,
|
pub result_type: String,
|
||||||
|
|
Loading…
Reference in New Issue