Skip to main content

Transaction

@midnight/ledger v7.0.0


@midnight/ledger / Transaction

Class: Transaction<S, P, B>

A Midnight transaction, consisting a section of ContractActions, and a guaranteed and fallible ZswapOffer.

The guaranteed section are run first, and fee payment is taken during this part. If it succeeds, the fallible section is also run, and atomically rolled back if it fails.

Type Parameters

S

S extends Signaturish

P

P extends Proofish

B

B extends Bindingish

Properties

bindingRandomness

readonly bindingRandomness: bigint;

The binding randomness associated with this transaction


fallibleOffer

fallibleOffer: undefined | Map<number, ZswapOffer<P>>;

The fallible Zswap offer

Note that writing to this re-computes binding information if and only if this transaction is unbound and unproven. If this is not the case, creating or removing offer components will lead to a binding error down the line.

Throws

On writing if B is Binding or this is not a standard transaction


guaranteedOffer

guaranteedOffer: undefined | ZswapOffer<P>;

The guaranteed Zswap offer

Note that writing to this re-computes binding information if and only if this transaction is unbound and unproven. If this is not the case, creating or removing offer components will lead to a binding error down the line.

Throws

On writing if B is Binding or this is not a standard transaction


intents

intents: undefined | Map<number, Intent<S, P, B>>;

The intents contained in this transaction

Note that writing to this re-computes binding information if and only if this transaction is unbound and unproven. If this is not the case, creating or removing intents will lead to a binding error down the line, but modifying existing intents will succeed.

Throws

On writing if B is Binding or this is not a standard transaction


rewards

readonly rewards: 
| undefined
| ClaimRewardsTransaction<S>;

The rewards this transaction represents, if applicable

Methods

addCalls()

addCalls(
segment,
calls,
params,
ttl,
zswapInputs?,
zswapOutputs?,
zswapTransient?): Transaction<S, P, B>;

Adds a set of new calls to the transaction.

In contrast to Intent.addCall, this takes calls before transcript partitioning (partitionTranscripts), will create the target intent where needed, and will ensure that relevant Zswap parts are placed in the same section as contract interactions with them.

Parameters

segment

SegmentSpecifier

calls

PrePartitionContractCall[]

params

LedgerParameters

ttl

Date

zswapInputs?

ZswapInput<PreProof>[]

zswapOutputs?

ZswapOutput<PreProof>[]

zswapTransient?

ZswapTransient<PreProof>[]

Returns

Transaction<S, P, B>

Throws

If called on bound, proven, or proof-erased transactions.


bind()

bind(): Transaction<S, P, Binding>;

Enforces binding for this transaction. This is irreversible.

Returns

Transaction<S, P, Binding>


cost()

cost(params, enforceTimeToDismiss?): SyntheticCost;

The underlying resource cost of this transaction.

Parameters

params

LedgerParameters

enforceTimeToDismiss?

boolean

Returns

SyntheticCost


eraseProofs()

eraseProofs(): Transaction<S, NoProof, NoBinding>;

Erases the proofs contained in this transaction

Returns

Transaction<S, NoProof, NoBinding>


eraseSignatures()

eraseSignatures(): Transaction<SignatureErased, P, B>;

Removes signatures from this transaction.

Returns

Transaction<SignatureErased, P, B>


fees()

fees(params, enforceTimeToDismiss?): bigint;

The cost of this transaction, in SPECKs.

Note that this is only accurate when called with proven transactions.

Parameters

params

LedgerParameters

enforceTimeToDismiss?

boolean

Returns

bigint


feesWithMargin()

feesWithMargin(params, margin): bigint;

The cost of this transaction, in SPECKs, with a safety margin of n blocks applied.

As with fees, this is only accurate for proven transactions.

Warning: n must be a non-negative integer, and it is an exponent, it is very easy to get a completely unreasonable margin here!

Parameters

params

LedgerParameters

margin

number

Returns

bigint


identifiers()

identifiers(): string[];

Returns the set of identifiers contained within this transaction. Any of these may be used to watch for a specific transaction.

Returns

string[]


imbalances()

imbalances(segment, fees?): Map<TokenType, bigint>;

For given fees, and a given section (guaranteed/fallible), what the surplus or deficit of this transaction in any token type is.

Parameters

segment

number

fees?

bigint

Returns

Map<TokenType, bigint>

Throws

If segment is not a valid segment ID


merge()

merge(other): Transaction<S, P, B>;

Merges this transaction with another

Parameters

other

Transaction<S, P, B>

Returns

Transaction<S, P, B>

Throws

If both transactions have contract interactions, or they spend the same coins


mockProve()

mockProve(): Transaction<S, Proof, Binding>;

Mocks proving, producing a 'proven' transaction that, while it will not verify, is accurate for fee computation purposes.

Due to the variability in proof sizes, this only works for transactions that do not contain unproven contract calls.

Returns

Transaction<S, Proof, Binding>

Throws

If called on bound, proven, or proof-erased transactions, or if the transaction contains unproven contract calls.


prove()

prove(provider, cost_model): Promise<Transaction<S, Proof, B>>;

Proves the transaction, with access to a low-level proving provider. This may only be called for P = PreProof.

Parameters

provider

ProvingProvider

cost_model

CostModel

Returns

Promise<Transaction<S, Proof, B>>

Throws

If called on bound, proven, or proof-erased transactions.


serialize()

serialize(): Uint8Array;

Returns

Uint8Array


toString()

toString(compact?): string;

Parameters

compact?

boolean

Returns

string


transactionHash()

transactionHash(): string;

Returns the hash associated with this transaction. Due to the ability to merge transactions, this should not be used to watch for a specific transaction.

Returns

string


wellFormed()

wellFormed(
ref_state,
strictness,
tblock): VerifiedTransaction;

Tests well-formedness criteria, optionally including transaction balancing

Parameters

ref_state

LedgerState

strictness

WellFormedStrictness

tblock

Date

Returns

VerifiedTransaction

Throws

If the transaction is not well-formed for any reason


deserialize()

static deserialize<S, P, B>(
markerS,
markerP,
markerB,
raw): Transaction<S, P, B>;

Type Parameters

S

S extends Signaturish

P

P extends Proofish

B

B extends Bindingish

Parameters

markerS

S["instance"]

markerP

P["instance"]

markerB

B["instance"]

raw

Uint8Array

Returns

Transaction<S, P, B>


fromParts()

static fromParts(
network_id,
guaranteed?,
fallible?,
intent?): UnprovenTransaction;

Creates a transaction from its parts.

Parameters

network_id

string

guaranteed?

UnprovenOffer

fallible?

UnprovenOffer

intent?

UnprovenIntent

Returns

UnprovenTransaction


fromPartsRandomized()

static fromPartsRandomized(
network_id,
guaranteed?,
fallible?,
intent?): UnprovenTransaction;

Creates a transaction from its parts, randomizing the segment ID to better allow merging.

Parameters

network_id

string

guaranteed?

UnprovenOffer

fallible?

UnprovenOffer

intent?

UnprovenIntent

Returns

UnprovenTransaction


fromRewards()

static fromRewards<S>(rewards): Transaction<S, PreProof, Binding>;

Creates a rewards claim transaction, the funds claimed must have been legitimately rewarded previously.

Type Parameters

S

S extends Signaturish

Parameters

rewards

ClaimRewardsTransaction<S>

Returns

Transaction<S, PreProof, Binding>