@stellar/stellar-sdk 16.0.0-rc.1 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -28
- package/dist/stellar-sdk-axios.js +245 -232
- package/dist/stellar-sdk-axios.js.map +1 -1
- package/dist/stellar-sdk-axios.min.js +1 -1
- package/dist/stellar-sdk-axios.min.js.map +1 -1
- package/dist/stellar-sdk.js +49 -36
- package/dist/stellar-sdk.js.map +1 -1
- package/dist/stellar-sdk.min.js +2 -2
- package/dist/stellar-sdk.min.js.map +1 -1
- package/lib/axios/cjs/base/auth.js +11 -11
- package/lib/axios/cjs/base/auth.js.map +1 -1
- package/lib/axios/cjs/base/keypair.js +1 -1
- package/lib/axios/cjs/base/keypair.js.map +1 -1
- package/lib/axios/cjs/base/transaction_builder.js +13 -1
- package/lib/axios/cjs/base/transaction_builder.js.map +1 -1
- package/lib/axios/cjs/bindings/config.js +1 -1
- package/lib/axios/cjs/bindings/config.js.map +1 -1
- package/lib/axios/cjs/bindings/wasm_fetcher.js +1 -1
- package/lib/axios/cjs/bindings/wasm_fetcher.js.map +1 -1
- package/lib/axios/cjs/contract/client.js.map +1 -1
- package/lib/axios/cjs/contract/spec.js.map +1 -1
- package/lib/axios/cjs/contract/types.js.map +1 -1
- package/lib/axios/cjs/contract/utils.js.map +1 -1
- package/lib/axios/cjs/contract/wasm_spec_parser.js +1 -1
- package/lib/axios/cjs/contract/wasm_spec_parser.js.map +1 -1
- package/lib/axios/cjs/horizon/call_builder.js.map +1 -1
- package/lib/axios/cjs/horizon/horizon_api.js.map +1 -1
- package/lib/axios/cjs/horizon/horizon_axios_client.js +1 -1
- package/lib/axios/cjs/horizon/horizon_axios_client.js.map +1 -1
- package/lib/axios/cjs/http-client/fetch-client.js +1 -1
- package/lib/axios/cjs/http-client/fetch-client.js.map +1 -1
- package/lib/axios/cjs/http-client/types.js.map +1 -1
- package/lib/axios/cjs/rpc/axios.js +1 -1
- package/lib/axios/cjs/rpc/axios.js.map +1 -1
- package/lib/axios/cjs/rpc/jsonrpc.js.map +1 -1
- package/lib/axios/cjs/rpc/server.js +2 -2
- package/lib/axios/cjs/rpc/server.js.map +1 -1
- package/lib/axios/cjs/webauth/challenge_transaction.js.map +1 -1
- package/lib/axios/esm/base/auth.d.ts +19 -7
- package/lib/axios/esm/base/auth.js +11 -11
- package/lib/axios/esm/base/auth.js.map +1 -1
- package/lib/axios/esm/base/keypair.js +1 -1
- package/lib/axios/esm/base/keypair.js.map +1 -1
- package/lib/axios/esm/base/transaction_builder.js +13 -1
- package/lib/axios/esm/base/transaction_builder.js.map +1 -1
- package/lib/axios/esm/bindings/config.js +1 -1
- package/lib/axios/esm/bindings/config.js.map +1 -1
- package/lib/axios/esm/bindings/wasm_fetcher.js +1 -1
- package/lib/axios/esm/bindings/wasm_fetcher.js.map +1 -1
- package/lib/axios/esm/contract/client.js.map +1 -1
- package/lib/axios/esm/contract/spec.js.map +1 -1
- package/lib/axios/esm/contract/types.js.map +1 -1
- package/lib/axios/esm/contract/utils.js.map +1 -1
- package/lib/axios/esm/contract/wasm_spec_parser.js +1 -1
- package/lib/axios/esm/contract/wasm_spec_parser.js.map +1 -1
- package/lib/axios/esm/horizon/call_builder.js.map +1 -1
- package/lib/axios/esm/horizon/horizon_api.js.map +1 -1
- package/lib/axios/esm/horizon/horizon_axios_client.js +1 -1
- package/lib/axios/esm/horizon/horizon_axios_client.js.map +1 -1
- package/lib/axios/esm/http-client/fetch-client.js +1 -1
- package/lib/axios/esm/http-client/fetch-client.js.map +1 -1
- package/lib/axios/esm/http-client/types.js.map +1 -1
- package/lib/axios/esm/rpc/axios.js +1 -1
- package/lib/axios/esm/rpc/axios.js.map +1 -1
- package/lib/axios/esm/rpc/jsonrpc.js.map +1 -1
- package/lib/axios/esm/rpc/server.js +2 -2
- package/lib/axios/esm/rpc/server.js.map +1 -1
- package/lib/axios/esm/webauth/challenge_transaction.js.map +1 -1
- package/lib/cjs/base/auth.js +11 -11
- package/lib/cjs/base/auth.js.map +1 -1
- package/lib/cjs/base/keypair.js +1 -1
- package/lib/cjs/base/keypair.js.map +1 -1
- package/lib/cjs/base/transaction_builder.js +13 -1
- package/lib/cjs/base/transaction_builder.js.map +1 -1
- package/lib/cjs/bindings/config.js +1 -1
- package/lib/cjs/bindings/config.js.map +1 -1
- package/lib/cjs/bindings/wasm_fetcher.js +1 -1
- package/lib/cjs/bindings/wasm_fetcher.js.map +1 -1
- package/lib/cjs/contract/client.js.map +1 -1
- package/lib/cjs/contract/spec.js.map +1 -1
- package/lib/cjs/contract/types.js.map +1 -1
- package/lib/cjs/contract/utils.js.map +1 -1
- package/lib/cjs/contract/wasm_spec_parser.js +1 -1
- package/lib/cjs/contract/wasm_spec_parser.js.map +1 -1
- package/lib/cjs/horizon/call_builder.js.map +1 -1
- package/lib/cjs/horizon/horizon_api.js.map +1 -1
- package/lib/cjs/horizon/horizon_axios_client.js +1 -1
- package/lib/cjs/horizon/horizon_axios_client.js.map +1 -1
- package/lib/cjs/http-client/fetch-client.js +1 -1
- package/lib/cjs/http-client/fetch-client.js.map +1 -1
- package/lib/cjs/http-client/types.js.map +1 -1
- package/lib/cjs/rpc/axios.js +1 -1
- package/lib/cjs/rpc/axios.js.map +1 -1
- package/lib/cjs/rpc/jsonrpc.js.map +1 -1
- package/lib/cjs/rpc/server.js +2 -2
- package/lib/cjs/rpc/server.js.map +1 -1
- package/lib/cjs/webauth/challenge_transaction.js.map +1 -1
- package/lib/esm/base/auth.d.ts +19 -7
- package/lib/esm/base/auth.js +11 -11
- package/lib/esm/base/auth.js.map +1 -1
- package/lib/esm/base/keypair.js +1 -1
- package/lib/esm/base/keypair.js.map +1 -1
- package/lib/esm/base/transaction_builder.js +13 -1
- package/lib/esm/base/transaction_builder.js.map +1 -1
- package/lib/esm/bindings/config.js +1 -1
- package/lib/esm/bindings/config.js.map +1 -1
- package/lib/esm/bindings/wasm_fetcher.js +1 -1
- package/lib/esm/bindings/wasm_fetcher.js.map +1 -1
- package/lib/esm/contract/client.js.map +1 -1
- package/lib/esm/contract/spec.js.map +1 -1
- package/lib/esm/contract/types.js.map +1 -1
- package/lib/esm/contract/utils.js.map +1 -1
- package/lib/esm/contract/wasm_spec_parser.js +1 -1
- package/lib/esm/contract/wasm_spec_parser.js.map +1 -1
- package/lib/esm/horizon/call_builder.js.map +1 -1
- package/lib/esm/horizon/horizon_api.js.map +1 -1
- package/lib/esm/horizon/horizon_axios_client.js +1 -1
- package/lib/esm/horizon/horizon_axios_client.js.map +1 -1
- package/lib/esm/http-client/fetch-client.js +1 -1
- package/lib/esm/http-client/fetch-client.js.map +1 -1
- package/lib/esm/http-client/types.js.map +1 -1
- package/lib/esm/rpc/axios.js +1 -1
- package/lib/esm/rpc/axios.js.map +1 -1
- package/lib/esm/rpc/jsonrpc.js.map +1 -1
- package/lib/esm/rpc/server.js +2 -2
- package/lib/esm/rpc/server.js.map +1 -1
- package/lib/esm/webauth/challenge_transaction.js.map +1 -1
- package/package.json +2 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction_builder.js","sources":["../../../src/base/transaction_builder.ts"],"sourcesContent":["import { Hyper } from \"@stellar/js-xdr\";\nimport BigNumber from \"./util/bignumber.js\";\n\nimport xdr from \"./xdr.js\";\n\nimport { Account } from \"./account.js\";\nimport { MuxedAccount } from \"./muxed_account.js\";\nimport type { TransactionSource } from \"./transaction_source.js\";\nimport {\n decodeAddressToMuxedAccount,\n extractBaseAddress,\n} from \"./util/decode_encode_muxed_account.js\";\n\nimport { Transaction } from \"./transaction.js\";\nimport { FeeBumpTransaction } from \"./fee_bump_transaction.js\";\nimport { SorobanDataBuilder } from \"./sorobandata_builder.js\";\n\nimport { StrKey } from \"./strkey.js\";\nimport { SignerKey } from \"./signerkey.js\";\nimport { Memo } from \"./memo.js\";\nimport { Asset } from \"./asset.js\";\nimport { nativeToScVal } from \"./scval.js\";\nimport { Operation } from \"./operation.js\";\nimport { Address } from \"./address.js\";\nimport { Keypair } from \"./keypair.js\";\n\nconst HYPER_MAX_VALUE = Hyper.MAX_VALUE as unknown as bigint;\nconst UINT32_MAX = 4294967295; // 2^32 - 1\n\n/**\n * Minimum base fee for transactions. If this fee is below the network\n * minimum, the transaction will fail. The more operations in the\n * transaction, the greater the required fee. Use\n * {@link Horizon.Server.fetchBaseFee} to get an accurate value of minimum\n * transaction fee on the network.\n *\n * @see [Fees](https://developers.stellar.org/docs/glossary/fees/)\n */\nexport const BASE_FEE = \"100\"; // Stroops\n\n/**\n * @see {@link TransactionBuilder.setTimeout}\n * @see [Timeout](https://developers.stellar.org/api/resources/transactions/post/)\n */\nexport const TimeoutInfinite = 0;\n\n/**\n * Soroban fee parameters for resource-limited transactions.\n */\nexport interface SorobanFees {\n /** The number of instructions executed by the transaction. */\n instructions: number;\n /** The number of bytes read from the ledger by the transaction. */\n readBytes: number;\n /** The number of bytes written to the ledger by the transaction. */\n writeBytes: number;\n /** The fee to be paid for the transaction, in stroops. */\n resourceFee: bigint;\n}\n\n/**\n * Options for constructing a {@link TransactionBuilder}.\n */\nexport interface TransactionBuilderOptions {\n /** Max fee you're willing to pay per operation in this transaction (**in stroops**). */\n fee: string;\n /** Memo for the transaction. */\n memo?: Memo;\n /**\n * Passphrase of the target Stellar network (e.g. \"Public Global Stellar\n * Network ; September 2015\" for the pubnet).\n */\n networkPassphrase?: string;\n /** Timebounds for the validity of this transaction. */\n timebounds?: {\n /** 64-bit UNIX timestamp or Date object. */\n minTime?: Date | number | string;\n /** 64-bit UNIX timestamp or Date object. */\n maxTime?: Date | number | string;\n };\n /** Ledger bounds for the validity of this transaction. */\n ledgerbounds?: {\n /** Number of the minimum ledger sequence. */\n minLedger?: number;\n /** Number of the maximum ledger sequence. */\n maxLedger?: number;\n };\n /** Minimum source account sequence number this transaction is valid for. */\n minAccountSequence?: string;\n /** Minimum seconds between source account sequence time and ledger time. */\n minAccountSequenceAge?: bigint;\n /** Minimum ledgers between source account sequence and current ledger. */\n minAccountSequenceLedgerGap?: number;\n /** List of extra signers required for this transaction. */\n extraSigners?: string[];\n /**\n * An instance of {@link xdr.SorobanTransactionData} or a base64 string.\n * Provides resource estimations for Soroban transactions. Has no effect on\n * non-contract transactions.\n */\n sorobanData?: xdr.SorobanTransactionData | string;\n}\n\n/**\n * <p>Transaction builder helps constructs a new `{@link Transaction}` using the\n * given {@link Account} as the transaction's \"source account\". The transaction\n * will use the current sequence number of the given account as its sequence\n * number and increment the given account's sequence number by one. The given\n * source account must include a private key for signing the transaction or an\n * error will be thrown.</p>\n *\n * <p>Operations can be added to the transaction via their corresponding builder\n * methods, and each returns the TransactionBuilder object so they can be\n * chained together. After adding the desired operations, call the `build()`\n * method on the `TransactionBuilder` to return a fully constructed\n * {@link Transaction} that can be signed. The returned transaction will contain the\n * sequence number of the source account and include the signature from the\n * source account.</p>\n *\n * <p><strong>Be careful about unsubmitted transactions!</strong> When you build\n * a transaction, `stellar-sdk` automatically increments the source account's\n * sequence number. If you end up not submitting this transaction and submitting\n * another one instead, it'll fail due to the sequence number being wrong. So if\n * you decide not to use a built transaction, make sure to update the source\n * account's sequence number with\n * [Server.loadAccount](https://stellar.github.io/js-stellar-sdk/Server.html#loadAccount)\n * before creating another transaction.</p>\n *\n * <p>The following code example creates a new transaction with {@link\n * Operation.createAccount} and {@link Operation.payment} operations. The\n * Transaction's source account first funds `destinationA`, then sends a payment\n * to `destinationB`. The built transaction is then signed by\n * `sourceKeypair`.</p>\n *\n * ```\n * var transaction = new TransactionBuilder(source, { fee, networkPassphrase: Networks.TESTNET })\n * .addOperation(Operation.createAccount({\n * destination: destinationA,\n * startingBalance: \"20\"\n * })) // <- funds and creates destinationA\n * .addOperation(Operation.payment({\n * destination: destinationB,\n * amount: \"100\",\n * asset: Asset.native()\n * })) // <- sends 100 XLM to destinationB\n * .setTimeout(30)\n * .build();\n *\n * transaction.sign(sourceKeypair);\n * ```\n *\n */\nexport class TransactionBuilder {\n source: TransactionSource;\n operations: xdr.Operation[];\n baseFee: string;\n timebounds: {\n minTime?: Date | number | string;\n maxTime?: Date | number | string;\n } | null;\n ledgerbounds: { minLedger?: number; maxLedger?: number } | null;\n minAccountSequence: string | null;\n minAccountSequenceAge: bigint | null;\n minAccountSequenceLedgerGap: number | null;\n extraSigners: string[] | null;\n memo: Memo;\n networkPassphrase: string | null;\n sorobanData: xdr.SorobanTransactionData | null;\n\n /**\n * @param sourceAccount - source account for this transaction\n * @param opts - options object (see {@link TransactionBuilderOptions})\n */\n constructor(\n sourceAccount: TransactionSource,\n opts: TransactionBuilderOptions = {} as TransactionBuilderOptions,\n ) {\n if (!sourceAccount) {\n throw new Error(\"must specify source account for the transaction\");\n }\n\n if (opts.fee === undefined) {\n throw new Error(\"must specify fee for the transaction (in stroops)\");\n }\n\n this.source = sourceAccount;\n this.operations = [];\n\n this.baseFee = opts.fee;\n if (opts.timebounds) {\n const minTime = toEpochSeconds(opts.timebounds.minTime);\n const maxTime = toEpochSeconds(opts.timebounds.maxTime);\n\n if (minTime !== undefined && minTime < 0) {\n throw new Error(\"min_time cannot be negative\");\n }\n\n if (maxTime !== undefined && maxTime < 0) {\n throw new Error(\"max_time cannot be negative\");\n }\n\n if (\n minTime !== undefined &&\n maxTime !== undefined &&\n maxTime > 0 &&\n minTime > maxTime\n ) {\n throw new Error(\"min_time cannot be greater than max_time\");\n }\n\n this.timebounds = { ...opts.timebounds };\n } else {\n this.timebounds = null;\n }\n\n if (opts.ledgerbounds) {\n const minLedger = opts.ledgerbounds.minLedger;\n const maxLedger = opts.ledgerbounds.maxLedger;\n\n if (minLedger !== undefined && minLedger < 0) {\n throw new Error(\"min_ledger cannot be negative\");\n }\n\n if (maxLedger !== undefined && maxLedger < 0) {\n throw new Error(\"max_ledger cannot be negative\");\n }\n\n if (\n minLedger !== undefined &&\n maxLedger !== undefined &&\n maxLedger > 0 &&\n minLedger > maxLedger\n ) {\n throw new Error(\"min_ledger cannot be greater than max_ledger\");\n }\n\n this.ledgerbounds = { ...opts.ledgerbounds };\n } else {\n this.ledgerbounds = null;\n }\n this.minAccountSequence = opts.minAccountSequence || null;\n this.minAccountSequenceAge =\n opts.minAccountSequenceAge !== undefined\n ? opts.minAccountSequenceAge\n : null;\n this.minAccountSequenceLedgerGap =\n opts.minAccountSequenceLedgerGap !== undefined\n ? opts.minAccountSequenceLedgerGap\n : null;\n this.extraSigners = opts.extraSigners ? [...opts.extraSigners] : null;\n this.memo = opts.memo || Memo.none();\n this.networkPassphrase = opts.networkPassphrase || null;\n\n this.sorobanData = opts.sorobanData\n ? new SorobanDataBuilder(opts.sorobanData).build()\n : null;\n }\n\n /**\n * Creates a builder instance using an existing {@link Transaction} as a\n * template, ignoring any existing envelope signatures.\n *\n * Note that the sequence number WILL be cloned, so EITHER this transaction or\n * the one it was cloned from will be valid. This is useful in situations\n * where you are constructing a transaction in pieces and need to make\n * adjustments as you go (for example, when filling out Soroban resource\n * information).\n *\n * @param tx - a \"template\" transaction to clone exactly\n * @param opts - additional options to override the clone, e.g.\n * `{fee: '1000'}` will override the existing base fee derived from `tx`\n * (see the {@link TransactionBuilder} constructor for detailed options)\n *\n * **Warning:** This does not clone the transaction's\n * {@link xdr.SorobanTransactionData} (if applicable), use\n * {@link SorobanDataBuilder} and {@link TransactionBuilder.setSorobanData}\n * as needed, instead.\n *\n * TODO: This cannot clone {@link FeeBumpTransaction}s, yet.\n */\n static cloneFrom(\n tx: Transaction,\n opts: Partial<TransactionBuilderOptions> = {},\n ): TransactionBuilder {\n if (!(tx instanceof Transaction)) {\n throw new TypeError(`expected a 'Transaction', got: ${String(tx)}`);\n }\n\n const sequenceNum = (BigInt(tx.sequence) - 1n).toString();\n\n let source;\n\n // rebuild the source account based on the strkey\n if (StrKey.isValidMed25519PublicKey(tx.source)) {\n source = MuxedAccount.fromAddress(tx.source, sequenceNum);\n } else if (StrKey.isValidEd25519PublicKey(tx.source)) {\n source = new Account(tx.source, sequenceNum);\n } else {\n throw new TypeError(`unsupported tx source account: ${tx.source}`);\n }\n\n if (tx.operations.length === 0) {\n throw new Error(\n \"cannot clone a transaction with no operations: \" +\n \"per-operation base fee cannot be determined\",\n );\n }\n\n // the initial fee passed to the builder gets scaled up based on the number\n // of operations at the end, so we have to down-scale first\n const unscaledFee = Math.floor(parseInt(tx.fee, 10) / tx.operations.length);\n\n const builderOpts: TransactionBuilderOptions = {\n fee: (unscaledFee || BASE_FEE).toString(),\n memo: tx.memo,\n networkPassphrase: tx.networkPassphrase,\n };\n\n if (tx.timeBounds) {\n builderOpts.timebounds = tx.timeBounds;\n }\n if (tx.ledgerBounds) {\n builderOpts.ledgerbounds = tx.ledgerBounds;\n }\n if (tx.minAccountSequence) {\n builderOpts.minAccountSequence = tx.minAccountSequence;\n }\n if (tx.minAccountSequenceAge !== undefined) {\n builderOpts.minAccountSequenceAge = tx.minAccountSequenceAge;\n }\n if (tx.minAccountSequenceLedgerGap !== undefined) {\n builderOpts.minAccountSequenceLedgerGap = tx.minAccountSequenceLedgerGap;\n }\n if (tx.extraSigners) {\n builderOpts.extraSigners = tx.extraSigners.map((s) =>\n SignerKey.encodeSignerKey(s),\n );\n }\n\n // User-provided opts override transaction defaults\n Object.assign(builderOpts, opts);\n\n const builder = new TransactionBuilder(source, builderOpts);\n\n tx.tx.operations().forEach((op) => builder.addOperation(op));\n\n return builder;\n }\n\n /**\n * Adds an operation to the transaction.\n *\n * @param operation - The xdr operation object, use {@link\n * Operation} static methods.\n */\n addOperation(operation: xdr.Operation): TransactionBuilder {\n this.operations.push(operation);\n return this;\n }\n\n /**\n * Adds an operation to the transaction at a specific index.\n *\n * @param operation - The xdr operation object to add, use {@link Operation} static methods.\n * @param index - The index at which to insert the operation.\n */\n addOperationAt(operation: xdr.Operation, index: number): TransactionBuilder {\n this.operations.splice(index, 0, operation);\n return this;\n }\n\n /**\n * Removes the operations from the builder (useful when cloning).\n */\n clearOperations(): TransactionBuilder {\n this.operations = [];\n return this;\n }\n\n /**\n * Removes the operation at the specified index from the transaction.\n *\n * @param index - The index of the operation to remove.\n */\n clearOperationAt(index: number): TransactionBuilder {\n this.operations.splice(index, 1);\n return this;\n }\n\n /**\n * Adds a memo to the transaction.\n * @param memo - {@link Memo} object\n */\n addMemo(memo: Memo): TransactionBuilder {\n this.memo = memo;\n return this;\n }\n\n /**\n * Sets a timeout precondition on the transaction.\n *\n * Because of the distributed nature of the Stellar network it is possible\n * that the status of your transaction will be determined after a long time\n * if the network is highly congested. If you want to be sure to receive the\n * status of the transaction within a given period you should set the\n * time bounds with `maxTime` on the transaction (this is what `setTimeout`\n * does internally; if there's `minTime` set but no `maxTime` it will be\n * added).\n *\n * A call to `TransactionBuilder.setTimeout` is **required** if Transaction\n * does not have `max_time` set. If you don't want to set timeout, use\n * {@link TimeoutInfinite}. In general you should set\n * {@link TimeoutInfinite} only in smart contracts.\n *\n * Please note that Horizon may still return <code>504 Gateway Timeout</code>\n * error, even for short timeouts. In such case you need to resubmit the same\n * transaction again without making any changes to receive a status. This\n * method is using the machine system time (UTC), make sure it is set\n * correctly.\n *\n * @param timeoutSeconds - Number of seconds the transaction is good.\n * Can't be negative. If the value is {@link TimeoutInfinite}, the\n * transaction is good indefinitely.\n *\n * @see {@link TimeoutInfinite}\n * @see https://developers.stellar.org/docs/tutorials/handling-errors/\n */\n setTimeout(timeoutSeconds: number): TransactionBuilder {\n if (this.timebounds !== null && Number(this.timebounds.maxTime) > 0) {\n throw new Error(\n \"TimeBounds.max_time has been already set - setting timeout would overwrite it.\",\n );\n }\n\n if (timeoutSeconds < 0) {\n throw new Error(\"timeout cannot be negative\");\n }\n\n if (timeoutSeconds > 0) {\n const timeoutTimestamp = Math.floor(Date.now() / 1000) + timeoutSeconds;\n\n if (this.timebounds === null) {\n this.timebounds = { minTime: 0, maxTime: timeoutTimestamp };\n } else {\n this.timebounds = {\n minTime: this.timebounds.minTime ?? 0,\n maxTime: timeoutTimestamp,\n };\n }\n } else {\n this.timebounds = {\n minTime: 0,\n maxTime: 0,\n };\n }\n\n return this;\n }\n\n /**\n * If you want to prepare a transaction which will become valid at some point\n * in the future, or be invalid after some time, you can set a timebounds\n * precondition. Internally this will set the `minTime`, and `maxTime`\n * preconditions. Conflicts with `setTimeout`, so use one or the other.\n *\n * @param minEpochOrDate - Either a JS Date object, or a number\n * of UNIX epoch seconds. The transaction is valid after this timestamp.\n * Can't be negative. If the value is `0`, the transaction is valid\n * immediately.\n * @param maxEpochOrDate - Either a JS Date object, or a number\n * of UNIX epoch seconds. The transaction is valid until this timestamp.\n * Can't be negative. If the value is `0`, the transaction is valid\n * indefinitely.\n */\n setTimebounds(\n minEpochOrDate: Date | number,\n maxEpochOrDate: Date | number,\n ): TransactionBuilder {\n // Force it to a date type\n if (typeof minEpochOrDate === \"number\") {\n minEpochOrDate = new Date(minEpochOrDate * 1000);\n }\n if (typeof maxEpochOrDate === \"number\") {\n maxEpochOrDate = new Date(maxEpochOrDate * 1000);\n }\n\n if (this.timebounds !== null) {\n throw new Error(\n \"TimeBounds has been already set - setting timebounds would overwrite it.\",\n );\n }\n\n // Convert that date to the epoch seconds\n const minTime = Math.floor(minEpochOrDate.valueOf() / 1000);\n const maxTime = Math.floor(maxEpochOrDate.valueOf() / 1000);\n if (minTime < 0) {\n throw new Error(\"min_time cannot be negative\");\n }\n if (maxTime < 0) {\n throw new Error(\"max_time cannot be negative\");\n }\n if (maxTime > 0 && minTime > maxTime) {\n throw new Error(\"min_time cannot be greater than max_time\");\n }\n\n this.timebounds = { minTime, maxTime };\n\n return this;\n }\n\n /**\n * If you want to prepare a transaction which will only be valid within some\n * range of ledgers, you can set a ledgerbounds precondition.\n * Internally this will set the `minLedger` and `maxLedger` preconditions.\n *\n * @param minLedger - The minimum ledger this transaction is valid at\n * or after. Cannot be negative. If the value is `0` (the default), the\n * transaction is valid immediately.\n *\n * @param maxLedger - The maximum ledger this transaction is valid\n * before. Cannot be negative. If the value is `0`, the transaction is\n * valid indefinitely.\n */\n setLedgerbounds(minLedger: number, maxLedger: number): TransactionBuilder {\n if (this.ledgerbounds !== null) {\n throw new Error(\n \"LedgerBounds has been already set - setting ledgerbounds would overwrite it.\",\n );\n }\n\n if (minLedger < 0) {\n throw new Error(\"min_ledger cannot be negative\");\n }\n if (maxLedger < 0) {\n throw new Error(\"max_ledger cannot be negative\");\n }\n if (maxLedger > 0 && minLedger > maxLedger) {\n throw new Error(\"min_ledger cannot be greater than max_ledger\");\n }\n\n this.ledgerbounds = { minLedger, maxLedger };\n\n return this;\n }\n\n /**\n * If you want to prepare a transaction which will be valid only while the\n * account sequence number is\n *\n * `minAccountSequence <= sourceAccountSequence < tx.seqNum`\n *\n * Note that after execution the account's sequence number is always raised to\n * `tx.seqNum`. Internally this will set the `minAccountSequence`\n * precondition.\n *\n * @param minAccountSequence - The minimum source account sequence\n * number this transaction is valid for. If the value is `0` (the\n * default), the transaction is valid when `sourceAccount`'s sequence\n * number `== tx.seqNum - 1`.\n */\n setMinAccountSequence(minAccountSequence: string): TransactionBuilder {\n if (this.minAccountSequence !== null) {\n throw new Error(\n \"min_account_sequence has been already set - setting min_account_sequence would overwrite it.\",\n );\n }\n\n this.minAccountSequence = minAccountSequence;\n\n return this;\n }\n\n /**\n * For the transaction to be valid, the current ledger time must be at least\n * `minAccountSequenceAge` greater than sourceAccount's `sequenceTime`.\n * Internally this will set the `minAccountSequenceAge` precondition.\n *\n * @param durationInSeconds - The minimum amount of time between\n * source account sequence time and the ledger time when this transaction\n * will become valid. If the value is `0`, the transaction is unrestricted\n * by the account sequence age. Cannot be negative.\n */\n setMinAccountSequenceAge(durationInSeconds: bigint): TransactionBuilder {\n if (typeof durationInSeconds !== \"bigint\") {\n throw new Error(\"min_account_sequence_age must be a bigint\");\n }\n if (this.minAccountSequenceAge !== null) {\n throw new Error(\n \"min_account_sequence_age has been already set - setting min_account_sequence_age would overwrite it.\",\n );\n }\n\n if (durationInSeconds < 0) {\n throw new Error(\"min_account_sequence_age cannot be negative\");\n }\n\n this.minAccountSequenceAge = durationInSeconds;\n\n return this;\n }\n\n /**\n * For the transaction to be valid, the current ledger number must be at least\n * `minAccountSequenceLedgerGap` greater than sourceAccount's ledger sequence.\n * Internally this will set the `minAccountSequenceLedgerGap` precondition.\n *\n * @param gap - The minimum number of ledgers between source account\n * sequence and the ledger number when this transaction will become valid.\n * If the value is `0`, the transaction is unrestricted by the account\n * sequence ledger. Cannot be negative.\n */\n setMinAccountSequenceLedgerGap(gap: number): TransactionBuilder {\n if (this.minAccountSequenceLedgerGap !== null) {\n throw new Error(\n \"min_account_sequence_ledger_gap has been already set - setting min_account_sequence_ledger_gap would overwrite it.\",\n );\n }\n\n if (gap < 0) {\n throw new Error(\"min_account_sequence_ledger_gap cannot be negative\");\n }\n\n this.minAccountSequenceLedgerGap = gap;\n\n return this;\n }\n\n /**\n * For the transaction to be valid, there must be a signature corresponding to\n * every Signer in this array, even if the signature is not otherwise required\n * by the sourceAccount or operations. Internally this will set the\n * `extraSigners` precondition.\n *\n * @param extraSigners - required extra signers (as {@link StrKey}s)\n */\n setExtraSigners(extraSigners: string[]): TransactionBuilder {\n if (!Array.isArray(extraSigners)) {\n throw new Error(\"extra_signers must be an array of strings.\");\n }\n\n if (this.extraSigners !== null) {\n throw new Error(\n \"extra_signers has been already set - setting extra_signers would overwrite it.\",\n );\n }\n\n if (extraSigners.length > 2) {\n throw new Error(\"extra_signers cannot be longer than 2 elements.\");\n }\n\n this.extraSigners = [...extraSigners];\n\n return this;\n }\n\n /**\n * Set network passphrase for the Transaction that will be built.\n *\n * @param networkPassphrase - passphrase of the target Stellar\n * network (e.g. \"Public Global Stellar Network ; September 2015\").\n */\n setNetworkPassphrase(networkPassphrase: string): TransactionBuilder {\n this.networkPassphrase = networkPassphrase;\n return this;\n }\n\n /**\n * Sets the transaction's internal Soroban transaction data (resources,\n * footprint, etc.).\n *\n * For non-contract(non-Soroban) transactions, this setting has no effect. In\n * the case of Soroban transactions, this is either an instance of\n * {@link xdr.SorobanTransactionData} or a base64-encoded string of said\n * structure. This is usually obtained from the simulation response based on a\n * transaction with a Soroban operation (e.g.\n * {@link Operation.invokeHostFunction}, providing necessary resource\n * and storage footprint estimations for contract invocation.\n *\n * @param sorobanData - the {@link xdr.SorobanTransactionData} as a raw xdr\n * object or a base64 string to be decoded\n *\n * @see {@link SorobanDataBuilder}\n */\n setSorobanData(\n sorobanData: xdr.SorobanTransactionData | string,\n ): TransactionBuilder {\n this.sorobanData = new SorobanDataBuilder(sorobanData).build();\n return this;\n }\n\n /**\n * Creates and adds an invoke host function operation for transferring SAC tokens.\n * This method removes the need for simulation by handling the creation of the\n * appropriate authorization entries and ledger footprint for the transfer operation.\n *\n * @param destination - the address of the recipient of the SAC transfer (should be a valid Stellar address or contract ID)\n * @param asset - the SAC asset to be transferred\n * @param amount - the amount of tokens to be transferred in 7 decimals. IE 1 token with 7 decimals of precision would be represented as \"1_0000000\"\n * @param sorobanFees - optional Soroban fees for the transaction to override the default fees used\n */\n addSacTransferOperation(\n destination: string,\n asset: Asset,\n amount: bigint | string,\n sorobanFees?: SorobanFees,\n ): TransactionBuilder {\n if (BigInt(amount) <= 0n) {\n throw new Error(\"Amount must be a positive integer\");\n } else if (BigInt(amount) > HYPER_MAX_VALUE) {\n // The largest supported value for SAC is i64 however the contract interface uses i128 which is why we convert it to i128\n throw new Error(\"Amount exceeds maximum value for i64\");\n }\n\n if (sorobanFees) {\n const { instructions, readBytes, writeBytes, resourceFee } = sorobanFees;\n const U32_MAX = 4294967295;\n\n if (instructions <= 0 || instructions > U32_MAX) {\n throw new Error(\n `instructions must be greater than 0 and at most ${U32_MAX}`,\n );\n }\n if (readBytes <= 0 || readBytes > U32_MAX) {\n throw new Error(\n `readBytes must be greater than 0 and at most ${U32_MAX}`,\n );\n }\n if (writeBytes <= 0 || writeBytes > U32_MAX) {\n throw new Error(\n `writeBytes must be greater than 0 and at most ${U32_MAX}`,\n );\n }\n if (resourceFee <= 0n || resourceFee > HYPER_MAX_VALUE) {\n throw new Error(\n \"resourceFee must be greater than 0 and at most i64 max\",\n );\n }\n }\n\n const isDestinationContract = StrKey.isValidContract(destination);\n if (!isDestinationContract) {\n if (\n !StrKey.isValidEd25519PublicKey(destination) &&\n !StrKey.isValidMed25519PublicKey(destination)\n ) {\n throw new Error(\n \"Invalid destination address. Must be a valid Stellar address or contract ID.\",\n );\n }\n }\n\n // Resolve M... muxed addresses to their underlying G... address for\n // ledger key construction (Keypair.fromPublicKey only accepts G... keys).\n const destinationBaseAddress = isDestinationContract\n ? destination\n : extractBaseAddress(destination);\n\n if (\n destinationBaseAddress === extractBaseAddress(this.source.accountId())\n ) {\n throw new Error(\"Destination cannot be the same as the source account.\");\n }\n\n if (this.networkPassphrase === null) {\n throw new Error(\n \"networkPassphrase must be set to add a SAC transfer operation\",\n );\n }\n\n const contractId = asset.contractId(this.networkPassphrase);\n const functionName = \"transfer\";\n const source = this.source.accountId();\n const sourceBaseAddress = extractBaseAddress(source);\n const args = [\n nativeToScVal(source, { type: \"address\" }),\n nativeToScVal(destination, { type: \"address\" }),\n nativeToScVal(amount, { type: \"i128\" }),\n ];\n const isAssetNative = asset.isNative();\n\n const auths = new xdr.SorobanAuthorizationEntry({\n credentials: xdr.SorobanCredentials.sorobanCredentialsSourceAccount(),\n rootInvocation: new xdr.SorobanAuthorizedInvocation({\n function:\n xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeContractFn(\n new xdr.InvokeContractArgs({\n contractAddress: Address.fromString(contractId).toScAddress(),\n functionName,\n args,\n }),\n ),\n subInvocations: [],\n }),\n });\n\n const footprint = new xdr.LedgerFootprint({\n readOnly: [\n xdr.LedgerKey.contractData(\n new xdr.LedgerKeyContractData({\n contract: Address.fromString(contractId).toScAddress(),\n key: xdr.ScVal.scvLedgerKeyContractInstance(),\n durability: xdr.ContractDataDurability.persistent(),\n }),\n ),\n ],\n readWrite: [],\n });\n\n // Ledger entries for the destination account\n if (isDestinationContract) {\n footprint.readWrite().push(\n xdr.LedgerKey.contractData(\n new xdr.LedgerKeyContractData({\n contract: Address.fromString(contractId).toScAddress(),\n key: xdr.ScVal.scvVec([\n nativeToScVal(\"Balance\", { type: \"symbol\" }),\n nativeToScVal(destination, { type: \"address\" }),\n ]),\n durability: xdr.ContractDataDurability.persistent(),\n }),\n ),\n );\n\n if (!isAssetNative) {\n const assetIssuer = asset.getIssuer();\n\n if (!assetIssuer) {\n throw new Error(\"Asset issuer must be set for non-native assets.\");\n }\n\n footprint.readOnly().push(\n xdr.LedgerKey.account(\n new xdr.LedgerKeyAccount({\n accountId: Keypair.fromPublicKey(assetIssuer).xdrPublicKey(),\n }),\n ),\n );\n }\n } else if (isAssetNative) {\n footprint.readWrite().push(\n xdr.LedgerKey.account(\n new xdr.LedgerKeyAccount({\n accountId: Keypair.fromPublicKey(\n destinationBaseAddress,\n ).xdrPublicKey(),\n }),\n ),\n );\n } else if (asset.getIssuer() !== destinationBaseAddress) {\n footprint.readWrite().push(\n xdr.LedgerKey.trustline(\n new xdr.LedgerKeyTrustLine({\n accountId: Keypair.fromPublicKey(\n destinationBaseAddress,\n ).xdrPublicKey(),\n asset: asset.toTrustLineXDRObject(),\n }),\n ),\n );\n }\n\n // Ledger entries for the source account\n if (asset.isNative()) {\n footprint.readWrite().push(\n xdr.LedgerKey.account(\n new xdr.LedgerKeyAccount({\n accountId: Keypair.fromPublicKey(sourceBaseAddress).xdrPublicKey(),\n }),\n ),\n );\n } else if (asset.getIssuer() !== sourceBaseAddress) {\n footprint.readWrite().push(\n xdr.LedgerKey.trustline(\n new xdr.LedgerKeyTrustLine({\n accountId: Keypair.fromPublicKey(sourceBaseAddress).xdrPublicKey(),\n asset: asset.toTrustLineXDRObject(),\n }),\n ),\n );\n }\n\n const defaultPaymentFees = {\n instructions: 400_000,\n readBytes: 1_000,\n writeBytes: 1_000,\n resourceFee: BigInt(5_000_000),\n };\n\n const sorobanData = new xdr.SorobanTransactionData({\n resources: new xdr.SorobanResources({\n footprint,\n instructions: sorobanFees\n ? sorobanFees.instructions\n : defaultPaymentFees.instructions,\n diskReadBytes: sorobanFees\n ? sorobanFees.readBytes\n : defaultPaymentFees.readBytes,\n writeBytes: sorobanFees\n ? sorobanFees.writeBytes\n : defaultPaymentFees.writeBytes,\n }),\n ext: new xdr.SorobanTransactionDataExt(0),\n resourceFee: new xdr.Int64(\n sorobanFees ? sorobanFees.resourceFee : defaultPaymentFees.resourceFee,\n ),\n });\n const operation = Operation.invokeContractFunction({\n contract: contractId,\n function: functionName,\n args,\n auth: [auths],\n });\n this.setSorobanData(sorobanData);\n return this.addOperation(operation);\n }\n\n /**\n * Builds the transaction and increments the source account's sequence\n * number by 1.\n */\n build(): Transaction {\n const sequenceNumber = new BigNumber(this.source.sequenceNumber()).plus(1);\n const fee = new BigNumber(this.baseFee)\n .times(this.operations.length)\n .toNumber();\n\n if (fee > UINT32_MAX) {\n throw new Error(\n `Total fee (baseFee * operations) exceeds the maximum uint32 value (${UINT32_MAX}). ` +\n `Got ${fee} from baseFee=${this.baseFee} and ${this.operations.length} operation(s).`,\n );\n }\n\n const attrs: {\n fee: number;\n seqNum: xdr.SequenceNumber;\n memo: xdr.Memo | null;\n cond?: xdr.Preconditions;\n sourceAccount?: xdr.MuxedAccount;\n ext?: xdr.TransactionExt;\n } = {\n fee,\n seqNum: xdr.Int64.fromString(sequenceNumber.toString()),\n memo: this.memo ? this.memo.toXDRObject() : null,\n };\n\n if (\n this.timebounds === null ||\n typeof this.timebounds.minTime === \"undefined\" ||\n typeof this.timebounds.maxTime === \"undefined\"\n ) {\n throw new Error(\n \"TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).\",\n );\n }\n\n if (isValidDate(this.timebounds.minTime)) {\n this.timebounds.minTime = Math.floor(\n this.timebounds.minTime.getTime() / 1000,\n );\n }\n\n if (isValidDate(this.timebounds.maxTime)) {\n this.timebounds.maxTime = Math.floor(\n this.timebounds.maxTime.getTime() / 1000,\n );\n }\n\n const minTime = xdr.Uint64.fromString(this.timebounds.minTime.toString());\n const maxTime = xdr.Uint64.fromString(this.timebounds.maxTime.toString());\n\n const timeBounds = new xdr.TimeBounds({ minTime, maxTime });\n\n if (this.hasV2Preconditions()) {\n let ledgerBounds = null;\n\n if (this.ledgerbounds !== null) {\n ledgerBounds = new xdr.LedgerBounds({\n minLedger: this.ledgerbounds.minLedger ?? 0,\n maxLedger: this.ledgerbounds.maxLedger ?? 0,\n });\n }\n\n const minSeqNum = this.minAccountSequence\n ? xdr.Int64.fromString(this.minAccountSequence)\n : null;\n\n const minSeqAge = xdr.Uint64.fromString(\n this.minAccountSequenceAge !== null\n ? this.minAccountSequenceAge.toString()\n : \"0\",\n );\n\n const minSeqLedgerGap = this.minAccountSequenceLedgerGap || 0;\n\n const extraSigners =\n this.extraSigners !== null\n ? this.extraSigners.map((s) => SignerKey.decodeAddress(s))\n : [];\n\n attrs.cond = xdr.Preconditions.precondV2(\n new xdr.PreconditionsV2({\n timeBounds,\n ledgerBounds,\n minSeqNum,\n minSeqAge,\n minSeqLedgerGap,\n extraSigners,\n }),\n );\n } else {\n attrs.cond = xdr.Preconditions.precondTime(timeBounds);\n }\n\n attrs.sourceAccount = decodeAddressToMuxedAccount(this.source.accountId());\n\n // Previously used @ts-ignore and passed xdr.Void as second arg to TransactionExt(0)\n // due to broken TransactionExt types in dts-xdr.\n // Fixed upstream: https://github.com/stellar/dts-xdr/issues/5\n if (this.sorobanData) {\n attrs.ext = new xdr.TransactionExt(1, this.sorobanData);\n // Soroban transactions pay the resource fee in addition to the regular fee, so we need to add it here.\n attrs.fee = new BigNumber(attrs.fee)\n .plus(this.sorobanData.resourceFee().toString())\n .toNumber();\n\n if (attrs.fee > UINT32_MAX) {\n throw new Error(\n `Total fee (baseFee * operations + resourceFee) exceeds the maximum uint32 value (${UINT32_MAX}). ` +\n `Got ${attrs.fee}.`,\n );\n }\n } else {\n attrs.ext = new xdr.TransactionExt(0);\n }\n\n const xtx = new xdr.Transaction(\n attrs as ConstructorParameters<typeof xdr.Transaction>[0],\n );\n xtx.operations(this.operations);\n\n const txEnvelope = xdr.TransactionEnvelope.envelopeTypeTx(\n new xdr.TransactionV1Envelope({ tx: xtx, signatures: [] }),\n );\n\n if (this.networkPassphrase === null) {\n throw new Error(\"networkPassphrase must be set to build a transaction\");\n }\n\n const tx = new Transaction(txEnvelope, this.networkPassphrase);\n\n this.source.incrementSequenceNumber();\n\n return tx;\n }\n\n /**\n * Checks whether any v2 preconditions have been set on this builder.\n */\n hasV2Preconditions() {\n return (\n this.ledgerbounds !== null ||\n this.minAccountSequence !== null ||\n this.minAccountSequenceAge !== null ||\n this.minAccountSequenceLedgerGap !== null ||\n (this.extraSigners !== null && this.extraSigners.length > 0)\n );\n }\n\n /**\n * Builds a {@link FeeBumpTransaction}, enabling you to resubmit an existing\n * transaction with a higher fee.\n *\n * @param feeSource - account paying for the transaction,\n * in the form of either a Keypair (only the public key is used) or\n * an account ID (in G... or M... form, but refer to `withMuxing`)\n * @param baseFee - max fee willing to pay per operation\n * in inner transaction (**in stroops**)\n * @param innerTx - {@link Transaction} to be bumped by\n * the fee bump transaction\n * @param networkPassphrase - passphrase of the target\n * Stellar network (e.g. \"Public Global Stellar Network ; September 2015\",\n * see {@link Networks})\n *\n * TODO: Alongside the next major version bump, this type signature can be\n * changed to be less awkward: accept a MuxedAccount as the `feeSource`\n * rather than a keypair or string.\n *\n * Your fee-bump amount should be `>= 10x` the original fee.\n * @see https://developers.stellar.org/docs/glossary/fee-bumps/#replace-by-fee\n */\n static buildFeeBumpTransaction(\n feeSource: Keypair | string,\n baseFee: string,\n innerTx: Transaction,\n networkPassphrase: string,\n ): FeeBumpTransaction {\n const innerOps = innerTx.operations.length;\n\n const minBaseFee = new BigNumber(BASE_FEE);\n let resourceFee = new BigNumber(0);\n\n // Do we need to do special Soroban fee handling? We only want the fee-bump\n // requirement to match the inclusion fee, not the inclusion+resource fee.\n const env = innerTx.toEnvelope();\n switch (env.switch().value) {\n case xdr.EnvelopeType.envelopeTypeTx().value: {\n const sorobanData = env.v1().tx().ext().value();\n resourceFee = new BigNumber(sorobanData?.resourceFee().toString() ?? 0);\n\n break;\n }\n default:\n break;\n }\n const innerInclusionFee = new BigNumber(innerTx.fee)\n .minus(resourceFee)\n .div(innerOps);\n const base = new BigNumber(baseFee);\n\n // The fee rate for fee bump is at least the fee rate of the inner transaction\n if (base.lt(innerInclusionFee)) {\n throw new Error(\n `Invalid baseFee, it should be at least ${innerInclusionFee.toString()} stroops.`,\n );\n }\n\n // The fee rate is at least the minimum fee\n if (base.lt(minBaseFee)) {\n throw new Error(\n `Invalid baseFee, it should be at least ${minBaseFee.toString()} stroops.`,\n );\n }\n\n let innerTxEnvelope = innerTx.toEnvelope();\n if (innerTxEnvelope.switch() === xdr.EnvelopeType.envelopeTypeTxV0()) {\n const v0Tx = innerTxEnvelope.v0().tx();\n const v0TimeBounds = v0Tx.timeBounds();\n\n if (v0TimeBounds === null) {\n throw new Error(\"Inner transaction must have time bounds\");\n }\n\n const v1Tx = new xdr.Transaction({\n sourceAccount: xdr.MuxedAccount.keyTypeEd25519(\n v0Tx.sourceAccountEd25519(),\n ),\n fee: v0Tx.fee(),\n seqNum: v0Tx.seqNum(),\n cond: xdr.Preconditions.precondTime(v0TimeBounds),\n memo: v0Tx.memo(),\n operations: v0Tx.operations(),\n ext: new xdr.TransactionExt(0),\n });\n innerTxEnvelope = xdr.TransactionEnvelope.envelopeTypeTx(\n new xdr.TransactionV1Envelope({\n tx: v1Tx,\n signatures: innerTxEnvelope.v0().signatures(),\n }),\n );\n }\n\n let feeSourceAccount;\n if (typeof feeSource === \"string\") {\n feeSourceAccount = decodeAddressToMuxedAccount(feeSource);\n } else {\n feeSourceAccount = feeSource.xdrMuxedAccount();\n }\n\n const tx = new xdr.FeeBumpTransaction({\n feeSource: feeSourceAccount,\n fee: xdr.Int64.fromString(\n base\n .times(innerOps + 1)\n .plus(resourceFee)\n .toString(),\n ),\n innerTx: xdr.FeeBumpTransactionInnerTx.envelopeTypeTx(\n innerTxEnvelope.v1(),\n ),\n ext: new xdr.FeeBumpTransactionExt(0),\n });\n const feeBumpTxEnvelope = new xdr.FeeBumpTransactionEnvelope({\n tx,\n signatures: [],\n });\n const envelope =\n xdr.TransactionEnvelope.envelopeTypeTxFeeBump(feeBumpTxEnvelope);\n\n return new FeeBumpTransaction(envelope, networkPassphrase);\n }\n\n /**\n * Build a {@link Transaction} or {@link FeeBumpTransaction} from an\n * xdr.TransactionEnvelope.\n *\n * @param envelope - The transaction envelope\n * object or base64 encoded string.\n * @param networkPassphrase - The network passphrase of the target\n * Stellar network (e.g. \"Public Global Stellar Network ; September\n * 2015\"), see {@link Networks}.\n */\n static fromXDR(\n envelope: xdr.TransactionEnvelope | string,\n networkPassphrase: string,\n ): FeeBumpTransaction | Transaction {\n if (typeof envelope === \"string\") {\n envelope = xdr.TransactionEnvelope.fromXDR(envelope, \"base64\");\n }\n\n if (envelope.switch() === xdr.EnvelopeType.envelopeTypeTxFeeBump()) {\n return new FeeBumpTransaction(envelope, networkPassphrase);\n }\n\n return new Transaction(envelope, networkPassphrase);\n }\n}\n\n/**\n * Checks whether a provided object is a valid Date.\n * @param d - date object\n */\nexport function isValidDate(d: Date | number | string): d is Date {\n return d instanceof Date && !Number.isNaN(d.getTime());\n}\n\n/**\n * Converts a Date, number, or string time value to epoch seconds for\n * validation. Returns undefined if the value is undefined.\n */\nfunction toEpochSeconds(\n value: Date | number | string | undefined,\n): number | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n const num =\n value instanceof Date ? Math.floor(value.getTime() / 1000) : Number(value);\n\n if (!Number.isFinite(num) || num % 1 !== 0) {\n throw new Error(\"timebounds value must be a finite integer or Date\");\n }\n\n return num;\n}\n"],"names":["xdr"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,kBAAkB,KAAA,CAAM,SAAA;AAC9B,MAAM,UAAA,GAAa,UAAA;AAWZ,MAAM,QAAA,GAAW;AAMjB,MAAM,eAAA,GAAkB;AA4GxB,MAAM,kBAAA,CAAmB;AAAA,EAC9B,MAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EAIA,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A,EAAU,iBAAiB,CAAA;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,OAAO,OAAA,CACL,QAAA,EACA,iBAAA,EACkC;AAClC,IAAA,IAAI,OAAO,aAAa,QAAA,EAAU;AAChC,MAAA,QAAA,GAAWA,KAAA,CAAI,mBAAA,CAAoB,OAAA,CAAQ,QAAA,EAAU,QAAQ,CAAA;AAAA,IAC/D;AAEA,IAAA,IAAI,SAAS,MAAA,EAAO,KAAMA,KAAA,CAAI,YAAA,CAAa,uBAAsB,EAAG;AAClE,MAAA,OAAO,IAAI,kBAAA,CAAmB,QAAA,EAAU,iBAAiB,CAAA;AAAA,IAC3D;AAEA,IAAA,OAAO,IAAI,WAAA,CAAY,QAAA,EAAU,iBAAiB,CAAA;AAAA,EACpD;AACF;AAMO,SAAS,YAAY,CAAA,EAAsC;AAChE,EAAA,OAAO,aAAa,IAAA,IAAQ,CAAC,OAAO,KAAA,CAAM,CAAA,CAAE,SAAS,CAAA;AACvD;AAMA,SAAS,eACP,KAAA,EACoB;AACpB,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,GAAA,GACJ,KAAA,YAAiB,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,KAAA,CAAM,OAAA,EAAQ,GAAI,GAAI,CAAA,GAAI,MAAA,CAAO,KAAK,CAAA;AAE3E,EAAA,IAAI,CAAC,MAAA,CAAO,QAAA,CAAS,GAAG,CAAA,IAAK,GAAA,GAAM,MAAM,CAAA,EAAG;AAC1C,IAAA,MAAM,IAAI,MAAM,mDAAmD,CAAA;AAAA,EACrE;AAEA,EAAA,OAAO,GAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"transaction_builder.js","sources":["../../../src/base/transaction_builder.ts"],"sourcesContent":["import { Hyper } from \"@stellar/js-xdr\";\nimport BigNumber from \"./util/bignumber.js\";\n\nimport xdr from \"./xdr.js\";\n\nimport { Account } from \"./account.js\";\nimport { MuxedAccount } from \"./muxed_account.js\";\nimport type { TransactionSource } from \"./transaction_source.js\";\nimport {\n decodeAddressToMuxedAccount,\n extractBaseAddress,\n} from \"./util/decode_encode_muxed_account.js\";\n\nimport { Transaction } from \"./transaction.js\";\nimport { FeeBumpTransaction } from \"./fee_bump_transaction.js\";\nimport { SorobanDataBuilder } from \"./sorobandata_builder.js\";\n\nimport { StrKey } from \"./strkey.js\";\nimport { SignerKey } from \"./signerkey.js\";\nimport { Memo } from \"./memo.js\";\nimport { Asset } from \"./asset.js\";\nimport { nativeToScVal } from \"./scval.js\";\nimport { Operation } from \"./operation.js\";\nimport { Address } from \"./address.js\";\nimport { Keypair } from \"./keypair.js\";\n\nconst HYPER_MAX_VALUE = Hyper.MAX_VALUE as unknown as bigint;\nconst UINT32_MAX = 4294967295; // 2^32 - 1\n\n/**\n * Minimum base fee for transactions. If this fee is below the network\n * minimum, the transaction will fail. The more operations in the\n * transaction, the greater the required fee. Use\n * {@link Horizon.Server.fetchBaseFee} to get an accurate value of minimum\n * transaction fee on the network.\n *\n * @see [Fees](https://developers.stellar.org/docs/glossary/fees/)\n */\nexport const BASE_FEE = \"100\"; // Stroops\n\n/**\n * @see {@link TransactionBuilder.setTimeout}\n * @see [Timeout](https://developers.stellar.org/api/resources/transactions/post/)\n */\nexport const TimeoutInfinite = 0;\n\n/**\n * Soroban fee parameters for resource-limited transactions.\n */\nexport interface SorobanFees {\n /** The number of instructions executed by the transaction. */\n instructions: number;\n /** The number of bytes read from the ledger by the transaction. */\n readBytes: number;\n /** The number of bytes written to the ledger by the transaction. */\n writeBytes: number;\n /** The fee to be paid for the transaction, in stroops. */\n resourceFee: bigint;\n}\n\n/**\n * Options for constructing a {@link TransactionBuilder}.\n */\nexport interface TransactionBuilderOptions {\n /** Max fee you're willing to pay per operation in this transaction (**in stroops**). */\n fee: string;\n /** Memo for the transaction. */\n memo?: Memo;\n /**\n * Passphrase of the target Stellar network (e.g. \"Public Global Stellar\n * Network ; September 2015\" for the pubnet).\n */\n networkPassphrase?: string;\n /** Timebounds for the validity of this transaction. */\n timebounds?: {\n /** 64-bit UNIX timestamp or Date object. */\n minTime?: Date | number | string;\n /** 64-bit UNIX timestamp or Date object. */\n maxTime?: Date | number | string;\n };\n /** Ledger bounds for the validity of this transaction. */\n ledgerbounds?: {\n /** Number of the minimum ledger sequence. */\n minLedger?: number;\n /** Number of the maximum ledger sequence. */\n maxLedger?: number;\n };\n /** Minimum source account sequence number this transaction is valid for. */\n minAccountSequence?: string;\n /** Minimum seconds between source account sequence time and ledger time. */\n minAccountSequenceAge?: bigint;\n /** Minimum ledgers between source account sequence and current ledger. */\n minAccountSequenceLedgerGap?: number;\n /** List of extra signers required for this transaction. */\n extraSigners?: string[];\n /**\n * An instance of {@link xdr.SorobanTransactionData} or a base64 string.\n * Provides resource estimations for Soroban transactions. Has no effect on\n * non-contract transactions.\n */\n sorobanData?: xdr.SorobanTransactionData | string;\n}\n\n/**\n * <p>Transaction builder helps constructs a new `{@link Transaction}` using the\n * given {@link Account} as the transaction's \"source account\". The transaction\n * will use the current sequence number of the given account as its sequence\n * number and increment the given account's sequence number by one. The given\n * source account must include a private key for signing the transaction or an\n * error will be thrown.</p>\n *\n * <p>Operations can be added to the transaction via their corresponding builder\n * methods, and each returns the TransactionBuilder object so they can be\n * chained together. After adding the desired operations, call the `build()`\n * method on the `TransactionBuilder` to return a fully constructed\n * {@link Transaction} that can be signed. The returned transaction will contain the\n * sequence number of the source account and include the signature from the\n * source account.</p>\n *\n * <p><strong>Be careful about unsubmitted transactions!</strong> When you build\n * a transaction, `stellar-sdk` automatically increments the source account's\n * sequence number. If you end up not submitting this transaction and submitting\n * another one instead, it'll fail due to the sequence number being wrong. So if\n * you decide not to use a built transaction, make sure to update the source\n * account's sequence number with\n * [Server.loadAccount](https://stellar.github.io/js-stellar-sdk/Server.html#loadAccount)\n * before creating another transaction.</p>\n *\n * <p>The following code example creates a new transaction with {@link\n * Operation.createAccount} and {@link Operation.payment} operations. The\n * Transaction's source account first funds `destinationA`, then sends a payment\n * to `destinationB`. The built transaction is then signed by\n * `sourceKeypair`.</p>\n *\n * ```\n * var transaction = new TransactionBuilder(source, { fee, networkPassphrase: Networks.TESTNET })\n * .addOperation(Operation.createAccount({\n * destination: destinationA,\n * startingBalance: \"20\"\n * })) // <- funds and creates destinationA\n * .addOperation(Operation.payment({\n * destination: destinationB,\n * amount: \"100\",\n * asset: Asset.native()\n * })) // <- sends 100 XLM to destinationB\n * .setTimeout(30)\n * .build();\n *\n * transaction.sign(sourceKeypair);\n * ```\n *\n */\nexport class TransactionBuilder {\n source: TransactionSource;\n operations: xdr.Operation[];\n baseFee: string;\n timebounds: {\n minTime?: Date | number | string;\n maxTime?: Date | number | string;\n } | null;\n ledgerbounds: { minLedger?: number; maxLedger?: number } | null;\n minAccountSequence: string | null;\n minAccountSequenceAge: bigint | null;\n minAccountSequenceLedgerGap: number | null;\n extraSigners: string[] | null;\n memo: Memo;\n networkPassphrase: string | null;\n sorobanData: xdr.SorobanTransactionData | null;\n\n /**\n * @param sourceAccount - source account for this transaction\n * @param opts - options object (see {@link TransactionBuilderOptions})\n */\n constructor(\n sourceAccount: TransactionSource,\n opts: TransactionBuilderOptions = {} as TransactionBuilderOptions,\n ) {\n if (!sourceAccount) {\n throw new Error(\"must specify source account for the transaction\");\n }\n\n if (opts.fee === undefined) {\n throw new Error(\"must specify fee for the transaction (in stroops)\");\n }\n\n this.source = sourceAccount;\n this.operations = [];\n\n this.baseFee = opts.fee;\n if (opts.timebounds) {\n const minTime = toEpochSeconds(opts.timebounds.minTime);\n const maxTime = toEpochSeconds(opts.timebounds.maxTime);\n\n if (minTime !== undefined && minTime < 0) {\n throw new Error(\"min_time cannot be negative\");\n }\n\n if (maxTime !== undefined && maxTime < 0) {\n throw new Error(\"max_time cannot be negative\");\n }\n\n if (\n minTime !== undefined &&\n maxTime !== undefined &&\n maxTime > 0 &&\n minTime > maxTime\n ) {\n throw new Error(\"min_time cannot be greater than max_time\");\n }\n\n this.timebounds = { ...opts.timebounds };\n } else {\n this.timebounds = null;\n }\n\n if (opts.ledgerbounds) {\n const minLedger = opts.ledgerbounds.minLedger;\n const maxLedger = opts.ledgerbounds.maxLedger;\n\n if (minLedger !== undefined && minLedger < 0) {\n throw new Error(\"min_ledger cannot be negative\");\n }\n\n if (maxLedger !== undefined && maxLedger < 0) {\n throw new Error(\"max_ledger cannot be negative\");\n }\n\n if (\n minLedger !== undefined &&\n maxLedger !== undefined &&\n maxLedger > 0 &&\n minLedger > maxLedger\n ) {\n throw new Error(\"min_ledger cannot be greater than max_ledger\");\n }\n\n this.ledgerbounds = { ...opts.ledgerbounds };\n } else {\n this.ledgerbounds = null;\n }\n this.minAccountSequence = opts.minAccountSequence || null;\n this.minAccountSequenceAge =\n opts.minAccountSequenceAge !== undefined\n ? opts.minAccountSequenceAge\n : null;\n this.minAccountSequenceLedgerGap =\n opts.minAccountSequenceLedgerGap !== undefined\n ? opts.minAccountSequenceLedgerGap\n : null;\n this.extraSigners = opts.extraSigners ? [...opts.extraSigners] : null;\n this.memo = opts.memo || Memo.none();\n this.networkPassphrase = opts.networkPassphrase || null;\n\n this.sorobanData = opts.sorobanData\n ? new SorobanDataBuilder(opts.sorobanData).build()\n : null;\n }\n\n /**\n * Creates a builder instance using an existing {@link Transaction} as a\n * template, ignoring any existing envelope signatures.\n *\n * Note that the sequence number WILL be cloned, so EITHER this transaction or\n * the one it was cloned from will be valid. This is useful in situations\n * where you are constructing a transaction in pieces and need to make\n * adjustments as you go (for example, when filling out Soroban resource\n * information).\n *\n * @param tx - a \"template\" transaction to clone exactly\n * @param opts - additional options to override the clone, e.g.\n * `{fee: '1000'}` will override the existing base fee derived from `tx`\n * (see the {@link TransactionBuilder} constructor for detailed options)\n *\n * **Warning:** This does not clone the transaction's\n * {@link xdr.SorobanTransactionData} (if applicable), use\n * {@link SorobanDataBuilder} and {@link TransactionBuilder.setSorobanData}\n * as needed, instead.\n *\n * TODO: This cannot clone {@link FeeBumpTransaction}s, yet.\n */\n static cloneFrom(\n tx: Transaction,\n opts: Partial<TransactionBuilderOptions> = {},\n ): TransactionBuilder {\n if (!(tx instanceof Transaction)) {\n throw new TypeError(`expected a 'Transaction', got: ${String(tx)}`);\n }\n\n const sequenceNum = (BigInt(tx.sequence) - 1n).toString();\n\n let source;\n\n // rebuild the source account based on the strkey\n if (StrKey.isValidMed25519PublicKey(tx.source)) {\n source = MuxedAccount.fromAddress(tx.source, sequenceNum);\n } else if (StrKey.isValidEd25519PublicKey(tx.source)) {\n source = new Account(tx.source, sequenceNum);\n } else {\n throw new TypeError(`unsupported tx source account: ${tx.source}`);\n }\n\n if (tx.operations.length === 0) {\n throw new Error(\n \"cannot clone a transaction with no operations: \" +\n \"per-operation base fee cannot be determined\",\n );\n }\n\n // if this is a Soroban transaction, the resource fee is folded into the\n // total fee and gets re-added on build(), so it has to be excluded before\n // deriving the per-operation base fee\n let sorobanData: xdr.SorobanTransactionData | undefined;\n const envelope = tx.toEnvelope();\n if (envelope.switch() === xdr.EnvelopeType.envelopeTypeTx()) {\n sorobanData = envelope.v1().tx().ext().value() ?? undefined;\n }\n let totalFee = parseInt(tx.fee, 10);\n if (sorobanData) {\n const resourceFee = Number(sorobanData.resourceFee().toBigInt());\n // only subtract if it leaves a positive inclusion fee: a malformed tx\n // can declare a resource fee that eats the entire fee (or more)\n if (totalFee - resourceFee > 0) {\n totalFee -= resourceFee;\n }\n }\n\n // the initial fee passed to the builder gets scaled up based on the number\n // of operations at the end, so we have to down-scale first\n const unscaledFee = Math.floor(totalFee / tx.operations.length);\n\n const builderOpts: TransactionBuilderOptions = {\n fee: (unscaledFee || BASE_FEE).toString(),\n memo: tx.memo,\n networkPassphrase: tx.networkPassphrase,\n };\n\n if (tx.timeBounds) {\n builderOpts.timebounds = tx.timeBounds;\n }\n if (tx.ledgerBounds) {\n builderOpts.ledgerbounds = tx.ledgerBounds;\n }\n if (tx.minAccountSequence) {\n builderOpts.minAccountSequence = tx.minAccountSequence;\n }\n if (tx.minAccountSequenceAge !== undefined) {\n builderOpts.minAccountSequenceAge = tx.minAccountSequenceAge;\n }\n if (tx.minAccountSequenceLedgerGap !== undefined) {\n builderOpts.minAccountSequenceLedgerGap = tx.minAccountSequenceLedgerGap;\n }\n if (tx.extraSigners) {\n builderOpts.extraSigners = tx.extraSigners.map((s) =>\n SignerKey.encodeSignerKey(s),\n );\n }\n\n // User-provided opts override transaction defaults\n Object.assign(builderOpts, opts);\n\n const builder = new TransactionBuilder(source, builderOpts);\n\n tx.tx.operations().forEach((op) => builder.addOperation(op));\n\n return builder;\n }\n\n /**\n * Adds an operation to the transaction.\n *\n * @param operation - The xdr operation object, use {@link\n * Operation} static methods.\n */\n addOperation(operation: xdr.Operation): TransactionBuilder {\n this.operations.push(operation);\n return this;\n }\n\n /**\n * Adds an operation to the transaction at a specific index.\n *\n * @param operation - The xdr operation object to add, use {@link Operation} static methods.\n * @param index - The index at which to insert the operation.\n */\n addOperationAt(operation: xdr.Operation, index: number): TransactionBuilder {\n this.operations.splice(index, 0, operation);\n return this;\n }\n\n /**\n * Removes the operations from the builder (useful when cloning).\n */\n clearOperations(): TransactionBuilder {\n this.operations = [];\n return this;\n }\n\n /**\n * Removes the operation at the specified index from the transaction.\n *\n * @param index - The index of the operation to remove.\n */\n clearOperationAt(index: number): TransactionBuilder {\n this.operations.splice(index, 1);\n return this;\n }\n\n /**\n * Adds a memo to the transaction.\n * @param memo - {@link Memo} object\n */\n addMemo(memo: Memo): TransactionBuilder {\n this.memo = memo;\n return this;\n }\n\n /**\n * Sets a timeout precondition on the transaction.\n *\n * Because of the distributed nature of the Stellar network it is possible\n * that the status of your transaction will be determined after a long time\n * if the network is highly congested. If you want to be sure to receive the\n * status of the transaction within a given period you should set the\n * time bounds with `maxTime` on the transaction (this is what `setTimeout`\n * does internally; if there's `minTime` set but no `maxTime` it will be\n * added).\n *\n * A call to `TransactionBuilder.setTimeout` is **required** if Transaction\n * does not have `max_time` set. If you don't want to set timeout, use\n * {@link TimeoutInfinite}. In general you should set\n * {@link TimeoutInfinite} only in smart contracts.\n *\n * Please note that Horizon may still return <code>504 Gateway Timeout</code>\n * error, even for short timeouts. In such case you need to resubmit the same\n * transaction again without making any changes to receive a status. This\n * method is using the machine system time (UTC), make sure it is set\n * correctly.\n *\n * @param timeoutSeconds - Number of seconds the transaction is good.\n * Can't be negative. If the value is {@link TimeoutInfinite}, the\n * transaction is good indefinitely.\n *\n * @see {@link TimeoutInfinite}\n * @see https://developers.stellar.org/docs/tutorials/handling-errors/\n */\n setTimeout(timeoutSeconds: number): TransactionBuilder {\n if (this.timebounds !== null && Number(this.timebounds.maxTime) > 0) {\n throw new Error(\n \"TimeBounds.max_time has been already set - setting timeout would overwrite it.\",\n );\n }\n\n if (timeoutSeconds < 0) {\n throw new Error(\"timeout cannot be negative\");\n }\n\n if (timeoutSeconds > 0) {\n const timeoutTimestamp = Math.floor(Date.now() / 1000) + timeoutSeconds;\n\n if (this.timebounds === null) {\n this.timebounds = { minTime: 0, maxTime: timeoutTimestamp };\n } else {\n this.timebounds = {\n minTime: this.timebounds.minTime ?? 0,\n maxTime: timeoutTimestamp,\n };\n }\n } else {\n this.timebounds = {\n minTime: 0,\n maxTime: 0,\n };\n }\n\n return this;\n }\n\n /**\n * If you want to prepare a transaction which will become valid at some point\n * in the future, or be invalid after some time, you can set a timebounds\n * precondition. Internally this will set the `minTime`, and `maxTime`\n * preconditions. Conflicts with `setTimeout`, so use one or the other.\n *\n * @param minEpochOrDate - Either a JS Date object, or a number\n * of UNIX epoch seconds. The transaction is valid after this timestamp.\n * Can't be negative. If the value is `0`, the transaction is valid\n * immediately.\n * @param maxEpochOrDate - Either a JS Date object, or a number\n * of UNIX epoch seconds. The transaction is valid until this timestamp.\n * Can't be negative. If the value is `0`, the transaction is valid\n * indefinitely.\n */\n setTimebounds(\n minEpochOrDate: Date | number,\n maxEpochOrDate: Date | number,\n ): TransactionBuilder {\n // Force it to a date type\n if (typeof minEpochOrDate === \"number\") {\n minEpochOrDate = new Date(minEpochOrDate * 1000);\n }\n if (typeof maxEpochOrDate === \"number\") {\n maxEpochOrDate = new Date(maxEpochOrDate * 1000);\n }\n\n if (this.timebounds !== null) {\n throw new Error(\n \"TimeBounds has been already set - setting timebounds would overwrite it.\",\n );\n }\n\n // Convert that date to the epoch seconds\n const minTime = Math.floor(minEpochOrDate.valueOf() / 1000);\n const maxTime = Math.floor(maxEpochOrDate.valueOf() / 1000);\n if (minTime < 0) {\n throw new Error(\"min_time cannot be negative\");\n }\n if (maxTime < 0) {\n throw new Error(\"max_time cannot be negative\");\n }\n if (maxTime > 0 && minTime > maxTime) {\n throw new Error(\"min_time cannot be greater than max_time\");\n }\n\n this.timebounds = { minTime, maxTime };\n\n return this;\n }\n\n /**\n * If you want to prepare a transaction which will only be valid within some\n * range of ledgers, you can set a ledgerbounds precondition.\n * Internally this will set the `minLedger` and `maxLedger` preconditions.\n *\n * @param minLedger - The minimum ledger this transaction is valid at\n * or after. Cannot be negative. If the value is `0` (the default), the\n * transaction is valid immediately.\n *\n * @param maxLedger - The maximum ledger this transaction is valid\n * before. Cannot be negative. If the value is `0`, the transaction is\n * valid indefinitely.\n */\n setLedgerbounds(minLedger: number, maxLedger: number): TransactionBuilder {\n if (this.ledgerbounds !== null) {\n throw new Error(\n \"LedgerBounds has been already set - setting ledgerbounds would overwrite it.\",\n );\n }\n\n if (minLedger < 0) {\n throw new Error(\"min_ledger cannot be negative\");\n }\n if (maxLedger < 0) {\n throw new Error(\"max_ledger cannot be negative\");\n }\n if (maxLedger > 0 && minLedger > maxLedger) {\n throw new Error(\"min_ledger cannot be greater than max_ledger\");\n }\n\n this.ledgerbounds = { minLedger, maxLedger };\n\n return this;\n }\n\n /**\n * If you want to prepare a transaction which will be valid only while the\n * account sequence number is\n *\n * `minAccountSequence <= sourceAccountSequence < tx.seqNum`\n *\n * Note that after execution the account's sequence number is always raised to\n * `tx.seqNum`. Internally this will set the `minAccountSequence`\n * precondition.\n *\n * @param minAccountSequence - The minimum source account sequence\n * number this transaction is valid for. If the value is `0` (the\n * default), the transaction is valid when `sourceAccount`'s sequence\n * number `== tx.seqNum - 1`.\n */\n setMinAccountSequence(minAccountSequence: string): TransactionBuilder {\n if (this.minAccountSequence !== null) {\n throw new Error(\n \"min_account_sequence has been already set - setting min_account_sequence would overwrite it.\",\n );\n }\n\n this.minAccountSequence = minAccountSequence;\n\n return this;\n }\n\n /**\n * For the transaction to be valid, the current ledger time must be at least\n * `minAccountSequenceAge` greater than sourceAccount's `sequenceTime`.\n * Internally this will set the `minAccountSequenceAge` precondition.\n *\n * @param durationInSeconds - The minimum amount of time between\n * source account sequence time and the ledger time when this transaction\n * will become valid. If the value is `0`, the transaction is unrestricted\n * by the account sequence age. Cannot be negative.\n */\n setMinAccountSequenceAge(durationInSeconds: bigint): TransactionBuilder {\n if (typeof durationInSeconds !== \"bigint\") {\n throw new Error(\"min_account_sequence_age must be a bigint\");\n }\n if (this.minAccountSequenceAge !== null) {\n throw new Error(\n \"min_account_sequence_age has been already set - setting min_account_sequence_age would overwrite it.\",\n );\n }\n\n if (durationInSeconds < 0) {\n throw new Error(\"min_account_sequence_age cannot be negative\");\n }\n\n this.minAccountSequenceAge = durationInSeconds;\n\n return this;\n }\n\n /**\n * For the transaction to be valid, the current ledger number must be at least\n * `minAccountSequenceLedgerGap` greater than sourceAccount's ledger sequence.\n * Internally this will set the `minAccountSequenceLedgerGap` precondition.\n *\n * @param gap - The minimum number of ledgers between source account\n * sequence and the ledger number when this transaction will become valid.\n * If the value is `0`, the transaction is unrestricted by the account\n * sequence ledger. Cannot be negative.\n */\n setMinAccountSequenceLedgerGap(gap: number): TransactionBuilder {\n if (this.minAccountSequenceLedgerGap !== null) {\n throw new Error(\n \"min_account_sequence_ledger_gap has been already set - setting min_account_sequence_ledger_gap would overwrite it.\",\n );\n }\n\n if (gap < 0) {\n throw new Error(\"min_account_sequence_ledger_gap cannot be negative\");\n }\n\n this.minAccountSequenceLedgerGap = gap;\n\n return this;\n }\n\n /**\n * For the transaction to be valid, there must be a signature corresponding to\n * every Signer in this array, even if the signature is not otherwise required\n * by the sourceAccount or operations. Internally this will set the\n * `extraSigners` precondition.\n *\n * @param extraSigners - required extra signers (as {@link StrKey}s)\n */\n setExtraSigners(extraSigners: string[]): TransactionBuilder {\n if (!Array.isArray(extraSigners)) {\n throw new Error(\"extra_signers must be an array of strings.\");\n }\n\n if (this.extraSigners !== null) {\n throw new Error(\n \"extra_signers has been already set - setting extra_signers would overwrite it.\",\n );\n }\n\n if (extraSigners.length > 2) {\n throw new Error(\"extra_signers cannot be longer than 2 elements.\");\n }\n\n this.extraSigners = [...extraSigners];\n\n return this;\n }\n\n /**\n * Set network passphrase for the Transaction that will be built.\n *\n * @param networkPassphrase - passphrase of the target Stellar\n * network (e.g. \"Public Global Stellar Network ; September 2015\").\n */\n setNetworkPassphrase(networkPassphrase: string): TransactionBuilder {\n this.networkPassphrase = networkPassphrase;\n return this;\n }\n\n /**\n * Sets the transaction's internal Soroban transaction data (resources,\n * footprint, etc.).\n *\n * For non-contract(non-Soroban) transactions, this setting has no effect. In\n * the case of Soroban transactions, this is either an instance of\n * {@link xdr.SorobanTransactionData} or a base64-encoded string of said\n * structure. This is usually obtained from the simulation response based on a\n * transaction with a Soroban operation (e.g.\n * {@link Operation.invokeHostFunction}, providing necessary resource\n * and storage footprint estimations for contract invocation.\n *\n * @param sorobanData - the {@link xdr.SorobanTransactionData} as a raw xdr\n * object or a base64 string to be decoded\n *\n * @see {@link SorobanDataBuilder}\n */\n setSorobanData(\n sorobanData: xdr.SorobanTransactionData | string,\n ): TransactionBuilder {\n this.sorobanData = new SorobanDataBuilder(sorobanData).build();\n return this;\n }\n\n /**\n * Creates and adds an invoke host function operation for transferring SAC tokens.\n * This method removes the need for simulation by handling the creation of the\n * appropriate authorization entries and ledger footprint for the transfer operation.\n *\n * @param destination - the address of the recipient of the SAC transfer (should be a valid Stellar address or contract ID)\n * @param asset - the SAC asset to be transferred\n * @param amount - the amount of tokens to be transferred in 7 decimals. IE 1 token with 7 decimals of precision would be represented as \"1_0000000\"\n * @param sorobanFees - optional Soroban fees for the transaction to override the default fees used\n */\n addSacTransferOperation(\n destination: string,\n asset: Asset,\n amount: bigint | string,\n sorobanFees?: SorobanFees,\n ): TransactionBuilder {\n if (BigInt(amount) <= 0n) {\n throw new Error(\"Amount must be a positive integer\");\n } else if (BigInt(amount) > HYPER_MAX_VALUE) {\n // The largest supported value for SAC is i64 however the contract interface uses i128 which is why we convert it to i128\n throw new Error(\"Amount exceeds maximum value for i64\");\n }\n\n if (sorobanFees) {\n const { instructions, readBytes, writeBytes, resourceFee } = sorobanFees;\n const U32_MAX = 4294967295;\n\n if (instructions <= 0 || instructions > U32_MAX) {\n throw new Error(\n `instructions must be greater than 0 and at most ${U32_MAX}`,\n );\n }\n if (readBytes <= 0 || readBytes > U32_MAX) {\n throw new Error(\n `readBytes must be greater than 0 and at most ${U32_MAX}`,\n );\n }\n if (writeBytes <= 0 || writeBytes > U32_MAX) {\n throw new Error(\n `writeBytes must be greater than 0 and at most ${U32_MAX}`,\n );\n }\n if (resourceFee <= 0n || resourceFee > HYPER_MAX_VALUE) {\n throw new Error(\n \"resourceFee must be greater than 0 and at most i64 max\",\n );\n }\n }\n\n const isDestinationContract = StrKey.isValidContract(destination);\n if (!isDestinationContract) {\n if (\n !StrKey.isValidEd25519PublicKey(destination) &&\n !StrKey.isValidMed25519PublicKey(destination)\n ) {\n throw new Error(\n \"Invalid destination address. Must be a valid Stellar address or contract ID.\",\n );\n }\n }\n\n // Resolve M... muxed addresses to their underlying G... address for\n // ledger key construction (Keypair.fromPublicKey only accepts G... keys).\n const destinationBaseAddress = isDestinationContract\n ? destination\n : extractBaseAddress(destination);\n\n if (\n destinationBaseAddress === extractBaseAddress(this.source.accountId())\n ) {\n throw new Error(\"Destination cannot be the same as the source account.\");\n }\n\n if (this.networkPassphrase === null) {\n throw new Error(\n \"networkPassphrase must be set to add a SAC transfer operation\",\n );\n }\n\n const contractId = asset.contractId(this.networkPassphrase);\n const functionName = \"transfer\";\n const source = this.source.accountId();\n const sourceBaseAddress = extractBaseAddress(source);\n const args = [\n nativeToScVal(source, { type: \"address\" }),\n nativeToScVal(destination, { type: \"address\" }),\n nativeToScVal(amount, { type: \"i128\" }),\n ];\n const isAssetNative = asset.isNative();\n\n const auths = new xdr.SorobanAuthorizationEntry({\n credentials: xdr.SorobanCredentials.sorobanCredentialsSourceAccount(),\n rootInvocation: new xdr.SorobanAuthorizedInvocation({\n function:\n xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeContractFn(\n new xdr.InvokeContractArgs({\n contractAddress: Address.fromString(contractId).toScAddress(),\n functionName,\n args,\n }),\n ),\n subInvocations: [],\n }),\n });\n\n const footprint = new xdr.LedgerFootprint({\n readOnly: [\n xdr.LedgerKey.contractData(\n new xdr.LedgerKeyContractData({\n contract: Address.fromString(contractId).toScAddress(),\n key: xdr.ScVal.scvLedgerKeyContractInstance(),\n durability: xdr.ContractDataDurability.persistent(),\n }),\n ),\n ],\n readWrite: [],\n });\n\n // Ledger entries for the destination account\n if (isDestinationContract) {\n footprint.readWrite().push(\n xdr.LedgerKey.contractData(\n new xdr.LedgerKeyContractData({\n contract: Address.fromString(contractId).toScAddress(),\n key: xdr.ScVal.scvVec([\n nativeToScVal(\"Balance\", { type: \"symbol\" }),\n nativeToScVal(destination, { type: \"address\" }),\n ]),\n durability: xdr.ContractDataDurability.persistent(),\n }),\n ),\n );\n\n if (!isAssetNative) {\n const assetIssuer = asset.getIssuer();\n\n if (!assetIssuer) {\n throw new Error(\"Asset issuer must be set for non-native assets.\");\n }\n\n footprint.readOnly().push(\n xdr.LedgerKey.account(\n new xdr.LedgerKeyAccount({\n accountId: Keypair.fromPublicKey(assetIssuer).xdrPublicKey(),\n }),\n ),\n );\n }\n } else if (isAssetNative) {\n footprint.readWrite().push(\n xdr.LedgerKey.account(\n new xdr.LedgerKeyAccount({\n accountId: Keypair.fromPublicKey(\n destinationBaseAddress,\n ).xdrPublicKey(),\n }),\n ),\n );\n } else if (asset.getIssuer() !== destinationBaseAddress) {\n footprint.readWrite().push(\n xdr.LedgerKey.trustline(\n new xdr.LedgerKeyTrustLine({\n accountId: Keypair.fromPublicKey(\n destinationBaseAddress,\n ).xdrPublicKey(),\n asset: asset.toTrustLineXDRObject(),\n }),\n ),\n );\n }\n\n // Ledger entries for the source account\n if (asset.isNative()) {\n footprint.readWrite().push(\n xdr.LedgerKey.account(\n new xdr.LedgerKeyAccount({\n accountId: Keypair.fromPublicKey(sourceBaseAddress).xdrPublicKey(),\n }),\n ),\n );\n } else if (asset.getIssuer() !== sourceBaseAddress) {\n footprint.readWrite().push(\n xdr.LedgerKey.trustline(\n new xdr.LedgerKeyTrustLine({\n accountId: Keypair.fromPublicKey(sourceBaseAddress).xdrPublicKey(),\n asset: asset.toTrustLineXDRObject(),\n }),\n ),\n );\n }\n\n const defaultPaymentFees = {\n instructions: 400_000,\n readBytes: 1_000,\n writeBytes: 1_000,\n resourceFee: BigInt(5_000_000),\n };\n\n const sorobanData = new xdr.SorobanTransactionData({\n resources: new xdr.SorobanResources({\n footprint,\n instructions: sorobanFees\n ? sorobanFees.instructions\n : defaultPaymentFees.instructions,\n diskReadBytes: sorobanFees\n ? sorobanFees.readBytes\n : defaultPaymentFees.readBytes,\n writeBytes: sorobanFees\n ? sorobanFees.writeBytes\n : defaultPaymentFees.writeBytes,\n }),\n ext: new xdr.SorobanTransactionDataExt(0),\n resourceFee: new xdr.Int64(\n sorobanFees ? sorobanFees.resourceFee : defaultPaymentFees.resourceFee,\n ),\n });\n const operation = Operation.invokeContractFunction({\n contract: contractId,\n function: functionName,\n args,\n auth: [auths],\n });\n this.setSorobanData(sorobanData);\n return this.addOperation(operation);\n }\n\n /**\n * Builds the transaction and increments the source account's sequence\n * number by 1.\n */\n build(): Transaction {\n const sequenceNumber = new BigNumber(this.source.sequenceNumber()).plus(1);\n const fee = new BigNumber(this.baseFee)\n .times(this.operations.length)\n .toNumber();\n\n if (fee > UINT32_MAX) {\n throw new Error(\n `Total fee (baseFee * operations) exceeds the maximum uint32 value (${UINT32_MAX}). ` +\n `Got ${fee} from baseFee=${this.baseFee} and ${this.operations.length} operation(s).`,\n );\n }\n\n const attrs: {\n fee: number;\n seqNum: xdr.SequenceNumber;\n memo: xdr.Memo | null;\n cond?: xdr.Preconditions;\n sourceAccount?: xdr.MuxedAccount;\n ext?: xdr.TransactionExt;\n } = {\n fee,\n seqNum: xdr.Int64.fromString(sequenceNumber.toString()),\n memo: this.memo ? this.memo.toXDRObject() : null,\n };\n\n if (\n this.timebounds === null ||\n typeof this.timebounds.minTime === \"undefined\" ||\n typeof this.timebounds.maxTime === \"undefined\"\n ) {\n throw new Error(\n \"TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).\",\n );\n }\n\n if (isValidDate(this.timebounds.minTime)) {\n this.timebounds.minTime = Math.floor(\n this.timebounds.minTime.getTime() / 1000,\n );\n }\n\n if (isValidDate(this.timebounds.maxTime)) {\n this.timebounds.maxTime = Math.floor(\n this.timebounds.maxTime.getTime() / 1000,\n );\n }\n\n const minTime = xdr.Uint64.fromString(this.timebounds.minTime.toString());\n const maxTime = xdr.Uint64.fromString(this.timebounds.maxTime.toString());\n\n const timeBounds = new xdr.TimeBounds({ minTime, maxTime });\n\n if (this.hasV2Preconditions()) {\n let ledgerBounds = null;\n\n if (this.ledgerbounds !== null) {\n ledgerBounds = new xdr.LedgerBounds({\n minLedger: this.ledgerbounds.minLedger ?? 0,\n maxLedger: this.ledgerbounds.maxLedger ?? 0,\n });\n }\n\n const minSeqNum = this.minAccountSequence\n ? xdr.Int64.fromString(this.minAccountSequence)\n : null;\n\n const minSeqAge = xdr.Uint64.fromString(\n this.minAccountSequenceAge !== null\n ? this.minAccountSequenceAge.toString()\n : \"0\",\n );\n\n const minSeqLedgerGap = this.minAccountSequenceLedgerGap || 0;\n\n const extraSigners =\n this.extraSigners !== null\n ? this.extraSigners.map((s) => SignerKey.decodeAddress(s))\n : [];\n\n attrs.cond = xdr.Preconditions.precondV2(\n new xdr.PreconditionsV2({\n timeBounds,\n ledgerBounds,\n minSeqNum,\n minSeqAge,\n minSeqLedgerGap,\n extraSigners,\n }),\n );\n } else {\n attrs.cond = xdr.Preconditions.precondTime(timeBounds);\n }\n\n attrs.sourceAccount = decodeAddressToMuxedAccount(this.source.accountId());\n\n // Previously used @ts-ignore and passed xdr.Void as second arg to TransactionExt(0)\n // due to broken TransactionExt types in dts-xdr.\n // Fixed upstream: https://github.com/stellar/dts-xdr/issues/5\n if (this.sorobanData) {\n attrs.ext = new xdr.TransactionExt(1, this.sorobanData);\n // Soroban transactions pay the resource fee in addition to the regular fee, so we need to add it here.\n attrs.fee = new BigNumber(attrs.fee)\n .plus(this.sorobanData.resourceFee().toString())\n .toNumber();\n\n if (attrs.fee > UINT32_MAX) {\n throw new Error(\n `Total fee (baseFee * operations + resourceFee) exceeds the maximum uint32 value (${UINT32_MAX}). ` +\n `Got ${attrs.fee}.`,\n );\n }\n } else {\n attrs.ext = new xdr.TransactionExt(0);\n }\n\n const xtx = new xdr.Transaction(\n attrs as ConstructorParameters<typeof xdr.Transaction>[0],\n );\n xtx.operations(this.operations);\n\n const txEnvelope = xdr.TransactionEnvelope.envelopeTypeTx(\n new xdr.TransactionV1Envelope({ tx: xtx, signatures: [] }),\n );\n\n if (this.networkPassphrase === null) {\n throw new Error(\"networkPassphrase must be set to build a transaction\");\n }\n\n const tx = new Transaction(txEnvelope, this.networkPassphrase);\n\n this.source.incrementSequenceNumber();\n\n return tx;\n }\n\n /**\n * Checks whether any v2 preconditions have been set on this builder.\n */\n hasV2Preconditions() {\n return (\n this.ledgerbounds !== null ||\n this.minAccountSequence !== null ||\n this.minAccountSequenceAge !== null ||\n this.minAccountSequenceLedgerGap !== null ||\n (this.extraSigners !== null && this.extraSigners.length > 0)\n );\n }\n\n /**\n * Builds a {@link FeeBumpTransaction}, enabling you to resubmit an existing\n * transaction with a higher fee.\n *\n * @param feeSource - account paying for the transaction,\n * in the form of either a Keypair (only the public key is used) or\n * an account ID (in G... or M... form, but refer to `withMuxing`)\n * @param baseFee - max fee willing to pay per operation\n * in inner transaction (**in stroops**)\n * @param innerTx - {@link Transaction} to be bumped by\n * the fee bump transaction\n * @param networkPassphrase - passphrase of the target\n * Stellar network (e.g. \"Public Global Stellar Network ; September 2015\",\n * see {@link Networks})\n *\n * TODO: Alongside the next major version bump, this type signature can be\n * changed to be less awkward: accept a MuxedAccount as the `feeSource`\n * rather than a keypair or string.\n *\n * Your fee-bump amount should be `>= 10x` the original fee.\n * @see https://developers.stellar.org/docs/glossary/fee-bumps/#replace-by-fee\n */\n static buildFeeBumpTransaction(\n feeSource: Keypair | string,\n baseFee: string,\n innerTx: Transaction,\n networkPassphrase: string,\n ): FeeBumpTransaction {\n const innerOps = innerTx.operations.length;\n\n const minBaseFee = new BigNumber(BASE_FEE);\n let resourceFee = new BigNumber(0);\n\n // Do we need to do special Soroban fee handling? We only want the fee-bump\n // requirement to match the inclusion fee, not the inclusion+resource fee.\n const env = innerTx.toEnvelope();\n switch (env.switch().value) {\n case xdr.EnvelopeType.envelopeTypeTx().value: {\n const sorobanData = env.v1().tx().ext().value();\n resourceFee = new BigNumber(sorobanData?.resourceFee().toString() ?? 0);\n\n break;\n }\n default:\n break;\n }\n const innerInclusionFee = new BigNumber(innerTx.fee)\n .minus(resourceFee)\n .div(innerOps);\n const base = new BigNumber(baseFee);\n\n // The fee rate for fee bump is at least the fee rate of the inner transaction\n if (base.lt(innerInclusionFee)) {\n throw new Error(\n `Invalid baseFee, it should be at least ${innerInclusionFee.toString()} stroops.`,\n );\n }\n\n // The fee rate is at least the minimum fee\n if (base.lt(minBaseFee)) {\n throw new Error(\n `Invalid baseFee, it should be at least ${minBaseFee.toString()} stroops.`,\n );\n }\n\n let innerTxEnvelope = innerTx.toEnvelope();\n if (innerTxEnvelope.switch() === xdr.EnvelopeType.envelopeTypeTxV0()) {\n const v0Tx = innerTxEnvelope.v0().tx();\n const v0TimeBounds = v0Tx.timeBounds();\n\n if (v0TimeBounds === null) {\n throw new Error(\"Inner transaction must have time bounds\");\n }\n\n const v1Tx = new xdr.Transaction({\n sourceAccount: xdr.MuxedAccount.keyTypeEd25519(\n v0Tx.sourceAccountEd25519(),\n ),\n fee: v0Tx.fee(),\n seqNum: v0Tx.seqNum(),\n cond: xdr.Preconditions.precondTime(v0TimeBounds),\n memo: v0Tx.memo(),\n operations: v0Tx.operations(),\n ext: new xdr.TransactionExt(0),\n });\n innerTxEnvelope = xdr.TransactionEnvelope.envelopeTypeTx(\n new xdr.TransactionV1Envelope({\n tx: v1Tx,\n signatures: innerTxEnvelope.v0().signatures(),\n }),\n );\n }\n\n let feeSourceAccount;\n if (typeof feeSource === \"string\") {\n feeSourceAccount = decodeAddressToMuxedAccount(feeSource);\n } else {\n feeSourceAccount = feeSource.xdrMuxedAccount();\n }\n\n const tx = new xdr.FeeBumpTransaction({\n feeSource: feeSourceAccount,\n fee: xdr.Int64.fromString(\n base\n .times(innerOps + 1)\n .plus(resourceFee)\n .toString(),\n ),\n innerTx: xdr.FeeBumpTransactionInnerTx.envelopeTypeTx(\n innerTxEnvelope.v1(),\n ),\n ext: new xdr.FeeBumpTransactionExt(0),\n });\n const feeBumpTxEnvelope = new xdr.FeeBumpTransactionEnvelope({\n tx,\n signatures: [],\n });\n const envelope =\n xdr.TransactionEnvelope.envelopeTypeTxFeeBump(feeBumpTxEnvelope);\n\n return new FeeBumpTransaction(envelope, networkPassphrase);\n }\n\n /**\n * Build a {@link Transaction} or {@link FeeBumpTransaction} from an\n * xdr.TransactionEnvelope.\n *\n * @param envelope - The transaction envelope\n * object or base64 encoded string.\n * @param networkPassphrase - The network passphrase of the target\n * Stellar network (e.g. \"Public Global Stellar Network ; September\n * 2015\"), see {@link Networks}.\n */\n static fromXDR(\n envelope: xdr.TransactionEnvelope | string,\n networkPassphrase: string,\n ): FeeBumpTransaction | Transaction {\n if (typeof envelope === \"string\") {\n envelope = xdr.TransactionEnvelope.fromXDR(envelope, \"base64\");\n }\n\n if (envelope.switch() === xdr.EnvelopeType.envelopeTypeTxFeeBump()) {\n return new FeeBumpTransaction(envelope, networkPassphrase);\n }\n\n return new Transaction(envelope, networkPassphrase);\n }\n}\n\n/**\n * Checks whether a provided object is a valid Date.\n * @param d - date object\n */\nexport function isValidDate(d: Date | number | string): d is Date {\n return d instanceof Date && !Number.isNaN(d.getTime());\n}\n\n/**\n * Converts a Date, number, or string time value to epoch seconds for\n * validation. Returns undefined if the value is undefined.\n */\nfunction toEpochSeconds(\n value: Date | number | string | undefined,\n): number | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n const num =\n value instanceof Date ? Math.floor(value.getTime() / 1000) : Number(value);\n\n if (!Number.isFinite(num) || num % 1 !== 0) {\n throw new Error(\"timebounds value must be a finite integer or Date\");\n }\n\n return num;\n}\n"],"names":["xdr"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,kBAAkB,KAAA,CAAM,SAAA;AAC9B,MAAM,UAAA,GAAa,UAAA;AAWZ,MAAM,QAAA,GAAW;AAMjB,MAAM,eAAA,GAAkB;AA4GxB,MAAM,kBAAA,CAAmB;AAAA,EAC9B,MAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EAIA,YAAA;AAAA,EACA,kBAAA;AAAA,EACA,qBAAA;AAAA,EACA,2BAAA;AAAA,EACA,YAAA;AAAA,EACA,IAAA;AAAA,EACA,iBAAA;AAAA,EACA,WAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAA,CACE,aAAA,EACA,IAAA,GAAkC,EAAC,EACnC;AACA,IAAA,IAAI,CAAC,aAAA,EAAe;AAClB,MAAA,MAAM,IAAI,MAAM,iDAAiD,CAAA;AAAA,IACnE;AAEA,IAAA,IAAI,IAAA,CAAK,QAAQ,MAAA,EAAW;AAC1B,MAAA,MAAM,IAAI,MAAM,mDAAmD,C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
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/bindings/config.ts"],"sourcesContent":["// The SDK version is baked in at build time via babel-plugin-transform-define.\n// Previously this was `import packageJson from \"../../package.json\"`, which\n// failed at runtime in deeper build outputs (e.g. lib/axios) because the\n// relative path `../../package.json` resolved into the output tree rather\n// than the project root.\n
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/bindings/config.ts"],"sourcesContent":["// The SDK version is baked in at build time via babel-plugin-transform-define.\n// Previously this was `import packageJson from \"../../package.json\"`, which\n// failed at runtime in deeper build outputs (e.g. lib/axios) because the\n// relative path `../../package.json` resolved into the output tree rather\n// than the project root.\n\ndeclare const __PACKAGE_VERSION__: string;\n\nexport interface ConfigGenerateOptions {\n contractName: string;\n}\n\nexport interface Configs {\n packageJson: string;\n tsConfig: string;\n gitignore: string;\n readme: string;\n}\n\n/**\n * Generates a complete TypeScript project structure with contract bindings\n */\nexport class ConfigGenerator {\n /**\n * Generate the complete TypeScript project\n */\n generate(options: ConfigGenerateOptions): Configs {\n const { contractName } = options;\n\n // Generate all project files\n return {\n packageJson: this.generatePackageJson(contractName),\n tsConfig: this.generateTsConfig(),\n gitignore: this.generateGitignore(),\n readme: this.generateReadme(contractName),\n };\n }\n\n /**\n * Generate package.json\n */\n private generatePackageJson(contractName: string): string {\n const generatedPackageJson = {\n name: contractName.toLowerCase().replace(/[^a-z0-9-]/g, \"-\"),\n version: \"0.0.1\",\n description: `Generated TypeScript bindings for ${contractName} Stellar contract`,\n type: \"module\",\n main: \"dist/index.js\",\n types: \"dist/index.d.ts\",\n scripts: {\n build: \"tsc\",\n },\n dependencies: {\n \"@stellar/stellar-sdk\": `^${__PACKAGE_VERSION__}`,\n buffer: \"6.0.3\",\n },\n devDependencies: {\n typescript: \"^5.6.3\",\n },\n };\n\n return JSON.stringify(generatedPackageJson, null, 2);\n }\n\n /**\n * Generate tsconfig.json\n */\n private generateTsConfig(): string {\n const tsConfig = {\n compilerOptions: {\n target: \"ESNext\",\n module: \"NodeNext\",\n moduleResolution: \"nodenext\",\n declaration: true,\n outDir: \"./dist\",\n strictNullChecks: true,\n skipLibCheck: true,\n },\n include: [\"src/*\"],\n };\n\n return JSON.stringify(tsConfig, null, 2);\n }\n\n /**\n * Generate .gitignore\n */\n private generateGitignore(): string {\n const gitignore = [\n \"# Dependencies\",\n \"node_modules/\",\n \"\",\n \"# Build outputs\",\n \"dist/\",\n \"*.tgz\",\n \"\",\n \"# IDE\",\n \".vscode/\",\n \".idea/\",\n \"\",\n \"# OS\",\n \".DS_Store\",\n \"Thumbs.db\",\n \"\",\n \"# Logs\",\n \"*.log\",\n \"npm-debug.log*\",\n \"\",\n \"# Runtime data\",\n \"*.pid\",\n \"*.seed\",\n ].join(\"\\n\");\n\n return gitignore;\n }\n\n /**\n * Generate README.md\n */\n private generateReadme(contractName: string): string {\n const readme = [\n `# ${contractName} Contract Bindings`,\n \"\",\n `TypeScript bindings for the ${contractName} Stellar smart contract.`,\n \"\",\n \"## Installation\",\n \"\",\n \"```bash\",\n \"npm install\",\n \"```\",\n \"\",\n \"## Build\",\n \"\",\n \"```bash\",\n \"npm run build\",\n \"```\",\n \"\",\n \"## Usage\",\n \"\",\n \"```typescript\",\n 'import { Client } from \"./src\";',\n \"\",\n \"const client = new Client({\",\n ' contractId: \"YOUR_CONTRACT_ID\",',\n ' rpcUrl: \"https://soroban-testnet.stellar.org:443\",',\n ' networkPassphrase: \"Test SDF Network ; September 2015\",',\n \"});\",\n \"\",\n \"// Call contract methods\",\n \"// const result = await client.methodName();\",\n \"```\",\n \"\",\n \"## Generated Files\",\n \"\",\n \"- `src/index.ts` - Entry point exporting the Client\",\n \"- `src/types.ts` - Type definitions for contract structs, enums, and unions\",\n \"- `src/contract.ts` - Client implementation\",\n \"- `tsconfig.json` - TypeScript configuration\",\n \"- `package.json` - NPM package configuration\",\n \"\",\n \"This package was generated using the Js-Stellar-SDK contract binding generator.\",\n ].join(\"\\n\");\n\n return readme;\n }\n}\n"],"names":[],"mapp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eAAA;AAAA,MACA,iCAAA;AAAA,MACA,EAAA;AAAA,MACA,6BAAA;AAAA,MACA,mCAAA;AAAA,MACA,sDAAA;AAAA,MACA,2DAAA;AAAA,MACA,KAAA;AAAA,MACA,EAAA;AAAA,MACA,0BAAA;AAAA,MACA,8CAAA;AAAA,MACA,KAAA;AAAA,MACA,EAAA;AAAA,MACA,oBAAA;AAAA,MACA,EAAA;AAAA,MACA,qDAAA;AAAA,MACA,6EAAA;AAAA,MACA,6CAAA;AAAA,MACA,8CAAA;AAAA,MACA,8CAAA;AAAA,MACA,EAAA;AAAA,MACA;AAAA,KACF,CAAE,KAAK,IAAI,CAAA;AAEX,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
|
|
@@ -73,7 +73,7 @@ async function fetchWasmFromContract(server, contractAddress) {
|
|
|
73
73
|
return { type: "stellar-asset-contract" };
|
|
74
74
|
}
|
|
75
75
|
const wasmHash = instance.executable().wasmHash();
|
|
76
|
-
|
|
76
|
+
const wasmBytes = await getRemoteWasmFromHash(server, wasmHash);
|
|
77
77
|
return { type: "wasm", wasmBytes };
|
|
78
78
|
} catch (error) {
|
|
79
79
|
if (error instanceof WasmFetchError) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm_fetcher.js","sources":["../../../src/bindings/wasm_fetcher.ts"],"sourcesContent":["import { Address, Contract, StrKey, xdr } from \"../base/index.js\";\nimport { Server } from \"../rpc/index.js\";\n\nimport { RpcServer } from \"../rpc/server.js\";\n\n/**\n * Types of contract data that can be fetched\n */\nexport type ContractData =\n | { type: \"wasm\"; wasmBytes: Buffer }\n | { type: \"stellar-asset-contract\" };\n\n/**\n * Errors that can occur during WASM fetching\n */\nexport class WasmFetchError extends Error {\n constructor(\n message: string,\n public readonly cause?: Error,\n ) {\n super(message);\n this.name = \"WasmFetchError\";\n }\n}\n\n/**\n * Get WASM bytes from a WASM hash on the network\n */\nasync function getRemoteWasmFromHash(\n server: RpcServer,\n hashBuffer: Buffer,\n): Promise<Buffer> {\n try {\n // Create the ledger key for the contract code\n const contractCodeKey = xdr.LedgerKey.contractCode(\n new xdr.LedgerKeyContractCode({\n hash: xdr.Hash.fromXDR(hashBuffer, \"raw\"),\n }),\n );\n\n // Get the ledger entries\n const response = await server.getLedgerEntries(contractCodeKey);\n\n if (!response.entries || response.entries.length === 0) {\n throw new WasmFetchError(\"WASM not found for the given hash\");\n }\n\n const entry = response.entries[0];\n if (entry.key.switch() !== xdr.LedgerEntryType.contractCode()) {\n throw new WasmFetchError(\"Invalid ledger entry type returned\");\n }\n\n const contractCode = entry.val.contractCode();\n return Buffer.from(contractCode.code());\n } catch (error) {\n if (error instanceof WasmFetchError) {\n throw error;\n }\n throw new WasmFetchError(\"Failed to fetch WASM from hash\", error as Error);\n }\n}\n\n/**\n * Check if a contract is a Stellar Asset Contract\n */\nfunction isStellarAssetContract(instance: xdr.ScContractInstance): boolean {\n // Check if it's a Stellar Asset Contract (has no WASM hash)\n return (\n instance.executable().switch() ===\n xdr.ContractExecutableType.contractExecutableStellarAsset()\n );\n}\n\n/**\n * Fetch WASM bytes from a deployed contract\n */\nasync function fetchWasmFromContract(\n server: RpcServer,\n contractAddress: Address,\n): Promise<ContractData> {\n try {\n const contract = new Contract(contractAddress.toString());\n\n const response = await server.getLedgerEntries(contract.getFootprint());\n if (!response.entries || response.entries.length === 0) {\n throw new WasmFetchError(\"Contract instance not found\");\n }\n\n const entry = response.entries[0];\n if (entry.key.switch() !== xdr.LedgerEntryType.contractData()) {\n throw new WasmFetchError(\"Invalid ledger entry type returned\");\n }\n\n const contractData = entry.val.contractData();\n const instance = contractData.val().instance();\n\n if (isStellarAssetContract(instance)) {\n return { type: \"stellar-asset-contract\" };\n }\n\n const wasmHash = instance.executable().wasmHash();\n
|
|
1
|
+
{"version":3,"file":"wasm_fetcher.js","sources":["../../../src/bindings/wasm_fetcher.ts"],"sourcesContent":["import { Address, Contract, StrKey, xdr } from \"../base/index.js\";\nimport { Server } from \"../rpc/index.js\";\n\nimport { RpcServer } from \"../rpc/server.js\";\n\n/**\n * Types of contract data that can be fetched\n */\nexport type ContractData =\n | { type: \"wasm\"; wasmBytes: Buffer }\n | { type: \"stellar-asset-contract\" };\n\n/**\n * Errors that can occur during WASM fetching\n */\nexport class WasmFetchError extends Error {\n constructor(\n message: string,\n public readonly cause?: Error,\n ) {\n super(message);\n this.name = \"WasmFetchError\";\n }\n}\n\n/**\n * Get WASM bytes from a WASM hash on the network\n */\nasync function getRemoteWasmFromHash(\n server: RpcServer,\n hashBuffer: Buffer,\n): Promise<Buffer> {\n try {\n // Create the ledger key for the contract code\n const contractCodeKey = xdr.LedgerKey.contractCode(\n new xdr.LedgerKeyContractCode({\n hash: xdr.Hash.fromXDR(hashBuffer, \"raw\"),\n }),\n );\n\n // Get the ledger entries\n const response = await server.getLedgerEntries(contractCodeKey);\n\n if (!response.entries || response.entries.length === 0) {\n throw new WasmFetchError(\"WASM not found for the given hash\");\n }\n\n const entry = response.entries[0];\n if (entry.key.switch() !== xdr.LedgerEntryType.contractCode()) {\n throw new WasmFetchError(\"Invalid ledger entry type returned\");\n }\n\n const contractCode = entry.val.contractCode();\n return Buffer.from(contractCode.code());\n } catch (error) {\n if (error instanceof WasmFetchError) {\n throw error;\n }\n throw new WasmFetchError(\"Failed to fetch WASM from hash\", error as Error);\n }\n}\n\n/**\n * Check if a contract is a Stellar Asset Contract\n */\nfunction isStellarAssetContract(instance: xdr.ScContractInstance): boolean {\n // Check if it's a Stellar Asset Contract (has no WASM hash)\n return (\n instance.executable().switch() ===\n xdr.ContractExecutableType.contractExecutableStellarAsset()\n );\n}\n\n/**\n * Fetch WASM bytes from a deployed contract\n */\nasync function fetchWasmFromContract(\n server: RpcServer,\n contractAddress: Address,\n): Promise<ContractData> {\n try {\n const contract = new Contract(contractAddress.toString());\n\n const response = await server.getLedgerEntries(contract.getFootprint());\n if (!response.entries || response.entries.length === 0) {\n throw new WasmFetchError(\"Contract instance not found\");\n }\n\n const entry = response.entries[0];\n if (entry.key.switch() !== xdr.LedgerEntryType.contractData()) {\n throw new WasmFetchError(\"Invalid ledger entry type returned\");\n }\n\n const contractData = entry.val.contractData();\n const instance = contractData.val().instance();\n\n if (isStellarAssetContract(instance)) {\n return { type: \"stellar-asset-contract\" };\n }\n\n const wasmHash = instance.executable().wasmHash();\n const wasmBytes = await getRemoteWasmFromHash(server, wasmHash);\n return { type: \"wasm\", wasmBytes };\n } catch (error) {\n if (error instanceof WasmFetchError) {\n throw error;\n }\n throw new WasmFetchError(\n \"Failed to fetch WASM from contract\",\n error as Error,\n );\n }\n}\n\n/**\n * Fetch WASM from network using WASM hash\n */\nexport async function fetchFromWasmHash(\n wasmHash: string,\n rpcServer: Server,\n): Promise<ContractData> {\n try {\n // Validate and decode the hash\n const hashBuffer = Buffer.from(wasmHash, \"hex\");\n if (hashBuffer.length !== 32) {\n throw new WasmFetchError(\n `Invalid WASM hash length: expected 32 bytes, got ${hashBuffer.length}`,\n );\n }\n\n // Get WASM from hash\n const wasmBytes = await getRemoteWasmFromHash(rpcServer, hashBuffer);\n\n return { type: \"wasm\", wasmBytes };\n } catch (error) {\n throw new WasmFetchError(\n `Failed to fetch WASM from hash ${wasmHash}`,\n error as Error,\n );\n }\n}\n\n/**\n * Fetch WASM from network using contract ID\n */\nexport async function fetchFromContractId(\n contractId: string,\n rpcServer: Server,\n): Promise<ContractData> {\n try {\n if (!StrKey.isValidContract(contractId)) {\n throw new WasmFetchError(`Invalid contract ID: ${contractId}`);\n }\n // Parse contract address\n const contractAddress = Address.fromString(contractId);\n\n // Try to get WASM from contract\n return await fetchWasmFromContract(rpcServer, contractAddress);\n } catch (error) {\n throw new WasmFetchError(\n `Failed to fetch WASM from contract ${contractId}`,\n error as Error,\n );\n }\n}\n"],"names":["xdr"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAeO,MAAM,uBAAuB,KAAA,CAAM;AAAA,EACxC,WAAA,CACE,SACgB,KAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAA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A;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF;AAKA,eAAsB,iBAAA,CACpB,UACA,SAAA,EACuB;AACvB,EAAA,IAAI;AAEF,IAAA,MAAM,UAAA,GAAa,MAAA,CAAO,IAAA,CAAK,QAAA,EAAU,KAAK,CAAA;AAC9C,IAAA,IAAI,UAAA,CAAW,WAAW,EAAA,EAAI;AAC5B,MAAA,MAAM,IAAI,cAAA;AAAA,QACR,CAAA,iDAAA,EAAoD,WAAW,MAAM,CAAA;AAAA,OACvE;AAAA,IACF;AAGA,IAAA,MAAM,SAAA,GAAY,MAAM,qBAAA,CAAsB,SAAA,EAAW,UAAU,CAAA;AAEnE,IAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAA,EAAU;AAAA,EACnC,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,cAAA;AAAA,MACR,kCAAkC,QAAQ,CAAA,CAAA;AAAA,MAC1C;AAAA,KACF;AAAA,EACF;AACF;AAKA,eAAsB,mBAAA,CACpB,YACA,SAAA,EACuB;AACvB,EAAA,IAAI;AACF,IAAA,IAAI,CAAC,MAAA,CAAO,eAAA,CAAgB,UAAU,CAAA,EAAG;AACvC,MAAA,MAAM,IAAI,cAAA,CAAe,CAAA,qBAAA,EAAwB,UAAU,CAAA,CAAE,CAAA;AAAA,IAC/D;AAEA,IAAA,MAAM,eAAA,GAAkB,OAAA,CAAQ,UAAA,CAAW,UAAU,CAAA;AAGrD,IAAA,OAAO,MAAM,qBAAA,CAAsB,SAAA,EAAW,eAAe,CAAA;AAAA,EAC/D,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,cAAA;AAAA,MACR,sCAAsC,UAAU,CAAA,CAAA;AAAA,MAChD;AAAA,KACF;AAAA,EACF;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../../src/contract/client.ts"],"sourcesContent":["import { Operation, xdr, Address } from \"../base/index.js\";\nimport { Spec } from \"./spec.js\";\nimport { Server } from \"../rpc/index.js\";\nimport { AssembledTransaction } from \"./assembled_transaction.js\";\nimport type { ClientOptions, MethodOptions } from \"./types.js\";\nimport { sanitizeIdentifier } from \"../bindings/utils.js\";\n\nconst CONSTRUCTOR_FUNC = \"__constructor\";\n\nasync function specFromWasmHash(\n wasmHash: Buffer | string,\n options: Server.Options & { rpcUrl: string },\n format: \"hex\" | \"base64\" = \"hex\",\n): Promise<Spec> {\n if (!options || !options.rpcUrl) {\n throw new TypeError(\"options must contain rpcUrl\");\n }\n const { rpcUrl, allowHttp, headers } = options;\n const serverOpts: Server.Options = { allowHttp, headers };\n const server = new Server(rpcUrl, serverOpts);\n const wasm = await server.getContractWasmByHash(wasmHash, format);\n return Spec.fromWasm(wasm);\n}\n\n/**\n * Generate a class from the contract spec that where each contract method\n * gets included with an identical name.\n *\n * Each method returns an {@link contract.AssembledTransaction | AssembledTransaction} that can\n * be used to modify, simulate, decode results, and possibly sign, & submit the\n * transaction.\n *\n *\n * @param spec - {@link Spec} to construct a Client for\n * @param options - see {@link ClientOptions}\n */\nexport class Client {\n static async deploy<T = Client>(\n /** Constructor/Initialization Args for the contract's `__constructor` method */\n args: Record<string, any> | null,\n /** Options for initializing a Client as well as for calling a method, with extras specific to deploying. */\n options: MethodOptions &\n Omit<ClientOptions, \"contractId\"> & {\n /** The hash of the Wasm blob, which must already be installed on-chain. */\n wasmHash: Buffer | string;\n /** Salt used to generate the contract's ID. Passed through to {@link Operation.createCustomContract}. Default: random. */\n salt?: Buffer | Uint8Array;\n /** The format used to decode `wasmHash`, if it's provided as a string. */\n format?: \"hex\" | \"base64\";\n /** The address to use to deploy the custom contract */\n address?: string;\n },\n ): Promise<AssembledTransaction<T>> {\n const {\n wasmHash,\n salt,\n format,\n fee,\n timeoutInSeconds,\n simulate,\n ...clientOptions\n } = options;\n const spec = await specFromWasmHash(wasmHash, clientOptions, format);\n\n const operation = Operation.createCustomContract({\n address: new Address(options.address || options.publicKey!),\n wasmHash:\n typeof wasmHash === \"string\"\n ? Buffer.from(wasmHash, format ?? \"hex\")\n : (wasmHash as Buffer),\n salt,\n constructorArgs: args\n ? spec.funcArgsToScVals(CONSTRUCTOR_FUNC, args)\n : [],\n });\n\n return AssembledTransaction.buildWithOp(operation, {\n fee,\n timeoutInSeconds,\n simulate,\n ...clientOptions,\n contractId: \"ignored\",\n method: CONSTRUCTOR_FUNC,\n parseResultXdr: (result) =>\n new Client(spec, {\n ...clientOptions,\n contractId: Address.fromScVal(result).toString(),\n }),\n }) as unknown as AssembledTransaction<T>;\n }\n\n constructor(\n public readonly spec: Spec,\n public readonly options: ClientOptions,\n ) {\n // Ensure we have a server to reuse for all AssembledTransactions\n if (options.server === undefined) {\n const { allowHttp, headers } = options;\n options.server = new Server(options.rpcUrl, {\n allowHttp,\n headers,\n });\n }\n\n this.spec.funcs().forEach((xdrFn) => {\n const method = xdrFn.name().toString();\n if (method === CONSTRUCTOR_FUNC) {\n return;\n }\n const assembleTransaction = (\n args?: Record<string, any>,\n methodOptions?: MethodOptions,\n ) =>\n AssembledTransaction.build({\n method,\n args: args && spec.funcArgsToScVals(method, args),\n ...options,\n ...methodOptions,\n errorTypes: spec.errorCases().reduce(\n (acc, curr) => ({\n ...acc,\n [curr.value()]: { message: curr.doc().toString() },\n }),\n {} as Pick<ClientOptions, \"errorTypes\">,\n ),\n parseResultXdr: (result: xdr.ScVal) =>\n spec.funcResToNative(method, result),\n });\n\n // @ts-ignore error TS7053: Element implicitly has an 'any' type\n this[sanitizeIdentifier(method)] =\n spec.getFunc(method).inputs().length === 0\n ? (opts?: MethodOptions) => assembleTransaction(undefined, opts)\n : assembleTransaction;\n });\n }\n\n /**\n * Generates a Client instance from the provided ClientOptions and the contract's wasm hash.\n * The wasmHash can be provided in either hex or base64 format.\n *\n * @param wasmHash - The hash of the contract's wasm binary, in either hex or base64 format.\n * @param options - The ClientOptions object containing the necessary configuration, including the rpcUrl.\n * @param format - (optional) The format of the provided wasmHash, either \"hex\" or \"base64\". Defaults to \"hex\".\n * @returns A Promise that resolves to a Client instance.\n * @throws If the provided options object does not contain an rpcUrl.\n */\n static async fromWasmHash(\n wasmHash: Buffer | string,\n options: ClientOptions,\n format: \"hex\" | \"base64\" = \"hex\",\n ): Promise<Client> {\n if (!options || !options.rpcUrl) {\n throw new TypeError(\"options must contain rpcUrl\");\n }\n const { rpcUrl, allowHttp, headers } = options;\n const server =\n options.server ??\n new Server(rpcUrl, {\n allowHttp,\n headers,\n });\n const wasm = await server.getContractWasmByHash(wasmHash, format);\n\n return Client.fromWasm(wasm, options);\n }\n\n /**\n * Generates a Client instance from the provided ClientOptions and the contract's wasm binary.\n *\n * @param wasm - The contract's wasm binary as a Buffer.\n * @param options - The ClientOptions object containing the necessary configuration.\n * @returns A Promise that resolves to a Client instance.\n * @throws If the contract spec cannot be obtained from the provided wasm binary.\n */\n static async fromWasm(wasm: Buffer, options: ClientOptions): Promise<Client> {\n const spec = await Spec.fromWasm(wasm);\n return new Client(spec, options);\n }\n\n /**\n * Generates a Client instance from the provided ClientOptions, which must include the contractId and rpcUrl.\n *\n * @param options - The ClientOptions object containing the necessary configuration, including the contractId and rpcUrl.\n * @returns A Promise that resolves to a Client instance.\n * @throws If the provided options object does not contain both rpcUrl and contractId.\n */\n static async from(options: ClientOptions): Promise<Client> {\n if (!options || !options.rpcUrl || !options.contractId) {\n throw new TypeError(\"options must contain rpcUrl and contractId\");\n }\n const { rpcUrl, contractId, allowHttp, headers } = options;\n const server = new Server(rpcUrl, {\n allowHttp,\n headers,\n });\n const wasm = await server.getContractWasmByContractId(contractId);\n return Client.fromWasm(wasm, options);\n }\n\n txFromJSON = <T>(json: string): AssembledTransaction<T> => {\n const { method, ...tx } = JSON.parse(json);\n return AssembledTransaction.fromJSON(\n {\n ...this.options,\n method,\n parseResultXdr: (result: xdr.ScVal) =>\n this.spec.funcResToNative(method, result),\n },\n tx,\n );\n };\n\n txFromXDR = <T>(xdrBase64: string): AssembledTransaction<T> =>\n AssembledTransaction.fromX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,OAC5C;AAAA,MACA;AAAA,KACF;AAAA,EACF,CAAA;AAAA,EAEA,SAAA,GAAY,CAAI,SAAA,KACd,oBAAA,CAAqB,QAAQ,IAAA,CAAK,OAAA,EAAS,SAAA,EAAW,IAAA,CAAK,IAAI,CAAA;AACnE;;;;"}
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../../src/contract/client.ts"],"sourcesContent":["import { Operation, xdr, Address } from \"../base/index.js\";\nimport { Spec } from \"./spec.js\";\nimport { Server } from \"../rpc/index.js\";\nimport { AssembledTransaction } from \"./assembled_transaction.js\";\nimport type { ClientOptions, MethodOptions } from \"./types.js\";\nimport { sanitizeIdentifier } from \"../bindings/utils.js\";\n\nconst CONSTRUCTOR_FUNC = \"__constructor\";\n\nasync function specFromWasmHash(\n wasmHash: Buffer | string,\n options: Server.Options & { rpcUrl: string },\n format: \"hex\" | \"base64\" = \"hex\",\n): Promise<Spec> {\n if (!options || !options.rpcUrl) {\n throw new TypeError(\"options must contain rpcUrl\");\n }\n const { rpcUrl, allowHttp, headers } = options;\n const serverOpts: Server.Options = { allowHttp, headers };\n const server = new Server(rpcUrl, serverOpts);\n const wasm = await server.getContractWasmByHash(wasmHash, format);\n return Spec.fromWasm(wasm);\n}\n\n/**\n * Generate a class from the contract spec that where each contract method\n * gets included with an identical name.\n *\n * Each method returns an {@link contract.AssembledTransaction | AssembledTransaction} that can\n * be used to modify, simulate, decode results, and possibly sign, & submit the\n * transaction.\n *\n *\n * @param spec - {@link Spec} to construct a Client for\n * @param options - see {@link ClientOptions}\n */\nexport class Client {\n static async deploy<T = Client>(\n /** Constructor/Initialization Args for the contract's `__constructor` method */\n args: Record<string, any> | null,\n /** Options for initializing a Client as well as for calling a method, with extras specific to deploying. */\n options: MethodOptions &\n Omit<ClientOptions, \"contractId\"> & {\n /** The hash of the Wasm blob, which must already be installed on-chain. */\n wasmHash: Buffer | string;\n /** Salt used to generate the contract's ID. Passed through to {@link Operation.createCustomContract}. Default: random. */\n salt?: Buffer | Uint8Array;\n /** The format used to decode `wasmHash`, if it's provided as a string. */\n format?: \"hex\" | \"base64\";\n /** The address to use to deploy the custom contract */\n address?: string;\n },\n ): Promise<AssembledTransaction<T>> {\n const {\n wasmHash,\n salt,\n format,\n fee,\n timeoutInSeconds,\n simulate,\n ...clientOptions\n } = options;\n const spec = await specFromWasmHash(wasmHash, clientOptions, format);\n\n const operation = Operation.createCustomContract({\n address: new Address(options.address || options.publicKey!),\n wasmHash:\n typeof wasmHash === \"string\"\n ? Buffer.from(wasmHash, format ?? \"hex\")\n : (wasmHash as Buffer),\n salt,\n constructorArgs: args\n ? spec.funcArgsToScVals(CONSTRUCTOR_FUNC, args)\n : [],\n });\n\n return AssembledTransaction.buildWithOp(operation, {\n fee,\n timeoutInSeconds,\n simulate,\n ...clientOptions,\n contractId: \"ignored\",\n method: CONSTRUCTOR_FUNC,\n parseResultXdr: (result) =>\n new Client(spec, {\n ...clientOptions,\n contractId: Address.fromScVal(result).toString(),\n }),\n }) as unknown as AssembledTransaction<T>;\n }\n\n constructor(\n public readonly spec: Spec,\n public readonly options: ClientOptions,\n ) {\n // Ensure we have a server to reuse for all AssembledTransactions\n if (options.server === undefined) {\n const { allowHttp, headers } = options;\n options.server = new Server(options.rpcUrl, {\n allowHttp,\n headers,\n });\n }\n\n this.spec.funcs().forEach((xdrFn) => {\n const method = xdrFn.name().toString();\n if (method === CONSTRUCTOR_FUNC) {\n return;\n }\n const assembleTransaction = (\n args?: Record<string, any>,\n methodOptions?: MethodOptions,\n ) =>\n AssembledTransaction.build({\n method,\n args: args && spec.funcArgsToScVals(method, args),\n ...options,\n ...methodOptions,\n errorTypes: spec.errorCases().reduce(\n (acc, curr) => ({\n ...acc,\n [curr.value()]: { message: curr.doc().toString() },\n }),\n {} as Pick<ClientOptions, \"errorTypes\">,\n ),\n parseResultXdr: (result: xdr.ScVal) =>\n spec.funcResToNative(method, result),\n });\n\n // @ts-expect-error error TS7053: Element implicitly has an 'any' type\n this[sanitizeIdentifier(method)] =\n spec.getFunc(method).inputs().length === 0\n ? (opts?: MethodOptions) => assembleTransaction(undefined, opts)\n : assembleTransaction;\n });\n }\n\n /**\n * Generates a Client instance from the provided ClientOptions and the contract's wasm hash.\n * The wasmHash can be provided in either hex or base64 format.\n *\n * @param wasmHash - The hash of the contract's wasm binary, in either hex or base64 format.\n * @param options - The ClientOptions object containing the necessary configuration, including the rpcUrl.\n * @param format - (optional) The format of the provided wasmHash, either \"hex\" or \"base64\". Defaults to \"hex\".\n * @returns A Promise that resolves to a Client instance.\n * @throws If the provided options object does not contain an rpcUrl.\n */\n static async fromWasmHash(\n wasmHash: Buffer | string,\n options: ClientOptions,\n format: \"hex\" | \"base64\" = \"hex\",\n ): Promise<Client> {\n if (!options || !options.rpcUrl) {\n throw new TypeError(\"options must contain rpcUrl\");\n }\n const { rpcUrl, allowHttp, headers } = options;\n const server =\n options.server ??\n new Server(rpcUrl, {\n allowHttp,\n headers,\n });\n const wasm = await server.getContractWasmByHash(wasmHash, format);\n\n return Client.fromWasm(wasm, options);\n }\n\n /**\n * Generates a Client instance from the provided ClientOptions and the contract's wasm binary.\n *\n * @param wasm - The contract's wasm binary as a Buffer.\n * @param options - The ClientOptions object containing the necessary configuration.\n * @returns A Promise that resolves to a Client instance.\n * @throws If the contract spec cannot be obtained from the provided wasm binary.\n */\n static async fromWasm(wasm: Buffer, options: ClientOptions): Promise<Client> {\n const spec = await Spec.fromWasm(wasm);\n return new Client(spec, options);\n }\n\n /**\n * Generates a Client instance from the provided ClientOptions, which must include the contractId and rpcUrl.\n *\n * @param options - The ClientOptions object containing the necessary configuration, including the contractId and rpcUrl.\n * @returns A Promise that resolves to a Client instance.\n * @throws If the provided options object does not contain both rpcUrl and contractId.\n */\n static async from(options: ClientOptions): Promise<Client> {\n if (!options || !options.rpcUrl || !options.contractId) {\n throw new TypeError(\"options must contain rpcUrl and contractId\");\n }\n const { rpcUrl, contractId, allowHttp, headers } = options;\n const server = new Server(rpcUrl, {\n allowHttp,\n headers,\n });\n const wasm = await server.getContractWasmByContractId(contractId);\n return Client.fromWasm(wasm, options);\n }\n\n txFromJSON = <T>(json: string): AssembledTransaction<T> => {\n const { method, ...tx } = JSON.parse(json);\n return AssembledTransaction.fromJSON(\n {\n ...this.options,\n method,\n parseResultXdr: (result: xdr.ScVal) =>\n this.spec.funcResToNative(method, result),\n },\n tx,\n );\n };\n\n txFromXDR = <T>(xdrBase64: string): AssembledTransaction<T> =>\n AssembledTransaction.fromXDR(this.options, xdrBase64, this.spec);\n}\n"],"names":["Server"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAM,gBAAA,GAAmB,eAAA;AAEzB,eAAe,gBAAA,CACb,QAAA,EACA,OAAA,EACA,MAAA,GAA2B,KAAA,EACZ;AACf,EAAA,IAAI,CAAC,OAAA,IAAW,CAAC,OAAA,CAAQ,MAAA,EAAQ;AAC/B,IAAA,MAAM,IAAI,UAAU,6BAA6B,CAAA;AAAA,EACnD;AACA,EAAA,MAAM,EAAE,MAAA,EAAQ,SAAA,EAAW,OAAA,EAAQ,GAAI,OAAA;AACvC,EAAA,MAAM,UAAA,GAA6B,EAAE,SAAA,EAAW,OAAA,EAAQ;AACxD,EAAA,MAAM,MAAA,GAAS,IAAIA,SAAA,CAAO,MAAA,EAAQ,UAAU,CAAA;AAC5C,EAAA,MAAM,IAAA,GAAO,MAAM,MAAA,CAAO,qBAAA,CAAsB,UAAU,MAAM,CAAA;AAChE,EAAA,OAAO,IAAA,CAAK,SAAS,IAAI,CAAA;AAC3B;AAcO,MAAM,MAAA,CAAO;AAAA,EAuDlB,WAAA,CACkB,MACA,OAAA,EAChB;AAFgB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAGhB,IAAA,IAAI,OAAA,CAAQ,WAAW,MAAA,EAAW;AAChC,MAAA,MAAM,EAAE,SAAA,EAAW,OAAA,EAAQ,GAAI,OAAA;AAC/B,MAAA,OAAA,C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