Skip to content

Instantly share code, notes, and snippets.

@palozano
Created March 11, 2025 11:03
Show Gist options
  • Save palozano/e2830eb9512c0f4366373a53a60dfd33 to your computer and use it in GitHub Desktop.
Save palozano/e2830eb9512c0f4366373a53a60dfd33 to your computer and use it in GitHub Desktop.
sign and cross-contract call
pub fn request_signature(
&self,
to_address: String,
value: u128,
data: Base64VecU8,
nonce: u64,
) -> Promise {
let (omni_evm_tx, _, signature_request) =
self.create_tx_signature_request(to_address, value, data.into(), nonce);
log!("creating cross-contract call...");
// Make cross-contract call to MPC contract
ext(self.mpc_contract.clone())
.with_static_gas(Gas::from_tgas(250))
.with_attached_deposit(DEPOSIT_AMOUNT)
.sign(signature_request)
.then(
Self::ext(env::current_account_id())
.with_static_gas(Gas::from_tgas(10))
.on_sign(omni_evm_tx),
)
}
#[private]
pub fn on_sign(
&self,
#[callback_result] result: Result<SignatureResponse, PromiseError>,
omni_evm_tx: EVMTransaction,
) -> Option<Vec<u8>> {
match result {
Ok(signature) => {
// Convert the signature to OmniSignature
let signature_omni = OmniSignature {
r: signature.big_r.0, // the field .0 is because I defined it as a tuple-struct
s: signature.s.0, // the field .0 is because I defined it as a tuple-struct
v: signature.recovery_id,
};
// Build the final signed transaction
let omni_evm_tx_encoded_with_signature = omni_evm_tx.build_with_signature(&signature_omni);
// Log the event instead of emit
let event = SignedTransactionEvent {
signed_transaction: omni_evm_tx_encoded_with_signature.clone(),
};
log!("Signed transaction event: {:?}", event);
Some(omni_evm_tx_encoded_with_signature)
}
Err(e) => {
log!("Failed to get signature from MPC contract. Error: {:?}", e);
None
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment