mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-12 05:44:53 +00:00
Don't have the ERC20 collapse the top-level transfer ID to the transaction ID
Uses the ID of the transfer event associated with the top-level transfer.
This commit is contained in:
parent
ae76749513
commit
294462641e
1 changed files with 9 additions and 21 deletions
|
@ -30,8 +30,8 @@ pub use abi::IERC20::Transfer;
|
|||
/// A top-level ERC20 transfer
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TopLevelTransfer {
|
||||
/// The transaction ID which effected this transfer.
|
||||
pub id: [u8; 32],
|
||||
/// The ID of the event for this transfer.
|
||||
pub id: ([u8; 32], u64),
|
||||
/// The address which made the transfer.
|
||||
pub from: [u8; 20],
|
||||
/// The amount transferred.
|
||||
|
@ -40,14 +40,6 @@ pub struct TopLevelTransfer {
|
|||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
/// A transaction with a top-level transfer, matched to the log index of the transfer.
|
||||
pub struct MatchedTopLevelTransfer {
|
||||
/// The transfer.
|
||||
pub transfer: TopLevelTransfer,
|
||||
/// The log index of the transfer.
|
||||
pub log_index: u64,
|
||||
}
|
||||
|
||||
/// A view for an ERC20 contract.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Erc20(Arc<RootProvider<SimpleRequest>>, Address);
|
||||
|
@ -62,7 +54,7 @@ impl Erc20 {
|
|||
provider: impl AsRef<RootProvider<SimpleRequest>>,
|
||||
transaction_id: B256,
|
||||
to: Address,
|
||||
) -> Result<Option<MatchedTopLevelTransfer>, RpcError<TransportErrorKind>> {
|
||||
) -> Result<Option<TopLevelTransfer>, RpcError<TransportErrorKind>> {
|
||||
// Fetch the transaction
|
||||
let transaction =
|
||||
provider.as_ref().get_transaction_by_hash(transaction_id).await?.ok_or_else(|| {
|
||||
|
@ -132,15 +124,11 @@ impl Erc20 {
|
|||
let encoded = call.abi_encode();
|
||||
let data = transaction.input.as_ref()[encoded.len() ..].to_vec();
|
||||
|
||||
return Ok(Some(MatchedTopLevelTransfer {
|
||||
transfer: TopLevelTransfer {
|
||||
// Since there's only one top-level transfer per TX, set the ID to the TX ID
|
||||
id: *transaction_id,
|
||||
from: *log.from.0,
|
||||
amount: log.value,
|
||||
data,
|
||||
},
|
||||
log_index,
|
||||
return Ok(Some(TopLevelTransfer {
|
||||
id: (*transaction_id, log_index),
|
||||
from: *log.from.0,
|
||||
amount: log.value,
|
||||
data,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +181,7 @@ impl Erc20 {
|
|||
// Panicking on a task panic is desired behavior, and we haven't aborted any tasks
|
||||
match top_level_transfer.unwrap() {
|
||||
// Top-level transfer
|
||||
Ok(Some(top_level_transfer)) => top_level_transfers.push(top_level_transfer.transfer),
|
||||
Ok(Some(top_level_transfer)) => top_level_transfers.push(top_level_transfer),
|
||||
// Not a top-level transfer
|
||||
Ok(None) => continue,
|
||||
// Failed to get this transaction's information so abort
|
||||
|
|
Loading…
Reference in a new issue