pub struct WasmTxBuilder { /* private fields */ }Implementations§
Source§impl WasmTxBuilder
impl WasmTxBuilder
Sourcepub fn from_tx(
tx: WasmRawTx,
notes: Vec<WasmNote>,
spend_conditions: Vec<WasmSpendCondition>,
) -> Result<Self, JsValue>
pub fn from_tx( tx: WasmRawTx, notes: Vec<WasmNote>, spend_conditions: Vec<WasmSpendCondition>, ) -> Result<Self, JsValue>
Reconstruct a builder from raw transaction and its input notes.
To get the builder back, you must pass the notes and their corresponding spend conditions.
If serializing the builder, call WasmTxBuilder::all_notes.
Sourcepub fn simple_spend(
&mut self,
notes: Vec<WasmNote>,
spend_conditions: Vec<WasmSpendCondition>,
recipient: WasmDigest,
gift: Nicks,
fee_override: Option<Nicks>,
refund_pkh: WasmDigest,
include_lock_data: bool,
) -> Result<(), JsValue>
pub fn simple_spend( &mut self, notes: Vec<WasmNote>, spend_conditions: Vec<WasmSpendCondition>, recipient: WasmDigest, gift: Nicks, fee_override: Option<Nicks>, refund_pkh: WasmDigest, include_lock_data: bool, ) -> Result<(), JsValue>
Perform a simple-spend on this builder.
It is HIGHLY recommended to not mix simpleSpend with other types of spends.
This performs a fairly complex set of operations, in order to mimic behavior of nockchain
CLI wallet’s create-tx option. Note that we do not do 1-1 mapping of that functionality,
most notably - if recipient is the same as refund_pkh, we will create 1 seed, while the
CLI wallet will create 2.
Another difference is that you should call sign and validate after calling this method.
Internally, the transaction builder takes ALL of the notes provided, and stores them for
fee adjustments. If there are multiple notes being used, our fee setup also differs from
the CLI, because we first greedily spend the notes out, and then take fees from any
remaining refunds.
This function prioritizes using the least number of notes possible, because that lowers the fee used.
You may choose to override the fee with fee_override, but do note that validate will
fail, in case this fee is too small.
include_lock_data can be used to include %lock key in note-data, with the
SpendCondition used. However, note-data costs 1 << 15 nicks, which means, it can get
expensive.
Optional parameter remove_unused_notes, if set to false, will keep the notes in the
transaction builder. This is meant to be used whenever additional operations are performed
on the builder, such as additional spends, or addPreimage calls. All of these increase
the required fee (which can be checked with calcFee), and unused notes can then be used
to adjust fees with setFeeAndBalanceRefund or recalcAndSetFee. Once all operations are
done, one should call removeUnusedNotes to ensure these notes are not used within the
transaction.
Sourcepub fn spend(&mut self, spend: WasmSpendBuilder) -> Option<WasmSpendBuilder>
pub fn spend(&mut self, spend: WasmSpendBuilder) -> Option<WasmSpendBuilder>
Append a SpendBuilder to this transaction
Sourcepub fn set_fee_and_balance_refund(
&mut self,
fee: Nicks,
adjust_fee: bool,
include_lock_data: bool,
) -> Result<(), JsValue>
pub fn set_fee_and_balance_refund( &mut self, fee: Nicks, adjust_fee: bool, include_lock_data: bool, ) -> Result<(), JsValue>
Distributes fee across builder’s spends, and balances refunds out
adjust_fee parameter allows the fee to be slightly tweaked, whenever notes are added or
removed to/from the builder’s fee note pool. This is because using more or less notes
impacts the exact fee being required. If the caller estimates fee and sets it, adding more
notes will change the exact fee needed, and setting this parameter to true will allow one
to not have to call this function multiple times.
Sourcepub fn recalc_and_set_fee(
&mut self,
include_lock_data: bool,
) -> Result<(), JsValue>
pub fn recalc_and_set_fee( &mut self, include_lock_data: bool, ) -> Result<(), JsValue>
Recalculate fee and set it, balancing things out with refunds
Sourcepub fn add_preimage(
&mut self,
preimage_jam: &[u8],
) -> Result<Option<WasmDigest>, JsValue>
pub fn add_preimage( &mut self, preimage_jam: &[u8], ) -> Result<Option<WasmDigest>, JsValue>
Appends preimage_jam to all spend conditions that expect this preimage.
Sourcepub fn sign(&mut self, signing_key_bytes: &[u8]) -> Result<(), JsValue>
pub fn sign(&mut self, signing_key_bytes: &[u8]) -> Result<(), JsValue>
Sign the transaction with a private key.
This will sign all spends that are still missing signature from
Sourcepub fn calc_fee(&self) -> Nicks
pub fn calc_fee(&self) -> Nicks
Calculates the fee needed for the transaction.
NOTE: if the transaction is unsigned, this function will estimate the fee needed, supposing all signatures are added. However, this heuristic is only accurate for one signature. In addition, this fee calculation does not estimate the size of missing preimages.
So, first, add missing preimages, and only then calc the fee. If you’re building a multisig transaction, this value might be incorrect.
pub fn all_notes(&self) -> WasmTxNotes
pub fn build(&self) -> Result<WasmRawTx, JsValue>
Trait Implementations§
Source§impl From<WasmTxBuilder> for JsValue
impl From<WasmTxBuilder> for JsValue
Source§fn from(value: WasmTxBuilder) -> Self
fn from(value: WasmTxBuilder) -> Self
Source§impl FromWasmAbi for WasmTxBuilder
impl FromWasmAbi for WasmTxBuilder
Source§impl IntoWasmAbi for WasmTxBuilder
impl IntoWasmAbi for WasmTxBuilder
Source§impl LongRefFromWasmAbi for WasmTxBuilder
impl LongRefFromWasmAbi for WasmTxBuilder
Source§impl OptionFromWasmAbi for WasmTxBuilder
impl OptionFromWasmAbi for WasmTxBuilder
Source§impl OptionIntoWasmAbi for WasmTxBuilder
impl OptionIntoWasmAbi for WasmTxBuilder
Source§impl RefFromWasmAbi for WasmTxBuilder
impl RefFromWasmAbi for WasmTxBuilder
Source§type Anchor = RcRef<WasmTxBuilder>
type Anchor = RcRef<WasmTxBuilder>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for WasmTxBuilder
impl RefMutFromWasmAbi for WasmTxBuilder
Source§impl TryFromJsValue for WasmTxBuilder
impl TryFromJsValue for WasmTxBuilder
Source§impl VectorFromWasmAbi for WasmTxBuilder
impl VectorFromWasmAbi for WasmTxBuilder
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[WasmTxBuilder]>
Source§impl VectorIntoWasmAbi for WasmTxBuilder
impl VectorIntoWasmAbi for WasmTxBuilder
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[WasmTxBuilder]>) -> Self::Abi
Source§impl WasmDescribeVector for WasmTxBuilder
impl WasmDescribeVector for WasmTxBuilder
impl SupportsConstructor for WasmTxBuilder
impl SupportsInstanceProperty for WasmTxBuilder
impl SupportsStaticProperty for WasmTxBuilder
Auto Trait Implementations§
impl Freeze for WasmTxBuilder
impl RefUnwindSafe for WasmTxBuilder
impl Send for WasmTxBuilder
impl Sync for WasmTxBuilder
impl Unpin for WasmTxBuilder
impl UnwindSafe for WasmTxBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.