-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: separate initial transaction type (#98)
* chore: separate initial transaction type * chore: rename gas_limit * fix: remove nonce from initial txn * regenerate dart code * chore: lint * chore: add 3rd txn type, rename data -> input, add Flutter CI * chore: rename job --------- Co-authored-by: Alfreedom <[email protected]>
- Loading branch information
1 parent
79fdd0d
commit befa0cb
Showing
15 changed files
with
372 additions
and
2,687 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,27 +1,101 @@ | ||
use { | ||
alloy::primitives::{Address, Bytes, U256, U64}, | ||
alloy::{ | ||
network::TransactionBuilder, | ||
primitives::{Address, Bytes, U128, U256, U64}, | ||
rpc::types::TransactionRequest, | ||
}, | ||
alloy_provider::utils::Eip1559Estimation, | ||
serde::{Deserialize, Serialize}, | ||
}; | ||
|
||
pub mod fungible_price; | ||
pub mod route; | ||
pub mod status; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
#[cfg_attr(feature = "uniffi", derive(uniffi_macros::Record))] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct InitialTransaction { | ||
// CAIP-2 chain ID | ||
pub chain_id: String, | ||
|
||
pub from: Address, | ||
pub to: Address, | ||
pub value: U256, | ||
pub input: Bytes, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
#[cfg_attr(feature = "uniffi", derive(uniffi_macros::Record))] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Transaction { | ||
// CAIP-2 chain ID | ||
pub chain_id: String, | ||
|
||
pub from: Address, | ||
pub to: Address, | ||
pub value: U256, | ||
pub gas: U64, | ||
pub data: Bytes, | ||
pub input: Bytes, | ||
|
||
pub gas_limit: U64, | ||
pub nonce: U64, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
#[cfg_attr(feature = "uniffi", derive(uniffi_macros::Record))] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct FeeEstimatedTransaction { | ||
// CAIP-2 chain ID | ||
pub chain_id: String, | ||
|
||
// deprecated | ||
pub gas_price: U256, | ||
pub max_fee_per_gas: U256, | ||
pub max_priority_fee_per_gas: U256, | ||
pub from: Address, | ||
pub to: Address, | ||
pub value: U256, | ||
pub input: Bytes, | ||
|
||
pub gas_limit: U64, | ||
pub nonce: U64, | ||
|
||
pub max_fee_per_gas: U128, | ||
pub max_priority_fee_per_gas: U128, | ||
} | ||
|
||
impl FeeEstimatedTransaction { | ||
pub fn from_transaction_and_estimate( | ||
transaction: Transaction, | ||
estimate: Eip1559Estimation, | ||
) -> Self { | ||
Self { | ||
chain_id: transaction.chain_id, | ||
from: transaction.from, | ||
to: transaction.to, | ||
value: transaction.value, | ||
input: transaction.input, | ||
gas_limit: transaction.gas_limit, | ||
nonce: transaction.nonce, | ||
max_fee_per_gas: U128::from(estimate.max_fee_per_gas), | ||
max_priority_fee_per_gas: U128::from( | ||
estimate.max_priority_fee_per_gas, | ||
), | ||
} | ||
} | ||
|
||
pub fn into_transaction_request(self) -> TransactionRequest { | ||
let chain_id = self | ||
.chain_id | ||
.strip_prefix("eip155:") | ||
.unwrap() | ||
.parse::<U64>() | ||
.unwrap(); | ||
TransactionRequest::default() | ||
.with_chain_id(chain_id.to()) | ||
.with_from(self.from) | ||
.with_to(self.to) | ||
.with_value(self.value) | ||
.with_input(self.input) | ||
.with_gas_limit(self.gas_limit.to()) | ||
.with_nonce(self.nonce.to()) | ||
.with_max_fee_per_gas(self.max_fee_per_gas.to()) | ||
.with_max_priority_fee_per_gas(self.max_priority_fee_per_gas.to()) | ||
} | ||
} |
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
Oops, something went wrong.