Skip to content

Commit

Permalink
refactor: simplify creation of EIP-1559 transaction and arguments for…
Browse files Browse the repository at this point in the history
… sign_promise
  • Loading branch information
denbite committed Oct 14, 2024
1 parent d632a33 commit 528b6bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 5 additions & 9 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<u8>) {
let tx = create_eip1559_tx(request.payload.clone(), other_payload);
) -> Promise {
let payload = build_tx_payload(tx.clone());

let args = json!({
Expand All @@ -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<u8>) -> Promise {
let function = "sign".to_owned();
let deposit = env::attached_deposit();
// calculate unused gas
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 528b6bb

Please sign in to comment.