@aptos-labs/ts-sdk 7.2.0 → 7.4.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/LICENSE +43 -43
- package/README.md +36 -20
- package/dist/account/AbstractKeylessAccount.d.ts.map +1 -1
- package/dist/account/AbstractKeylessAccount.js.map +1 -1
- package/dist/account/AbstractedAccount.d.ts.map +1 -1
- package/dist/account/Account.d.ts.map +1 -1
- package/dist/account/Account.js.map +1 -1
- package/dist/account/AccountUtils.js.map +1 -1
- package/dist/account/DerivableAbstractedAccount.d.ts.map +1 -1
- package/dist/account/DerivableAbstractedAccount.js.map +1 -1
- package/dist/account/Ed25519Account.d.ts.map +1 -1
- package/dist/account/EphemeralKeyPair.d.ts.map +1 -1
- package/dist/account/EphemeralKeyPair.js.map +1 -1
- package/dist/account/FederatedKeylessAccount.d.ts.map +1 -1
- package/dist/account/KeylessAccount.d.ts.map +1 -1
- package/dist/account/MultiEd25519Account.d.ts.map +1 -1
- package/dist/account/MultiKeyAccount.d.ts.map +1 -1
- package/dist/account/SingleKeyAccount.d.ts.map +1 -1
- package/dist/account/SingleKeyAccount.js.map +1 -1
- package/dist/api/account/abstraction.d.ts +10 -0
- package/dist/api/account/abstraction.d.ts.map +1 -1
- package/dist/api/account/abstraction.js +19 -6
- package/dist/api/account/abstraction.js.map +1 -1
- package/dist/api/account.d.ts.map +1 -1
- package/dist/api/account.js.map +1 -1
- package/dist/api/ans.d.ts +9 -0
- package/dist/api/ans.d.ts.map +1 -1
- package/dist/api/ans.js +5 -0
- package/dist/api/ans.js.map +1 -1
- package/dist/api/aptos.d.ts.map +1 -1
- package/dist/api/aptosConfig.d.ts +12 -0
- package/dist/api/aptosConfig.d.ts.map +1 -1
- package/dist/api/aptosConfig.js +13 -0
- package/dist/api/aptosConfig.js.map +1 -1
- package/dist/api/coin.d.ts +2 -0
- package/dist/api/coin.d.ts.map +1 -1
- package/dist/api/coin.js +1 -0
- package/dist/api/coin.js.map +1 -1
- package/dist/api/digitalAsset.d.ts +30 -0
- package/dist/api/digitalAsset.d.ts.map +1 -1
- package/dist/api/digitalAsset.js +15 -0
- package/dist/api/digitalAsset.js.map +1 -1
- package/dist/api/faucet.d.ts.map +1 -1
- package/dist/api/faucet.js.map +1 -1
- package/dist/api/fungibleAsset.d.ts +4 -0
- package/dist/api/fungibleAsset.d.ts.map +1 -1
- package/dist/api/fungibleAsset.js +2 -0
- package/dist/api/fungibleAsset.js.map +1 -1
- package/dist/api/general.d.ts.map +1 -1
- package/dist/api/keyless.d.ts +38 -1
- package/dist/api/keyless.d.ts.map +1 -1
- package/dist/api/keyless.js +29 -1
- package/dist/api/keyless.js.map +1 -1
- package/dist/api/object.d.ts.map +1 -1
- package/dist/api/object.js.map +1 -1
- package/dist/api/staking.d.ts.map +1 -1
- package/dist/api/staking.js.map +1 -1
- package/dist/api/table.d.ts.map +1 -1
- package/dist/api/transaction.d.ts +41 -1
- package/dist/api/transaction.d.ts.map +1 -1
- package/dist/api/transaction.js +42 -2
- package/dist/api/transaction.js.map +1 -1
- package/dist/api/transactionSubmission/build.d.ts +7 -5
- package/dist/api/transactionSubmission/build.d.ts.map +1 -1
- package/dist/api/transactionSubmission/build.js +13 -5
- package/dist/api/transactionSubmission/build.js.map +1 -1
- package/dist/api/transactionSubmission/management.d.ts.map +1 -1
- package/dist/api/transactionSubmission/sign.d.ts.map +1 -1
- package/dist/api/transactionSubmission/simulate.d.ts +7 -3
- package/dist/api/transactionSubmission/simulate.d.ts.map +1 -1
- package/dist/api/transactionSubmission/simulate.js +7 -3
- package/dist/api/transactionSubmission/simulate.js.map +1 -1
- package/dist/api/transactionSubmission/submit.d.ts.map +1 -1
- package/dist/bcs/deserializer.d.ts.map +1 -1
- package/dist/bcs/serializable/entryFunctionBytes.d.ts.map +1 -1
- package/dist/bcs/serializable/fixedBytes.d.ts.map +1 -1
- package/dist/bcs/serializable/movePrimitives.d.ts.map +1 -1
- package/dist/bcs/serializable/moveStructs.d.ts +72 -28
- package/dist/bcs/serializable/moveStructs.d.ts.map +1 -1
- package/dist/bcs/serializable/moveStructs.js +76 -28
- package/dist/bcs/serializable/moveStructs.js.map +1 -1
- package/dist/bcs/serializer.d.ts.map +1 -1
- package/dist/bcs/serializer.js.map +1 -1
- package/dist/cli/localNode.d.ts.map +1 -1
- package/dist/cli/localNode.js +16 -3
- package/dist/cli/localNode.js.map +1 -1
- package/dist/cli/move.d.ts.map +1 -1
- package/dist/cli/move.js.map +1 -1
- package/dist/client/core.d.ts +3 -0
- package/dist/client/core.d.ts.map +1 -1
- package/dist/client/core.js +116 -9
- package/dist/client/core.js.map +1 -1
- package/dist/core/account/utils/address.d.ts.map +1 -1
- package/dist/core/accountAddress.d.ts.map +1 -1
- package/dist/core/accountAddress.js.map +1 -1
- package/dist/core/authenticationKey.d.ts.map +1 -1
- package/dist/core/authenticationKey.js.map +1 -1
- package/dist/core/common.d.ts.map +1 -1
- package/dist/core/crypto/abstraction.d.ts.map +1 -1
- package/dist/core/crypto/ed25519.d.ts.map +1 -1
- package/dist/core/crypto/ed25519.js.map +1 -1
- package/dist/core/crypto/encryption/ciphertext.d.ts.map +1 -1
- package/dist/core/crypto/encryption/symmetric.d.ts.map +1 -1
- package/dist/core/crypto/encryption/symmetric.js.map +1 -1
- package/dist/core/crypto/ephemeral.d.ts.map +1 -1
- package/dist/core/crypto/federatedKeyless.d.ts.map +1 -1
- package/dist/core/crypto/hdKey.d.ts.map +1 -1
- package/dist/core/crypto/keyless.d.ts.map +1 -1
- package/dist/core/crypto/keyless.js.map +1 -1
- package/dist/core/crypto/multiEd25519.d.ts.map +1 -1
- package/dist/core/crypto/multiEd25519.js.map +1 -1
- package/dist/core/crypto/multiKey.d.ts.map +1 -1
- package/dist/core/crypto/multiKey.js.map +1 -1
- package/dist/core/crypto/privateKey.d.ts.map +1 -1
- package/dist/core/crypto/privateKey.js.map +1 -1
- package/dist/core/crypto/publicKey.d.ts.map +1 -1
- package/dist/core/crypto/secp256k1.d.ts.map +1 -1
- package/dist/core/crypto/secp256k1.js.map +1 -1
- package/dist/core/crypto/secp256r1.d.ts.map +1 -1
- package/dist/core/crypto/secp256r1.js.map +1 -1
- package/dist/core/crypto/signature.d.ts.map +1 -1
- package/dist/core/crypto/singleKey.d.ts.map +1 -1
- package/dist/core/crypto/singleKey.js.map +1 -1
- package/dist/core/crypto/utils.d.ts.map +1 -1
- package/dist/core/hex.d.ts.map +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/functions/keyless.d.ts +1 -1
- package/dist/functions/keyless.d.ts.map +1 -1
- package/dist/functions/keyless.js +1 -1
- package/dist/functions/keyless.js.map +1 -1
- package/dist/functions/transaction.d.ts +1 -1
- package/dist/functions/transaction.d.ts.map +1 -1
- package/dist/functions/transaction.js +1 -1
- package/dist/functions/transaction.js.map +1 -1
- package/dist/internal/abstraction.d.ts +35 -0
- package/dist/internal/abstraction.d.ts.map +1 -1
- package/dist/internal/abstraction.js +38 -3
- package/dist/internal/abstraction.js.map +1 -1
- package/dist/internal/account.d.ts +6 -0
- package/dist/internal/account.d.ts.map +1 -1
- package/dist/internal/account.js +55 -37
- package/dist/internal/account.js.map +1 -1
- package/dist/internal/ans.d.ts +11 -0
- package/dist/internal/ans.d.ts.map +1 -1
- package/dist/internal/ans.js +18 -6
- package/dist/internal/ans.js.map +1 -1
- package/dist/internal/coin.d.ts +2 -0
- package/dist/internal/coin.d.ts.map +1 -1
- package/dist/internal/coin.js +3 -1
- package/dist/internal/coin.js.map +1 -1
- package/dist/internal/digitalAsset.d.ts +30 -0
- package/dist/internal/digitalAsset.d.ts.map +1 -1
- package/dist/internal/digitalAsset.js +45 -15
- package/dist/internal/digitalAsset.js.map +1 -1
- package/dist/internal/fungibleAsset.d.ts +4 -0
- package/dist/internal/fungibleAsset.d.ts.map +1 -1
- package/dist/internal/fungibleAsset.js +6 -2
- package/dist/internal/fungibleAsset.js.map +1 -1
- package/dist/internal/keyless.d.ts +39 -1
- package/dist/internal/keyless.d.ts.map +1 -1
- package/dist/internal/keyless.js +71 -13
- package/dist/internal/keyless.js.map +1 -1
- package/dist/internal/transaction.d.ts +24 -1
- package/dist/internal/transaction.d.ts.map +1 -1
- package/dist/internal/transaction.js +125 -4
- package/dist/internal/transaction.js.map +1 -1
- package/dist/internal/transactionSubmission.d.ts +2 -0
- package/dist/internal/transactionSubmission.d.ts.map +1 -1
- package/dist/internal/transactionSubmission.js +3 -1
- package/dist/internal/transactionSubmission.js.map +1 -1
- package/dist/transactions/authenticator/account.d.ts.map +1 -1
- package/dist/transactions/authenticator/transaction.d.ts.map +1 -1
- package/dist/transactions/instances/chainId.d.ts.map +1 -1
- package/dist/transactions/instances/encryptedPayload.d.ts.map +1 -1
- package/dist/transactions/instances/encryptedPayload.js.map +1 -1
- package/dist/transactions/instances/identifier.d.ts.map +1 -1
- package/dist/transactions/instances/moduleId.d.ts.map +1 -1
- package/dist/transactions/instances/multiAgentTransaction.d.ts.map +1 -1
- package/dist/transactions/instances/rawTransaction.d.ts.map +1 -1
- package/dist/transactions/instances/rotationProofChallenge.d.ts.map +1 -1
- package/dist/transactions/instances/signedTransaction.d.ts.map +1 -1
- package/dist/transactions/instances/simpleTransaction.d.ts.map +1 -1
- package/dist/transactions/instances/transactionPayload.d.ts.map +1 -1
- package/dist/transactions/management/accountSequenceNumber.d.ts.map +1 -1
- package/dist/transactions/management/asyncQueue.d.ts.map +1 -1
- package/dist/transactions/management/transactionWorker.d.ts +10 -6
- package/dist/transactions/management/transactionWorker.d.ts.map +1 -1
- package/dist/transactions/management/transactionWorker.js +28 -24
- package/dist/transactions/management/transactionWorker.js.map +1 -1
- package/dist/transactions/transactionBuilder/index.d.ts +1 -0
- package/dist/transactions/transactionBuilder/index.d.ts.map +1 -1
- package/dist/transactions/transactionBuilder/index.js +1 -0
- package/dist/transactions/transactionBuilder/index.js.map +1 -1
- package/dist/transactions/transactionBuilder/scriptAbi.d.ts +10 -0
- package/dist/transactions/transactionBuilder/scriptAbi.d.ts.map +1 -0
- package/dist/transactions/transactionBuilder/scriptAbi.js +863 -0
- package/dist/transactions/transactionBuilder/scriptAbi.js.map +1 -0
- package/dist/transactions/transactionBuilder/structEnumParser.d.ts.map +1 -1
- package/dist/transactions/transactionBuilder/structEnumParser.js.map +1 -1
- package/dist/transactions/transactionBuilder/transactionBuilder.d.ts +7 -2
- package/dist/transactions/transactionBuilder/transactionBuilder.d.ts.map +1 -1
- package/dist/transactions/transactionBuilder/transactionBuilder.js +65 -1
- package/dist/transactions/transactionBuilder/transactionBuilder.js.map +1 -1
- package/dist/transactions/typeTag/index.d.ts.map +1 -1
- package/dist/transactions/typeTag/index.js.map +1 -1
- package/dist/transactions/typeTag/parser.d.ts.map +1 -1
- package/dist/transactions/typeTag/parser.js.map +1 -1
- package/dist/transactions/types.d.ts +9 -4
- package/dist/transactions/types.d.ts.map +1 -1
- package/dist/types/generated/queries.d.ts.map +1 -1
- package/dist/types/generated/queries.js.map +1 -1
- package/dist/types/keyless.d.ts +2 -2
- package/dist/types/keyless.d.ts.map +1 -1
- package/dist/types/types.d.ts +7 -2
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js.map +1 -1
- package/dist/utils/const.d.ts +11 -0
- package/dist/utils/const.d.ts.map +1 -1
- package/dist/utils/const.js +11 -0
- package/dist/utils/const.js.map +1 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/runtime.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +27 -25
- package/src/api/account/abstraction.ts +23 -6
- package/src/api/ans.ts +9 -0
- package/src/api/aptosConfig.ts +14 -0
- package/src/api/coin.ts +2 -0
- package/src/api/digitalAsset.ts +30 -0
- package/src/api/fungibleAsset.ts +4 -0
- package/src/api/keyless.ts +39 -1
- package/src/api/transaction.ts +48 -1
- package/src/api/transactionSubmission/build.ts +16 -6
- package/src/api/transactionSubmission/simulate.ts +7 -3
- package/src/bcs/serializable/moveStructs.ts +80 -28
- package/src/cli/localNode.ts +17 -3
- package/src/client/core.ts +150 -10
- package/src/functions/keyless.ts +1 -0
- package/src/functions/transaction.ts +1 -0
- package/src/internal/abstraction.ts +41 -3
- package/src/internal/account.ts +60 -38
- package/src/internal/ans.ts +24 -6
- package/src/internal/coin.ts +4 -1
- package/src/internal/digitalAsset.ts +60 -9
- package/src/internal/fungibleAsset.ts +8 -2
- package/src/internal/keyless.ts +91 -14
- package/src/internal/transaction.ts +154 -4
- package/src/internal/transactionSubmission.ts +4 -1
- package/src/transactions/management/transactionWorker.ts +35 -23
- package/src/transactions/transactionBuilder/index.ts +1 -0
- package/src/transactions/transactionBuilder/scriptAbi.ts +1145 -0
- package/src/transactions/transactionBuilder/transactionBuilder.ts +97 -6
- package/src/transactions/types.ts +10 -4
- package/src/types/keyless.ts +2 -2
- package/src/types/types.ts +8 -2
- package/src/utils/const.ts +12 -0
- package/src/version.ts +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright © Aptos Foundation
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { Account } from "../../account/index.js";
|
|
4
5
|
import { AccountAddressInput } from "../../core/index.js";
|
|
5
6
|
import { generateTransaction } from "../../internal/transactionSubmission.js";
|
|
6
7
|
import { InputGenerateTransactionPayloadData, InputGenerateTransactionOptions } from "../../transactions/index.js";
|
|
@@ -8,6 +9,10 @@ import { MultiAgentTransaction } from "../../transactions/instances/multiAgentTr
|
|
|
8
9
|
import { SimpleTransaction } from "../../transactions/instances/simpleTransaction.js";
|
|
9
10
|
import { AptosConfig } from "../aptosConfig.js";
|
|
10
11
|
|
|
12
|
+
function accountAddressInput(input: Account | AccountAddressInput): AccountAddressInput {
|
|
13
|
+
return typeof input === "object" && "accountAddress" in input ? input.accountAddress : input;
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
/**
|
|
12
17
|
* A class to handle all `Build` transaction operations.
|
|
13
18
|
* @group Implementation
|
|
@@ -53,7 +58,7 @@ export class Build {
|
|
|
53
58
|
*
|
|
54
59
|
* This function allows you to create a transaction with specified sender and data.
|
|
55
60
|
*
|
|
56
|
-
* @param args.sender - The sender account address.
|
|
61
|
+
* @param args.sender - The sender account or account address.
|
|
57
62
|
* @param args.data - The transaction data.
|
|
58
63
|
* @param args.options - Optional transaction configurations.
|
|
59
64
|
* @param args.withFeePayer - Whether there is a fee payer for the transaction.
|
|
@@ -62,15 +67,16 @@ export class Build {
|
|
|
62
67
|
*
|
|
63
68
|
* @example
|
|
64
69
|
* ```typescript
|
|
65
|
-
* import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
|
|
70
|
+
* import { Account, Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
|
|
66
71
|
*
|
|
67
72
|
* const config = new AptosConfig({ network: Network.TESTNET });
|
|
68
73
|
* const aptos = new Aptos(config);
|
|
74
|
+
* const sender = Account.generate();
|
|
69
75
|
*
|
|
70
76
|
* async function runExample() {
|
|
71
77
|
* // Build a simple transaction
|
|
72
|
-
* const transaction = await aptos.transaction.simple({
|
|
73
|
-
* sender
|
|
78
|
+
* const transaction = await aptos.transaction.build.simple({
|
|
79
|
+
* sender,
|
|
74
80
|
* data: {
|
|
75
81
|
* function: "0x1::aptos_account::transfer",
|
|
76
82
|
* functionArguments: ["0x2", 100], // replace with a real destination account address
|
|
@@ -88,12 +94,16 @@ export class Build {
|
|
|
88
94
|
* @group Implementation
|
|
89
95
|
*/
|
|
90
96
|
async simple(args: {
|
|
91
|
-
sender: AccountAddressInput;
|
|
97
|
+
sender: Account | AccountAddressInput;
|
|
92
98
|
data: InputGenerateTransactionPayloadData;
|
|
93
99
|
options?: InputGenerateTransactionOptions;
|
|
94
100
|
withFeePayer?: boolean;
|
|
95
101
|
}): Promise<SimpleTransaction> {
|
|
96
|
-
return generateTransaction({
|
|
102
|
+
return generateTransaction({
|
|
103
|
+
aptosConfig: this.config,
|
|
104
|
+
...args,
|
|
105
|
+
sender: accountAddressInput(args.sender),
|
|
106
|
+
});
|
|
97
107
|
}
|
|
98
108
|
|
|
99
109
|
/**
|
|
@@ -48,8 +48,13 @@ export class Simulate {
|
|
|
48
48
|
* Simulates a transaction based on the provided parameters and returns the result.
|
|
49
49
|
* This function helps you understand the outcome of a transaction before executing it on the blockchain.
|
|
50
50
|
*
|
|
51
|
+
* To pre-check a multisig proposal, build its entry function directly with the multisig address as sender and
|
|
52
|
+
* `withFeePayer: true`, then omit `signerPublicKey` and `feePayerPublicKey`. The simulation uses no-account
|
|
53
|
+
* authenticators to skip authentication-key validation, so the proposal does not need to exist on-chain.
|
|
54
|
+
*
|
|
51
55
|
* @param args - The parameters for simulating the transaction.
|
|
52
|
-
* @param args.signerPublicKey -
|
|
56
|
+
* @param args.signerPublicKey - Optional public key used to validate the signer's authentication key.
|
|
57
|
+
* Omit it to simulate with the sender address already embedded in the transaction.
|
|
53
58
|
* @param args.transaction - The raw transaction data to simulate.
|
|
54
59
|
* @param args.feePayerPublicKey - The public key of the fee payer (optional).
|
|
55
60
|
* @param args.options - Additional options for simulating the transaction (optional).
|
|
@@ -78,7 +83,7 @@ export class Simulate {
|
|
|
78
83
|
*
|
|
79
84
|
* // 1. Build the transaction to preview the impact of it
|
|
80
85
|
* const transaction = await aptos.transaction.build.simple({
|
|
81
|
-
* sender
|
|
86
|
+
* sender,
|
|
82
87
|
* data: {
|
|
83
88
|
* // All transactions on Aptos are implemented via smart contracts.
|
|
84
89
|
* function: "0x1::aptos_account::transfer",
|
|
@@ -88,7 +93,6 @@ export class Simulate {
|
|
|
88
93
|
*
|
|
89
94
|
* // 2. Simulate to see what would happen if we execute this transaction
|
|
90
95
|
* const [userTransactionResponse] = await aptos.transaction.simulate.simple({
|
|
91
|
-
* signerPublicKey: sender.publicKey,
|
|
92
96
|
* transaction,
|
|
93
97
|
* });
|
|
94
98
|
* console.log(userTransactionResponse);
|
|
@@ -6,6 +6,7 @@ import { Serializable, Serializer, serializeEntryFunctionBytesCompat } from "../
|
|
|
6
6
|
import { Deserializable, Deserializer } from "../deserializer.js";
|
|
7
7
|
import { AnyNumber, HexInput, ScriptTransactionArgumentVariants } from "../../types/index.js";
|
|
8
8
|
import { Hex } from "../../core/hex.js";
|
|
9
|
+
import { AccountAddress, AccountAddressInput } from "../../core/accountAddress.js";
|
|
9
10
|
import { EntryFunctionArgument, TransactionArgument } from "../../transactions/instances/transactionArgument.js";
|
|
10
11
|
import { TEXT_ENCODER } from "../../utils/const.js";
|
|
11
12
|
|
|
@@ -376,6 +377,23 @@ export class MoveVector<T extends Serializable & EntryFunctionArgument>
|
|
|
376
377
|
return new MoveVector<MoveString>(values.map((v) => new MoveString(v)));
|
|
377
378
|
}
|
|
378
379
|
|
|
380
|
+
/**
|
|
381
|
+
* Factory method to generate a MoveVector<AccountAddress> from an array of `AccountAddressInput` values.
|
|
382
|
+
*
|
|
383
|
+
* @param values - The values used to fill the MoveVector.
|
|
384
|
+
* @returns A MoveVector<AccountAddress> with the inner values.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```typescript
|
|
388
|
+
* const v = MoveVector.Address(["0x1", "0x2"]);
|
|
389
|
+
* ```
|
|
390
|
+
* @group Implementation
|
|
391
|
+
* @category BCS
|
|
392
|
+
*/
|
|
393
|
+
static Address(values: Array<AccountAddressInput>): MoveVector<AccountAddress> {
|
|
394
|
+
return new MoveVector<AccountAddress>(values.map((v) => AccountAddress.from(v)));
|
|
395
|
+
}
|
|
396
|
+
|
|
379
397
|
/**
|
|
380
398
|
* Serializes the current object using the provided serializer.
|
|
381
399
|
* This function will serialize the value if it is present.
|
|
@@ -575,13 +593,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
575
593
|
}
|
|
576
594
|
|
|
577
595
|
/**
|
|
578
|
-
* Factory method to generate a MoveOption<U8> from a `number` or `
|
|
596
|
+
* Factory method to generate a MoveOption<U8> from a `number`, `undefined`, or `null`.
|
|
579
597
|
*
|
|
580
598
|
* @example
|
|
581
599
|
* MoveOption.U8(1).isSome() === true;
|
|
582
600
|
* MoveOption.U8().isSome() === false;
|
|
583
601
|
* MoveOption.U8(undefined).isSome() === false;
|
|
584
|
-
*
|
|
602
|
+
* MoveOption.U8(null).isSome() === false;
|
|
603
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
585
604
|
* the resulting MoveOption's .isSome() method will return false.
|
|
586
605
|
* @returns a MoveOption<U8> with an inner value `value`
|
|
587
606
|
* @group Implementation
|
|
@@ -592,13 +611,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
592
611
|
}
|
|
593
612
|
|
|
594
613
|
/**
|
|
595
|
-
* Factory method to generate a MoveOption<U16> from a `number` or `
|
|
614
|
+
* Factory method to generate a MoveOption<U16> from a `number`, `undefined`, or `null`.
|
|
596
615
|
*
|
|
597
616
|
* @example
|
|
598
617
|
* MoveOption.U16(1).isSome() === true;
|
|
599
618
|
* MoveOption.U16().isSome() === false;
|
|
600
619
|
* MoveOption.U16(undefined).isSome() === false;
|
|
601
|
-
*
|
|
620
|
+
* MoveOption.U16(null).isSome() === false;
|
|
621
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
602
622
|
* the resulting MoveOption's .isSome() method will return false.
|
|
603
623
|
* @returns a MoveOption<U16> with an inner value `value`
|
|
604
624
|
* @group Implementation
|
|
@@ -609,13 +629,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
609
629
|
}
|
|
610
630
|
|
|
611
631
|
/**
|
|
612
|
-
* Factory method to generate a MoveOption<U32> from a `number` or `
|
|
632
|
+
* Factory method to generate a MoveOption<U32> from a `number`, `undefined`, or `null`.
|
|
613
633
|
*
|
|
614
634
|
* @example
|
|
615
635
|
* MoveOption.U32(1).isSome() === true;
|
|
616
636
|
* MoveOption.U32().isSome() === false;
|
|
617
637
|
* MoveOption.U32(undefined).isSome() === false;
|
|
618
|
-
*
|
|
638
|
+
* MoveOption.U32(null).isSome() === false;
|
|
639
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
619
640
|
* the resulting MoveOption's .isSome() method will return false.
|
|
620
641
|
* @returns a MoveOption<U32> with an inner value `value`
|
|
621
642
|
* @group Implementation
|
|
@@ -626,13 +647,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
626
647
|
}
|
|
627
648
|
|
|
628
649
|
/**
|
|
629
|
-
* Factory method to generate a MoveOption<U64> from a `number
|
|
650
|
+
* Factory method to generate a MoveOption<U64> from a `number`, `bigint`, `undefined`, or `null`.
|
|
630
651
|
*
|
|
631
652
|
* @example
|
|
632
653
|
* MoveOption.U64(1).isSome() === true;
|
|
633
654
|
* MoveOption.U64().isSome() === false;
|
|
634
655
|
* MoveOption.U64(undefined).isSome() === false;
|
|
635
|
-
*
|
|
656
|
+
* MoveOption.U64(null).isSome() === false;
|
|
657
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
636
658
|
* the resulting MoveOption's .isSome() method will return false.
|
|
637
659
|
* @returns a MoveOption<U64> with an inner value `value`
|
|
638
660
|
* @group Implementation
|
|
@@ -643,13 +665,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
643
665
|
}
|
|
644
666
|
|
|
645
667
|
/**
|
|
646
|
-
* Factory method to generate a MoveOption<U128> from a `number
|
|
668
|
+
* Factory method to generate a MoveOption<U128> from a `number`, `bigint`, `undefined`, or `null`.
|
|
647
669
|
*
|
|
648
670
|
* @example
|
|
649
671
|
* MoveOption.U128(1).isSome() === true;
|
|
650
672
|
* MoveOption.U128().isSome() === false;
|
|
651
673
|
* MoveOption.U128(undefined).isSome() === false;
|
|
652
|
-
*
|
|
674
|
+
* MoveOption.U128(null).isSome() === false;
|
|
675
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
653
676
|
* the resulting MoveOption's .isSome() method will return false.
|
|
654
677
|
* @returns a MoveOption<U128> with an inner value `value`
|
|
655
678
|
* @group Implementation
|
|
@@ -660,13 +683,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
660
683
|
}
|
|
661
684
|
|
|
662
685
|
/**
|
|
663
|
-
* Factory method to generate a MoveOption<U256> from a `number
|
|
686
|
+
* Factory method to generate a MoveOption<U256> from a `number`, `bigint`, `undefined`, or `null`.
|
|
664
687
|
*
|
|
665
688
|
* @example
|
|
666
689
|
* MoveOption.U256(1).isSome() === true;
|
|
667
690
|
* MoveOption.U256().isSome() === false;
|
|
668
691
|
* MoveOption.U256(undefined).isSome() === false;
|
|
669
|
-
*
|
|
692
|
+
* MoveOption.U256(null).isSome() === false;
|
|
693
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
670
694
|
* the resulting MoveOption's .isSome() method will return false.
|
|
671
695
|
* @returns a MoveOption<U256> with an inner value `value`
|
|
672
696
|
* @group Implementation
|
|
@@ -677,13 +701,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
677
701
|
}
|
|
678
702
|
|
|
679
703
|
/**
|
|
680
|
-
* Factory method to generate a MoveOption<Bool> from a `boolean` or `
|
|
704
|
+
* Factory method to generate a MoveOption<Bool> from a `boolean`, `undefined`, or `null`.
|
|
681
705
|
*
|
|
682
706
|
* @example
|
|
683
707
|
* MoveOption.Bool(true).isSome() === true;
|
|
684
708
|
* MoveOption.Bool().isSome() === false;
|
|
685
709
|
* MoveOption.Bool(undefined).isSome() === false;
|
|
686
|
-
*
|
|
710
|
+
* MoveOption.Bool(null).isSome() === false;
|
|
711
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
687
712
|
* the resulting MoveOption's .isSome() method will return false.
|
|
688
713
|
* @returns a MoveOption<Bool> with an inner value `value`
|
|
689
714
|
* @group Implementation
|
|
@@ -694,13 +719,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
694
719
|
}
|
|
695
720
|
|
|
696
721
|
/**
|
|
697
|
-
* Factory method to generate a MoveOption<I8> from a `number` or `
|
|
722
|
+
* Factory method to generate a MoveOption<I8> from a `number`, `undefined`, or `null`.
|
|
698
723
|
*
|
|
699
724
|
* @example
|
|
700
725
|
* MoveOption.I8(1).isSome() === true;
|
|
701
726
|
* MoveOption.I8().isSome() === false;
|
|
702
727
|
* MoveOption.I8(undefined).isSome() === false;
|
|
703
|
-
*
|
|
728
|
+
* MoveOption.I8(null).isSome() === false;
|
|
729
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
704
730
|
* the resulting MoveOption's .isSome() method will return false.
|
|
705
731
|
* @returns a MoveOption<I8> with an inner value `value`
|
|
706
732
|
* @group Implementation
|
|
@@ -711,13 +737,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
711
737
|
}
|
|
712
738
|
|
|
713
739
|
/**
|
|
714
|
-
* Factory method to generate a MoveOption<I16> from a `number` or `
|
|
740
|
+
* Factory method to generate a MoveOption<I16> from a `number`, `undefined`, or `null`.
|
|
715
741
|
*
|
|
716
742
|
* @example
|
|
717
743
|
* MoveOption.I16(1).isSome() === true;
|
|
718
744
|
* MoveOption.I16().isSome() === false;
|
|
719
745
|
* MoveOption.I16(undefined).isSome() === false;
|
|
720
|
-
*
|
|
746
|
+
* MoveOption.I16(null).isSome() === false;
|
|
747
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
721
748
|
* the resulting MoveOption's .isSome() method will return false.
|
|
722
749
|
* @returns a MoveOption<I16> with an inner value `value`
|
|
723
750
|
* @group Implementation
|
|
@@ -728,13 +755,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
728
755
|
}
|
|
729
756
|
|
|
730
757
|
/**
|
|
731
|
-
* Factory method to generate a MoveOption<I32> from a `number` or `
|
|
758
|
+
* Factory method to generate a MoveOption<I32> from a `number`, `undefined`, or `null`.
|
|
732
759
|
*
|
|
733
760
|
* @example
|
|
734
761
|
* MoveOption.I32(1).isSome() === true;
|
|
735
762
|
* MoveOption.I32().isSome() === false;
|
|
736
763
|
* MoveOption.I32(undefined).isSome() === false;
|
|
737
|
-
*
|
|
764
|
+
* MoveOption.I32(null).isSome() === false;
|
|
765
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
738
766
|
* the resulting MoveOption's .isSome() method will return false.
|
|
739
767
|
* @returns a MoveOption<I32> with an inner value `value`
|
|
740
768
|
* @group Implementation
|
|
@@ -745,13 +773,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
745
773
|
}
|
|
746
774
|
|
|
747
775
|
/**
|
|
748
|
-
* Factory method to generate a MoveOption<I64> from a `number
|
|
776
|
+
* Factory method to generate a MoveOption<I64> from a `number`, `bigint`, `undefined`, or `null`.
|
|
749
777
|
*
|
|
750
778
|
* @example
|
|
751
779
|
* MoveOption.I64(1).isSome() === true;
|
|
752
780
|
* MoveOption.I64().isSome() === false;
|
|
753
781
|
* MoveOption.I64(undefined).isSome() === false;
|
|
754
|
-
*
|
|
782
|
+
* MoveOption.I64(null).isSome() === false;
|
|
783
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
755
784
|
* the resulting MoveOption's .isSome() method will return false.
|
|
756
785
|
* @returns a MoveOption<I64> with an inner value `value`
|
|
757
786
|
* @group Implementation
|
|
@@ -762,13 +791,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
762
791
|
}
|
|
763
792
|
|
|
764
793
|
/**
|
|
765
|
-
* Factory method to generate a MoveOption<I128> from a `number
|
|
794
|
+
* Factory method to generate a MoveOption<I128> from a `number`, `bigint`, `undefined`, or `null`.
|
|
766
795
|
*
|
|
767
796
|
* @example
|
|
768
797
|
* MoveOption.I128(1).isSome() === true;
|
|
769
798
|
* MoveOption.I128().isSome() === false;
|
|
770
799
|
* MoveOption.I128(undefined).isSome() === false;
|
|
771
|
-
*
|
|
800
|
+
* MoveOption.I128(null).isSome() === false;
|
|
801
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
772
802
|
* the resulting MoveOption's .isSome() method will return false.
|
|
773
803
|
* @returns a MoveOption<I128> with an inner value `value`
|
|
774
804
|
* @group Implementation
|
|
@@ -779,13 +809,14 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
779
809
|
}
|
|
780
810
|
|
|
781
811
|
/**
|
|
782
|
-
* Factory method to generate a MoveOption<I256> from a `number
|
|
812
|
+
* Factory method to generate a MoveOption<I256> from a `number`, `bigint`, `undefined`, or `null`.
|
|
783
813
|
*
|
|
784
814
|
* @example
|
|
785
815
|
* MoveOption.I256(1).isSome() === true;
|
|
786
816
|
* MoveOption.I256().isSome() === false;
|
|
787
817
|
* MoveOption.I256(undefined).isSome() === false;
|
|
788
|
-
*
|
|
818
|
+
* MoveOption.I256(null).isSome() === false;
|
|
819
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
789
820
|
* the resulting MoveOption's .isSome() method will return false.
|
|
790
821
|
* @returns a MoveOption<I256> with an inner value `value`
|
|
791
822
|
* @group Implementation
|
|
@@ -796,14 +827,15 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
796
827
|
}
|
|
797
828
|
|
|
798
829
|
/**
|
|
799
|
-
* Factory method to generate a MoveOption<MoveString> from a `string` or `
|
|
830
|
+
* Factory method to generate a MoveOption<MoveString> from a `string`, `undefined`, or `null`.
|
|
800
831
|
*
|
|
801
832
|
* @example
|
|
802
833
|
* MoveOption.MoveString("hello").isSome() === true;
|
|
803
834
|
* MoveOption.MoveString("").isSome() === true;
|
|
804
835
|
* MoveOption.MoveString().isSome() === false;
|
|
805
836
|
* MoveOption.MoveString(undefined).isSome() === false;
|
|
806
|
-
*
|
|
837
|
+
* MoveOption.MoveString(null).isSome() === false;
|
|
838
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
807
839
|
* the resulting MoveOption's .isSome() method will return false.
|
|
808
840
|
* @returns a MoveOption<MoveString> with an inner value `value`
|
|
809
841
|
* @group Implementation
|
|
@@ -813,6 +845,26 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
|
813
845
|
return new MoveOption<MoveString>(value !== null && value !== undefined ? new MoveString(value) : undefined);
|
|
814
846
|
}
|
|
815
847
|
|
|
848
|
+
/**
|
|
849
|
+
* Factory method to generate a MoveOption<AccountAddress> from an `AccountAddressInput`, `undefined`, or `null`.
|
|
850
|
+
*
|
|
851
|
+
* @example
|
|
852
|
+
* MoveOption.Address("0x1").isSome() === true;
|
|
853
|
+
* MoveOption.Address().isSome() === false;
|
|
854
|
+
* MoveOption.Address(undefined).isSome() === false;
|
|
855
|
+
* MoveOption.Address(null).isSome() === false;
|
|
856
|
+
* @param value the value used to fill the MoveOption. If `value` is undefined or null
|
|
857
|
+
* the resulting MoveOption's .isSome() method will return false.
|
|
858
|
+
* @returns a MoveOption<AccountAddress> with an inner value `value`
|
|
859
|
+
* @group Implementation
|
|
860
|
+
* @category BCS
|
|
861
|
+
*/
|
|
862
|
+
static Address(value?: AccountAddressInput | null): MoveOption<AccountAddress> {
|
|
863
|
+
return new MoveOption<AccountAddress>(
|
|
864
|
+
value !== null && value !== undefined ? AccountAddress.from(value) : undefined,
|
|
865
|
+
);
|
|
866
|
+
}
|
|
867
|
+
|
|
816
868
|
static deserialize<U extends Serializable & EntryFunctionArgument>(
|
|
817
869
|
deserializer: Deserializer,
|
|
818
870
|
cls: Deserializable<U>,
|
package/src/cli/localNode.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ChildProcessWithoutNullStreams, spawn } from "node:child_process";
|
|
2
|
+
import { appendFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
2
4
|
import kill from "tree-kill";
|
|
3
5
|
import { platform } from "node:os";
|
|
4
6
|
|
|
@@ -111,13 +113,25 @@ export class LocalNode {
|
|
|
111
113
|
|
|
112
114
|
this.process = spawn(cliCommand, cliArgs, spawnConfig);
|
|
113
115
|
|
|
114
|
-
|
|
116
|
+
// CI prints `${{ runner.temp }}/local-testnet-logs.txt` on failure (TMPDIR).
|
|
117
|
+
const logPath = process.env.TMPDIR ? join(process.env.TMPDIR, "local-testnet-logs.txt") : undefined;
|
|
118
|
+
|
|
119
|
+
const handleOutput = (data: any) => {
|
|
115
120
|
const str = data.toString();
|
|
116
|
-
// Print local node output log
|
|
117
121
|
if (this.showStdout) {
|
|
118
122
|
console.log(str);
|
|
119
123
|
}
|
|
120
|
-
|
|
124
|
+
if (logPath) {
|
|
125
|
+
try {
|
|
126
|
+
appendFileSync(logPath, str);
|
|
127
|
+
} catch {
|
|
128
|
+
// Best-effort logging only — never fail the node start on log I/O.
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
this.process.stdout?.on("data", handleOutput);
|
|
134
|
+
this.process.stderr?.on("data", handleOutput);
|
|
121
135
|
}
|
|
122
136
|
|
|
123
137
|
/**
|
package/src/client/core.ts
CHANGED
|
@@ -68,26 +68,107 @@ export async function request<Req, Res>(options: ClientRequest<Req>, client: Cli
|
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
const HTTP_STATUS_GONE = 410;
|
|
72
|
+
|
|
73
|
+
const CREDENTIAL_HEADERS = new Set(["authorization", "cookie", "x-api-key"]);
|
|
74
|
+
|
|
75
|
+
const warnedArchivalEndpoints = new Set<string>();
|
|
76
|
+
|
|
77
|
+
type ArchivalRetryTarget = {
|
|
78
|
+
url: string;
|
|
79
|
+
forwardCredentials: boolean;
|
|
80
|
+
};
|
|
81
|
+
|
|
71
82
|
/**
|
|
72
|
-
*
|
|
83
|
+
* Registrable domain, approximated as the last two labels.
|
|
84
|
+
* Hosts under a multi-part suffix like `co.uk` compare equal.
|
|
85
|
+
*/
|
|
86
|
+
function siteOf(hostname: string): string {
|
|
87
|
+
return hostname.toLowerCase().split(".").slice(-2).join(".");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Validates the archival endpoint advertised in a pruning error, returning undefined if it is unusable.
|
|
73
92
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @param apiType - The type of API being accessed, which determines how the response is handled.
|
|
77
|
-
* @returns The response from the API request or throws an AptosApiError if the request fails.
|
|
78
|
-
* @group Implementation
|
|
79
|
-
* @category Client
|
|
93
|
+
* The endpoint is chosen by the node rather than the caller, so it must be an absolute http(s) URL that does
|
|
94
|
+
* not downgrade an https request, and credentials are only forwarded to it when it is same-site.
|
|
80
95
|
*/
|
|
81
|
-
|
|
96
|
+
function resolveArchivalRetryTarget(originalUrl: string, responseData: any): ArchivalRetryTarget | undefined {
|
|
97
|
+
const advertisedEndpoint = responseData?.archival_endpoint;
|
|
98
|
+
if (typeof advertisedEndpoint !== "string" || advertisedEndpoint.length === 0) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let archivalUrl: URL;
|
|
103
|
+
let originUrl: URL;
|
|
104
|
+
try {
|
|
105
|
+
archivalUrl = new URL(advertisedEndpoint);
|
|
106
|
+
originUrl = new URL(originalUrl);
|
|
107
|
+
} catch {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (archivalUrl.protocol !== "https:" && archivalUrl.protocol !== "http:") {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (originUrl.protocol === "https:" && archivalUrl.protocol !== "https:") {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
url: advertisedEndpoint.replace(/\/+$/, ""),
|
|
120
|
+
forwardCredentials: siteOf(archivalUrl.hostname) === siteOf(originUrl.hostname),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function hasCredentials(overrides: AptosRequest["overrides"]): boolean {
|
|
125
|
+
if (!overrides) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (overrides.API_KEY || overrides.AUTH_TOKEN) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
return Object.keys(overrides.HEADERS ?? {}).some((name) => CREDENTIAL_HEADERS.has(name.toLowerCase()));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function withoutCredentials(overrides: AptosRequest["overrides"]): AptosRequest["overrides"] {
|
|
135
|
+
if (!overrides) {
|
|
136
|
+
return overrides;
|
|
137
|
+
}
|
|
138
|
+
const { API_KEY, AUTH_TOKEN, HEADERS, ...rest } = overrides;
|
|
139
|
+
if (!HEADERS) {
|
|
140
|
+
return rest;
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
...rest,
|
|
144
|
+
HEADERS: Object.fromEntries(
|
|
145
|
+
Object.entries(HEADERS).filter(([name]) => !CREDENTIAL_HEADERS.has(name.toLowerCase())),
|
|
146
|
+
),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function warnOnceAboutDroppedCredentials(originalUrl: string, archivalUrl: string): void {
|
|
151
|
+
if (warnedArchivalEndpoints.has(archivalUrl)) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
warnedArchivalEndpoints.add(archivalUrl);
|
|
155
|
+
console.warn(
|
|
156
|
+
`[Aptos SDK] ${originalUrl} reported pruned data and advertised the archival endpoint ${archivalUrl}. ` +
|
|
157
|
+
"Retrying there without credentials because it is not on the same site. If that endpoint requires " +
|
|
158
|
+
"authentication, set it as your `fullnode` URL, or disable this retry with `archivalFallback: false`.",
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Sends a request and shapes the client response into an `AptosResponse`, without interpreting the status. */
|
|
163
|
+
async function sendAptosRequest<Req extends {}, Res extends {}>(
|
|
82
164
|
aptosRequestOpts: AptosRequest,
|
|
83
165
|
aptosConfig: AptosConfig,
|
|
84
|
-
apiType: AptosApiType,
|
|
85
166
|
): Promise<AptosResponse<Req, Res>> {
|
|
86
167
|
const { url, path } = aptosRequestOpts;
|
|
87
168
|
const fullUrl = path ? `${url}/${path}` : url;
|
|
88
169
|
const clientResponse = await request<Req, Res>({ ...aptosRequestOpts, url: fullUrl }, aptosConfig.client);
|
|
89
170
|
|
|
90
|
-
|
|
171
|
+
return {
|
|
91
172
|
status: clientResponse.status,
|
|
92
173
|
statusText: clientResponse.statusText ?? "No status text provided",
|
|
93
174
|
data: clientResponse.data,
|
|
@@ -96,7 +177,14 @@ export async function aptosRequest<Req extends {}, Res extends {}>(
|
|
|
96
177
|
request: clientResponse.request,
|
|
97
178
|
url: fullUrl,
|
|
98
179
|
};
|
|
180
|
+
}
|
|
99
181
|
|
|
182
|
+
/** Returns the response on success, or throws an `AptosApiError` describing the failure. */
|
|
183
|
+
function handleAptosResponse<Req extends {}, Res extends {}>(
|
|
184
|
+
aptosResponse: AptosResponse<Req, Res>,
|
|
185
|
+
aptosRequestOpts: AptosRequest,
|
|
186
|
+
apiType: AptosApiType,
|
|
187
|
+
): AptosResponse<Req, Res> {
|
|
100
188
|
// Handle case for `Unauthorized` error (i.e. API_KEY error)
|
|
101
189
|
if (aptosResponse.status === 401) {
|
|
102
190
|
throw new AptosApiError({ apiType, aptosRequest: aptosRequestOpts, aptosResponse });
|
|
@@ -135,3 +223,55 @@ export async function aptosRequest<Req extends {}, Res extends {}>(
|
|
|
135
223
|
// comes from an indexer request (e.g. 404), we'll need to mention it appropriately
|
|
136
224
|
throw new AptosApiError({ apiType, aptosRequest: aptosRequestOpts, aptosResponse });
|
|
137
225
|
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The main function to use when making an API request, returning the response or throwing an AptosApiError on failure.
|
|
229
|
+
*
|
|
230
|
+
* A Node API read of pruned data answers `410 Gone` with an `archival_endpoint`. Such requests are replayed
|
|
231
|
+
* once against that endpoint and the result returned transparently. Opt out with `archivalFallback: false`.
|
|
232
|
+
*
|
|
233
|
+
* @param aptosRequestOpts - Options for the Aptos request, including the URL and path.
|
|
234
|
+
* @param aptosConfig - The configuration information for the SDK client instance.
|
|
235
|
+
* @param apiType - The type of API being accessed, which determines how the response is handled.
|
|
236
|
+
* @returns The response from the API request or throws an AptosApiError if the request fails.
|
|
237
|
+
* @group Implementation
|
|
238
|
+
* @category Client
|
|
239
|
+
*/
|
|
240
|
+
export async function aptosRequest<Req extends {}, Res extends {}>(
|
|
241
|
+
aptosRequestOpts: AptosRequest,
|
|
242
|
+
aptosConfig: AptosConfig,
|
|
243
|
+
apiType: AptosApiType,
|
|
244
|
+
): Promise<AptosResponse<Req, Res>> {
|
|
245
|
+
const aptosResponse = await sendAptosRequest<Req, Res>(aptosRequestOpts, aptosConfig);
|
|
246
|
+
|
|
247
|
+
const archivalTarget =
|
|
248
|
+
apiType === AptosApiType.FULLNODE && aptosResponse.status === HTTP_STATUS_GONE && aptosConfig.archivalFallback
|
|
249
|
+
? resolveArchivalRetryTarget(aptosResponse.url, aptosResponse.data)
|
|
250
|
+
: undefined;
|
|
251
|
+
|
|
252
|
+
if (archivalTarget === undefined) {
|
|
253
|
+
return handleAptosResponse<Req, Res>(aptosResponse, aptosRequestOpts, apiType);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (!archivalTarget.forwardCredentials && hasCredentials(aptosRequestOpts.overrides)) {
|
|
257
|
+
warnOnceAboutDroppedCredentials(aptosResponse.url, archivalTarget.url);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const archivalRequestOpts: AptosRequest = {
|
|
261
|
+
...aptosRequestOpts,
|
|
262
|
+
url: archivalTarget.url,
|
|
263
|
+
overrides: archivalTarget.forwardCredentials
|
|
264
|
+
? aptosRequestOpts.overrides
|
|
265
|
+
: withoutCredentials(aptosRequestOpts.overrides),
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
let archivalResponse: AptosResponse<Req, Res>;
|
|
269
|
+
try {
|
|
270
|
+
archivalResponse = await sendAptosRequest<Req, Res>(archivalRequestOpts, aptosConfig);
|
|
271
|
+
} catch {
|
|
272
|
+
// Archival was unreachable, so the pruning error remains the more useful one to surface.
|
|
273
|
+
throw new AptosApiError({ apiType, aptosRequest: aptosRequestOpts, aptosResponse });
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return handleAptosResponse<Req, Res>(archivalResponse, archivalRequestOpts, apiType);
|
|
277
|
+
}
|
package/src/functions/keyless.ts
CHANGED