Skip to content

Commit

Permalink
adds build method in napi bindings for ProposedTransaction.build() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jowparks authored Jan 17, 2024
1 parent 6da4748 commit d309975
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
42 changes: 41 additions & 1 deletion ironfish-rust-nodejs/src/structs/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ use std::cell::RefCell;
use std::convert::TryInto;

use ironfish::assets::asset_identifier::AssetIdentifier;
use ironfish::serializing::hex_to_bytes;
use ironfish::transaction::{
batch_verify_transactions, TransactionVersion, TRANSACTION_EXPIRATION_SIZE,
TRANSACTION_FEE_SIZE, TRANSACTION_PUBLIC_KEY_SIZE, TRANSACTION_SIGNATURE_SIZE,
};
use ironfish::{MerkleNoteHash, ProposedTransaction, PublicAddress, SaplingKey, Transaction};
use ironfish::{
MerkleNoteHash, OutgoingViewKey, ProofGenerationKey, ProofGenerationKeySerializable,
ProposedTransaction, PublicAddress, SaplingKey, Transaction, ViewKey,
};
use napi::{
bindgen_prelude::{i64n, BigInt, Buffer, Env, Object, Result, Undefined},
JsBuffer,
Expand Down Expand Up @@ -308,6 +312,42 @@ impl NativeTransaction {
Ok(Buffer::from(vec))
}

// Outputs buffer of an unsigned transaction
#[napi]
pub fn build(
&mut self,
proof_generation_key_str: String,
view_key_str: String,
outgoing_view_key_str: String,
public_address_str: String,
intended_transaction_fee: BigInt,
) -> Result<Buffer> {
let view_key = ViewKey::from_hex(&view_key_str).map_err(to_napi_err)?;
let outgoing_view_key =
OutgoingViewKey::from_hex(&outgoing_view_key_str).map_err(to_napi_err)?;
let public_address = PublicAddress::from_hex(&public_address_str).map_err(to_napi_err)?;
let proof_generation_key = ProofGenerationKey::deserialize(
hex_to_bytes(&proof_generation_key_str)
.map_err(|_| to_napi_err("PublicKeyPackage hex to bytes failed"))?,
)
.map_err(to_napi_err)?;
let unsigned_transaction = self
.transaction
.build(
proof_generation_key,
view_key,
outgoing_view_key,
public_address,
intended_transaction_fee.get_i64().0,
)
.map_err(to_napi_err)?;

let mut vec: Vec<u8> = vec![];
unsigned_transaction.write(&mut vec).map_err(to_napi_err)?;

Ok(Buffer::from(vec))
}

#[napi]
pub fn set_expiration(&mut self, sequence: u32) -> Undefined {
self.transaction.set_expiration(sequence);
Expand Down
3 changes: 3 additions & 0 deletions ironfish-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ pub mod signal_catcher;
pub mod transaction;
pub mod util;
pub mod witness;
pub use ironfish_zkp::primitives::ProofGenerationKeySerializable;
pub use ironfish_zkp::ProofGenerationKey;
pub use {
ironfish_frost::frost,
keys::{IncomingViewKey, OutgoingViewKey, PublicAddress, SaplingKey, ViewKey},
merkle_note::MerkleNote,
merkle_note_hash::MerkleNoteHash,
Expand Down

0 comments on commit d309975

Please sign in to comment.