Skip to content

Commit

Permalink
update to the latest chain-libs (#4001)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy authored May 30, 2022
1 parent ad4fce5 commit 6a42100
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 103 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 7 additions & 36 deletions jcli/src/jcli_lib/transaction/staging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,22 +375,9 @@ impl Staging {
}

match &self.extra {
None => match &self.evm_transaction {
None => self.finalize_payload(
&chain::transaction::NoExtra,
fee_algorithm,
output_policy,
),
Some(_tx) => {
#[cfg(feature = "evm")]
{
let _tx: chain::evm::EvmTransaction = _tx.clone().into();
self.finalize_payload(&_tx, fee_algorithm, output_policy)
}
#[cfg(not(feature = "evm"))]
unreachable!()
}
},
None => {
self.finalize_payload(&chain::transaction::NoExtra, fee_algorithm, output_policy)
}
Some(c) => match c.clone().into() {
Certificate::PoolRegistration(c) => {
self.finalize_payload(&c, fee_algorithm, output_policy)
Expand Down Expand Up @@ -522,14 +509,9 @@ impl Staging {
return Err(Error::TxNeedPayloadAuth);
}
match &self.extra {
None => match &self.evm_transaction {
None => self.make_fragment(
&chain::transaction::NoExtra,
&(),
Fragment::Transaction,
),
Some(tx) => self.make_fragment(&tx.clone().into(), &(), Fragment::Evm),
},
None => {
self.make_fragment(&chain::transaction::NoExtra, &(), Fragment::Transaction)
}
Some(cert) => match cert.clone().into() {
Certificate::OwnerStakeDelegation(osd) => {
self.make_fragment(&osd, &(), Fragment::OwnerStakeDelegation)
Expand Down Expand Up @@ -608,18 +590,7 @@ impl Staging {
}

let res = match &self.extra {
None => match &self.evm_transaction {
None => self.transaction_sign_data_hash_on(TxBuilder::new().set_nopayload()),
Some(_tx) => {
#[cfg(feature = "evm")]
{
let _tx: chain::evm::EvmTransaction = _tx.clone().into();
self.transaction_sign_data_hash_on(TxBuilder::new().set_payload(&_tx))
}
#[cfg(not(feature = "evm"))]
unreachable!()
}
},
None => self.transaction_sign_data_hash_on(TxBuilder::new().set_nopayload()),
Some(c) => match c.clone().into() {
Certificate::PoolRegistration(c) => {
self.transaction_sign_data_hash_on(TxBuilder::new().set_payload(&c))
Expand Down
11 changes: 6 additions & 5 deletions jormungandr-lib/src/interfaces/evm_transaction.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use chain_core::{
packer::Codec,
property::{DeserializeFromSlice, ReadError},
property::{DeserializeFromSlice, ReadError, Serialize as _},
};
use chain_impl_mockchain::evm;
use serde::{Deserialize, Serialize};
use std::{fmt, str::FromStr};
use thiserror::Error;
use typed_bytes::ByteBuilder;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EvmTransaction(pub evm::EvmTransaction);

Expand Down Expand Up @@ -36,7 +34,7 @@ impl fmt::Display for EvmTransaction {
write!(
f,
"{}",
hex::encode(self.0.serialize_in(ByteBuilder::new()).finalize_as_vec())
hex::encode(self.0.serialize_as_vec().map_err(|_| fmt::Error)?)
)
}
}
Expand All @@ -56,7 +54,10 @@ impl Serialize for EvmTransaction {
where
S: serde::Serializer,
{
let data = self.0.serialize_in(ByteBuilder::new()).finalize_as_vec();
let data = self
.0
.serialize_as_vec()
.map_err(|e| serde::ser::Error::custom(e.to_string()))?;
if serializer.is_human_readable() {
hex::encode(data).serialize(serializer)
} else {
Expand Down
6 changes: 4 additions & 2 deletions jormungandr/src/fragment/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ fn is_fragment_valid(fragment: &Fragment) -> bool {
Fragment::VoteCast(ref tx) => is_transaction_valid(tx),
Fragment::VoteTally(ref tx) => is_transaction_valid(tx),
Fragment::MintToken(ref tx) => is_transaction_valid(tx),
Fragment::Evm(ref tx) => is_transaction_valid(tx),
// evm stuff
// TODO, maybe we need to develop some evm specific stateless validation in this place
Fragment::Evm(_) => true,
Fragment::EvmMapping(ref tx) => is_transaction_valid(tx),
}
}
Expand All @@ -372,6 +374,7 @@ fn get_transaction_expiry_date(fragment: &Fragment) -> Option<BlockDate> {
match fragment {
Fragment::Initial(_) => None,
Fragment::OldUtxoDeclaration(_) => None,
Fragment::Evm(_) => None,
Fragment::Transaction(tx) => Some(tx.as_slice().valid_until()),
Fragment::OwnerStakeDelegation(tx) => Some(tx.as_slice().valid_until()),
Fragment::StakeDelegation(tx) => Some(tx.as_slice().valid_until()),
Expand All @@ -384,7 +387,6 @@ fn get_transaction_expiry_date(fragment: &Fragment) -> Option<BlockDate> {
Fragment::VoteCast(tx) => Some(tx.as_slice().valid_until()),
Fragment::VoteTally(tx) => Some(tx.as_slice().valid_until()),
Fragment::MintToken(tx) => Some(tx.as_slice().valid_until()),
Fragment::Evm(tx) => Some(tx.as_slice().valid_until()),
Fragment::EvmMapping(tx) => Some(tx.as_slice().valid_until()),
}
}
Expand Down
7 changes: 3 additions & 4 deletions jormungandr/src/jrpc/eth_types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ impl Block {
let mut res = Vec::new();
for (i, fragment) in block.fragments().enumerate() {
if let Fragment::Evm(evm_tx) = fragment {
let evm_tx = evm_tx.as_slice().payload().into_payload();
res.push(Transaction::build(
evm_tx,
evm_tx.clone(),
Some(header.hash),
Some(header.number.clone()),
Some((i as u64).into()),
Expand All @@ -121,8 +120,8 @@ impl Block {
} else {
let mut res = Vec::new();
for fragment in block.fragments() {
if let Fragment::Evm(evm_tx) = fragment {
res.push(H256::from_slice(evm_tx.hash().as_ref()));
if let Fragment::Evm(_) = fragment {
res.push(H256::from_slice(fragment.hash().as_ref()));
}
}
BlockTransactions::Hashes(res)
Expand Down
54 changes: 17 additions & 37 deletions jormungandr/src/jrpc/eth_types/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{bytes::Bytes, number::Number};
use chain_evm::ethereum_types::{H160, H256, U256};
use chain_impl_mockchain::evm::EvmTransaction;
use chain_impl_mockchain::evm::{EvmActionType, EvmTransaction};
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -47,22 +47,15 @@ impl Transaction {
transaction_index: Option<Number>,
gas_price: u64,
) -> Self {
match tx {
EvmTransaction::Call {
caller,
address,
value,
data,
gas_limit,
access_list: _,
} => Self {
match tx.action_type {
EvmActionType::Call { address, data } => Self {
block_hash,
block_number,
nonce: 1.into(),
from: caller,
nonce: tx.nonce.into(),
from: tx.caller,
to: Some(address),
value: value.into(),
gas: gas_limit.into(),
value: tx.value.into(),
gas: tx.gas_limit.into(),
input: data.into(),
gas_price: gas_price.into(),
chain_id: Some(1.into()),
Expand All @@ -72,20 +65,14 @@ impl Transaction {
s: U256::one(),
transaction_type: 1.into(),
},
EvmTransaction::Create {
caller,
value,
init_code,
gas_limit,
access_list: _,
} => Self {
EvmActionType::Create { init_code } => Self {
block_hash,
block_number,
nonce: 1.into(),
from: caller,
nonce: tx.nonce.into(),
from: tx.caller,
to: None,
value: value.into(),
gas: gas_limit.into(),
value: tx.value.into(),
gas: tx.gas_limit.into(),
input: init_code.into(),
gas_price: gas_price.into(),
chain_id: Some(1.into()),
Expand All @@ -95,21 +82,14 @@ impl Transaction {
s: U256::one(),
transaction_type: 1.into(),
},
EvmTransaction::Create2 {
caller,
value,
init_code,
salt: _,
gas_limit,
access_list: _,
} => Self {
EvmActionType::Create2 { init_code, salt: _ } => Self {
block_hash,
block_number,
nonce: 1.into(),
from: caller,
nonce: tx.nonce.into(),
from: tx.caller,
to: None,
value: value.into(),
gas: gas_limit.into(),
value: tx.value.into(),
gas: tx.gas_limit.into(),
input: init_code.into(),
gas_price: gas_price.into(),
chain_id: Some(1.into()),
Expand Down
5 changes: 3 additions & 2 deletions jormungandr/src/metrics/backends/prometheus_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ impl MetricsBackend for Prometheus {
Fragment::MintToken(tx) => totals(tx),
Fragment::UpdateProposal(tx) => totals(tx),
Fragment::UpdateVote(tx) => totals(tx),
Fragment::Evm(tx) => totals(tx),
Fragment::EvmMapping(tx) => totals(tx),
Fragment::Initial(_) | Fragment::OldUtxoDeclaration(_) => return Ok(()),
Fragment::Initial(_) | Fragment::OldUtxoDeclaration(_) | Fragment::Evm(_) => {
return Ok(())
}
}?;
block_tx_count += 1;
block_input_sum = (block_input_sum + total_input)?;
Expand Down
5 changes: 3 additions & 2 deletions jormungandr/src/metrics/backends/simple_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ impl MetricsBackend for SimpleCounter {
Fragment::MintToken(tx) => totals(tx),
Fragment::UpdateProposal(tx) => totals(tx),
Fragment::UpdateVote(tx) => totals(tx),
Fragment::Evm(tx) => totals(tx),
Fragment::EvmMapping(tx) => totals(tx),
Fragment::Initial(_) | Fragment::OldUtxoDeclaration(_) => return Ok(()),
Fragment::Initial(_) | Fragment::OldUtxoDeclaration(_) | Fragment::Evm(_) => {
return Ok(())
}
}?;
block_tx_count += 1;
block_input_sum = (block_input_sum + total_input)?;
Expand Down

0 comments on commit 6a42100

Please sign in to comment.