@aeternity/aepp-sdk 11.0.1 → 12.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/LICENSE +1 -1
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +12 -19
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +37 -0
- package/es/AeSdk.mjs +81 -0
- package/es/AeSdk.mjs.map +1 -0
- package/es/AeSdkAepp.d.ts +69 -0
- package/es/AeSdkAepp.mjs +175 -0
- package/es/AeSdkAepp.mjs.map +1 -0
- package/es/AeSdkBase.d.ts +212 -0
- package/es/AeSdkBase.mjs +310 -0
- package/es/AeSdkBase.mjs.map +1 -0
- package/es/AeSdkWallet.d.ts +103 -0
- package/es/AeSdkWallet.mjs +322 -0
- package/es/AeSdkWallet.mjs.map +1 -0
- package/es/Node.d.ts +44 -0
- package/es/Node.mjs +141 -0
- package/es/Node.mjs.map +1 -0
- package/es/account/Base.d.ts +65 -0
- package/es/account/Base.mjs +123 -0
- package/es/account/Base.mjs.map +1 -0
- package/es/account/Memory.d.ts +25 -0
- package/es/account/Memory.mjs +81 -0
- package/es/account/Memory.mjs.map +1 -0
- package/es/account/Rpc.d.ts +27 -0
- package/es/account/Rpc.mjs +79 -0
- package/es/account/Rpc.mjs.map +1 -0
- package/es/aens.d.ts +209 -0
- package/es/aens.mjs +332 -0
- package/es/aens.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
- package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
- package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +90 -46
- package/es/aepp-wallet-communication/schema.mjs +214 -0
- package/es/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/apis/compiler/compiler.d.ts +92 -0
- package/es/apis/compiler/compiler.mjs +576 -0
- package/es/apis/compiler/compiler.mjs.map +1 -0
- package/es/apis/compiler/index.d.ts +2 -0
- package/es/apis/compiler/index.mjs +3 -0
- package/es/apis/compiler/index.mjs.map +1 -0
- package/es/apis/compiler/models/index.d.ts +248 -0
- package/es/apis/compiler/models/index.mjs +48 -0
- package/es/apis/compiler/models/index.mjs.map +1 -0
- package/es/apis/compiler/models/mappers.d.ts +23 -0
- package/es/apis/compiler/models/mappers.mjs +585 -0
- package/es/apis/compiler/models/mappers.mjs.map +1 -0
- package/es/apis/compiler/models/parameters.d.ts +13 -0
- package/es/apis/compiler/models/parameters.mjs +71 -0
- package/es/apis/compiler/models/parameters.mjs.map +1 -0
- package/es/apis/node/index.d.ts +2 -0
- package/es/apis/node/index.mjs +3 -0
- package/es/apis/node/index.mjs.map +1 -0
- package/es/apis/node/models/index.d.ts +1061 -0
- package/es/apis/node/models/index.mjs +2 -0
- package/es/apis/node/models/index.mjs.map +1 -0
- package/es/apis/node/models/mappers.d.ts +95 -0
- package/es/apis/node/models/mappers.mjs +4164 -0
- package/es/apis/node/models/mappers.mjs.map +1 -0
- package/es/apis/node/models/parameters.d.ts +17 -0
- package/es/apis/node/models/parameters.mjs +165 -0
- package/es/apis/node/models/parameters.mjs.map +1 -0
- package/es/apis/node/node.d.ts +215 -0
- package/es/apis/node/node.mjs +1165 -0
- package/es/apis/node/node.mjs.map +1 -0
- package/es/chain.d.ts +220 -0
- package/es/chain.mjs +524 -0
- package/es/chain.mjs.map +1 -0
- package/es/channel/handlers.d.ts +34 -0
- package/es/channel/handlers.mjs +147 -112
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +634 -0
- package/es/channel/index.mjs +898 -900
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +100 -0
- package/es/channel/internal.mjs +97 -51
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +17 -0
- package/es/contract/Compiler.mjs +67 -0
- package/es/contract/Compiler.mjs.map +1 -0
- package/es/contract/aci.d.ts +125 -0
- package/es/contract/aci.mjs +199 -180
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +68 -0
- package/es/contract/ga.mjs +190 -0
- package/es/contract/ga.mjs.map +1 -0
- package/es/contract/methods.d.ts +68 -0
- package/es/contract/methods.mjs +101 -0
- package/es/contract/methods.mjs.map +1 -0
- package/es/index.d.ts +32 -0
- package/es/index.mjs +32 -40
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +154 -0
- package/es/oracle.mjs +288 -0
- package/es/oracle.mjs.map +1 -0
- package/es/spend.d.ts +61 -0
- package/es/spend.mjs +122 -0
- package/es/spend.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +41 -0
- package/es/tx/builder/constants.mjs +11 -19
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types.d.ts +62 -0
- package/es/tx/builder/field-types.mjs +62 -10
- package/es/tx/builder/field-types.mjs.map +1 -1
- package/es/tx/builder/helpers.d.ts +131 -0
- package/es/tx/builder/helpers.mjs +71 -169
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +75 -0
- package/es/tx/builder/index.mjs +141 -323
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +350 -0
- package/es/tx/builder/schema.mjs +173 -510
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +63 -0
- package/es/tx/index.mjs +171 -265
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/min-fee.d.ts +20 -0
- package/es/tx/min-fee.mjs +148 -0
- package/es/tx/min-fee.mjs.map +1 -0
- package/es/tx/validator.d.ts +19 -0
- package/es/tx/validator.mjs +64 -71
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
- package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
- package/es/typings/bip32-path/index.d.mjs +2 -0
- package/es/typings/bip32-path/index.d.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
- package/es/utils/amount-formatter.d.ts +42 -0
- package/es/utils/amount-formatter.mjs +28 -41
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.d.ts +6 -0
- package/es/utils/autorest.mjs +97 -0
- package/es/utils/autorest.mjs.map +1 -0
- package/es/utils/bignumber.d.ts +13 -0
- package/es/utils/bignumber.mjs +10 -8
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
- package/es/utils/bytes.mjs +10 -14
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +103 -0
- package/es/utils/crypto.mjs +60 -68
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder.d.ts +26 -0
- package/es/utils/encoder.mjs +47 -51
- package/es/utils/encoder.mjs.map +1 -1
- package/es/{errors.d.ts → utils/errors.d.ts} +254 -57
- package/es/utils/errors.mjs +318 -125
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +34 -0
- package/es/utils/hd-wallet.mjs +27 -16
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.d.ts +5 -0
- package/es/utils/json-big.mjs +10 -14
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.d.ts +51 -0
- package/es/utils/keystore.mjs +98 -193
- package/es/utils/keystore.mjs.map +1 -1
- package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
- package/es/utils/mptree.mjs +13 -14
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +14 -0
- package/es/utils/other.mjs +21 -36
- package/es/utils/other.mjs.map +1 -1
- package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.d.ts +24 -0
- package/es/utils/string.mjs +8 -10
- package/es/utils/string.mjs.map +1 -1
- package/package.json +49 -39
- package/src/AeSdk.ts +65 -0
- package/src/AeSdkAepp.ts +167 -0
- package/src/AeSdkBase.ts +320 -0
- package/src/AeSdkWallet.ts +332 -0
- package/src/Node.ts +167 -0
- package/src/account/Base.ts +114 -0
- package/src/account/Memory.ts +83 -0
- package/src/account/Rpc.ts +67 -0
- package/src/aens.ts +391 -0
- package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
- package/{es/utils/crypto-ts.mjs → src/aepp-wallet-communication/connection-proxy.ts} +16 -17
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
- package/src/aepp-wallet-communication/rpc/types.ts +66 -0
- package/src/aepp-wallet-communication/schema.ts +181 -0
- package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
- package/src/apis/compiler/code-model-v4.yaml +2649 -0
- package/src/apis/compiler/compiler.ts +585 -0
- package/src/apis/compiler/index.ts +2 -0
- package/src/apis/compiler/models/index.ts +301 -0
- package/src/apis/compiler/models/mappers.ts +583 -0
- package/src/apis/compiler/models/parameters.ts +93 -0
- package/src/apis/node/code-model-v4.yaml +10046 -0
- package/src/apis/node/index.ts +2 -0
- package/src/apis/node/models/index.ts +1253 -0
- package/src/apis/node/models/mappers.ts +4278 -0
- package/src/apis/node/models/parameters.ts +188 -0
- package/src/apis/node/node.ts +1299 -0
- package/src/chain.ts +444 -0
- package/src/channel/{handlers.js → handlers.ts} +220 -128
- package/src/channel/index.ts +991 -0
- package/src/channel/internal.ts +345 -0
- package/src/contract/Compiler.ts +66 -0
- package/src/contract/aci.ts +529 -0
- package/src/contract/ga.ts +178 -0
- package/src/contract/methods.ts +118 -0
- package/src/index.ts +51 -0
- package/src/oracle.ts +342 -0
- package/src/spend.ts +152 -0
- package/src/tx/builder/{constants.js → constants.ts} +12 -16
- package/src/tx/builder/field-types.ts +111 -0
- package/src/tx/builder/helpers.ts +253 -0
- package/src/tx/builder/index.ts +394 -0
- package/src/tx/builder/schema.ts +771 -0
- package/src/tx/index.ts +199 -0
- package/src/tx/min-fee.ts +136 -0
- package/src/tx/validator.ts +226 -0
- package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
- package/src/typings/@aeternity__uuid/index.d.ts +3 -0
- package/src/typings/bip32-path/index.d.ts +33 -0
- package/src/typings/tweetnacl-auth/index.d.ts +14 -0
- package/src/utils/amount-formatter.ts +29 -42
- package/src/utils/autorest.ts +90 -0
- package/src/utils/bignumber.ts +9 -11
- package/src/utils/bytes.ts +12 -14
- package/src/utils/crypto.ts +217 -0
- package/src/utils/encoder.ts +52 -55
- package/src/utils/errors.ts +268 -134
- package/src/utils/hd-wallet.ts +134 -0
- package/src/utils/json-big.ts +26 -0
- package/src/utils/keystore.ts +179 -0
- package/src/utils/mptree.ts +14 -14
- package/src/utils/other.ts +28 -43
- package/src/utils/string.ts +8 -10
- package/es/account/base.mjs +0 -179
- package/es/account/base.mjs.map +0 -1
- package/es/account/memory.mjs +0 -99
- package/es/account/memory.mjs.map +0 -1
- package/es/account/multiple.mjs +0 -179
- package/es/account/multiple.mjs.map +0 -1
- package/es/ae/aens.mjs +0 -404
- package/es/ae/aens.mjs.map +0 -1
- package/es/ae/aepp.mjs +0 -45
- package/es/ae/aepp.mjs.map +0 -1
- package/es/ae/contract.mjs +0 -159
- package/es/ae/contract.mjs.map +0 -1
- package/es/ae/index.mjs +0 -207
- package/es/ae/index.mjs.map +0 -1
- package/es/ae/oracle.mjs +0 -339
- package/es/ae/oracle.mjs.map +0 -1
- package/es/ae/universal.mjs +0 -45
- package/es/ae/universal.mjs.map +0 -1
- package/es/ae/wallet.mjs +0 -50
- package/es/ae/wallet.mjs.map +0 -1
- package/es/amount-formatter.d.ts +0 -58
- package/es/bignumber.d.ts +0 -18
- package/es/chain/index.mjs +0 -272
- package/es/chain/index.mjs.map +0 -1
- package/es/chain/node.mjs +0 -442
- package/es/chain/node.mjs.map +0 -1
- package/es/contract/compiler.mjs +0 -115
- package/es/contract/compiler.mjs.map +0 -1
- package/es/contract/ga/helpers.mjs +0 -30
- package/es/contract/ga/helpers.mjs.map +0 -1
- package/es/contract/ga/index.mjs +0 -178
- package/es/contract/ga/index.mjs.map +0 -1
- package/es/crypto-ts.d.ts +0 -9
- package/es/encoder.d.ts +0 -26
- package/es/node-pool/index.mjs +0 -188
- package/es/node-pool/index.mjs.map +0 -1
- package/es/node.mjs +0 -133
- package/es/node.mjs.map +0 -1
- package/es/other.d.ts +0 -31
- package/es/string.d.ts +0 -26
- package/es/tx/tx-object.mjs +0 -283
- package/es/tx/tx-object.mjs.map +0 -1
- package/es/tx/tx.mjs +0 -938
- package/es/tx/tx.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
- package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
- package/es/utils/async-init.mjs +0 -64
- package/es/utils/async-init.mjs.map +0 -1
- package/es/utils/crypto-ts.mjs.map +0 -1
- package/es/utils/swagger.mjs +0 -164
- package/es/utils/swagger.mjs.map +0 -1
- package/src/account/base.js +0 -153
- package/src/account/memory.js +0 -83
- package/src/account/multiple.js +0 -162
- package/src/ae/aens.js +0 -361
- package/src/ae/aepp.js +0 -45
- package/src/ae/contract.js +0 -148
- package/src/ae/index.js +0 -168
- package/src/ae/oracle.js +0 -311
- package/src/ae/universal.js +0 -47
- package/src/ae/wallet.js +0 -50
- package/src/chain/index.js +0 -269
- package/src/chain/node.js +0 -320
- package/src/channel/index.js +0 -903
- package/src/channel/internal.js +0 -236
- package/src/contract/aci.js +0 -376
- package/src/contract/compiler.js +0 -100
- package/src/contract/ga/helpers.js +0 -19
- package/src/contract/ga/index.js +0 -150
- package/src/index.js +0 -89
- package/src/node-pool/index.js +0 -172
- package/src/node.js +0 -116
- package/src/tx/builder/field-types.js +0 -61
- package/src/tx/builder/helpers.js +0 -334
- package/src/tx/builder/index.js +0 -465
- package/src/tx/builder/schema.js +0 -1100
- package/src/tx/index.js +0 -301
- package/src/tx/tx-object.js +0 -187
- package/src/tx/tx.js +0 -631
- package/src/tx/validator.js +0 -181
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
- package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
- package/src/utils/aepp-wallet-communication/helpers.js +0 -60
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
- package/src/utils/aepp-wallet-communication/schema.ts +0 -80
- package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
- package/src/utils/async-init.js +0 -45
- package/src/utils/crypto.js +0 -219
- package/src/utils/hd-wallet.js +0 -100
- package/src/utils/json-big.js +0 -26
- package/src/utils/keystore.js +0 -219
- package/src/utils/swagger.js +0 -156
package/es/spend.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { sendTransaction, resolveName } from './chain';
|
|
2
|
+
import { BuildTxOptions } from './tx';
|
|
3
|
+
import { EncodedData } from './utils/encoder';
|
|
4
|
+
import { createMetaTx } from './contract/ga';
|
|
5
|
+
import { TX_TYPE, AensName } from './tx/builder/schema';
|
|
6
|
+
import AccountBase from './account/Base';
|
|
7
|
+
/**
|
|
8
|
+
* Sign and post a transaction to the chain
|
|
9
|
+
* @param tx - Transaction
|
|
10
|
+
* @param options - Options
|
|
11
|
+
* @param options.verify - Verify transaction before broadcast, throw error if not
|
|
12
|
+
* valid
|
|
13
|
+
* @returns Transaction
|
|
14
|
+
*/
|
|
15
|
+
export declare function send(tx: EncodedData<'tx'>, options: SendOptions): Promise<SendReturnType>;
|
|
16
|
+
declare type SendOptionsType = Parameters<AccountBase['signTransaction']>[1] & Parameters<typeof sendTransaction>[1] & Partial<Omit<Parameters<typeof signUsingGA>[1], 'onAccount' | 'onCompiler'>> & Pick<Parameters<typeof signUsingGA>[1], 'onAccount' | 'onCompiler'>;
|
|
17
|
+
export interface SendOptions extends SendOptionsType {
|
|
18
|
+
}
|
|
19
|
+
interface SendReturnType extends Awaited<ReturnType<typeof sendTransaction>> {
|
|
20
|
+
}
|
|
21
|
+
export declare function signUsingGA(tx: EncodedData<'tx'>, { authData, authFun, ...options }: {
|
|
22
|
+
authData: Parameters<typeof createMetaTx>[1];
|
|
23
|
+
authFun: Parameters<typeof createMetaTx>[2];
|
|
24
|
+
} & Parameters<typeof createMetaTx>[3]): Promise<EncodedData<'tx'>>;
|
|
25
|
+
/**
|
|
26
|
+
* Send coins to another account
|
|
27
|
+
* @param amount - Amount to spend
|
|
28
|
+
* @param recipientIdOrName - Address or name of recipient account
|
|
29
|
+
* @param options - Options
|
|
30
|
+
* @returns Transaction
|
|
31
|
+
*/
|
|
32
|
+
export declare function spend(amount: number | string, recipientIdOrName: EncodedData<'ak'> | AensName, options: SpendOptions): ReturnType<typeof send>;
|
|
33
|
+
declare type SpendOptionsType = BuildTxOptions<TX_TYPE.spend, 'senderId' | 'recipientId' | 'amount'> & Parameters<typeof resolveName>[2] & {
|
|
34
|
+
onAccount: AccountBase;
|
|
35
|
+
} & SendOptions;
|
|
36
|
+
interface SpendOptions extends SpendOptionsType {
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Send a fraction of coin balance to another account
|
|
40
|
+
* @param fraction - Fraction of balance to spend (between 0 and 1)
|
|
41
|
+
* @param recipientIdOrName - Address or name of recipient account
|
|
42
|
+
* @param options - Options
|
|
43
|
+
* @returns Transaction
|
|
44
|
+
*/
|
|
45
|
+
export declare function transferFunds(fraction: number | string, recipientIdOrName: AensName | EncodedData<'ak'>, options: TransferFundsOptions): ReturnType<typeof send>;
|
|
46
|
+
declare type TransferFundsOptionsType = BuildTxOptions<TX_TYPE.spend, 'senderId' | 'recipientId' | 'amount'> & Parameters<typeof resolveName>[2] & {
|
|
47
|
+
onAccount: AccountBase;
|
|
48
|
+
} & SendOptions;
|
|
49
|
+
interface TransferFundsOptions extends TransferFundsOptionsType {
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Submit transaction of another account paying for it (fee and gas)
|
|
53
|
+
* @param transaction - tx_<base64>-encoded transaction
|
|
54
|
+
* @param options - Options
|
|
55
|
+
* @returns Object Transaction
|
|
56
|
+
*/
|
|
57
|
+
export declare function payForTransaction(transaction: EncodedData<'tx'>, options: PayForTransactionOptions): ReturnType<typeof send>;
|
|
58
|
+
interface PayForTransactionOptions extends BuildTxOptions<TX_TYPE.payingFor, 'payerId' | 'tx'>, SendOptions {
|
|
59
|
+
onAccount: AccountBase;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
package/es/spend.mjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2022 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
import { sendTransaction, getAccount, getBalance, resolveName } from "./chain.mjs";
|
|
18
|
+
import { _buildTx } from "./tx/index.mjs";
|
|
19
|
+
import { buildTxHash, unpackTx } from "./tx/builder/index.mjs";
|
|
20
|
+
import BigNumber from 'bignumber.js';
|
|
21
|
+
import { ArgumentError } from "./utils/errors.mjs";
|
|
22
|
+
import { createMetaTx } from "./contract/ga.mjs";
|
|
23
|
+
import { TX_TYPE } from "./tx/builder/schema.mjs";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Sign and post a transaction to the chain
|
|
27
|
+
* @param tx - Transaction
|
|
28
|
+
* @param options - Options
|
|
29
|
+
* @param options.verify - Verify transaction before broadcast, throw error if not
|
|
30
|
+
* valid
|
|
31
|
+
* @returns Transaction
|
|
32
|
+
*/
|
|
33
|
+
export async function send(tx, options) {
|
|
34
|
+
const {
|
|
35
|
+
contractId,
|
|
36
|
+
authFun = undefined
|
|
37
|
+
} = options.innerTx === true ? {
|
|
38
|
+
contractId: null
|
|
39
|
+
} : await getAccount(await options.onAccount.address(options), options);
|
|
40
|
+
const signed = contractId != null // TODO: not required arguments become required depending on account type, can ga be extracted?
|
|
41
|
+
? await signUsingGA(tx, {
|
|
42
|
+
authData: {},
|
|
43
|
+
...options,
|
|
44
|
+
authFun: authFun
|
|
45
|
+
}) : await options.onAccount.signTransaction(tx, options);
|
|
46
|
+
return options.innerTx === true ? {
|
|
47
|
+
hash: buildTxHash(signed),
|
|
48
|
+
rawTx: signed
|
|
49
|
+
} : await sendTransaction(signed, options);
|
|
50
|
+
}
|
|
51
|
+
export async function signUsingGA(tx, _ref) {
|
|
52
|
+
let {
|
|
53
|
+
authData,
|
|
54
|
+
authFun,
|
|
55
|
+
...options
|
|
56
|
+
} = _ref;
|
|
57
|
+
return await createMetaTx(tx, authData, authFun, options);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Send coins to another account
|
|
61
|
+
* @param amount - Amount to spend
|
|
62
|
+
* @param recipientIdOrName - Address or name of recipient account
|
|
63
|
+
* @param options - Options
|
|
64
|
+
* @returns Transaction
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
export async function spend(amount, recipientIdOrName, options) {
|
|
68
|
+
return await send(await _buildTx(TX_TYPE.spend, { ...options,
|
|
69
|
+
senderId: await options.onAccount.address(options),
|
|
70
|
+
recipientId: await resolveName(recipientIdOrName, 'account_pubkey', options),
|
|
71
|
+
amount
|
|
72
|
+
}), options);
|
|
73
|
+
}
|
|
74
|
+
// TODO: Rename to spendFraction
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Send a fraction of coin balance to another account
|
|
78
|
+
* @param fraction - Fraction of balance to spend (between 0 and 1)
|
|
79
|
+
* @param recipientIdOrName - Address or name of recipient account
|
|
80
|
+
* @param options - Options
|
|
81
|
+
* @returns Transaction
|
|
82
|
+
*/
|
|
83
|
+
export async function transferFunds(fraction, recipientIdOrName, options) {
|
|
84
|
+
if (fraction < 0 || fraction > 1) {
|
|
85
|
+
throw new ArgumentError('fraction', 'a number between 0 and 1', fraction);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const recipientId = await resolveName(recipientIdOrName, 'account_pubkey', options);
|
|
89
|
+
const senderId = await options.onAccount.address(options);
|
|
90
|
+
const balance = new BigNumber(await getBalance.bind(options.onAccount)(senderId, options));
|
|
91
|
+
const desiredAmount = balance.times(fraction).integerValue(BigNumber.ROUND_HALF_UP);
|
|
92
|
+
const {
|
|
93
|
+
tx: {
|
|
94
|
+
fee
|
|
95
|
+
}
|
|
96
|
+
} = unpackTx(await _buildTx(TX_TYPE.spend, { ...options,
|
|
97
|
+
senderId,
|
|
98
|
+
recipientId,
|
|
99
|
+
amount: desiredAmount
|
|
100
|
+
}), TX_TYPE.spend); // Reducing of the amount may reduce transaction fee, so this is not completely accurate
|
|
101
|
+
|
|
102
|
+
const amount = desiredAmount.plus(fee).gt(balance) ? balance.minus(fee) : desiredAmount;
|
|
103
|
+
return await send(await _buildTx(TX_TYPE.spend, { ...options,
|
|
104
|
+
senderId,
|
|
105
|
+
recipientId,
|
|
106
|
+
amount
|
|
107
|
+
}), options);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Submit transaction of another account paying for it (fee and gas)
|
|
112
|
+
* @param transaction - tx_<base64>-encoded transaction
|
|
113
|
+
* @param options - Options
|
|
114
|
+
* @returns Object Transaction
|
|
115
|
+
*/
|
|
116
|
+
export async function payForTransaction(transaction, options) {
|
|
117
|
+
return await send(await _buildTx(TX_TYPE.payingFor, { ...options,
|
|
118
|
+
payerId: await options.onAccount.address(options),
|
|
119
|
+
tx: transaction
|
|
120
|
+
}), options);
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=spend.mjs.map
|
package/es/spend.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spend.mjs","names":["sendTransaction","getAccount","getBalance","resolveName","_buildTx","buildTxHash","unpackTx","BigNumber","ArgumentError","createMetaTx","TX_TYPE","send","tx","options","contractId","authFun","undefined","innerTx","onAccount","address","signed","signUsingGA","authData","signTransaction","hash","rawTx","spend","amount","recipientIdOrName","senderId","recipientId","transferFunds","fraction","balance","bind","desiredAmount","times","integerValue","ROUND_HALF_UP","fee","plus","gt","minus","payForTransaction","transaction","payingFor","payerId"],"sources":["../src/spend.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\nimport { sendTransaction, getAccount, getBalance, resolveName } from './chain'\nimport { _buildTx, BuildTxOptions } from './tx'\nimport { buildTxHash, unpackTx } from './tx/builder'\nimport BigNumber from 'bignumber.js'\nimport { ArgumentError } from './utils/errors'\nimport { EncodedData } from './utils/encoder'\nimport { createMetaTx } from './contract/ga'\nimport { TX_TYPE, AensName } from './tx/builder/schema'\nimport AccountBase from './account/Base'\n\n/**\n * Sign and post a transaction to the chain\n * @param tx - Transaction\n * @param options - Options\n * @param options.verify - Verify transaction before broadcast, throw error if not\n * valid\n * @returns Transaction\n */\nexport async function send (tx: EncodedData<'tx'>, options: SendOptions): Promise<SendReturnType> {\n const { contractId, authFun = undefined } = options.innerTx === true\n ? { contractId: null }\n : await getAccount(await options.onAccount.address(options), options)\n\n const signed = contractId != null\n // TODO: not required arguments become required depending on account type, can ga be extracted?\n ? await signUsingGA(tx, { authData: {}, ...options, authFun: authFun as string })\n : await options.onAccount.signTransaction(tx, options)\n\n return options.innerTx === true\n ? { hash: buildTxHash(signed), rawTx: signed }\n : await sendTransaction(signed, options)\n}\n\ntype SendOptionsType = Parameters<AccountBase['signTransaction']>[1] & Parameters<typeof sendTransaction>[1]\n& Partial<Omit<Parameters<typeof signUsingGA>[1], 'onAccount' | 'onCompiler'>>\n& Pick<Parameters<typeof signUsingGA>[1], 'onAccount' | 'onCompiler'>\nexport interface SendOptions extends SendOptionsType {}\ninterface SendReturnType extends Awaited<ReturnType<typeof sendTransaction>> {}\n\nexport async function signUsingGA (\n tx: EncodedData<'tx'>,\n { authData, authFun, ...options }: {\n authData: Parameters<typeof createMetaTx>[1]\n authFun: Parameters<typeof createMetaTx>[2]\n } & Parameters<typeof createMetaTx>[3]\n): Promise<EncodedData<'tx'>> {\n return await createMetaTx(tx, authData, authFun, options)\n}\n\n/**\n * Send coins to another account\n * @param amount - Amount to spend\n * @param recipientIdOrName - Address or name of recipient account\n * @param options - Options\n * @returns Transaction\n */\nexport async function spend (\n amount: number | string,\n recipientIdOrName: EncodedData<'ak'> | AensName,\n options: SpendOptions\n): ReturnType<typeof send> {\n return await send(\n await _buildTx(TX_TYPE.spend, {\n ...options,\n senderId: await options.onAccount.address(options),\n recipientId: await resolveName(recipientIdOrName, 'account_pubkey', options),\n amount\n }),\n options\n )\n}\n\ntype SpendOptionsType = BuildTxOptions<TX_TYPE.spend, 'senderId' | 'recipientId' | 'amount'>\n& Parameters<typeof resolveName>[2] & { onAccount: AccountBase } & SendOptions\ninterface SpendOptions extends SpendOptionsType {}\n\n// TODO: Rename to spendFraction\n/**\n * Send a fraction of coin balance to another account\n * @param fraction - Fraction of balance to spend (between 0 and 1)\n * @param recipientIdOrName - Address or name of recipient account\n * @param options - Options\n * @returns Transaction\n */\nexport async function transferFunds (\n fraction: number | string,\n recipientIdOrName: AensName | EncodedData<'ak'>,\n options: TransferFundsOptions\n): ReturnType<typeof send> {\n if (fraction < 0 || fraction > 1) {\n throw new ArgumentError('fraction', 'a number between 0 and 1', fraction)\n }\n const recipientId = await resolveName<'ak'>(recipientIdOrName, 'account_pubkey', options)\n const senderId = await options.onAccount.address(options)\n const balance = new BigNumber(\n await getBalance.bind(options.onAccount)(senderId, options)\n )\n const desiredAmount = balance.times(fraction).integerValue(BigNumber.ROUND_HALF_UP)\n const { tx: { fee } } = unpackTx(\n await _buildTx(TX_TYPE.spend, { ...options, senderId, recipientId, amount: desiredAmount }),\n TX_TYPE.spend\n )\n // Reducing of the amount may reduce transaction fee, so this is not completely accurate\n const amount = desiredAmount.plus(fee).gt(balance) ? balance.minus(fee) : desiredAmount\n return await send(\n await _buildTx(TX_TYPE.spend, { ...options, senderId, recipientId, amount }),\n options\n )\n}\n\ntype TransferFundsOptionsType = BuildTxOptions<TX_TYPE.spend, 'senderId' | 'recipientId' | 'amount'>\n& Parameters<typeof resolveName>[2] & { onAccount: AccountBase } & SendOptions\ninterface TransferFundsOptions extends TransferFundsOptionsType {}\n\n/**\n * Submit transaction of another account paying for it (fee and gas)\n * @param transaction - tx_<base64>-encoded transaction\n * @param options - Options\n * @returns Object Transaction\n */\nexport async function payForTransaction (\n transaction: EncodedData<'tx'>, options: PayForTransactionOptions\n): ReturnType<typeof send> {\n return await send(\n await _buildTx(\n TX_TYPE.payingFor,\n { ...options, payerId: await options.onAccount.address(options), tx: transaction }\n ),\n options\n )\n}\n\ninterface PayForTransactionOptions extends\n BuildTxOptions<TX_TYPE.payingFor, 'payerId' | 'tx'>, SendOptions {\n onAccount: AccountBase\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;SACSA,e,EAAiBC,U,EAAYC,U,EAAYC,W;SACzC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gB,KAFsB,CAAhC,CAVyB,CAczB;;EACA,MAAMC,MAAM,GAAGQ,aAAa,CAACK,IAAd,CAAmBD,GAAnB,EAAwBE,EAAxB,CAA2BR,OAA3B,IAAsCA,OAAO,CAACS,KAAR,CAAcH,GAAd,CAAtC,GAA2DJ,aAA1E;EACA,OAAO,MAAMxB,IAAI,CACf,MAAMP,QAAQ,CAACM,OAAO,CAACgB,KAAT,EAAgB,EAAE,GAAGb,OAAL;IAAcgB,QAAd;IAAwBC,WAAxB;IAAqCH;EAArC,CAAhB,CADC,EAEfd,OAFe,CAAjB;AAID;;AAMD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAe8B,iBAAf,CACLC,WADK,EAC2B/B,OAD3B,EAEoB;EACzB,OAAO,MAAMF,IAAI,CACf,MAAMP,QAAQ,CACZM,OAAO,CAACmC,SADI,EAEZ,EAAE,GAAGhC,OAAL;IAAciC,OAAO,EAAE,MAAMjC,OAAO,CAACK,SAAR,CAAkBC,OAAlB,CAA0BN,OAA1B,CAA7B;IAAiED,EAAE,EAAEgC;EAArE,CAFY,CADC,EAKf/B,OALe,CAAjB;AAOD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { EncodingType } from './../../utils/encoder';
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
export declare type AensName = `${string}.chain`;
|
|
4
|
+
export declare const NAME_TTL = 180000;
|
|
5
|
+
export declare const NAME_MAX_TTL = 36000;
|
|
6
|
+
export declare const NAME_MAX_CLIENT_TTL = 84600;
|
|
7
|
+
export declare const CLIENT_TTL = 84600;
|
|
8
|
+
export declare const MIN_GAS_PRICE = 1000000000;
|
|
9
|
+
export declare const NAME_FEE_MULTIPLIER = 100000000000000;
|
|
10
|
+
export declare const NAME_FEE_BID_INCREMENT = 0.05;
|
|
11
|
+
export declare const NAME_BID_TIMEOUT_BLOCKS = 480;
|
|
12
|
+
export declare const NAME_MAX_LENGTH_FEE = 31;
|
|
13
|
+
export declare const NAME_BID_MAX_LENGTH = 12;
|
|
14
|
+
export declare enum POINTER_KEY_BY_PREFIX {
|
|
15
|
+
ak = "account_pubkey",
|
|
16
|
+
ok = "oracle_pubkey",
|
|
17
|
+
ct = "contract_pubkey",
|
|
18
|
+
ch = "channel"
|
|
19
|
+
}
|
|
20
|
+
export declare const NAME_BID_RANGES: {
|
|
21
|
+
[k: string]: BigNumber;
|
|
22
|
+
};
|
|
23
|
+
export declare const ID_TAG: {
|
|
24
|
+
account: number;
|
|
25
|
+
name: number;
|
|
26
|
+
commitment: number;
|
|
27
|
+
oracle: number;
|
|
28
|
+
contract: number;
|
|
29
|
+
channel: number;
|
|
30
|
+
};
|
|
31
|
+
export declare const PREFIX_ID_TAG: {
|
|
32
|
+
readonly ak: number;
|
|
33
|
+
readonly nm: number;
|
|
34
|
+
readonly cm: number;
|
|
35
|
+
readonly ok: number;
|
|
36
|
+
readonly ct: number;
|
|
37
|
+
readonly ch: number;
|
|
38
|
+
};
|
|
39
|
+
export declare const ID_TAG_PREFIX: {
|
|
40
|
+
[k: string]: EncodingType;
|
|
41
|
+
};
|
|
@@ -7,7 +7,8 @@ export const NAME_TTL = 180000; // # max number of block into the future that th
|
|
|
7
7
|
|
|
8
8
|
export const NAME_MAX_TTL = 36000;
|
|
9
9
|
export const NAME_MAX_CLIENT_TTL = 84600;
|
|
10
|
-
export const CLIENT_TTL = NAME_MAX_CLIENT_TTL;
|
|
10
|
+
export const CLIENT_TTL = NAME_MAX_CLIENT_TTL;
|
|
11
|
+
export const MIN_GAS_PRICE = 1e9; // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67
|
|
11
12
|
|
|
12
13
|
export const NAME_FEE_MULTIPLIER = 1e14; // 100000000000000
|
|
13
14
|
|
|
@@ -20,15 +21,17 @@ export const NAME_BID_TIMEOUT_BLOCKS = 480; // # ~1 day
|
|
|
20
21
|
export const NAME_MAX_LENGTH_FEE = 31;
|
|
21
22
|
export const NAME_BID_MAX_LENGTH = 12; // # this is the max length for a domain to be part of a bid
|
|
22
23
|
|
|
23
|
-
export
|
|
24
|
-
ak: 'account_pubkey',
|
|
25
|
-
ok: 'oracle_pubkey',
|
|
26
|
-
ct: 'contract_pubkey',
|
|
27
|
-
ch: 'channel'
|
|
28
|
-
}; // # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
|
|
24
|
+
export let POINTER_KEY_BY_PREFIX; // # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
|
|
29
25
|
// # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times
|
|
30
26
|
// # bid ranges:
|
|
31
27
|
|
|
28
|
+
(function (POINTER_KEY_BY_PREFIX) {
|
|
29
|
+
POINTER_KEY_BY_PREFIX["ak"] = "account_pubkey";
|
|
30
|
+
POINTER_KEY_BY_PREFIX["ok"] = "oracle_pubkey";
|
|
31
|
+
POINTER_KEY_BY_PREFIX["ct"] = "contract_pubkey";
|
|
32
|
+
POINTER_KEY_BY_PREFIX["ch"] = "channel";
|
|
33
|
+
})(POINTER_KEY_BY_PREFIX || (POINTER_KEY_BY_PREFIX = {}));
|
|
34
|
+
|
|
32
35
|
export const NAME_BID_RANGES = mapObject({
|
|
33
36
|
31: 3,
|
|
34
37
|
30: 5,
|
|
@@ -64,18 +67,7 @@ export const NAME_BID_RANGES = mapObject({
|
|
|
64
67
|
}, _ref => {
|
|
65
68
|
let [key, value] = _ref;
|
|
66
69
|
return [key, new BigNumber(value).times(NAME_FEE_MULTIPLIER)];
|
|
67
|
-
}); // #
|
|
68
|
-
// # name bid timeouts
|
|
69
|
-
|
|
70
|
-
export const NAME_BID_TIMEOUTS = {
|
|
71
|
-
13: BigNumber(0),
|
|
72
|
-
12: BigNumber(NAME_BID_TIMEOUT_BLOCKS),
|
|
73
|
-
// # 480 blocks
|
|
74
|
-
8: BigNumber(31).times(NAME_BID_TIMEOUT_BLOCKS),
|
|
75
|
-
// # 14880 blocks
|
|
76
|
-
4: BigNumber(62).times(NAME_BID_TIMEOUT_BLOCKS) // # 29760 blocks
|
|
77
|
-
|
|
78
|
-
}; // # Tag constant for ids (type uint8)
|
|
70
|
+
}); // # Tag constant for ids (type uint8)
|
|
79
71
|
// # see https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type
|
|
80
72
|
// # <<Tag:1/unsigned-integer-unit:8, Hash:32/binary-unit:8>>
|
|
81
73
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":["BigNumber","mapObject","NAME_TTL","NAME_MAX_TTL","NAME_MAX_CLIENT_TTL","CLIENT_TTL","MIN_GAS_PRICE","NAME_FEE_MULTIPLIER","NAME_FEE_BID_INCREMENT","NAME_BID_TIMEOUT_BLOCKS","NAME_MAX_LENGTH_FEE","NAME_BID_MAX_LENGTH","POINTER_KEY_BY_PREFIX","NAME_BID_RANGES","key","value","times","ID_TAG_ACCOUNT","ID_TAG_NAME","ID_TAG_COMMITMENT","ID_TAG_ORACLE","ID_TAG_CONTRACT","ID_TAG_CHANNEL","ID_TAG","account","name","commitment","oracle","contract","channel","PREFIX_ID_TAG","ak","nm","cm","ok","ct","ch","ID_TAG_PREFIX"],"sources":["../../../src/tx/builder/constants.ts"],"sourcesContent":["import { EncodingType } from './../../utils/encoder'\nimport BigNumber from 'bignumber.js'\nimport { mapObject } from '../../utils/other'\n\n// # AENS\nexport type AensName = `${string}.chain`\nexport const NAME_TTL = 180000\n// # max number of block into the future that the name is going to be available\n// # https://github.com/aeternity/protocol/blob/epoch-v0.22.0/AENS.md#update\n// # https://github.com/aeternity/protocol/blob/44a93d3aab957ca820183c3520b9daf6b0fedff4/AENS.md#aens-entry\nexport const NAME_MAX_TTL = 36000\nexport const NAME_MAX_CLIENT_TTL = 84600\nexport const CLIENT_TTL = NAME_MAX_CLIENT_TTL\nexport const MIN_GAS_PRICE = 1e9\n// # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67\nexport const NAME_FEE_MULTIPLIER = 1e14 // 100000000000000\nexport const NAME_FEE_BID_INCREMENT = 0.05 // # the increment is in percentage\n// # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L272\nexport const NAME_BID_TIMEOUT_BLOCKS = 480 // # ~1 day\n// # this is the max length for a domain that requires a base fee to be paid\nexport const NAME_MAX_LENGTH_FEE = 31\nexport const NAME_BID_MAX_LENGTH = 12 // # this is the max length for a domain to be part of a bid\nexport enum POINTER_KEY_BY_PREFIX {\n ak = 'account_pubkey',\n ok = 'oracle_pubkey',\n ct = 'contract_pubkey',\n ch = 'channel'\n}\n// # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290\n// # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times\n// # bid ranges:\nexport const NAME_BID_RANGES = mapObject({\n 31: 3,\n 30: 5,\n 29: 8,\n 28: 13,\n 27: 21,\n 26: 34,\n 25: 55,\n 24: 89,\n 23: 144,\n 22: 233,\n 21: 377,\n 20: 610,\n 19: 987,\n 18: 1597,\n 17: 2584,\n 16: 4181,\n 15: 6765,\n 14: 10946,\n 13: 17711,\n 12: 28657,\n 11: 46368,\n 10: 75025,\n 9: 121393,\n 8: 196418,\n 7: 317811,\n 6: 514229,\n 5: 832040,\n 4: 1346269,\n 3: 2178309,\n 2: 3524578,\n 1: 5702887\n}, ([key, value]) => [key, new BigNumber(value).times(NAME_FEE_MULTIPLIER)])\n\n// # Tag constant for ids (type uint8)\n// # see https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type\n// # <<Tag:1/unsigned-integer-unit:8, Hash:32/binary-unit:8>>\nconst ID_TAG_ACCOUNT = 1\nconst ID_TAG_NAME = 2\nconst ID_TAG_COMMITMENT = 3\nconst ID_TAG_ORACLE = 4\nconst ID_TAG_CONTRACT = 5\nconst ID_TAG_CHANNEL = 6\n\nexport const ID_TAG = {\n account: ID_TAG_ACCOUNT,\n name: ID_TAG_NAME,\n commitment: ID_TAG_COMMITMENT,\n oracle: ID_TAG_ORACLE,\n contract: ID_TAG_CONTRACT,\n channel: ID_TAG_CHANNEL\n}\n\nexport const PREFIX_ID_TAG = {\n ak: ID_TAG.account,\n nm: ID_TAG.name,\n cm: ID_TAG.commitment,\n ok: ID_TAG.oracle,\n ct: ID_TAG.contract,\n ch: ID_TAG.channel\n} as const\n\nexport const ID_TAG_PREFIX = mapObject(\n PREFIX_ID_TAG, ([key, value]: [EncodingType, number]) => [value, key]\n)\n"],"mappings":"AACA,OAAOA,SAAP,MAAsB,cAAtB;SACSC,S,iCAET;;AAEA,OAAO,MAAMC,QAAQ,GAAG,MAAjB,C,CACP;AACA;AACA;;AACA,OAAO,MAAMC,YAAY,GAAG,KAArB;AACP,OAAO,MAAMC,mBAAmB,GAAG,KAA5B;AACP,OAAO,MAAMC,UAAU,GAAGD,mBAAnB;AACP,OAAO,MAAME,aAAa,GAAG,GAAtB,C,CACP;;AACA,OAAO,MAAMC,mBAAmB,GAAG,IAA5B,C,CAAiC;;AACxC,OAAO,MAAMC,sBAAsB,GAAG,IAA/B,C,CAAoC;AAC3C;;AACA,OAAO,MAAMC,uBAAuB,GAAG,GAAhC,C,CAAoC;AAC3C;;AACA,OAAO,MAAMC,mBAAmB,GAAG,EAA5B;AACP,OAAO,MAAMC,mBAAmB,GAAG,EAA5B,C,CAA+B;;AACtC,WAAYC,qBAAZ,C,CAMA;AACA;AACA;;WARYA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;GAAAA,qB,KAAAA,qB;;AASZ,OAAO,MAAMC,eAAe,GAAGZ,SAAS,CAAC;EACvC,IAAI,CADmC;EAEvC,IA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P,OAAO,MAAMQ,aAAa,GAAG;EAC3BC,EAAE,EAAER,MAAM,CAACC,OADgB;EAE3BQ,EAAE,EAAET,MAAM,CAACE,IAFgB;EAG3BQ,EAAE,EAAEV,MAAM,CAACG,UAHgB;EAI3BQ,EAAE,EAAEX,MAAM,CAACI,MAJgB;EAK3BQ,EAAE,EAAEZ,MAAM,CAACK,QALgB;EAM3BQ,EAAE,EAAEb,MAAM,CAACM;AANgB,CAAtB;AASP,OAAO,MAAMQ,aAAa,GAAGpC,SAAS,CACpC6B,aADoC,EACrB;EAAA,IAAC,CAAChB,GAAD,EAAMC,KAAN,CAAD;EAAA,OAA0C,CAACA,KAAD,EAAQD,GAAR,CAA1C;AAAA,CADqB,CAA/B"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
import { AensName } from './constants';
|
|
4
|
+
import { EncodedData } from '../../utils/encoder';
|
|
5
|
+
declare type Int = number | string | BigNumber;
|
|
6
|
+
export declare class Field {
|
|
7
|
+
prototype: any;
|
|
8
|
+
static serialize(value: any, _txFields?: object): Buffer;
|
|
9
|
+
static deserialize(value: Buffer): any;
|
|
10
|
+
}
|
|
11
|
+
export declare class Name extends Field {
|
|
12
|
+
/**
|
|
13
|
+
* @param value - AENS name
|
|
14
|
+
*/
|
|
15
|
+
static serialize(value: AensName): Buffer;
|
|
16
|
+
/**
|
|
17
|
+
* @param value - AENS name
|
|
18
|
+
*/
|
|
19
|
+
static deserialize(value: Buffer): string;
|
|
20
|
+
}
|
|
21
|
+
export declare class NameId extends Field {
|
|
22
|
+
/**
|
|
23
|
+
* @param value - AENS name ID
|
|
24
|
+
*/
|
|
25
|
+
static serialize(value: AensName | EncodedData<'nm'>): Buffer;
|
|
26
|
+
/**
|
|
27
|
+
* @param value - AENS name ID Buffer
|
|
28
|
+
*/
|
|
29
|
+
static deserialize(value: Buffer): string;
|
|
30
|
+
}
|
|
31
|
+
export declare class NameFee extends Field {
|
|
32
|
+
/**
|
|
33
|
+
* @param value - AENS name fee Buffer
|
|
34
|
+
* @param txFields - Transaction fields
|
|
35
|
+
* @param txFields.name - AENS Name in transaction
|
|
36
|
+
*/
|
|
37
|
+
static serialize(value: Int | undefined, { name }: {
|
|
38
|
+
name: AensName;
|
|
39
|
+
}): Buffer;
|
|
40
|
+
/**
|
|
41
|
+
* @param value - AENS name fee Buffer
|
|
42
|
+
* @returns AENS name fee
|
|
43
|
+
*/
|
|
44
|
+
static deserialize(value: Buffer): string;
|
|
45
|
+
}
|
|
46
|
+
export declare class Deposit extends Field {
|
|
47
|
+
/**
|
|
48
|
+
* @param value - Deposit value in string format. Should be equal to '0'.
|
|
49
|
+
* @returns Deposit value Buffer.
|
|
50
|
+
*/
|
|
51
|
+
static serialize(value?: string): Buffer;
|
|
52
|
+
/**
|
|
53
|
+
* @param value - Deposit value Buffer.
|
|
54
|
+
* @returns Deposit value.
|
|
55
|
+
*/
|
|
56
|
+
static deserialize(value: Buffer): string;
|
|
57
|
+
}
|
|
58
|
+
export declare class GasPrice extends Field {
|
|
59
|
+
static serialize(value?: Int): Buffer;
|
|
60
|
+
static deserialize(value: Buffer): string;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -2,23 +2,35 @@ import _buffer from "buffer";
|
|
|
2
2
|
const {
|
|
3
3
|
Buffer: _Buffer
|
|
4
4
|
} = _buffer;
|
|
5
|
-
import { writeId, readId,
|
|
5
|
+
import { writeId, readId, produceNameId, getMinimumNameFee, readInt, writeInt, isNameValid } from "./helpers.mjs";
|
|
6
6
|
import { InsufficientNameFeeError, IllegalArgumentError } from "../../utils/errors.mjs";
|
|
7
|
+
import BigNumber from 'bignumber.js';
|
|
8
|
+
import { MIN_GAS_PRICE } from "./constants.mjs";
|
|
9
|
+
// todo: update me
|
|
10
|
+
// ? This is a TS workaround because this has to be a class with only static methods
|
|
7
11
|
export class Field {
|
|
8
12
|
static serialize(value) {
|
|
9
|
-
|
|
13
|
+
let _txFields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
14
|
+
|
|
15
|
+
return _Buffer.from(value);
|
|
10
16
|
}
|
|
11
17
|
|
|
12
18
|
static deserialize(value) {
|
|
13
|
-
return value;
|
|
19
|
+
return value.toString();
|
|
14
20
|
}
|
|
15
21
|
|
|
16
22
|
}
|
|
17
23
|
export class Name extends Field {
|
|
24
|
+
/**
|
|
25
|
+
* @param value - AENS name
|
|
26
|
+
*/
|
|
18
27
|
static serialize(value) {
|
|
19
|
-
ensureNameValid(value);
|
|
20
28
|
return _Buffer.from(value);
|
|
21
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* @param value - AENS name
|
|
32
|
+
*/
|
|
33
|
+
|
|
22
34
|
|
|
23
35
|
static deserialize(value) {
|
|
24
36
|
return value.toString();
|
|
@@ -26,9 +38,16 @@ export class Name extends Field {
|
|
|
26
38
|
|
|
27
39
|
}
|
|
28
40
|
export class NameId extends Field {
|
|
41
|
+
/**
|
|
42
|
+
* @param value - AENS name ID
|
|
43
|
+
*/
|
|
29
44
|
static serialize(value) {
|
|
30
45
|
return writeId(isNameValid(value) ? produceNameId(value) : value);
|
|
31
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* @param value - AENS name ID Buffer
|
|
49
|
+
*/
|
|
50
|
+
|
|
32
51
|
|
|
33
52
|
static deserialize(value) {
|
|
34
53
|
return readId(value);
|
|
@@ -36,6 +55,11 @@ export class NameId extends Field {
|
|
|
36
55
|
|
|
37
56
|
}
|
|
38
57
|
export class NameFee extends Field {
|
|
58
|
+
/**
|
|
59
|
+
* @param value - AENS name fee Buffer
|
|
60
|
+
* @param txFields - Transaction fields
|
|
61
|
+
* @param txFields.name - AENS Name in transaction
|
|
62
|
+
*/
|
|
39
63
|
static serialize(value, _ref) {
|
|
40
64
|
var _value;
|
|
41
65
|
|
|
@@ -46,11 +70,16 @@ export class NameFee extends Field {
|
|
|
46
70
|
(_value = value) !== null && _value !== void 0 ? _value : value = minNameFee;
|
|
47
71
|
|
|
48
72
|
if (minNameFee.gt(value)) {
|
|
49
|
-
throw new InsufficientNameFeeError(value, minNameFee);
|
|
73
|
+
throw new InsufficientNameFeeError(new BigNumber(value), minNameFee);
|
|
50
74
|
}
|
|
51
75
|
|
|
52
76
|
return writeInt(value);
|
|
53
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* @param value - AENS name fee Buffer
|
|
80
|
+
* @returns AENS name fee
|
|
81
|
+
*/
|
|
82
|
+
|
|
54
83
|
|
|
55
84
|
static deserialize(value) {
|
|
56
85
|
return readInt(value);
|
|
@@ -58,13 +87,36 @@ export class NameFee extends Field {
|
|
|
58
87
|
|
|
59
88
|
}
|
|
60
89
|
export class Deposit extends Field {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
90
|
+
/**
|
|
91
|
+
* @param value - Deposit value in string format. Should be equal to '0'.
|
|
92
|
+
* @returns Deposit value Buffer.
|
|
93
|
+
*/
|
|
94
|
+
static serialize() {
|
|
95
|
+
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '0';
|
|
96
|
+
if (parseInt(value) !== 0) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value.toString()} instead`);
|
|
66
97
|
return writeInt(0);
|
|
67
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* @param value - Deposit value Buffer.
|
|
101
|
+
* @returns Deposit value.
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
static deserialize(value) {
|
|
106
|
+
return readInt(value);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
export class GasPrice extends Field {
|
|
111
|
+
static serialize() {
|
|
112
|
+
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MIN_GAS_PRICE;
|
|
113
|
+
|
|
114
|
+
if (+value < MIN_GAS_PRICE) {
|
|
115
|
+
throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger then ${MIN_GAS_PRICE}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return writeInt(value);
|
|
119
|
+
}
|
|
68
120
|
|
|
69
121
|
static deserialize(value) {
|
|
70
122
|
return readInt(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"field-types.mjs","names":["writeId","readId","produceNameId","getMinimumNameFee","readInt","writeInt","isNameValid","InsufficientNameFeeError","IllegalArgumentError","BigNumber","MIN_GAS_PRICE","Field","serialize","value","_txFields","from","deserialize","toString","Name","NameId","NameFee","name","minNameFee","gt","Deposit","parseInt","GasPrice"],"sources":["../../../src/tx/builder/field-types.ts"],"sourcesContent":["import {\n writeId, readId, produceNameId, getMinimumNameFee, readInt, writeInt, isNameValid\n} from './helpers'\nimport { InsufficientNameFeeError, IllegalArgumentError } from '../../utils/errors'\nimport BigNumber from 'bignumber.js'\nimport { MIN_GAS_PRICE, AensName } from './constants'\nimport { EncodedData } from '../../utils/encoder'\n\ntype Int = number | string | BigNumber\n\n// todo: update me\n// ? This is a TS workaround because this has to be a class with only static methods\nexport class Field {\n public prototype: any\n\n static serialize (value: any, _txFields: object = {}): Buffer {\n return Buffer.from(value)\n }\n\n static deserialize (value: Buffer): any {\n return value.toString()\n }\n}\n\nexport class Name extends Field {\n /**\n * @param value - AENS name\n */\n static serialize (value: AensName): Buffer {\n return Buffer.from(value)\n }\n\n /**\n * @param value - AENS name\n */\n static deserialize (value: Buffer): string {\n return value.toString()\n }\n}\n\nexport class NameId extends Field {\n /**\n * @param value - AENS name ID\n */\n static serialize (value: AensName | EncodedData<'nm'>): Buffer {\n return writeId(isNameValid(value) ? produceNameId(value) : value)\n }\n\n /**\n * @param value - AENS name ID Buffer\n */\n static deserialize (value: Buffer): string {\n return readId(value)\n }\n}\n\nexport class NameFee extends Field {\n /**\n * @param value - AENS name fee Buffer\n * @param txFields - Transaction fields\n * @param txFields.name - AENS Name in transaction\n */\n static serialize (value: Int | undefined, { name }: { name: AensName }): Buffer {\n const minNameFee = getMinimumNameFee(name)\n value ??= minNameFee\n if (minNameFee.gt(value)) {\n throw new InsufficientNameFeeError(new BigNumber(value), minNameFee)\n }\n return writeInt(value)\n }\n\n /**\n * @param value - AENS name fee Buffer\n * @returns AENS name fee\n */\n static deserialize (value: Buffer): string {\n return readInt(value)\n }\n}\n\nexport class Deposit extends Field {\n /**\n * @param value - Deposit value in string format. Should be equal to '0'.\n * @returns Deposit value Buffer.\n */\n static serialize (value: string = '0'): Buffer {\n if (parseInt(value) !== 0) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value.toString()} instead`)\n return writeInt(0)\n }\n\n /**\n * @param value - Deposit value Buffer.\n * @returns Deposit value.\n */\n static deserialize (value: Buffer): string {\n return readInt(value)\n }\n}\n\nexport class GasPrice extends Field {\n static serialize (value: Int = MIN_GAS_PRICE): Buffer {\n if (+value < MIN_GAS_PRICE) {\n throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger then ${MIN_GAS_PRICE}`)\n }\n return writeInt(value)\n }\n\n static deserialize (value: Buffer): string {\n return readInt(value)\n }\n}\n"],"mappings":";;;;SACEA,O,EAASC,M,EAAQC,a,EAAeC,iB,EAAmBC,O,EAASC,Q,EAAUC,W;SAE/DC,wB,EAA0BC,oB;AACnC,OAAOC,SAAP,MAAsB,cAAtB;SACSC,a;AAKT;AACA;AACA,OAAO,MAAMC,KAAN,CAAY;EAGD,OAATC,SAAS,CAAEC,KAAF,EAA8C;IAAA,IAAhCC,SAAgC,uEAAZ,EAAY;;IAC5D,OAAO,QAAOC,IAAP,CAAYF,KAAZ,CAAP;EACD;;EAEiB,OAAXG,WAAW,CAAEH,KAAF,EAAsB;IACtC,OAAOA,KAAK,CAACI,QAAN,EAAP;EACD;;AATgB;AAYnB,OAAO,MAAMC,IAAN,SAAmBP,KAAnB,CAAyB;EAC9B;AACF;AACA;EACkB,OAATC,SAAS,CAAEC,KAAF,EAA2B;IACzC,OAA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