mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add Transaction setters and separate random tx signing (#2951)
This commit is contained in:
@ -72,6 +72,11 @@ pub fn random_signed_tx() -> TransactionSigned {
|
|||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
let key_pair = KeyPair::new(&secp, &mut rand::thread_rng());
|
let key_pair = KeyPair::new(&secp, &mut rand::thread_rng());
|
||||||
let tx = random_tx();
|
let tx = random_tx();
|
||||||
|
sign_tx_with_key_pair(key_pair, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Signs the [Transaction] with the given key pair.
|
||||||
|
pub fn sign_tx_with_key_pair(key_pair: KeyPair, tx: Transaction) -> TransactionSigned {
|
||||||
let signature =
|
let signature =
|
||||||
sign_message(H256::from_slice(&key_pair.secret_bytes()[..]), tx.signature_hash()).unwrap();
|
sign_message(H256::from_slice(&key_pair.secret_bytes()[..]), tx.signature_hash()).unwrap();
|
||||||
TransactionSigned::from_transaction_and_signature(tx, signature)
|
TransactionSigned::from_transaction_and_signature(tx, signature)
|
||||||
|
|||||||
@ -224,6 +224,33 @@ impl Transaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This sets the transaction's nonce.
|
||||||
|
pub fn set_nonce(&mut self, nonce: u64) {
|
||||||
|
match self {
|
||||||
|
Transaction::Legacy(tx) => tx.nonce = nonce,
|
||||||
|
Transaction::Eip2930(tx) => tx.nonce = nonce,
|
||||||
|
Transaction::Eip1559(tx) => tx.nonce = nonce,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This sets the transaction's value.
|
||||||
|
pub fn set_value(&mut self, value: u128) {
|
||||||
|
match self {
|
||||||
|
Transaction::Legacy(tx) => tx.value = value,
|
||||||
|
Transaction::Eip2930(tx) => tx.value = value,
|
||||||
|
Transaction::Eip1559(tx) => tx.value = value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This sets the transaction's input field.
|
||||||
|
pub fn set_input(&mut self, input: Bytes) {
|
||||||
|
match self {
|
||||||
|
Transaction::Legacy(tx) => tx.input = input,
|
||||||
|
Transaction::Eip2930(tx) => tx.input = input,
|
||||||
|
Transaction::Eip1559(tx) => tx.input = input,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Compact for Transaction {
|
impl Compact for Transaction {
|
||||||
|
|||||||
Reference in New Issue
Block a user