-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into prepare-release-v9.3.0
- Loading branch information
Showing
7 changed files
with
172 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
mod builtin; | ||
mod convert; | ||
mod io; | ||
mod macros; | ||
mod r#mod; | ||
|
||
pub use self::builtin::*; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2019-2022 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
/// This macro iterates over each transaction, decodes the transaction key using variable-length integer encoding, | ||
/// and constructs a Transaction object with the decoded data. | ||
/// | ||
/// Parameters: | ||
/// - `$res`: A mutable reference to a collection where the parsed transactions will be stored. | ||
/// - `$txns`: A collection of transaction data to be parsed. | ||
#[macro_export] | ||
macro_rules! parse_pending_transactions { | ||
($res:ident, $txns:expr) => { | ||
$txns.for_each(|tx_key, txn| { | ||
match integer_encoding::VarInt::decode_var(&tx_key) { | ||
Some((tx_id, _)) => { | ||
$res.push(Transaction { | ||
id: tx_id, | ||
to: txn.to, | ||
value: txn.value.clone(), | ||
method: txn.method, | ||
params: txn.params.clone(), | ||
approved: txn.approved.clone(), | ||
}); | ||
} | ||
None => anyhow::bail!("Error decoding varint"), | ||
} | ||
Ok(()) | ||
})?; | ||
}; | ||
} | ||
|
||
/// This macro iterates over each transaction, decodes the transaction key, and constructs a Transaction object | ||
/// with additional processing for address and token formats using `from_address_v3_to_v2` and `from_token_v3_to_v2`. | ||
/// | ||
/// Parameters: | ||
/// - `$res`: A mutable reference to a collection where the parsed transactions will be stored. | ||
/// - `$txns`: A collection of transaction data to be parsed. | ||
#[macro_export] | ||
macro_rules! parse_pending_transactions_v3 { | ||
($res:ident, $txns:expr) => { | ||
$txns.for_each(|tx_key, txn| { | ||
match integer_encoding::VarInt::decode_var(&tx_key) { | ||
Some((tx_id, _)) => { | ||
$res.push(Transaction { | ||
id: tx_id, | ||
to: from_address_v3_to_v2(txn.to), | ||
value: from_token_v3_to_v2(txn.value.clone()), | ||
method: txn.method, | ||
params: txn.params.clone(), | ||
approved: txn | ||
.approved | ||
.iter() | ||
.map(|&addr| from_address_v3_to_v2(addr)) | ||
.collect(), | ||
}); | ||
} | ||
None => anyhow::bail!("Error decoding varint"), | ||
} | ||
Ok(()) | ||
})?; | ||
}; | ||
} | ||
|
||
/// This macro iterates over each transaction, assumes that transaction id's are directly available and not encoded. | ||
/// It constructs Transaction objects with transformations for address and token data from version 4 to version 2 | ||
/// using `from_address_v4_to_v2` and `from_token_v4_to_v2`. | ||
/// | ||
/// Parameters: | ||
/// - `$res`: A mutable reference to a collection where the parsed transactions will be stored. | ||
/// - `$txns`: A collection of transaction data to be parsed. | ||
#[macro_export] | ||
macro_rules! parse_pending_transactions_v4 { | ||
($res:ident, $txns:expr) => { | ||
$txns.for_each(|tx_id, txn| { | ||
$res.push(Transaction { | ||
id: tx_id.0, | ||
to: from_address_v4_to_v2(txn.to), | ||
value: from_token_v4_to_v2(txn.value.clone()), | ||
method: txn.method, | ||
params: txn.params.clone(), | ||
approved: txn | ||
.approved | ||
.iter() | ||
.map(|&addr| from_address_v4_to_v2(addr)) | ||
.collect(), | ||
}); | ||
Ok(()) | ||
})?; | ||
}; | ||
} |