From 65e11e5b599a723e2e1100108e06bd3f84f3c45a Mon Sep 17 00:00:00 2001 From: moana Date: Fri, 6 Sep 2024 08:25:31 +0200 Subject: [PATCH] wallet-core: Add moonlight-transaction support --- wallet-core/src/transaction.rs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/wallet-core/src/transaction.rs b/wallet-core/src/transaction.rs index 8f2427a775..80c265286e 100644 --- a/wallet-core/src/transaction.rs +++ b/wallet-core/src/transaction.rs @@ -14,10 +14,11 @@ use ff::Field; use zeroize::Zeroize; use execution_core::{ - signatures::bls::SecretKey as BlsSecretKey, + signatures::bls::{PublicKey as BlsPublicKey, SecretKey as BlsSecretKey}, stake::{Stake, Withdraw as StakeWithdraw, STAKE_CONTRACT}, transfer::{ data::{ContractCall, TransactionData}, + moonlight::Transaction as MoonlightTransaction, phoenix::{ Note, NoteOpening, Prove, PublicKey as PhoenixPublicKey, SecretKey as PhoenixSecretKey, Transaction as PhoenixTransaction, @@ -28,16 +29,26 @@ use execution_core::{ BlsScalar, ContractId, Error, JubJubScalar, }; -/// An unproven-transaction is nearly identical to a [`PhoenixTransaction`] with -/// the only difference being that it carries a serialized [`TxCircuitVec`] -/// instead of the proof bytes. -/// This way it is possible to delegate the proof generation of the -/// [`TxCircuitVec`] after the unproven transaction was created while at the -/// same time ensuring non-malleability of the transaction, as the transaction's -/// payload-hash is part of the public inputs of the circuit. -/// Once the proof is generated from the [`TxCircuitVec`] bytes, it can -/// replace the serialized circuit in the transaction by calling -/// [`Transaction::replace_proof`]. +/// Generate a moonlight transaction +#[allow(clippy::too_many_arguments)] +pub fn moonlight( + from_sk: &BlsSecretKey, + to_account: Option, + value: u64, + deposit: u64, + gas_limit: u64, + gas_price: u64, + nonce: u64, + chain_id: u8, + exec: Option>, +) -> MoonlightTransaction { + MoonlightTransaction::new( + from_sk, to_account, value, deposit, gas_limit, gas_price, nonce, + chain_id, exec, + ) +} + +/// Generate a phoenix-transaction with a given prover. /// /// # Errors /// The creation of a transaction is not possible and will error if: