From 528b6bbeed61f8e26ffed79eabb12a1dab948206 Mon Sep 17 00:00:00 2001 From: denbite Date: Mon, 14 Oct 2024 09:38:36 +0200 Subject: [PATCH] refactor: simplify creation of EIP-1559 transaction and arguments for sign_promise --- src/helpers.rs | 14 +++++--------- src/lib.rs | 8 ++++---- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index cbf08a5..51d04cd 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -40,7 +40,7 @@ pub fn calculate_deposit_for_used_storage(used_storage: StorageUsage) -> NearTok .expect("ERR_STORAGE_DEPOSIT_CALC") } -fn create_eip1559_tx( +pub fn create_eip1559_tx( base_payload: BaseEip1559TransactionPayload, other_payload: OtherEip1559TransactionPayload, ) -> Eip1559TransactionRequest { @@ -77,11 +77,11 @@ fn build_tx_payload(tx: Eip1559TransactionRequest) -> [u8; 32] { keccak256(vec) } -pub fn create_tx_and_args_for_sign( +pub fn create_sign_promise( + account_id: AccountId, + tx: Eip1559TransactionRequest, request: Request, - other_payload: OtherEip1559TransactionPayload, -) -> (Eip1559TransactionRequest, Vec) { - let tx = create_eip1559_tx(request.payload.clone(), other_payload); +) -> Promise { let payload = build_tx_payload(tx.clone()); let args = json!({ @@ -94,10 +94,6 @@ pub fn create_tx_and_args_for_sign( .to_string() .into_bytes(); - (tx, args) -} - -pub fn create_sign_promise(account_id: AccountId, args: Vec) -> Promise { let function = "sign".to_owned(); let deposit = env::attached_deposit(); // calculate unused gas diff --git a/src/lib.rs b/src/lib.rs index cf112a4..243e257 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,7 @@ mod primitives; use constants::{MIN_GAS_FOR_GET_SIGNATURE, ONE_MINUTE_NANOS}; use helpers::{ assert_deposit, assert_gas, calculate_deposit_for_used_storage, create_derivation_path, - create_on_sign_callback_promise, create_sign_promise, create_tx_and_args_for_sign, - refund_unused_deposit, + create_eip1559_tx, create_on_sign_callback_promise, create_sign_promise, refund_unused_deposit, }; use near_sdk::serde_json; use near_sdk::{ @@ -95,9 +94,10 @@ impl Contract { "ERR_FORBIDDEN" ); - let (tx, args) = create_tx_and_args_for_sign(request.clone(), other_payload); + let tx = create_eip1559_tx(request.payload.clone(), other_payload); - let sign_promise = create_sign_promise(self.mpc_contract_id.clone(), args); + let sign_promise = + create_sign_promise(self.mpc_contract_id.clone(), tx.clone(), request.clone()); let callback_promise = create_on_sign_callback_promise(tx); sign_promise.then(callback_promise)