{"version":3,"file":"Transaction.cjs","sources":["../../src/Transaction.ts"],"sourcesContent":["import { PublicKey } from '@metaplex-foundation/umi-public-keys';\nimport { Amount, SolAmount } from './Amount';\nimport type { Instruction } from './Instruction';\nimport type { Commitment } from './RpcInterface';\n\n/**\n * The maximum amount of bytes that can be used for a transaction.\n * @category Transactions\n */\nexport const TRANSACTION_SIZE_LIMIT = 1232;\n\n/**\n * The version of a transaction.\n * - Legacy is the very first iteration of Solana transactions.\n * - V0 introduces the concept of versioned transaction for\n * the first time and adds supports for address lookup tables.\n *\n * @category Transactions\n */\nexport type TransactionVersion = 'legacy' | 0;\n\n/**\n * A Uint8Array that represents a serialized transaction.\n * @category Transactions\n */\nexport type SerializedTransaction = Uint8Array;\n\n/**\n * A Uint8Array that represents the serialized message of a transaction.\n * @category Transactions\n */\nexport type SerializedTransactionMessage = Uint8Array;\n\n/**\n * A Uint8Array that represents a transaction signature.\n * @category Transactions\n */\nexport type TransactionSignature = Uint8Array;\n\n/**\n * Defines a transaction error.\n * @category Transactions\n */\nexport type TransactionError = {} | string;\n\n/**\n * Defines a blockhash.\n * @category Transactions\n */\nexport type Blockhash = string;\n\n/**\n * Defines a blockhash with its expiry block height.\n * @category Transactions\n */\nexport type BlockhashWithExpiryBlockHeight = {\n  blockhash: Blockhash;\n  lastValidBlockHeight: number;\n};\n\n/**\n * Defines a transaction.\n * @category Transactions\n */\nexport interface Transaction {\n  readonly message: TransactionMessage;\n  readonly serializedMessage: SerializedTransactionMessage;\n  readonly signatures: TransactionSignature[];\n}\n\n/**\n * Defines the message of a transaction.\n * @category Transactions\n */\nexport interface TransactionMessage {\n  readonly version: TransactionVersion;\n  readonly header: TransactionMessageHeader;\n  readonly accounts: PublicKey[];\n  readonly blockhash: Blockhash;\n  readonly instructions: CompiledInstruction[];\n  readonly addressLookupTables: CompiledAddressLookupTable[];\n}\n\n/**\n * Defines the header of a transaction message.\n * @category Transactions\n */\nexport type TransactionMessageHeader = {\n  readonly numRequiredSignatures: number;\n  readonly numReadonlySignedAccounts: number;\n  readonly numReadonlyUnsignedAccounts: number;\n};\n\n/**\n * Defines an instruction that uses indexes to reference accounts.\n * @category Transactions\n */\nexport type CompiledInstruction = {\n  readonly programIndex: number;\n  readonly accountIndexes: number[];\n  readonly data: Uint8Array;\n};\n\n/**\n * Defines an address lookup table that uses indexes to reference accounts.\n * @category Transactions\n */\nexport type CompiledAddressLookupTable = {\n  readonly publicKey: PublicKey;\n  readonly writableIndexes: number[];\n  readonly readonlyIndexes: number[];\n};\n\n/**\n * Defines a transaction with its post-execution metadata.\n * @category Transactions\n */\nexport type TransactionWithMeta = Transaction & {\n  readonly meta: TransactionMeta;\n};\n\n/**\n * Defines the post-execution metadata of a transaction.\n * @category Transactions\n */\nexport type TransactionMeta = {\n  readonly fee: SolAmount;\n  readonly logs: string[];\n  readonly preBalances: SolAmount[];\n  readonly postBalances: SolAmount[];\n  readonly preTokenBalances: TransactionMetaTokenBalance[];\n  readonly postTokenBalances: TransactionMetaTokenBalance[];\n  readonly innerInstructions: TransactionMetaInnerInstruction[] | null;\n  readonly loadedAddresses: TransactionMetaLoadedAddresses;\n  readonly computeUnitsConsumed: bigint | null;\n  readonly costUnits: bigint | null;\n  readonly err: TransactionError | null;\n};\n\n/**\n * The balance of a token account before or after a transaction.\n * @category Transactions\n */\nexport type TransactionMetaTokenBalance = {\n  accountIndex: number;\n  amount: Amount;\n  mint: PublicKey;\n  owner: PublicKey | null;\n};\n\n/**\n * The cross program invoked instructions of an instruction.\n * @category Transactions\n */\nexport type TransactionMetaInnerInstruction = {\n  index: number;\n  instructions: CompiledInstruction[];\n};\n\n/**\n * The collection of addresses loaded using address lookup tables.\n * @category Transactions\n */\nexport type TransactionMetaLoadedAddresses = {\n  writable: PublicKey[];\n  readonly: PublicKey[];\n};\n\n/**\n * Defines the various ways to create a transaction.\n * @category Transactions\n */\nexport type TransactionInput = TransactionInputLegacy | TransactionInputV0;\n\n/**\n * Defines transaction input for legacy transactions.\n * @category Transactions\n */\nexport type TransactionInputLegacy = TransactionInputBase & {\n  version: 'legacy';\n};\n\n/**\n * Defines transaction input for V0 transactions.\n * @category Transactions\n */\nexport type TransactionInputV0 = TransactionInputBase & {\n  version?: 0;\n  addressLookupTables?: AddressLookupTableInput[];\n};\n\n/**\n * Defines common transaction input.\n * @category Transactions\n */\nexport type TransactionInputBase = {\n  payer: PublicKey;\n  instructions: Instruction[];\n  blockhash: Blockhash;\n  signatures?: TransactionSignature[];\n};\n\n/**\n * The required data to add an address lookup table to a transaction.\n * @category Transactions\n */\nexport type AddressLookupTableInput = {\n  publicKey: PublicKey;\n  addresses: PublicKey[];\n};\n\n/**\n * The status of a sent transaction.\n * @category Transactions\n */\nexport type TransactionStatus = {\n  /** When the transaction was processed. */\n  slot: number;\n  /** The number of blocks that have been confirmed and voted on in the fork containing `slot`. */\n  confirmations: number | null;\n  /** The transaction error, if any. */\n  error: TransactionError | null;\n  /** The cluster confirmation status, if any. */\n  commitment: Commitment | null;\n};\n\n/**\n * Adds a given signature to the transaction's signature array\n * and returns the updated transaction as a new object.\n *\n * @category Transactions\n */\nexport const addTransactionSignature = (\n  transaction: Transaction,\n  signature: TransactionSignature,\n  signerPublicKey: PublicKey\n): Transaction => {\n  const maxSigners = transaction.message.header.numRequiredSignatures;\n  const signerPublicKeys = transaction.message.accounts.slice(0, maxSigners);\n  const signerIndex = signerPublicKeys.findIndex(\n    (key) => key === signerPublicKey\n  );\n\n  if (signerIndex < 0) {\n    throw new Error(\n      'The provided signer is not required to sign this transaction.'\n    );\n  }\n\n  const newSignatures = [...transaction.signatures];\n  newSignatures[signerIndex] = signature;\n  return { ...transaction, signatures: newSignatures };\n};\n"],"names":["TRANSACTION_SIZE_LIMIT","addTransactionSignature","transaction","signature","signerPublicKey","maxSigners","message","header","numRequiredSignatures","signerPublicKeys","accounts","slice","signerIndex","findIndex","key","Error","newSignatures","signatures"],"mappings":";;;;AAKA;AACA;AACA;AACA;AACO,MAAMA,sBAAsB,GAAG,KAAI;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAgNA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,uBAAuB,GAAG,CACrCC,WAAwB,EACxBC,SAA+B,EAC/BC,eAA0B,KACV;EAChB,MAAMC,UAAU,GAAGH,WAAW,CAACI,OAAO,CAACC,MAAM,CAACC,qBAAqB,CAAA;AACnE,EAAA,MAAMC,gBAAgB,GAAGP,WAAW,CAACI,OAAO,CAACI,QAAQ,CAACC,KAAK,CAAC,CAAC,EAAEN,UAAU,CAAC,CAAA;EAC1E,MAAMO,WAAW,GAAGH,gBAAgB,CAACI,SAAS,CAC3CC,GAAG,IAAKA,GAAG,KAAKV,eAAe,CACjC,CAAA;EAED,IAAIQ,WAAW,GAAG,CAAC,EAAE;AACnB,IAAA,MAAM,IAAIG,KAAK,CACb,+DAA+D,CAChE,CAAA;AACH,GAAA;AAEA,EAAA,MAAMC,aAAa,GAAG,CAAC,GAAGd,WAAW,CAACe,UAAU,CAAC,CAAA;AACjDD,EAAAA,aAAa,CAACJ,WAAW,CAAC,GAAGT,SAAS,CAAA;EACtC,OAAO;AAAE,IAAA,GAAGD,WAAW;AAAEe,IAAAA,UAAU,EAAED,aAAAA;GAAe,CAAA;AACtD;;;;;"}