@aeternity/aepp-sdk 12.0.0 → 12.1.2
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/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +2 -1
- package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +20765 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -7
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +4 -3
- package/es/AeSdkAepp.mjs +2 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +22 -21
- package/es/AeSdkBase.mjs +25 -21
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +4 -3
- package/es/AeSdkWallet.mjs +5 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +7 -10
- package/es/Node.mjs +63 -57
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +7 -4
- package/es/account/Base.mjs +3 -3
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Memory.d.ts +5 -4
- package/es/account/Memory.mjs +24 -2
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -6
- package/es/account/Rpc.mjs +3 -2
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +27 -14
- package/es/aens.mjs +27 -21
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +17 -2
- package/es/aepp-wallet-communication/schema.mjs +54 -17
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +6 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.mjs +4 -2
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/chain.d.ts +92 -64
- package/es/chain.mjs +190 -154
- package/es/chain.mjs.map +1 -1
- package/es/channel/handlers.d.ts +3 -3
- package/es/channel/handlers.mjs +42 -44
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +43 -52
- package/es/channel/index.mjs +46 -49
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +16 -15
- package/es/channel/internal.mjs +67 -62
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +1 -0
- package/es/contract/Compiler.mjs +5 -4
- package/es/contract/Compiler.mjs.map +1 -1
- package/es/contract/aci.d.ts +17 -15
- package/es/contract/aci.mjs +58 -45
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +16 -15
- package/es/contract/ga.mjs +12 -7
- package/es/contract/ga.mjs.map +1 -1
- package/es/contract/methods.d.ts +9 -6
- package/es/contract/methods.mjs +9 -6
- package/es/contract/methods.mjs.map +1 -1
- package/es/deprecated/index.d.ts +143 -0
- package/es/deprecated/index.mjs +162 -0
- package/es/deprecated/index.mjs.map +1 -0
- package/es/deprecated/methods.d.ts +18 -0
- package/es/deprecated/methods.mjs +26 -0
- package/es/deprecated/methods.mjs.map +1 -0
- package/es/index.d.ts +4 -1
- package/es/index.mjs +4 -1
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +69 -62
- package/es/oracle.mjs +121 -103
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +16 -15
- package/es/spend.mjs +19 -30
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/address.d.ts +25 -0
- package/es/tx/builder/address.mjs +45 -0
- package/es/tx/builder/address.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +55 -26
- package/es/tx/builder/constants.mjs +60 -38
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
- package/es/tx/builder/field-types/coin-amount.mjs +26 -0
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +15 -0
- package/es/tx/builder/field-types/deposit.mjs +19 -0
- package/es/tx/builder/field-types/deposit.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +25 -0
- package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
- package/es/tx/builder/field-types/fee.mjs.map +1 -0
- package/es/tx/builder/field-types/field.d.ts +6 -0
- package/es/tx/builder/field-types/field.mjs +15 -0
- package/es/tx/builder/field-types/field.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
- package/es/tx/builder/field-types/gas-limit.mjs +33 -0
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-price.d.ts +8 -0
- package/es/tx/builder/field-types/gas-price.mjs +18 -0
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
- package/es/tx/builder/field-types/index.d.ts +70 -0
- package/es/tx/builder/field-types/index.mjs +25 -0
- package/es/tx/builder/field-types/index.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +20 -0
- package/es/tx/builder/field-types/name-fee.mjs +24 -0
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/name-id.d.ts +14 -0
- package/es/tx/builder/field-types/name-id.mjs +19 -0
- package/es/tx/builder/field-types/name-id.mjs.map +1 -0
- package/es/tx/builder/field-types/name.d.ts +13 -0
- package/es/tx/builder/field-types/name.mjs +18 -0
- package/es/tx/builder/field-types/name.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/es/tx/builder/field-types/short-u-int.mjs +12 -0
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +8 -0
- package/es/tx/builder/field-types/u-int.mjs +14 -0
- package/es/tx/builder/field-types/u-int.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +27 -33
- package/es/tx/builder/helpers.mjs +41 -47
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +25 -12
- package/es/tx/builder/index.mjs +74 -83
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +995 -144
- package/es/tx/builder/schema.mjs +121 -170
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +28 -27
- package/es/tx/index.mjs +97 -117
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -3
- package/es/tx/validator.mjs +79 -92
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
- package/es/typings/bip32-path/index.d.mjs.map +1 -1
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/sha-js/index.d.mjs +2 -0
- package/es/typings/sha-js/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
- package/es/utils/amount-formatter.d.ts +9 -9
- package/es/utils/amount-formatter.mjs +17 -17
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs +7 -7
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +2 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +8 -23
- package/es/utils/crypto.mjs +15 -41
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +61 -0
- package/es/utils/encoder-types.mjs +36 -0
- package/es/utils/encoder-types.mjs.map +1 -0
- package/es/utils/encoder.d.ts +6 -7
- package/es/utils/encoder.mjs +42 -26
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +1 -11
- package/es/utils/errors.mjs +4 -20
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +18 -2
- package/es/utils/hd-wallet.mjs +64 -34
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -2
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.mjs +4 -2
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/mptree.d.ts +2 -2
- package/es/utils/mptree.mjs +11 -6
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +8 -2
- package/es/utils/other.mjs +15 -3
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -1
- package/es/utils/semver-satisfies.mjs +2 -2
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/package.json +36 -34
- package/src/AeSdk.ts +30 -27
- package/src/AeSdkAepp.ts +93 -84
- package/src/AeSdkBase.ts +148 -130
- package/src/AeSdkWallet.ts +172 -156
- package/src/Node.ts +108 -102
- package/src/account/Base.ts +42 -32
- package/src/account/Memory.ts +45 -30
- package/src/account/Rpc.ts +32 -30
- package/src/aens.ts +124 -108
- package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
- package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
- package/src/aepp-wallet-communication/rpc/types.ts +32 -32
- package/src/aepp-wallet-communication/schema.ts +117 -74
- package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
- package/src/apis/node/code-model-v4.yaml +54 -20
- package/src/apis/node/models/index.ts +6 -2
- package/src/apis/node/models/mappers.ts +4 -2
- package/src/chain.ts +286 -228
- package/src/channel/handlers.ts +424 -372
- package/src/channel/index.ts +285 -251
- package/src/channel/internal.ts +248 -232
- package/src/contract/Compiler.ts +22 -21
- package/src/contract/aci.ts +267 -258
- package/src/contract/ga.ts +93 -72
- package/src/contract/methods.ts +32 -27
- package/src/deprecated/index.ts +172 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +37 -32
- package/src/oracle.ts +211 -189
- package/src/spend.ts +82 -70
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +82 -52
- package/src/tx/builder/field-types/coin-amount.ts +27 -0
- package/src/tx/builder/field-types/deposit.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +143 -0
- package/src/tx/builder/field-types/field.ts +9 -0
- package/src/tx/builder/field-types/gas-limit.ts +41 -0
- package/src/tx/builder/field-types/gas-price.ts +16 -0
- package/src/tx/builder/field-types/index.ts +45 -0
- package/src/tx/builder/field-types/name-fee.ts +32 -0
- package/src/tx/builder/field-types/name-id.ts +20 -0
- package/src/tx/builder/field-types/name.ts +18 -0
- package/src/tx/builder/field-types/short-u-int.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +16 -0
- package/src/tx/builder/helpers.ts +112 -117
- package/src/tx/builder/index.ts +203 -197
- package/src/tx/builder/schema.ts +421 -465
- package/src/tx/index.ts +128 -135
- package/src/tx/validator.ts +165 -161
- package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
- package/src/typings/@aeternity__uuid/index.d.ts +3 -1
- package/src/typings/bip32-path/index.d.ts +6 -6
- package/src/typings/blakejs/index.d.ts +4 -32
- package/src/typings/sha-js/index.d.ts +5 -0
- package/src/typings/tweetnacl-auth/index.d.ts +2 -2
- package/src/utils/amount-formatter.ts +41 -41
- package/src/utils/autorest.ts +57 -54
- package/src/utils/bignumber.ts +7 -6
- package/src/utils/bytes.ts +19 -19
- package/src/utils/crypto.ts +82 -94
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +104 -56
- package/src/utils/errors.ts +246 -264
- package/src/utils/hd-wallet.ts +114 -82
- package/src/utils/json-big.ts +16 -15
- package/src/utils/keystore.ts +65 -62
- package/src/utils/mptree.ts +59 -56
- package/src/utils/other.ts +26 -18
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +10 -10
- package/es/tx/builder/field-types.d.ts +0 -62
- package/es/tx/builder/field-types.mjs +0 -126
- package/es/tx/builder/field-types.mjs.map +0 -1
- package/es/tx/min-fee.d.ts +0 -20
- package/es/tx/min-fee.mjs.map +0 -1
- package/src/tx/builder/field-types.ts +0 -111
- package/src/tx/min-fee.ts +0 -136
package/src/chain.ts
CHANGED
|
@@ -14,37 +14,148 @@
|
|
|
14
14
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
|
-
import { AE_AMOUNT_FORMATS, formatAmount } from './utils/amount-formatter'
|
|
18
|
-
import verifyTransaction from './tx/validator'
|
|
19
|
-
import { pause } from './utils/other'
|
|
20
|
-
import { isNameValid, produceNameId
|
|
21
|
-
import { DRY_RUN_ACCOUNT
|
|
17
|
+
import { AE_AMOUNT_FORMATS, formatAmount } from './utils/amount-formatter';
|
|
18
|
+
import verifyTransaction, { ValidatorResult } from './tx/validator';
|
|
19
|
+
import { pause } from './utils/other';
|
|
20
|
+
import { isNameValid, produceNameId } from './tx/builder/helpers';
|
|
21
|
+
import { DRY_RUN_ACCOUNT } from './tx/builder/schema';
|
|
22
|
+
import { AensName } from './tx/builder/constants';
|
|
22
23
|
import {
|
|
23
|
-
AensPointerContextError, DryRunError, InvalidAensNameError,
|
|
24
|
-
|
|
25
|
-
} from './utils/errors'
|
|
26
|
-
import Node, { TransformNodeType } from './Node'
|
|
24
|
+
AensPointerContextError, DryRunError, InvalidAensNameError, TransactionError,
|
|
25
|
+
TxTimedOutError, TxNotInChainError, InternalError,
|
|
26
|
+
} from './utils/errors';
|
|
27
|
+
import Node, { TransformNodeType } from './Node';
|
|
27
28
|
import {
|
|
28
29
|
Account as AccountNode, ByteCode, ContractObject, DryRunResult, DryRunResults,
|
|
29
|
-
Generation, KeyBlock, MicroBlockHeader, NameEntry, SignedTx
|
|
30
|
-
} from './apis/node'
|
|
31
|
-
import {
|
|
32
|
-
import AccountBase from './account/Base'
|
|
30
|
+
Generation, KeyBlock, MicroBlockHeader, NameEntry, SignedTx,
|
|
31
|
+
} from './apis/node';
|
|
32
|
+
import { decode, Encoded, Encoding } from './utils/encoder';
|
|
33
|
+
import AccountBase from './account/Base';
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
/**
|
|
36
|
+
* @category chain
|
|
37
|
+
*/
|
|
38
|
+
export function _getPollInterval(
|
|
35
39
|
type: 'block' | 'microblock',
|
|
36
40
|
{ _expectedMineRate = 180000, _microBlockCycle = 3000, _maxPollInterval = 5000 }:
|
|
37
|
-
{ _expectedMineRate?: number
|
|
41
|
+
{ _expectedMineRate?: number; _microBlockCycle?: number; _maxPollInterval?: number },
|
|
38
42
|
): number {
|
|
39
43
|
const base = {
|
|
40
44
|
block: _expectedMineRate,
|
|
41
|
-
microblock: _microBlockCycle
|
|
42
|
-
}[type]
|
|
43
|
-
return Math.min(base / 3, _maxPollInterval)
|
|
45
|
+
microblock: _microBlockCycle,
|
|
46
|
+
}[type];
|
|
47
|
+
return Math.min(base / 3, _maxPollInterval);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @category exception
|
|
52
|
+
*/
|
|
53
|
+
export class InvalidTxError extends TransactionError {
|
|
54
|
+
validation: ValidatorResult[];
|
|
55
|
+
|
|
56
|
+
transaction: Encoded.Transaction;
|
|
57
|
+
|
|
58
|
+
constructor(
|
|
59
|
+
message: string,
|
|
60
|
+
validation: ValidatorResult[],
|
|
61
|
+
transaction: Encoded.Transaction,
|
|
62
|
+
) {
|
|
63
|
+
super(message);
|
|
64
|
+
this.name = 'InvalidTxError';
|
|
65
|
+
this.validation = validation;
|
|
66
|
+
this.transaction = transaction;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Obtain current height of the chain
|
|
72
|
+
* @category chain
|
|
73
|
+
* @returns Current chain height
|
|
74
|
+
*/
|
|
75
|
+
export async function getHeight({ onNode }: { onNode: Node }): Promise<number> {
|
|
76
|
+
return (await onNode.getCurrentKeyBlockHeight()).height;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Wait for a transaction to be mined
|
|
81
|
+
* @category chain
|
|
82
|
+
* @param th - The hash of transaction to poll
|
|
83
|
+
* @param options - Options
|
|
84
|
+
* @param options.interval - Interval (in ms) at which to poll the chain
|
|
85
|
+
* @param options.blocks - Number of blocks mined after which to fail
|
|
86
|
+
* @param options.onNode - Node to use
|
|
87
|
+
* @returns The transaction as it was mined
|
|
88
|
+
*/
|
|
89
|
+
export async function poll(
|
|
90
|
+
th: Encoded.TxHash,
|
|
91
|
+
{
|
|
92
|
+
blocks = 10, interval, onNode, ...options
|
|
93
|
+
}:
|
|
94
|
+
{ blocks?: number; interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],
|
|
95
|
+
): Promise<TransformNodeType<SignedTx>> {
|
|
96
|
+
interval ??= _getPollInterval('microblock', options);
|
|
97
|
+
const max = await getHeight({ onNode }) + blocks;
|
|
98
|
+
do {
|
|
99
|
+
const tx = await onNode.getTransactionByHash(th);
|
|
100
|
+
if (tx.blockHeight !== -1) return tx;
|
|
101
|
+
await pause(interval);
|
|
102
|
+
} while (await getHeight({ onNode }) < max);
|
|
103
|
+
throw new TxTimedOutError(blocks, th);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Wait for the chain to reach a specific height
|
|
108
|
+
* @category chain
|
|
109
|
+
* @param height - Height to wait for
|
|
110
|
+
* @param options - Options
|
|
111
|
+
* @param options.interval - Interval (in ms) at which to poll the chain
|
|
112
|
+
* @param options.onNode - Node to use
|
|
113
|
+
* @returns Current chain height
|
|
114
|
+
*/
|
|
115
|
+
export async function awaitHeight(
|
|
116
|
+
height: number,
|
|
117
|
+
{ interval, onNode, ...options }:
|
|
118
|
+
{ interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],
|
|
119
|
+
): Promise<number> {
|
|
120
|
+
interval ??= _getPollInterval('block', options);
|
|
121
|
+
let currentHeight;
|
|
122
|
+
do {
|
|
123
|
+
if (currentHeight != null) await pause(interval);
|
|
124
|
+
currentHeight = (await onNode.getCurrentKeyBlockHeight()).height;
|
|
125
|
+
} while (currentHeight < height);
|
|
126
|
+
return currentHeight;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Wait for transaction confirmation
|
|
131
|
+
* @category chain
|
|
132
|
+
* @param txHash - Transaction hash
|
|
133
|
+
* @param options - Options
|
|
134
|
+
* @param options.confirm - Number of micro blocks to wait for transaction confirmation
|
|
135
|
+
* @param options.onNode - Node to use
|
|
136
|
+
* @returns Current Height
|
|
137
|
+
*/
|
|
138
|
+
export async function waitForTxConfirm(
|
|
139
|
+
txHash: Encoded.TxHash,
|
|
140
|
+
{ confirm = 3, onNode, ...options }:
|
|
141
|
+
{ confirm?: number; onNode: Node } & Parameters<typeof awaitHeight>[1],
|
|
142
|
+
): Promise<number> {
|
|
143
|
+
const { blockHeight } = await onNode.getTransactionByHash(txHash);
|
|
144
|
+
const height = await awaitHeight(blockHeight + confirm, { onNode, ...options });
|
|
145
|
+
const { blockHeight: newBlockHeight } = await onNode.getTransactionByHash(txHash);
|
|
146
|
+
switch (newBlockHeight) {
|
|
147
|
+
case -1:
|
|
148
|
+
throw new TxNotInChainError(txHash);
|
|
149
|
+
case blockHeight:
|
|
150
|
+
return height;
|
|
151
|
+
default:
|
|
152
|
+
return waitForTxConfirm(txHash, { onNode, confirm, ...options });
|
|
153
|
+
}
|
|
44
154
|
}
|
|
45
155
|
|
|
46
156
|
/**
|
|
47
157
|
* Submit a signed transaction for mining
|
|
158
|
+
* @category chain
|
|
48
159
|
* @param tx - Transaction to submit
|
|
49
160
|
* @param options - Options
|
|
50
161
|
* @param options.onNode - Node to use
|
|
@@ -54,115 +165,96 @@ export function _getPollInterval (
|
|
|
54
165
|
* @param options.confirm - Number of micro blocks that should be mined after tx get included
|
|
55
166
|
* @returns Transaction details
|
|
56
167
|
*/
|
|
57
|
-
export async function sendTransaction
|
|
58
|
-
tx:
|
|
59
|
-
{
|
|
60
|
-
|
|
168
|
+
export async function sendTransaction(
|
|
169
|
+
tx: Encoded.Transaction,
|
|
170
|
+
{
|
|
171
|
+
onNode, onAccount, verify = true, waitMined = true, confirm, ...options
|
|
172
|
+
}:
|
|
173
|
+
SendTransactionOptions,
|
|
61
174
|
): Promise<SendTransactionReturnType> {
|
|
62
175
|
if (verify) {
|
|
63
|
-
const validation = await verifyTransaction(tx, onNode)
|
|
176
|
+
const validation = await verifyTransaction(tx, onNode);
|
|
64
177
|
if (validation.length > 0) {
|
|
65
|
-
const message =
|
|
66
|
-
validation.map((v: { message: string }) => v.message).join(', ')
|
|
67
|
-
throw new InvalidTxError(message, validation, tx)
|
|
178
|
+
const message = `Transaction verification errors: ${
|
|
179
|
+
validation.map((v: { message: string }) => v.message).join(', ')}`;
|
|
180
|
+
throw new InvalidTxError(message, validation, tx);
|
|
68
181
|
}
|
|
69
182
|
}
|
|
70
183
|
|
|
71
184
|
try {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
185
|
+
let __queue;
|
|
186
|
+
try {
|
|
187
|
+
__queue = onAccount != null ? `tx-${await onAccount.address(options)}` : null;
|
|
188
|
+
} catch (error) {
|
|
189
|
+
__queue = null;
|
|
190
|
+
}
|
|
191
|
+
const { txHash } = await onNode.postTransaction(
|
|
192
|
+
{ tx },
|
|
193
|
+
__queue != null ? { requestOptions: { customHeaders: { __queue } } } : {},
|
|
194
|
+
);
|
|
79
195
|
|
|
80
196
|
if (waitMined) {
|
|
81
|
-
const pollResult = await poll(txHash, { onNode, ...options })
|
|
197
|
+
const pollResult = await poll(txHash, { onNode, ...options });
|
|
82
198
|
const txData = {
|
|
83
199
|
...pollResult,
|
|
84
|
-
hash: pollResult.hash as
|
|
85
|
-
rawTx: tx
|
|
86
|
-
}
|
|
200
|
+
hash: pollResult.hash as Encoded.TxHash,
|
|
201
|
+
rawTx: tx,
|
|
202
|
+
};
|
|
87
203
|
// wait for transaction confirmation
|
|
88
204
|
if (confirm != null && (confirm === true || confirm > 0)) {
|
|
89
|
-
const c = typeof confirm === 'boolean' ? undefined : confirm
|
|
205
|
+
const c = typeof confirm === 'boolean' ? undefined : confirm;
|
|
90
206
|
return {
|
|
91
207
|
...txData,
|
|
92
|
-
confirmationHeight: await waitForTxConfirm(txHash, { onNode, confirm: c, ...options })
|
|
93
|
-
}
|
|
208
|
+
confirmationHeight: await waitForTxConfirm(txHash, { onNode, confirm: c, ...options }),
|
|
209
|
+
};
|
|
94
210
|
}
|
|
95
|
-
return txData
|
|
211
|
+
return txData;
|
|
96
212
|
}
|
|
97
|
-
return { hash: txHash, rawTx: tx }
|
|
213
|
+
return { hash: txHash, rawTx: tx };
|
|
98
214
|
} catch (error) {
|
|
99
215
|
throw Object.assign(error, {
|
|
100
216
|
rawTx: tx,
|
|
101
|
-
verifyTx: async () =>
|
|
102
|
-
})
|
|
217
|
+
verifyTx: async () => verifyTransaction(tx, onNode),
|
|
218
|
+
});
|
|
103
219
|
}
|
|
104
220
|
}
|
|
105
221
|
|
|
106
222
|
type SendTransactionOptionsType = {
|
|
107
|
-
onNode: Node
|
|
108
|
-
onAccount?: AccountBase
|
|
109
|
-
verify?: boolean
|
|
110
|
-
waitMined?: boolean
|
|
111
|
-
confirm?: boolean | number
|
|
112
|
-
} & Parameters<typeof poll>[1] & Omit<Parameters<typeof waitForTxConfirm>[1], 'confirm'
|
|
223
|
+
onNode: Node;
|
|
224
|
+
onAccount?: AccountBase;
|
|
225
|
+
verify?: boolean;
|
|
226
|
+
waitMined?: boolean;
|
|
227
|
+
confirm?: boolean | number;
|
|
228
|
+
} & Parameters<typeof poll>[1] & Omit<Parameters<typeof waitForTxConfirm>[1], 'confirm'>;
|
|
113
229
|
interface SendTransactionOptions extends SendTransactionOptionsType {}
|
|
114
230
|
interface SendTransactionReturnType extends Partial<TransformNodeType<SignedTx>> {
|
|
115
|
-
hash:
|
|
116
|
-
rawTx:
|
|
117
|
-
confirmationHeight?: number
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Wait for transaction confirmation
|
|
122
|
-
* @param txHash - Transaction hash
|
|
123
|
-
* @param options - Options
|
|
124
|
-
* @param options.confirm - Number of micro blocks to wait for transaction confirmation
|
|
125
|
-
* @param options.onNode - Node to use
|
|
126
|
-
* @returns Current Height
|
|
127
|
-
*/
|
|
128
|
-
export async function waitForTxConfirm (
|
|
129
|
-
txHash: EncodedData<'th'>,
|
|
130
|
-
{ confirm = 3, onNode, ...options }:
|
|
131
|
-
{ confirm?: number, onNode: Node } & Parameters<typeof awaitHeight>[1]
|
|
132
|
-
): Promise<number> {
|
|
133
|
-
const { blockHeight } = await onNode.getTransactionByHash(txHash)
|
|
134
|
-
const height = await awaitHeight(blockHeight + confirm, { onNode, ...options })
|
|
135
|
-
const { blockHeight: newBlockHeight } = await onNode.getTransactionByHash(txHash)
|
|
136
|
-
switch (newBlockHeight) {
|
|
137
|
-
case -1:
|
|
138
|
-
throw new TxNotInChainError(txHash)
|
|
139
|
-
case blockHeight:
|
|
140
|
-
return height
|
|
141
|
-
default:
|
|
142
|
-
return await waitForTxConfirm(txHash, { onNode, confirm, ...options })
|
|
143
|
-
}
|
|
231
|
+
hash: Encoded.TxHash;
|
|
232
|
+
rawTx: Encoded.Transaction;
|
|
233
|
+
confirmationHeight?: number;
|
|
144
234
|
}
|
|
145
235
|
|
|
146
236
|
/**
|
|
147
237
|
* Get account by account public key
|
|
238
|
+
* @category chain
|
|
148
239
|
* @param address - Account address (public key)
|
|
149
240
|
* @param options - Options
|
|
150
241
|
* @param options.height - Get account on specific block by block height
|
|
151
242
|
* @param options.hash - Get account on specific block by micro block hash or key block hash
|
|
152
243
|
* @param options.onNode - Node to use
|
|
153
244
|
*/
|
|
154
|
-
export async function getAccount
|
|
155
|
-
address:
|
|
245
|
+
export async function getAccount(
|
|
246
|
+
address: Encoded.AccountAddress | Encoded.ContractAddress,
|
|
156
247
|
{ height, hash, onNode }:
|
|
157
|
-
{ height?: number
|
|
248
|
+
{ height?: number; hash?: Encoded.KeyBlockHash | Encoded.MicroBlockHash; onNode: Node },
|
|
158
249
|
): Promise<TransformNodeType<AccountNode>> {
|
|
159
|
-
if (height != null) return
|
|
160
|
-
if (hash != null) return
|
|
161
|
-
return
|
|
250
|
+
if (height != null) return onNode.getAccountByPubkeyAndHeight(address, height);
|
|
251
|
+
if (hash != null) return onNode.getAccountByPubkeyAndHash(address, hash);
|
|
252
|
+
return onNode.getAccountByPubkey(address);
|
|
162
253
|
}
|
|
163
254
|
|
|
164
255
|
/**
|
|
165
256
|
* Request the balance of specified account
|
|
257
|
+
* @category chain
|
|
166
258
|
* @param address - The public account address to obtain the balance for
|
|
167
259
|
* @param options - Options
|
|
168
260
|
* @param options.format
|
|
@@ -170,180 +262,133 @@ export async function getAccount (
|
|
|
170
262
|
* (default: top of chain)
|
|
171
263
|
* @param options.hash - The block hash on which to obtain the balance for (default: top of chain)
|
|
172
264
|
*/
|
|
173
|
-
export async function getBalance
|
|
174
|
-
address:
|
|
265
|
+
export async function getBalance(
|
|
266
|
+
address: Encoded.AccountAddress | Encoded.ContractAddress,
|
|
175
267
|
{ format = AE_AMOUNT_FORMATS.AETTOS, ...options }:
|
|
176
|
-
{ format?: AE_AMOUNT_FORMATS } & Parameters<typeof getAccount>[1]
|
|
268
|
+
{ format?: AE_AMOUNT_FORMATS } & Parameters<typeof getAccount>[1],
|
|
177
269
|
): Promise<string> {
|
|
178
|
-
const { balance } = await getAccount(address, options).catch(() => ({ balance: 0n }))
|
|
179
|
-
|
|
180
|
-
return formatAmount(balance, { targetDenomination: format })
|
|
181
|
-
}
|
|
270
|
+
const { balance } = await getAccount(address, options).catch(() => ({ balance: 0n }));
|
|
182
271
|
|
|
183
|
-
|
|
184
|
-
* Obtain current height of the chain
|
|
185
|
-
* @returns Current chain height
|
|
186
|
-
*/
|
|
187
|
-
export async function height ({ onNode }: { onNode: Node }): Promise<number> {
|
|
188
|
-
return (await onNode.getCurrentKeyBlockHeight()).height
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Wait for the chain to reach a specific height
|
|
193
|
-
* @param height - Height to wait for
|
|
194
|
-
* @param options - Options
|
|
195
|
-
* @param options.interval - Interval (in ms) at which to poll the chain
|
|
196
|
-
* @param options.attempts - Number of polling attempts after which to fail
|
|
197
|
-
* @param options.onNode - Node to use
|
|
198
|
-
* @returns Current chain height
|
|
199
|
-
*/
|
|
200
|
-
export async function awaitHeight (
|
|
201
|
-
height: number,
|
|
202
|
-
{ interval, attempts = 20, onNode, ...options }:
|
|
203
|
-
{ interval?: number, attempts?: number, onNode: Node }
|
|
204
|
-
& Parameters<typeof _getPollInterval>[1]
|
|
205
|
-
): Promise<number> {
|
|
206
|
-
interval ??= _getPollInterval('block', options)
|
|
207
|
-
let currentHeight
|
|
208
|
-
for (let i = 0; i < attempts; i++) {
|
|
209
|
-
if (i !== 0) await pause(interval)
|
|
210
|
-
currentHeight = (await onNode.getCurrentKeyBlockHeight()).height
|
|
211
|
-
if (currentHeight >= height) return currentHeight
|
|
212
|
-
}
|
|
213
|
-
throw new RequestTimedOutError((attempts - 1) * interval, currentHeight, height)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Wait for a transaction to be mined
|
|
218
|
-
* @param th - The hash of transaction to poll
|
|
219
|
-
* @param options - Options
|
|
220
|
-
* @param options.interval - Interval (in ms) at which to poll the chain
|
|
221
|
-
* @param options.blocks - Number of blocks mined after which to fail
|
|
222
|
-
* @param options.onNode - Node to use
|
|
223
|
-
* @returns The transaction as it was mined
|
|
224
|
-
*/
|
|
225
|
-
export async function poll (
|
|
226
|
-
th: EncodedData<'th'>,
|
|
227
|
-
{ blocks = 10, interval, onNode, ...options }:
|
|
228
|
-
{ blocks?: number, interval?: number, onNode: Node } & Parameters<typeof _getPollInterval>[1]
|
|
229
|
-
): Promise<TransformNodeType<SignedTx>> {
|
|
230
|
-
interval ??= _getPollInterval('microblock', options)
|
|
231
|
-
const max = await height({ onNode }) + blocks
|
|
232
|
-
do {
|
|
233
|
-
const tx = await onNode.getTransactionByHash(th)
|
|
234
|
-
if (tx.blockHeight !== -1) return tx
|
|
235
|
-
await pause(interval)
|
|
236
|
-
} while (await height({ onNode }) < max)
|
|
237
|
-
throw new TxTimedOutError(blocks, th)
|
|
272
|
+
return formatAmount(balance, { targetDenomination: format });
|
|
238
273
|
}
|
|
239
274
|
|
|
240
275
|
/**
|
|
241
276
|
* Obtain current generation
|
|
277
|
+
* @category chain
|
|
242
278
|
* @param options - Options
|
|
243
279
|
* @param options.onNode - Node to use
|
|
244
280
|
* @returns Current Generation
|
|
245
281
|
*/
|
|
246
|
-
export async function getCurrentGeneration
|
|
247
|
-
{ onNode }: { onNode: Node }
|
|
282
|
+
export async function getCurrentGeneration(
|
|
283
|
+
{ onNode }: { onNode: Node },
|
|
248
284
|
): Promise<TransformNodeType<Generation>> {
|
|
249
|
-
return
|
|
285
|
+
return onNode.getCurrentGeneration();
|
|
250
286
|
}
|
|
251
287
|
|
|
252
288
|
/**
|
|
253
289
|
* Get generation by hash or height
|
|
290
|
+
* @category chain
|
|
254
291
|
* @param hashOrHeight - Generation hash or height
|
|
255
292
|
* @param options - Options
|
|
256
293
|
* @param options.onNode - Node to use
|
|
257
294
|
* @returns Generation
|
|
258
295
|
*/
|
|
259
|
-
export async function getGeneration
|
|
260
|
-
hashOrHeight:
|
|
296
|
+
export async function getGeneration(
|
|
297
|
+
hashOrHeight: Encoded.KeyBlockHash | number,
|
|
298
|
+
{ onNode }: { onNode: Node },
|
|
261
299
|
): Promise<TransformNodeType<Generation>> {
|
|
262
|
-
if (typeof hashOrHeight === 'number') return
|
|
263
|
-
return
|
|
300
|
+
if (typeof hashOrHeight === 'number') return onNode.getGenerationByHeight(hashOrHeight);
|
|
301
|
+
return onNode.getGenerationByHash(hashOrHeight);
|
|
264
302
|
}
|
|
265
303
|
|
|
266
304
|
/**
|
|
267
305
|
* Get micro block transactions
|
|
306
|
+
* @category chain
|
|
268
307
|
* @param hash - Micro block hash
|
|
269
308
|
* @param options - Options
|
|
270
309
|
* @param options.onNode - Node to use
|
|
271
310
|
* @returns Transactions
|
|
272
311
|
*/
|
|
273
|
-
export async function getMicroBlockTransactions
|
|
274
|
-
hash:
|
|
312
|
+
export async function getMicroBlockTransactions(
|
|
313
|
+
hash: Encoded.MicroBlockHash,
|
|
314
|
+
{ onNode }: { onNode: Node },
|
|
275
315
|
): Promise<TransformNodeType<SignedTx[]>> {
|
|
276
|
-
return (await onNode.getMicroBlockTransactionsByHash(hash)).transactions
|
|
316
|
+
return (await onNode.getMicroBlockTransactionsByHash(hash)).transactions;
|
|
277
317
|
}
|
|
278
318
|
|
|
279
319
|
/**
|
|
280
320
|
* Get key block
|
|
321
|
+
* @category chain
|
|
281
322
|
* @param hashOrHeight - Key block hash or height
|
|
282
323
|
* @param options - Options
|
|
283
324
|
* @param options.onNode - Node to use
|
|
284
325
|
* @returns Key Block
|
|
285
326
|
*/
|
|
286
|
-
export async function getKeyBlock
|
|
287
|
-
hashOrHeight:
|
|
327
|
+
export async function getKeyBlock(
|
|
328
|
+
hashOrHeight: Encoded.KeyBlockHash | number,
|
|
329
|
+
{ onNode }: { onNode: Node },
|
|
288
330
|
): Promise<TransformNodeType<KeyBlock>> {
|
|
289
|
-
if (typeof hashOrHeight === 'number') return
|
|
290
|
-
return
|
|
331
|
+
if (typeof hashOrHeight === 'number') return onNode.getKeyBlockByHeight(hashOrHeight);
|
|
332
|
+
return onNode.getKeyBlockByHash(hashOrHeight);
|
|
291
333
|
}
|
|
292
334
|
|
|
293
335
|
/**
|
|
294
336
|
* Get micro block header
|
|
337
|
+
* @category chain
|
|
295
338
|
* @param hash - Micro block hash
|
|
296
339
|
* @param options - Options
|
|
297
340
|
* @param options.onNode - Node to use
|
|
298
341
|
* @returns Micro block header
|
|
299
342
|
*/
|
|
300
|
-
export async function getMicroBlockHeader
|
|
301
|
-
hash:
|
|
343
|
+
export async function getMicroBlockHeader(
|
|
344
|
+
hash: Encoded.MicroBlockHash,
|
|
345
|
+
{ onNode }: { onNode: Node },
|
|
302
346
|
): Promise<TransformNodeType<MicroBlockHeader>> {
|
|
303
|
-
return
|
|
347
|
+
return onNode.getMicroBlockHeaderByHash(hash);
|
|
304
348
|
}
|
|
305
349
|
|
|
306
350
|
interface TxDryRunArguments {
|
|
307
|
-
tx:
|
|
308
|
-
accountAddress:
|
|
309
|
-
top?: number
|
|
310
|
-
txEvents?: any
|
|
311
|
-
resolve: Function
|
|
312
|
-
reject: Function
|
|
351
|
+
tx: Encoded.Transaction;
|
|
352
|
+
accountAddress: Encoded.AccountAddress;
|
|
353
|
+
top?: number;
|
|
354
|
+
txEvents?: any;
|
|
355
|
+
resolve: Function;
|
|
356
|
+
reject: Function;
|
|
313
357
|
}
|
|
314
|
-
const txDryRunRequests: Map<string, TxDryRunArguments[] & { timeout?: NodeJS.Timeout }> = new Map()
|
|
358
|
+
const txDryRunRequests: Map<string, TxDryRunArguments[] & { timeout?: NodeJS.Timeout }> = new Map();
|
|
315
359
|
|
|
316
|
-
async function txDryRunHandler
|
|
317
|
-
const rs = txDryRunRequests.get(key)
|
|
318
|
-
txDryRunRequests.delete(key)
|
|
319
|
-
if (rs == null) throw new InternalError('Can\'t get dry-run request')
|
|
360
|
+
async function txDryRunHandler(key: string, onNode: Node): Promise<void> {
|
|
361
|
+
const rs = txDryRunRequests.get(key);
|
|
362
|
+
txDryRunRequests.delete(key);
|
|
363
|
+
if (rs == null) throw new InternalError('Can\'t get dry-run request');
|
|
320
364
|
|
|
321
|
-
let dryRunRes
|
|
365
|
+
let dryRunRes;
|
|
322
366
|
try {
|
|
323
367
|
dryRunRes = await onNode.protectedDryRunTxs({
|
|
324
368
|
top: rs[0].top,
|
|
325
369
|
txEvents: rs[0].txEvents,
|
|
326
|
-
txs: rs.map(req => ({ tx: req.tx })),
|
|
327
|
-
accounts: Array.from(new Set(rs.map(req => req.accountAddress)))
|
|
328
|
-
.map(pubKey => ({ pubKey, amount: DRY_RUN_ACCOUNT.amount }))
|
|
329
|
-
})
|
|
370
|
+
txs: rs.map((req) => ({ tx: req.tx })),
|
|
371
|
+
accounts: Array.from(new Set(rs.map((req) => req.accountAddress)))
|
|
372
|
+
.map((pubKey) => ({ pubKey, amount: DRY_RUN_ACCOUNT.amount })),
|
|
373
|
+
});
|
|
330
374
|
} catch (error) {
|
|
331
|
-
rs.forEach(({ reject }) => reject(error))
|
|
332
|
-
return
|
|
375
|
+
rs.forEach(({ reject }) => reject(error));
|
|
376
|
+
return;
|
|
333
377
|
}
|
|
334
378
|
|
|
335
|
-
const { results, txEvents } = dryRunRes
|
|
379
|
+
const { results, txEvents } = dryRunRes;
|
|
336
380
|
results.forEach(({ result, reason, ...resultPayload }, idx) => {
|
|
337
|
-
const {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
))
|
|
342
|
-
})
|
|
381
|
+
const {
|
|
382
|
+
resolve, reject, tx, accountAddress,
|
|
383
|
+
} = rs[idx];
|
|
384
|
+
if (result === 'ok') resolve({ ...resultPayload, txEvents });
|
|
385
|
+
else reject(Object.assign(new DryRunError(reason as string), { tx, accountAddress }));
|
|
386
|
+
});
|
|
343
387
|
}
|
|
344
388
|
|
|
345
389
|
/**
|
|
346
390
|
* Transaction dry-run
|
|
391
|
+
* @category chain
|
|
347
392
|
* @param tx - transaction to execute
|
|
348
393
|
* @param accountAddress - address that will be used to execute transaction
|
|
349
394
|
* @param options - Options
|
|
@@ -352,65 +397,76 @@ async function txDryRunHandler (key: string, onNode: Node): Promise<void> {
|
|
|
352
397
|
* @param options.combine - Enables combining of similar requests to a single dry-run call
|
|
353
398
|
* @param options.onNode - Node to use
|
|
354
399
|
*/
|
|
355
|
-
export async function txDryRun
|
|
356
|
-
tx:
|
|
357
|
-
accountAddress:
|
|
358
|
-
{
|
|
359
|
-
|
|
400
|
+
export async function txDryRun(
|
|
401
|
+
tx: Encoded.Transaction,
|
|
402
|
+
accountAddress: Encoded.AccountAddress,
|
|
403
|
+
{
|
|
404
|
+
top, txEvents, combine, onNode,
|
|
405
|
+
}:
|
|
406
|
+
{ top?: number; txEvents?: boolean; combine?: boolean; onNode: Node },
|
|
360
407
|
): Promise<{
|
|
361
|
-
txEvents?: TransformNodeType<DryRunResults['txEvents']
|
|
408
|
+
txEvents?: TransformNodeType<DryRunResults['txEvents']>;
|
|
362
409
|
} & TransformNodeType<DryRunResult>> {
|
|
363
|
-
const key = combine === true ? [top, txEvents].join() : 'immediate'
|
|
364
|
-
const requests = txDryRunRequests.get(key) ?? []
|
|
365
|
-
txDryRunRequests.set(key, requests)
|
|
366
|
-
return
|
|
367
|
-
requests.push({
|
|
410
|
+
const key = combine === true ? [top, txEvents].join() : 'immediate';
|
|
411
|
+
const requests = txDryRunRequests.get(key) ?? [];
|
|
412
|
+
txDryRunRequests.set(key, requests);
|
|
413
|
+
return new Promise((resolve, reject) => {
|
|
414
|
+
requests.push({
|
|
415
|
+
tx, accountAddress, top, txEvents, resolve, reject,
|
|
416
|
+
});
|
|
368
417
|
if (combine !== true) {
|
|
369
|
-
void txDryRunHandler(key, onNode)
|
|
370
|
-
return
|
|
418
|
+
void txDryRunHandler(key, onNode);
|
|
419
|
+
return;
|
|
371
420
|
}
|
|
372
|
-
requests.timeout ??= setTimeout(() => { void txDryRunHandler(key, onNode) })
|
|
373
|
-
})
|
|
421
|
+
requests.timeout ??= setTimeout(() => { void txDryRunHandler(key, onNode); });
|
|
422
|
+
});
|
|
374
423
|
}
|
|
375
424
|
|
|
376
425
|
/**
|
|
377
426
|
* Get contract byte code
|
|
427
|
+
* @category contract
|
|
378
428
|
* @param contractId - Contract address
|
|
379
429
|
* @param options - Options
|
|
380
430
|
* @param options.onNode - Node to use
|
|
381
431
|
*/
|
|
382
|
-
export async function getContractByteCode
|
|
383
|
-
contractId:
|
|
432
|
+
export async function getContractByteCode(
|
|
433
|
+
contractId: Encoded.ContractAddress,
|
|
434
|
+
{ onNode }: { onNode: Node },
|
|
384
435
|
): Promise<TransformNodeType<ByteCode>> {
|
|
385
|
-
return
|
|
436
|
+
return onNode.getContractCode(contractId);
|
|
386
437
|
}
|
|
387
438
|
|
|
388
439
|
/**
|
|
389
440
|
* Get contract entry
|
|
441
|
+
* @category contract
|
|
390
442
|
* @param contractId - Contract address
|
|
391
443
|
* @param options - Options
|
|
392
444
|
* @param options.onNode - Node to use
|
|
393
445
|
*/
|
|
394
|
-
export async function getContract
|
|
395
|
-
contractId:
|
|
446
|
+
export async function getContract(
|
|
447
|
+
contractId: Encoded.ContractAddress,
|
|
448
|
+
{ onNode }: { onNode: Node },
|
|
396
449
|
): Promise<TransformNodeType<ContractObject>> {
|
|
397
|
-
return
|
|
450
|
+
return onNode.getContract(contractId);
|
|
398
451
|
}
|
|
399
452
|
|
|
400
453
|
/**
|
|
401
454
|
* Get name entry
|
|
455
|
+
* @category AENS
|
|
402
456
|
* @param name - AENS name
|
|
403
457
|
* @param options - Options
|
|
404
458
|
* @param options.onNode - Node to use
|
|
405
459
|
*/
|
|
406
|
-
export async function getName
|
|
407
|
-
name: AensName,
|
|
460
|
+
export async function getName(
|
|
461
|
+
name: AensName,
|
|
462
|
+
{ onNode }: { onNode: Node },
|
|
408
463
|
): Promise<TransformNodeType<NameEntry>> {
|
|
409
|
-
return
|
|
464
|
+
return onNode.getNameEntryByName(name);
|
|
410
465
|
}
|
|
411
466
|
|
|
412
467
|
/**
|
|
413
468
|
* Resolve AENS name and return name hash
|
|
469
|
+
* @category AENS
|
|
414
470
|
* @param nameOrId - AENS name or address
|
|
415
471
|
* @param key - in AENS pointers record
|
|
416
472
|
* @param options - Options
|
|
@@ -420,25 +476,27 @@ export async function getName (
|
|
|
420
476
|
* @param options.onNode - Node to use
|
|
421
477
|
* @returns Address or AENS name hash
|
|
422
478
|
*/
|
|
423
|
-
export async function resolveName <
|
|
424
|
-
|
|
479
|
+
export async function resolveName <
|
|
480
|
+
Type extends Encoding.AccountAddress | Encoding.ContractAddress,
|
|
481
|
+
>(
|
|
482
|
+
nameOrId: AensName | Encoded.Generic<Type>,
|
|
425
483
|
key: string,
|
|
426
484
|
{ verify = true, resolveByNode = false, onNode }:
|
|
427
|
-
{ verify?: boolean
|
|
428
|
-
): Promise<
|
|
429
|
-
try {
|
|
430
|
-
const id = nameOrId as EncodedData<Type>
|
|
431
|
-
decode(id)
|
|
432
|
-
return id
|
|
433
|
-
} catch (error) {}
|
|
485
|
+
{ verify?: boolean; resolveByNode?: boolean; onNode: Node },
|
|
486
|
+
): Promise<Encoded.Generic<Type | Encoding.Name>> {
|
|
434
487
|
if (isNameValid(nameOrId)) {
|
|
435
488
|
if (verify || resolveByNode) {
|
|
436
|
-
const name = await onNode.getNameEntryByName(nameOrId)
|
|
437
|
-
const pointer = name.pointers.find(
|
|
438
|
-
if (pointer == null) throw new AensPointerContextError(nameOrId, key)
|
|
439
|
-
if (resolveByNode) return pointer.id as
|
|
489
|
+
const name = await onNode.getNameEntryByName(nameOrId);
|
|
490
|
+
const pointer = name.pointers.find((p) => p.key === key);
|
|
491
|
+
if (pointer == null) throw new AensPointerContextError(nameOrId, key);
|
|
492
|
+
if (resolveByNode) return pointer.id as Encoded.Generic<Type>;
|
|
440
493
|
}
|
|
441
|
-
return produceNameId(nameOrId)
|
|
494
|
+
return produceNameId(nameOrId);
|
|
495
|
+
}
|
|
496
|
+
try {
|
|
497
|
+
decode(nameOrId);
|
|
498
|
+
return nameOrId;
|
|
499
|
+
} catch (error) {
|
|
500
|
+
throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`);
|
|
442
501
|
}
|
|
443
|
-
throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`)
|
|
444
502
|
}
|