import { AccountTransaction, AccountTransactionHeader, AccountTransactionInput, AccountTransactionType, ConfigureBakerPayload, ConfigureDelegationPayload, DeployModulePayload, InitContractPayload, MakeOptional, MakeRequired, RegisterDataPayload, SimpleTransferPayload, SimpleTransferWithMemoPayload, TokenUpdatePayload, UpdateContractPayload, UpdateCredentialsPayload } from '../../index.js'; import { AccountAddress, DataBlob, Energy } from '../../types/index.js'; import { Payload } from '../index.js'; import { Header, HeaderJSON } from './shared.js'; import { type Signable, SignableJSON, SignableV0, SignableV1 } from './signable.js'; type Transaction
= { /** * The transaction input header. */ readonly header: Header; /** * The transaction payload, defining the transaction type and type specific data. */ readonly payload: P; }; export type Type
= Transaction
;
export type BuilderJSON = {
header: HeaderJSON;
payload: Payload.JSON;
};
export type JSON = BuilderJSON | SignableJSON;
/**
* Base metadata input with optional expiry field.
*/
export type Metadata = MakeOptional = BuilderAPI & {
/**
* The transaction input header of the initial transaction stage, i.e. without metadata.
*/
readonly header: Pick = {
/**
* Adds metadata (sender, nonce, expiry) to the transaction, making it configured and ready to be signed.
*
* @template T - the transaction builder type
* @param metadata - transaction metadata including sender, nonce, and optionally expiry
*
* @returns a signable transaction with metadata attached
* @throws if transaction metadata already exists.
*/
addMetadata ;
/**
* Attempts to convert a builder to a _configured_ builder. This is useful in case type information is lost
* during (de)serialization.
*
* @example
* const tx = Transaction.transfer(...).addMetadata(...);
* const json = Transaction.fromJSON(Transaction.toJSON(t));
* const rebuilt = builder(json).configured();
*
* @template T - the transaction builder type
* @returns a _configured transaction builder if the transaction is properly configured to be buildable. Otherwise
* returns `undefined`.
*/
configured | undefined;
};
type Configured = Transaction > = Omit (transaction: Transaction ): transaction is Configured ;
type MultiSigAPI = {
/**
* Configures the transaction for multi-signature by specifying the number of signatures required.
*
* @template T - the transaction builder type
* @param numSignaturesSender - the number of signatures required from the `sender` to authorize this transaction
*
* @returns a multi-sig transaction with the signature count configured
* @throws if number of sender signatures have already been added.
*/
addMultiSig ;
/**
* Attempts to convert a builder to a multi-sig configured builder. This is useful in case type information is lost
* during (de)serialization.
*
* @example
* const tx = Transaction.transfer(...).addMultiSig(4);
* const json = Transaction.fromJSON(Transaction.toJSON(t));
* const rebuilt = builder(json).multiSig();
*
* @template T - the transaction builder type
* @returns a multi-sig transaction builder if the transaction is properly configured for multi-sig. Otherwise
* returns `undefined`.
*/
multiSig | undefined;
};
type MultiSig = Transaction > = Omit (transaction: Transaction ): transaction is MultiSig ;
type SponsorableAPI = {
/**
* Configures the transaction for sponsorring by specifying the sponsor account.
* NOTE: this can be used from protocol version 10.
*
* @template T - the transaction builder type
* @param account - the sponsor account to use for sponsorring the transaction.
* @param [numSignaturesSponsor] - the number of signatures required to authorize this transaction. Defaults to `1` for if not specified.
*
* @returns a sponsorable transaction
* @throws if sponsor details already exits.
*/
addSponsor ;
/**
* Attempts to convert a builder to a multi-sig configured builder. This is useful in case type information is lost
* during (de)serialization.
*
* @example
* const tx = Transaction.transfer(...).addMultiSig(4);
* const json = Transaction.fromJSON(Transaction.toJSON(t));
* const rebuilt = builder(json).multiSig();
*
* @template T - the transaction builder type
* @returns a multi-sig transaction builder if the transaction is properly configured for multi-sig. Otherwise
* returns `undefined`.
*/
sponsorable | undefined;
};
type Sponsorable = Transaction > = Omit | 'header'> & {
/**
* The transaction input header of the sponsorable transaction stage, i.e. with the sponsor details and
* the number of signatures defined.
*/
readonly header: MakeRequired = Readonly & MultiSigAPI & SponsorableAPI & {
/**
* Build the transaction to it's pre-finalized stage.
*/
build(this: Sponsorable & Configured ): SignableV1 ;
build(this: Configured ): Signable ;
/**
* Serializes the transaction to JSON format.
*
* @returns the JSON representation of the transaction
*/
toJSON(): BuilderJSON;
};
/**
* Type predicate checking if the transaction is a _signable_ transaction.
*
* @template P extends Payload.Type
* @param transaction - the transaction to check
* @returns whether the transaction is a _signable transaction
*/
export declare function isSponsorable (transaction: Transaction ): transaction is Sponsorable ;
/**
* Describes an account transaction in its unprocessed form, i.e. defining the input required
* to create a transaction which can be signed
*/
export declare class Builder implements BuilderAPI {
readonly header: Header;
readonly payload: P;
constructor(header: Header, payload: P);
addMetadata ;
configured | undefined;
addMultiSig ;
multiSig | undefined;
addSponsor ;
sponsorable | undefined;
/**
* Build the transaction to it's pre-finalized stage.
*/
build(this: Sponsorable & Configured ): SignableV1 ;
build(this: Configured ): SignableV0 ;
/**
* Serializes the transaction to JSON format.
*
* @returns the JSON representation of the transaction
*/
toJSON(): BuilderJSON;
}
/**
* Dynamic `Transaction` creation based on the given transaction `type`.
*
* NOTE: this does _not_ check the payload structure, and thus assumes that the `type` and `payload`
* given actually match. If the transaction type is known, use the specialized creation functions
* per transaction type instead.
*
* @param type - transaction type
* @param payload - a transaction payload matching the transaction type.
*
* @returns The corresponding transaction
*
* @throws if transaction type is not currently supported.
* @throws if transaction cannot be created due to mismatch between `type` and `payload`.
*/
export declare function create(type: AccountTransactionType, payload: AccountTransactionInput): Initial;
/**
* Crates a {@linkcode Transaction} builder object from the legacy `AccountTransaction` format.
*
* @param transaction - The {@linkcode AccountTransaction} to convert.
* @returns a corresonding transaction builder object.
*/
export declare function fromLegacyAccountTransaction({ type, header, payload }: AccountTransaction): Configured;
/**
* Converts a {@linkcode Transaction} to the legacy format.
*
* @param transaction - the transaction details to convert
* @returns the legacy {@linkcode AccountTransaction} format
*/
export declare function toLegacyAccountTransaction(transaction: Transaction): AccountTransaction;
/**
* Creates a transfer transaction with memo
* @param payload the transfer payload containing recipient and amount and memo
* @returns a transfer with memo transaction
*/
export declare function transfer(payload: SimpleTransferWithMemoPayload | Payload.TransferWithMemo): Initial