gasPrice is required field for Transaction object (#481)
This commit is contained in:
parent
33908e8361
commit
eb42f0c5d9
@ -52,6 +52,7 @@ impl<C: BlockChainClient + 'static> Debug for DebugClient<C> {
|
||||
.map(|(block, reason)| {
|
||||
let number = block.header.number();
|
||||
let hash = block.header.hash();
|
||||
let base_fee = block.header.base_fee();
|
||||
RichBlock {
|
||||
inner: Block {
|
||||
hash: Some(hash),
|
||||
@ -76,7 +77,7 @@ impl<C: BlockChainClient + 'static> Debug for DebugClient<C> {
|
||||
.cloned()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
base_fee_per_gas: block.header.base_fee(),
|
||||
base_fee_per_gas: base_fee,
|
||||
uncles: block.uncles.iter().map(Header::hash).collect(),
|
||||
transactions: BlockTransactions::Full(
|
||||
block
|
||||
@ -84,13 +85,16 @@ impl<C: BlockChainClient + 'static> Debug for DebugClient<C> {
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(transaction_index, signed)| {
|
||||
Transaction::from_localized(LocalizedTransaction {
|
||||
block_number: number,
|
||||
block_hash: hash,
|
||||
transaction_index,
|
||||
signed,
|
||||
cached_sender: None,
|
||||
})
|
||||
Transaction::from_localized(
|
||||
LocalizedTransaction {
|
||||
block_number: number,
|
||||
block_hash: hash,
|
||||
transaction_index,
|
||||
signed,
|
||||
cached_sender: None,
|
||||
},
|
||||
base_fee,
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
|
@ -260,6 +260,11 @@ where
|
||||
(Some(block), Some(total_difficulty)) => {
|
||||
let view = block.header_view();
|
||||
let eip1559_enabled = client.engine().schedule(view.number()).eip1559;
|
||||
let base_fee = if eip1559_enabled {
|
||||
Some(view.base_fee())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Ok(Some(RichBlock {
|
||||
inner: Block {
|
||||
hash: match is_pending {
|
||||
@ -292,13 +297,7 @@ where
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
base_fee_per_gas: {
|
||||
if eip1559_enabled {
|
||||
Some(view.base_fee())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
base_fee_per_gas: base_fee,
|
||||
uncles: block.uncle_hashes(),
|
||||
transactions: match include_txs {
|
||||
true => BlockTransactions::Full(
|
||||
@ -306,7 +305,7 @@ where
|
||||
.view()
|
||||
.localized_transactions()
|
||||
.into_iter()
|
||||
.map(Transaction::from_localized)
|
||||
.map(|t| Transaction::from_localized(t, base_fee))
|
||||
.collect(),
|
||||
),
|
||||
false => BlockTransactions::Hashes(block.transaction_hashes()),
|
||||
@ -322,7 +321,23 @@ where
|
||||
|
||||
fn transaction(&self, id: PendingTransactionId) -> Result<Option<Transaction>> {
|
||||
let client_transaction = |id| match self.client.block_transaction(id) {
|
||||
Some(t) => Ok(Some(Transaction::from_localized(t))),
|
||||
Some(t) => {
|
||||
let block = self
|
||||
.rich_block(BlockNumber::Num(t.block_number).into(), false)
|
||||
.and_then(errors::check_block_number_existence(
|
||||
&*self.client,
|
||||
BlockNumber::Num(t.block_number).into(),
|
||||
self.options,
|
||||
));
|
||||
let base_fee = match block {
|
||||
Ok(block) => match block {
|
||||
Some(block) => block.base_fee_per_gas,
|
||||
None => return Ok(None),
|
||||
},
|
||||
Err(_) => return Ok(None),
|
||||
};
|
||||
Ok(Some(Transaction::from_localized(t, base_fee)))
|
||||
}
|
||||
None => Ok(None),
|
||||
};
|
||||
|
||||
@ -361,7 +376,7 @@ where
|
||||
cached_sender,
|
||||
}
|
||||
})
|
||||
.map(Transaction::from_localized);
|
||||
.map(|t| Transaction::from_localized(t, pending_block.header.base_fee()));
|
||||
|
||||
Ok(transaction)
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ mod tests {
|
||||
let serialized = serde_json::to_string(&t).unwrap();
|
||||
assert_eq!(
|
||||
serialized,
|
||||
r#"[{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null,"chainId":null,"v":"0x0","r":"0x0","s":"0x0","condition":null}]"#
|
||||
r#"[{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gasPrice":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null,"chainId":null,"v":"0x0","r":"0x0","s":"0x0","condition":null}]"#
|
||||
);
|
||||
|
||||
let t = BlockTransactions::Hashes(vec![H256::default().into()]);
|
||||
|
@ -50,8 +50,7 @@ pub struct Transaction {
|
||||
/// Transfered value
|
||||
pub value: U256,
|
||||
/// Gas Price
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub gas_price: Option<U256>,
|
||||
pub gas_price: U256,
|
||||
/// Max fee per gas
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub max_fee_per_gas: Option<U256>,
|
||||
@ -190,7 +189,7 @@ impl RichRawTransaction {
|
||||
|
||||
impl Transaction {
|
||||
/// Convert `LocalizedTransaction` into RPC Transaction.
|
||||
pub fn from_localized(mut t: LocalizedTransaction) -> Transaction {
|
||||
pub fn from_localized(mut t: LocalizedTransaction, base_fee: Option<U256>) -> Transaction {
|
||||
let signature = t.signature();
|
||||
let scheme = CreateContractAddress::FromSenderAndNonce;
|
||||
|
||||
@ -209,17 +208,11 @@ impl Transaction {
|
||||
TypedTransaction::Legacy(_) => None,
|
||||
};
|
||||
|
||||
let (gas_price, max_fee_per_gas) = match t.as_unsigned() {
|
||||
TypedTransaction::Legacy(_) => (Some(t.tx().gas_price), None),
|
||||
TypedTransaction::AccessList(_) => (Some(t.tx().gas_price), None),
|
||||
TypedTransaction::EIP1559Transaction(_) => (None, Some(t.tx().gas_price)),
|
||||
};
|
||||
|
||||
let max_priority_fee_per_gas =
|
||||
let (max_fee_per_gas, max_priority_fee_per_gas) =
|
||||
if let TypedTransaction::EIP1559Transaction(tx) = t.as_unsigned() {
|
||||
Some(tx.max_priority_fee_per_gas)
|
||||
(Some(tx.tx().gas_price), Some(tx.max_priority_fee_per_gas))
|
||||
} else {
|
||||
None
|
||||
(None, None)
|
||||
};
|
||||
|
||||
let standard_v = if t.tx_type() == TypedTxId::Legacy {
|
||||
@ -240,7 +233,7 @@ impl Transaction {
|
||||
Action::Call(ref address) => Some(*address),
|
||||
},
|
||||
value: t.tx().value,
|
||||
gas_price,
|
||||
gas_price: t.effective_gas_price(base_fee),
|
||||
max_fee_per_gas,
|
||||
gas: t.tx().gas,
|
||||
input: Bytes::new(t.tx().data.clone()),
|
||||
@ -284,17 +277,11 @@ impl Transaction {
|
||||
TypedTransaction::Legacy(_) => None,
|
||||
};
|
||||
|
||||
let (gas_price, max_fee_per_gas) = match t.as_unsigned() {
|
||||
TypedTransaction::Legacy(_) => (Some(t.tx().gas_price), None),
|
||||
TypedTransaction::AccessList(_) => (Some(t.tx().gas_price), None),
|
||||
TypedTransaction::EIP1559Transaction(_) => (None, Some(t.tx().gas_price)),
|
||||
};
|
||||
|
||||
let max_priority_fee_per_gas =
|
||||
let (max_fee_per_gas, max_priority_fee_per_gas) =
|
||||
if let TypedTransaction::EIP1559Transaction(tx) = t.as_unsigned() {
|
||||
Some(tx.max_priority_fee_per_gas)
|
||||
(Some(tx.tx().gas_price), Some(tx.max_priority_fee_per_gas))
|
||||
} else {
|
||||
None
|
||||
(None, None)
|
||||
};
|
||||
|
||||
let standard_v = if t.tx_type() == TypedTxId::Legacy {
|
||||
@ -315,7 +302,7 @@ impl Transaction {
|
||||
Action::Call(ref address) => Some(*address),
|
||||
},
|
||||
value: t.tx().value,
|
||||
gas_price,
|
||||
gas_price: t.tx().gas_price,
|
||||
max_fee_per_gas,
|
||||
gas: t.tx().gas,
|
||||
input: Bytes::new(t.tx().data.clone()),
|
||||
@ -387,7 +374,7 @@ mod tests {
|
||||
let serialized = serde_json::to_string(&t).unwrap();
|
||||
assert_eq!(
|
||||
serialized,
|
||||
r#"{"type":"0x1","hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null,"chainId":null,"v":"0x0","r":"0x0","s":"0x0","condition":null,"accessList":[{"address":"0x0000000000000000000000000000000000000000","storageKeys":[]}]}"#
|
||||
r#"{"type":"0x1","hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gasPrice":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null,"chainId":null,"v":"0x0","r":"0x0","s":"0x0","condition":null,"accessList":[{"address":"0x0000000000000000000000000000000000000000","storageKeys":[]}]}"#
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user