@aeternity/aepp-sdk 14.1.1 → 15.0.1
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.cjs +1 -1
- package/dist/aepp-sdk.browser-script.cjs.map +1 -1
- package/dist/aepp-sdk.browser.cjs +1 -1
- package/dist/aepp-sdk.browser.cjs.map +1 -1
- package/dist/aepp-sdk.cjs +3112 -506
- package/dist/aepp-sdk.cjs.map +1 -1
- package/es/account/Base.d.ts +6 -1
- package/es/account/Base.js.map +1 -1
- package/es/account/Generalized.d.ts +1 -1
- package/es/account/Generalized.js +7 -1
- package/es/account/Generalized.js.map +1 -1
- package/es/apis/node/models/index.d.ts +405 -79
- package/es/apis/node/models/index.js.map +1 -1
- package/es/apis/node/models/mappers.d.ts +54 -4
- package/es/apis/node/models/mappers.js +1910 -500
- package/es/apis/node/models/mappers.js.map +1 -1
- package/es/apis/node/node.d.ts +28 -6
- package/es/apis/node/node.js +276 -5
- package/es/apis/node/node.js.map +1 -1
- package/es/channel/Contract.d.ts +5 -0
- package/es/channel/Contract.js +8 -2
- package/es/channel/Contract.js.map +1 -1
- package/es/channel/handlers.js +3 -3
- package/es/channel/handlers.js.map +1 -1
- package/es/contract/ga.d.ts +5 -2
- package/es/contract/ga.js +53 -21
- package/es/contract/ga.js.map +1 -1
- package/es/index-browser.d.ts +3 -1
- package/es/index-browser.js +2 -1
- package/es/index-browser.js.map +1 -1
- package/es/tx/builder/constants.d.ts +13 -2
- package/es/tx/builder/constants.js +12 -1
- package/es/tx/builder/constants.js.map +1 -1
- package/es/tx/builder/entry/index.js +6 -0
- package/es/tx/builder/entry/index.js.map +1 -1
- package/es/tx/builder/entry/schema.d.ts +10 -10
- package/es/tx/builder/field-types/abi-version.js +6 -4
- package/es/tx/builder/field-types/abi-version.js.map +1 -1
- package/es/tx/builder/field-types/ct-version.d.ts +19 -0
- package/es/tx/builder/field-types/ct-version.js +27 -1
- package/es/tx/builder/field-types/ct-version.js.map +1 -1
- package/es/tx/builder/field-types/fee.d.ts +9 -7
- package/es/tx/builder/field-types/fee.js +75 -66
- package/es/tx/builder/field-types/fee.js.map +1 -1
- package/es/tx/builder/field-types/gas-limit.d.ts +5 -3
- package/es/tx/builder/field-types/gas-limit.js +25 -14
- package/es/tx/builder/field-types/gas-limit.js.map +1 -1
- package/es/tx/builder/field-types/gas-price.d.ts +6 -4
- package/es/tx/builder/field-types/gas-price.js +91 -21
- package/es/tx/builder/field-types/gas-price.js.map +1 -1
- package/es/tx/builder/field-types/interface.d.ts +20 -0
- package/es/tx/builder/field-types/interface.js +17 -1
- package/es/tx/builder/field-types/interface.js.map +1 -1
- package/es/tx/builder/field-types/name-fee.d.ts +3 -2
- package/es/tx/builder/field-types/name-fee.js +6 -0
- package/es/tx/builder/field-types/name-fee.js.map +1 -1
- package/es/tx/builder/field-types/pointers.d.ts +2 -1
- package/es/tx/builder/field-types/pointers.js +6 -2
- package/es/tx/builder/field-types/pointers.js.map +1 -1
- package/es/tx/builder/field-types/transaction.d.ts +4 -1
- package/es/tx/builder/field-types/transaction.js +18 -3
- package/es/tx/builder/field-types/transaction.js.map +1 -1
- package/es/tx/builder/field-types/with-formatting.d.ts +1 -1
- package/es/tx/builder/field-types/with-formatting.js +1 -1
- package/es/tx/builder/field-types/with-formatting.js.map +1 -1
- package/es/tx/builder/index.d.ts +13 -0
- package/es/tx/builder/index.js +92 -5
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/protocol-parameters.d.ts +134 -0
- package/es/tx/builder/protocol-parameters.js +539 -0
- package/es/tx/builder/protocol-parameters.js.map +1 -0
- package/es/tx/builder/schema.d.ts +156 -155
- package/es/tx/builder/schema.js +5 -1
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/execution-cost.js +5 -5
- package/es/tx/execution-cost.js.map +1 -1
- package/es/tx/transaction-signer.js +2 -2
- package/es/tx/transaction-signer.js.map +1 -1
- package/es/tx/validator.js +4 -4
- package/es/tx/validator.js.map +1 -1
- package/es/utils/wrap-proxy.d.ts +10 -0
- package/es/utils/wrap-proxy.js +18 -0
- package/es/utils/wrap-proxy.js.map +1 -1
- package/package.json +15 -3
package/es/tx/builder/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { decode, encode, Encoding } from '../../utils/encoder.js';
|
|
2
2
|
import { hash } from '../../utils/crypto.js';
|
|
3
|
+
import { serializeAsIsParam } from './field-types/interface.js';
|
|
3
4
|
import { txSchema } from './schema.js';
|
|
4
5
|
import { Tag } from './constants.js';
|
|
5
6
|
import { buildContractId } from './helpers.js';
|
|
6
7
|
import { getSchema as getSchemaCommon, packRecord, unpackRecord } from './common.js';
|
|
7
8
|
import { ArgumentError } from '../../utils/errors.js';
|
|
8
9
|
import { packEntry, unpackEntry } from './entry/index.js';
|
|
9
|
-
|
|
10
|
+
import { checkParametersUsable, getCachedProtocolParameters } from './protocol-parameters.js';
|
|
11
|
+
import { unwrapProxyIfPossible } from '../../utils/wrap-proxy.js';
|
|
10
12
|
/**
|
|
11
13
|
* JavaScript-based Transaction builder
|
|
12
14
|
*/
|
|
@@ -20,6 +22,11 @@ export function getSchema(tag, version) {
|
|
|
20
22
|
* @param params - Transaction params
|
|
21
23
|
*/
|
|
22
24
|
export function buildTx(params) {
|
|
25
|
+
// as trusted as `fee` is, see `checkParametersUsable`
|
|
26
|
+
const {
|
|
27
|
+
protocolParameters
|
|
28
|
+
} = params;
|
|
29
|
+
if (protocolParameters != null) checkParametersUsable(protocolParameters);
|
|
23
30
|
return packRecord(txSchema, Tag, params, {
|
|
24
31
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
25
32
|
unpackTx,
|
|
@@ -31,6 +38,58 @@ export function buildTx(params) {
|
|
|
31
38
|
packEntry
|
|
32
39
|
}, Encoding.Transaction);
|
|
33
40
|
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Serializes a transaction that already exists — the result of an `unpackTx` — back to its
|
|
44
|
+
* `tx_`-encoded form.
|
|
45
|
+
*
|
|
46
|
+
* Use it instead of `buildTx` for a round trip. The values of such a transaction are fixed, and
|
|
47
|
+
* belong to the protocol parameters of the node it was built for: a node running a lower minimum
|
|
48
|
+
* gas price than the SDK release, a hyperchain or a devnet, produces a transaction that plain
|
|
49
|
+
* `buildTx` would refuse to serialize again because its fee is below the minimum this process
|
|
50
|
+
* computes. Nothing about it can be changed by re-serializing it, so nothing about it is checked.
|
|
51
|
+
* @category transaction builder
|
|
52
|
+
* @param params - Unpacked transaction, as returned by `unpackTx`
|
|
53
|
+
*/
|
|
54
|
+
export function rebuildUnpackedTx(params) {
|
|
55
|
+
return buildTx({
|
|
56
|
+
...params,
|
|
57
|
+
[serializeAsIsParam]: true
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// the fields the protocol parameters price
|
|
61
|
+
const parametrizedFields = ['fee', 'gasPrice', 'gasLimit'];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The parameters are needed to compute a priced value the caller didn't provide, and to check one
|
|
65
|
+
* it did against what node accepts. A build that provides every priced field of its type, and
|
|
66
|
+
* nests no transaction that still has to be built, serializes to the same bytes with or without
|
|
67
|
+
* them — requesting them would turn a build that needs no node into one that waits for it, as it
|
|
68
|
+
* would for a caller that passes `fee` exactly to avoid the round trip.
|
|
69
|
+
*/
|
|
70
|
+
function needsProtocolParameters(schema, params) {
|
|
71
|
+
return schema.some(([key, field]) => {
|
|
72
|
+
const value = params[key];
|
|
73
|
+
if (parametrizedFields.includes(key)) return value == null;
|
|
74
|
+
// a nested transaction that is neither built (`tx_`) nor serialized (a buffer) yet is built
|
|
75
|
+
// here, and priced by these parameters in turn
|
|
76
|
+
if (field.nestedTransaction !== true) return false;
|
|
77
|
+
if (value == null || typeof value === 'string' || ArrayBuffer.isView(value)) return false;
|
|
78
|
+
// it is built here, but that doesn't mean anything in it is priced — the `SignedTx` wrapping
|
|
79
|
+
// an already serialized transaction that `AccountGeneralized` nests in its `GaMetaTx` has no
|
|
80
|
+
// priced field of its own
|
|
81
|
+
const nested = value;
|
|
82
|
+
let nestedSchema;
|
|
83
|
+
try {
|
|
84
|
+
nestedSchema = getSchema(nested.tag, nested.version);
|
|
85
|
+
} catch {
|
|
86
|
+
// an unknown tag or version fails later in `buildTx` with a better message than here
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return needsProtocolParameters(nestedSchema, nested);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
34
93
|
// TODO: require onNode because it is the only reason this builder is async [breaking change]
|
|
35
94
|
/**
|
|
36
95
|
* Build transaction async (may request node for additional data)
|
|
@@ -39,14 +98,42 @@ export function buildTx(params) {
|
|
|
39
98
|
* @returns tx_-encoded transaction
|
|
40
99
|
*/
|
|
41
100
|
export async function buildTxAsync(params) {
|
|
42
|
-
|
|
101
|
+
var _target$protocolParam;
|
|
102
|
+
// the caller may build another transaction out of the same object, and `prepare` writing the
|
|
103
|
+
// value it computed back would make the next build reuse them — the same nonce above all, and a
|
|
104
|
+
// `fee` that makes it skip the request for the parameters that priced this one
|
|
105
|
+
const paramsCopy = {
|
|
106
|
+
...params
|
|
107
|
+
};
|
|
108
|
+
const {
|
|
109
|
+
onNode
|
|
110
|
+
} = paramsCopy;
|
|
111
|
+
const target = paramsCopy;
|
|
112
|
+
const schema = getSchema(paramsCopy.tag, paramsCopy.version);
|
|
113
|
+
// `onNode` of an sdk instance is a proxy that is not `null` even when no node is selected, and
|
|
114
|
+
// dereferencing it throws — a transaction that needs no node is still buildable in that case
|
|
115
|
+
const node = onNode != null ? unwrapProxyIfPossible(onNode) : undefined;
|
|
116
|
+
// started before the `prepare` calls below so that it runs in parallel with them: they read the
|
|
117
|
+
// parameters, but get this very request from the cache it registers synchronously. Below the
|
|
118
|
+
// `Promise.all` it would make `prepare` the originator and serialize the two requests
|
|
119
|
+
const parametersPromise = node != null && target.protocolParameters == null && needsProtocolParameters(schema, paramsCopy) ? getCachedProtocolParameters(node) : undefined;
|
|
120
|
+
// it is awaited after the `prepare` calls below, don't report it as an unhandled rejection if
|
|
121
|
+
// one of them throws first
|
|
122
|
+
parametersPromise?.catch(() => {});
|
|
123
|
+
await Promise.all(schema.map(async ([key, field]) => {
|
|
43
124
|
if (field.prepare == null) return;
|
|
44
|
-
// @ts-expect-error the type of `
|
|
45
|
-
|
|
125
|
+
// @ts-expect-error the type of `paramsCopy[key]` can't be determined accurately
|
|
126
|
+
paramsCopy[key] = await field.prepare(paramsCopy[key], paramsCopy, paramsCopy);
|
|
46
127
|
}));
|
|
128
|
+
const protocolParameters = (_target$protocolParam = target.protocolParameters) !== null && _target$protocolParam !== void 0 ? _target$protocolParam : await parametersPromise;
|
|
47
129
|
|
|
48
130
|
// @ts-expect-error after preparation properties should be compatible with sync tx builder
|
|
49
|
-
return buildTx(
|
|
131
|
+
return buildTx({
|
|
132
|
+
...paramsCopy,
|
|
133
|
+
...(protocolParameters != null && {
|
|
134
|
+
protocolParameters
|
|
135
|
+
})
|
|
136
|
+
});
|
|
50
137
|
}
|
|
51
138
|
|
|
52
139
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["decode","encode","Encoding","hash","txSchema","Tag","buildContractId","getSchema","getSchemaCommon","packRecord","unpackRecord","ArgumentError","packEntry","unpackEntry","tag","version","buildTx","params","unpackTx","rebuildTx","overrideParams","Transaction","buildTxAsync","Promise","all","map","key","field","prepare","encodedTx","txType","buildTxHash","rawTx","data","startsWith","TxHash","buildContractIdByContractTx","contractTx","SignedTx","ContractCreateTx","GaAttachTx","ownerId","nonce"],"sources":["../../../src/tx/builder/index.ts"],"sourcesContent":["import { decode, encode, Encoded, Encoding } from '../../utils/encoder.js';\nimport { hash } from '../../utils/crypto.js';\nimport { Field } from './field-types/interface.js';\nimport { txSchema } from './schema.js';\nimport { TxUnpacked, TxParams, TxParamsAsync } from './schema.generated.js';\nimport { Tag } from './constants.js';\nimport { buildContractId } from './helpers.js';\nimport { getSchema as getSchemaCommon, packRecord, unpackRecord } from './common.js';\nimport { ArgumentError } from '../../utils/errors.js';\nimport { packEntry, unpackEntry } from './entry/index.js';\n\n/**\n * JavaScript-based Transaction builder\n */\n\nexport function getSchema(tag: Tag, version?: number): Array<[string, Field]> {\n return getSchemaCommon(txSchema, Tag, tag, version);\n}\n\ntype TxEncoding =\n | Encoding.Transaction\n | Encoding.Poi\n | Encoding.StateTrees\n | Encoding.CallStateTree;\n\n/**\n * Build transaction\n * @category transaction builder\n * @param params - Transaction params\n */\nexport function buildTx(params: TxParams): Encoded.Transaction {\n return packRecord(\n txSchema,\n Tag,\n params,\n {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n unpackTx,\n buildTx,\n rebuildTx: (overrideParams: any) => buildTx({ ...params, ...overrideParams }),\n packEntry,\n },\n Encoding.Transaction,\n );\n}\n\nexport type BuildTxOptions<TxType extends Tag, OmitFields extends string> = Omit<\n TxParamsAsync & { tag: TxType },\n 'tag' | OmitFields\n>;\n\n// TODO: require onNode because it is the only reason this builder is async [breaking change]\n/**\n * Build transaction async (may request node for additional data)\n * @category transaction builder\n * @param params - Transaction params\n * @returns tx_-encoded transaction\n */\nexport async function buildTxAsync(params: TxParamsAsync): Promise<Encoded.Transaction> {\n await Promise.all(\n getSchema(params.tag, params.version).map(async ([key, field]) => {\n if (field.prepare == null) return;\n // @ts-expect-error the type of `params[key]` can't be determined accurately\n params[key] = await field.prepare(params[key], params, params);\n }),\n );\n\n // @ts-expect-error after preparation properties should be compatible with sync tx builder\n return buildTx(params);\n}\n\n/**\n * Unpack transaction encoded as string\n * @category transaction builder\n * @param encodedTx - Encoded transaction\n * @param txType - Expected transaction type\n * @returns Transaction params\n */\nexport function unpackTx<TxType extends Tag>(\n encodedTx: Encoded.Generic<TxEncoding>,\n txType?: TxType,\n): TxUnpacked & { tag: TxType } {\n return unpackRecord(txSchema, Tag, encodedTx, txType, { unpackTx, unpackEntry }) as any;\n}\n\n/**\n * Build a transaction hash\n * @category transaction builder\n * @param rawTx - base64 or rlp encoded transaction\n * @returns Transaction hash\n */\nexport function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.TxHash {\n const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx) : rawTx;\n return encode(hash(data), Encoding.TxHash);\n}\n\n/**\n * Build a contract public key by contractCreateTx, gaAttach or signedTx\n * @category contract\n * @param contractTx - Transaction\n * @returns Contract public key\n */\nexport function buildContractIdByContractTx(\n contractTx: Encoded.Transaction,\n): Encoded.ContractAddress {\n let params = unpackTx(contractTx);\n if (Tag.SignedTx === params.tag) params = params.encodedTx;\n if (Tag.ContractCreateTx !== params.tag && Tag.GaAttachTx !== params.tag) {\n throw new ArgumentError('contractTx', 'a contractCreateTx or gaAttach', params.tag);\n }\n return buildContractId(params.ownerId, params.nonce);\n}\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,MAAM,EAAWC,QAAQ,QAAQ,wBAAwB;AAC1E,SAASC,IAAI,QAAQ,uBAAuB;AAE5C,SAASC,QAAQ,QAAQ,aAAa;AAEtC,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,eAAe,QAAQ,cAAc;AAC9C,SAASC,SAAS,IAAIC,eAAe,EAAEC,UAAU,EAAEC,YAAY,QAAQ,aAAa;AACpF,SAASC,aAAa,QAAQ,uBAAuB;AACrD,SAASC,SAAS,EAAEC,WAAW,QAAQ,kBAAkB;;AAEzD;AACA;AACA;;AAEA,OAAO,SAASN,SAASA,CAACO,GAAQ,EAAEC,OAAgB,EAA0B;EAC5E,OAAOP,eAAe,CAACJ,QAAQ,EAAEC,GAAG,EAAES,GAAG,EAAEC,OAAO,CAAC;AACrD;AAQA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CAACC,MAAgB,EAAuB;EAC7D,OAAOR,UAAU,CACfL,QAAQ,EACRC,GAAG,EACHY,MAAM,EACN;IACE;IACAC,QAAQ;IACRF,OAAO;IACPG,SAAS,EAAGC,cAAmB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EACzB,IAAIpB,MAAM,GAAGC,QAAQ,CAACmB,UAAU,CAAC;EACjC,IAAIhC,GAAG,CAACiC,QAAQ,KAAKrB,MAAM,CAACH,GAAG,EAAEG,MAAM,GAAGA,MAAM,CAACY,SAAS;EAC1D,IAAIxB,GAAG,CAACkC,gBAAgB,KAAKtB,MAAM,CAACH,GAAG,IAAIT,GAAG,CAACmC,UAAU,KAAKvB,MAAM,CAACH,GAAG,EAAE;IACxE,MAAM,IAAIH,aAAa,CAAC,YAAY,EAAE,gCAAgC,EAAEM,MAAM,CAACH,GAAG,CAAC;EACrF;EACA,OAAOR,eAAe,CAACW,MAAM,CAACwB,OAAO,EAAExB,MAAM,CAACyB,KAAK,CAAC;AACtD","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["decode","encode","Encoding","hash","serializeAsIsParam","txSchema","Tag","buildContractId","getSchema","getSchemaCommon","packRecord","unpackRecord","ArgumentError","packEntry","unpackEntry","checkParametersUsable","getCachedProtocolParameters","unwrapProxyIfPossible","tag","version","buildTx","params","protocolParameters","unpackTx","rebuildTx","overrideParams","Transaction","rebuildUnpackedTx","parametrizedFields","needsProtocolParameters","schema","some","key","field","value","includes","nestedTransaction","ArrayBuffer","isView","nested","nestedSchema","buildTxAsync","_target$protocolParam","paramsCopy","onNode","target","node","undefined","parametersPromise","catch","Promise","all","map","prepare","encodedTx","txType","buildTxHash","rawTx","data","startsWith","TxHash","buildContractIdByContractTx","contractTx","SignedTx","ContractCreateTx","GaAttachTx","ownerId","nonce"],"sources":["../../../src/tx/builder/index.ts"],"sourcesContent":["import { decode, encode, Encoded, Encoding } from '../../utils/encoder.js';\nimport { hash } from '../../utils/crypto.js';\nimport { Field, serializeAsIsParam } from './field-types/interface.js';\nimport { txSchema } from './schema.js';\nimport { TxUnpacked, TxParams, TxParamsAsync } from './schema.generated.js';\nimport { Tag } from './constants.js';\nimport { buildContractId } from './helpers.js';\nimport { getSchema as getSchemaCommon, packRecord, unpackRecord } from './common.js';\nimport { ArgumentError } from '../../utils/errors.js';\nimport { packEntry, unpackEntry } from './entry/index.js';\nimport {\n checkParametersUsable,\n getCachedProtocolParameters,\n ProtocolParameters,\n ProtocolParametersOption,\n} from './protocol-parameters.js';\nimport { unwrapProxyIfPossible } from '../../utils/wrap-proxy.js';\nimport type Node from '../../Node.js';\n\n/**\n * JavaScript-based Transaction builder\n */\n\nexport function getSchema(tag: Tag, version?: number): Array<[string, Field]> {\n return getSchemaCommon(txSchema, Tag, tag, version);\n}\n\ntype TxEncoding =\n | Encoding.Transaction\n | Encoding.Poi\n | Encoding.StateTrees\n | Encoding.CallStateTree;\n\n/**\n * Build transaction\n * @category transaction builder\n * @param params - Transaction params\n */\nexport function buildTx(params: TxParams): Encoded.Transaction {\n // as trusted as `fee` is, see `checkParametersUsable`\n const { protocolParameters } = params as ProtocolParametersOption;\n if (protocolParameters != null) checkParametersUsable(protocolParameters);\n return packRecord(\n txSchema,\n Tag,\n params,\n {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n unpackTx,\n buildTx,\n rebuildTx: (overrideParams: any) => buildTx({ ...params, ...overrideParams }),\n packEntry,\n },\n Encoding.Transaction,\n );\n}\n\n/**\n * Serializes a transaction that already exists — the result of an `unpackTx` — back to its\n * `tx_`-encoded form.\n *\n * Use it instead of `buildTx` for a round trip. The values of such a transaction are fixed, and\n * belong to the protocol parameters of the node it was built for: a node running a lower minimum\n * gas price than the SDK release, a hyperchain or a devnet, produces a transaction that plain\n * `buildTx` would refuse to serialize again because its fee is below the minimum this process\n * computes. Nothing about it can be changed by re-serializing it, so nothing about it is checked.\n * @category transaction builder\n * @param params - Unpacked transaction, as returned by `unpackTx`\n */\nexport function rebuildUnpackedTx(params: TxUnpacked): Encoded.Transaction {\n return buildTx({ ...params, [serializeAsIsParam]: true } as unknown as TxParams);\n}\n\nexport type BuildTxOptions<TxType extends Tag, OmitFields extends string> = Omit<\n TxParamsAsync & { tag: TxType },\n 'tag' | OmitFields\n>;\n\n// the fields the protocol parameters price\nconst parametrizedFields = ['fee', 'gasPrice', 'gasLimit'];\n\n/**\n * The parameters are needed to compute a priced value the caller didn't provide, and to check one\n * it did against what node accepts. A build that provides every priced field of its type, and\n * nests no transaction that still has to be built, serializes to the same bytes with or without\n * them — requesting them would turn a build that needs no node into one that waits for it, as it\n * would for a caller that passes `fee` exactly to avoid the round trip.\n */\nfunction needsProtocolParameters(schema: Array<[string, Field]>, params: TxParamsAsync): boolean {\n return schema.some(([key, field]) => {\n const value = (params as unknown as Record<string, unknown>)[key];\n if (parametrizedFields.includes(key)) return value == null;\n // a nested transaction that is neither built (`tx_`) nor serialized (a buffer) yet is built\n // here, and priced by these parameters in turn\n if (field.nestedTransaction !== true) return false;\n if (value == null || typeof value === 'string' || ArrayBuffer.isView(value)) return false;\n // it is built here, but that doesn't mean anything in it is priced — the `SignedTx` wrapping\n // an already serialized transaction that `AccountGeneralized` nests in its `GaMetaTx` has no\n // priced field of its own\n const nested = value as TxParamsAsync;\n let nestedSchema;\n try {\n nestedSchema = getSchema(nested.tag, nested.version);\n } catch {\n // an unknown tag or version fails later in `buildTx` with a better message than here\n return true;\n }\n return needsProtocolParameters(nestedSchema, nested);\n });\n}\n\n// TODO: require onNode because it is the only reason this builder is async [breaking change]\n/**\n * Build transaction async (may request node for additional data)\n * @category transaction builder\n * @param params - Transaction params\n * @returns tx_-encoded transaction\n */\nexport async function buildTxAsync(params: TxParamsAsync): Promise<Encoded.Transaction> {\n // the caller may build another transaction out of the same object, and `prepare` writing the\n // value it computed back would make the next build reuse them — the same nonce above all, and a\n // `fee` that makes it skip the request for the parameters that priced this one\n const paramsCopy = { ...params };\n const { onNode } = paramsCopy as { onNode?: Node };\n const target = paramsCopy as { protocolParameters?: ProtocolParameters };\n const schema = getSchema(paramsCopy.tag, paramsCopy.version);\n // `onNode` of an sdk instance is a proxy that is not `null` even when no node is selected, and\n // dereferencing it throws — a transaction that needs no node is still buildable in that case\n const node = onNode != null ? unwrapProxyIfPossible(onNode) : undefined;\n // started before the `prepare` calls below so that it runs in parallel with them: they read the\n // parameters, but get this very request from the cache it registers synchronously. Below the\n // `Promise.all` it would make `prepare` the originator and serialize the two requests\n const parametersPromise =\n node != null && target.protocolParameters == null && needsProtocolParameters(schema, paramsCopy)\n ? getCachedProtocolParameters(node)\n : undefined;\n // it is awaited after the `prepare` calls below, don't report it as an unhandled rejection if\n // one of them throws first\n parametersPromise?.catch(() => {});\n\n await Promise.all(\n schema.map(async ([key, field]) => {\n if (field.prepare == null) return;\n // @ts-expect-error the type of `paramsCopy[key]` can't be determined accurately\n paramsCopy[key] = await field.prepare(paramsCopy[key], paramsCopy, paramsCopy);\n }),\n );\n\n const protocolParameters = target.protocolParameters ?? (await parametersPromise);\n\n // @ts-expect-error after preparation properties should be compatible with sync tx builder\n return buildTx({ ...paramsCopy, ...(protocolParameters != null && { protocolParameters }) });\n}\n\n/**\n * Unpack transaction encoded as string\n * @category transaction builder\n * @param encodedTx - Encoded transaction\n * @param txType - Expected transaction type\n * @returns Transaction params\n */\nexport function unpackTx<TxType extends Tag>(\n encodedTx: Encoded.Generic<TxEncoding>,\n txType?: TxType,\n): TxUnpacked & { tag: TxType } {\n return unpackRecord(txSchema, Tag, encodedTx, txType, { unpackTx, unpackEntry }) as any;\n}\n\n/**\n * Build a transaction hash\n * @category transaction builder\n * @param rawTx - base64 or rlp encoded transaction\n * @returns Transaction hash\n */\nexport function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.TxHash {\n const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx) : rawTx;\n return encode(hash(data), Encoding.TxHash);\n}\n\n/**\n * Build a contract public key by contractCreateTx, gaAttach or signedTx\n * @category contract\n * @param contractTx - Transaction\n * @returns Contract public key\n */\nexport function buildContractIdByContractTx(\n contractTx: Encoded.Transaction,\n): Encoded.ContractAddress {\n let params = unpackTx(contractTx);\n if (Tag.SignedTx === params.tag) params = params.encodedTx;\n if (Tag.ContractCreateTx !== params.tag && Tag.GaAttachTx !== params.tag) {\n throw new ArgumentError('contractTx', 'a contractCreateTx or gaAttach', params.tag);\n }\n return buildContractId(params.ownerId, params.nonce);\n}\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,MAAM,EAAWC,QAAQ,QAAQ,wBAAwB;AAC1E,SAASC,IAAI,QAAQ,uBAAuB;AAC5C,SAAgBC,kBAAkB,QAAQ,4BAA4B;AACtE,SAASC,QAAQ,QAAQ,aAAa;AAEtC,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,eAAe,QAAQ,cAAc;AAC9C,SAASC,SAAS,IAAIC,eAAe,EAAEC,UAAU,EAAEC,YAAY,QAAQ,aAAa;AACpF,SAASC,aAAa,QAAQ,uBAAuB;AACrD,SAASC,SAAS,EAAEC,WAAW,QAAQ,kBAAkB;AACzD,SACEC,qBAAqB,EACrBC,2BAA2B,QAGtB,0BAA0B;AACjC,SAASC,qBAAqB,QAAQ,2BAA2B;AAGjE;AACA;AACA;;AAEA,OAAO,SAAST,SAASA,CAACU,GAAQ,EAAEC,OAAgB,EAA0B;EAC5E,OAAOV,eAAe,CAACJ,QAAQ,EAAEC,GAAG,EAAEY,GAAG,EAAEC,OAAO,CAAC;AACrD;AAQA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CAACC,MAAgB,EAAuB;EAC7D;EACA,MAAM;IAAEC;EAAmB,CAAC,GAAGD,MAAkC;EACjE,IAAIC,kBAAkB,IAAI,IAAI,EAAEP,qBAAqB,CAACO,kBAAkB,CAAC;EACzE,OAAOZ,UAAU,CACfL,QAAQ,EACRC,GAAG,EACHe,MAAM,EACN;IACE;IACAE,QAAQ;IACRH,OAAO;IACPI,SAAS,EAAGC,cAAmB,IAAKL,OAAO,CAAC;MAAE,GAAGC,MAAM;MAAE,GAAGI;IAAe,CAAC,CAAC;IAC7EZ;EACF,CAAC,EACDX,QAAQ,CAACwB,WACX,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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AAG,EAAEgD,SAAS,EAAEC,MAAM,EAAE;IAAEhC,QAAQ;IAAET;EAAY,CAAC,CAAC;AAClF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS0C,WAAWA,CAACC,KAAuC,EAAkB;EACnF,MAAMC,IAAI,GAAG,OAAOD,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACE,UAAU,CAAC,KAAK,CAAC,GAAG3D,MAAM,CAACyD,KAAK,CAAC,GAAGA,KAAK;EACzF,OAAOxD,MAAM,CAACE,IAAI,CAACuD,IAAI,CAAC,EAAExD,QAAQ,CAAC0D,MAAM,CAAC;AAC5C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,2BAA2BA,CACzCC,UAA+B,EACN;EACzB,IAAIzC,MAAM,GAAGE,QAAQ,CAACuC,UAAU,CAAC;EACjC,IAAIxD,GAAG,CAACyD,QAAQ,KAAK1C,MAAM,CAACH,GAAG,EAAEG,MAAM,GAAGA,MAAM,CAACiC,SAAS;EAC1D,IAAIhD,GAAG,CAAC0D,gBAAgB,KAAK3C,MAAM,CAACH,GAAG,IAAIZ,GAAG,CAAC2D,UAAU,KAAK5C,MAAM,CAACH,GAAG,EAAE;IACxE,MAAM,IAAIN,aAAa,CAAC,YAAY,EAAE,gCAAgC,EAAES,MAAM,CAACH,GAAG,CAAC;EACrF;EACA,OAAOX,eAAe,CAACc,MAAM,CAAC6C,OAAO,EAAE7C,MAAM,CAAC8C,KAAK,CAAC;AACtD","ignoreList":[]}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { AbiVersion, Tag } from './constants.js';
|
|
2
|
+
import type Node from '../../Node.js';
|
|
3
|
+
/**
|
|
4
|
+
* Consensus parameters and node policy settings the transaction builder needs to produce a
|
|
5
|
+
* transaction the node would accept — see {@link getCachedProtocolParameters}.
|
|
6
|
+
* @category transaction builder
|
|
7
|
+
*/
|
|
8
|
+
export interface ProtocolParameters {
|
|
9
|
+
/**
|
|
10
|
+
* Consensus minimum gas price in aettos. The minimum transaction fee is the transaction's fee
|
|
11
|
+
* gas multiplied by the higher of this and `minMinerGasPrice` — see {@link getFloorGasPrice}.
|
|
12
|
+
* To build for a network accepting a lower gas price, lower both.
|
|
13
|
+
*/
|
|
14
|
+
readonly minGasPrice: bigint;
|
|
15
|
+
/**
|
|
16
|
+
* Minimum gas price accepted by the miner of the node the SDK is connected to. A transaction
|
|
17
|
+
* below it stays valid by consensus, but this node refuses it from the mempool. Node policy
|
|
18
|
+
* rather than a consensus parameter.
|
|
19
|
+
*/
|
|
20
|
+
readonly minMinerGasPrice: bigint;
|
|
21
|
+
/** Gas per serialized transaction byte counted into the minimum fee */
|
|
22
|
+
readonly gasPerByte: number;
|
|
23
|
+
/**
|
|
24
|
+
* Maximum total gas the node the SDK is connected to accepts in a single micro block. Node
|
|
25
|
+
* policy rather than a consensus parameter, it may differ between nodes.
|
|
26
|
+
*/
|
|
27
|
+
readonly blockGasLimit: number;
|
|
28
|
+
/**
|
|
29
|
+
* Maximum gas accepted for a generalized account authentication function by the node the SDK is
|
|
30
|
+
* connected to. Node policy rather than a consensus parameter, it may differ between nodes.
|
|
31
|
+
*/
|
|
32
|
+
readonly maxAuthFunGas: number;
|
|
33
|
+
/** Base fee gas by transaction type, transactions not executing contract code */
|
|
34
|
+
readonly txBaseGas: Readonly<Partial<Record<Tag, number>>>;
|
|
35
|
+
/** Base fee gas of contract-executing transaction types, by ABI version */
|
|
36
|
+
readonly contractTxBaseGas: Readonly<Partial<Record<Tag, Readonly<Partial<Record<AbiVersion, number>>>>>>;
|
|
37
|
+
/**
|
|
38
|
+
* State rent gas fraction per key block by transaction type,
|
|
39
|
+
* state gas is `ceil(relativeTtl * part / whole)`
|
|
40
|
+
*/
|
|
41
|
+
readonly stateGasPerBlock: Readonly<Partial<Record<Tag, Readonly<{
|
|
42
|
+
part: number;
|
|
43
|
+
whole: number;
|
|
44
|
+
}>>>>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Transaction option to build a transaction against specific consensus parameters. `buildTxAsync`
|
|
48
|
+
* sets it to the parameters it requests from node, provide it to build a transaction offline for a
|
|
49
|
+
* node that doesn't run the protocol version the current SDK release was made for.
|
|
50
|
+
* @category transaction builder
|
|
51
|
+
*/
|
|
52
|
+
export interface ProtocolParametersOption {
|
|
53
|
+
protocolParameters?: ProtocolParameters;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Protocol parameters of Ceres as they were at the moment of the SDK release. Used to build
|
|
57
|
+
* transactions without a node connection, and on nodes that don't provide the protocol parameters
|
|
58
|
+
* endpoint yet.
|
|
59
|
+
* @category transaction builder
|
|
60
|
+
* @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}
|
|
61
|
+
*/
|
|
62
|
+
export declare const defaultProtocolParameters: ProtocolParameters;
|
|
63
|
+
/**
|
|
64
|
+
* `Math.max(...array)` passes every element as an argument and overflows the stack on an array
|
|
65
|
+
* node can make arbitrarily long — it reports one entry per transaction type and abi version.
|
|
66
|
+
*/
|
|
67
|
+
export declare function maxOf(numbers: number[]): number;
|
|
68
|
+
/**
|
|
69
|
+
* Checks that parameters a caller provided in options can price a transaction at all — only values
|
|
70
|
+
* that would produce `NaN`, `Infinity`, or a division by zero, not their magnitude: options are the
|
|
71
|
+
* way out of the bounds {@link convertProtocolParameters} applies, bounding them here would leave
|
|
72
|
+
* no way to build against a network the SDK release doesn't know. They are as trusted as `fee` and
|
|
73
|
+
* `gasLimit`: must not come from untrusted input, this only turns an unusable value into an error
|
|
74
|
+
* naming the field. See `serializeAsIsParam`.
|
|
75
|
+
* @param parameters - Parameters provided in options
|
|
76
|
+
*/
|
|
77
|
+
export declare function checkParametersUsable(parameters: ProtocolParameters): void;
|
|
78
|
+
/**
|
|
79
|
+
* Factor the gas price ceiling of `gas-price.ts` is lowered by, so that the worst case fee doesn't
|
|
80
|
+
* become the product of that ceiling and the fee gas bound of {@link convertProtocolParameters}.
|
|
81
|
+
* The gas limit raise is charged to the gas limit default instead ({@link getGasLimitDivisor}).
|
|
82
|
+
* It is 1 unless the parameters came from node.
|
|
83
|
+
*
|
|
84
|
+
* The biggest raise among all transaction types, not the one of the type being built — so a node
|
|
85
|
+
* repricing one type lowers the ceiling for every type. The ceiling is 100000 times the minimum
|
|
86
|
+
* gas price, far above the demand-based price this bounds in practice.
|
|
87
|
+
* @param parameters - Parameters a transaction is built against
|
|
88
|
+
*/
|
|
89
|
+
export declare function getGasPriceDivisor(parameters: ProtocolParameters): number;
|
|
90
|
+
/**
|
|
91
|
+
* The cost of a contract transaction is `gasPrice * gasLimit`, and the gas limit the SDK defaults
|
|
92
|
+
* to comes from `blockGasLimit` — from `maxAuthFunGas` on a `GaMetaTx`. This is the factor node
|
|
93
|
+
* raises the one `tag` reads by, so that lowering the default by it keeps the product within the
|
|
94
|
+
* one of the SDK release. It is 1 unless the parameters came from node.
|
|
95
|
+
*
|
|
96
|
+
* Only the limit `tag` reads: charging the other one would shrink a gas limit because node raised
|
|
97
|
+
* something that transaction never reads. The fee gas raise is charged to the gas price ceiling
|
|
98
|
+
* ({@link getGasPriceDivisor}) instead.
|
|
99
|
+
* @param parameters - Parameters a transaction is built against
|
|
100
|
+
* @param tag - Type of the transaction the gas limit is defaulted for
|
|
101
|
+
*/
|
|
102
|
+
export declare function getGasLimitDivisor(parameters: ProtocolParameters, tag: Tag): number;
|
|
103
|
+
/**
|
|
104
|
+
* Gas price the minimum fee is counted at and the `gasPrice` of a contract transaction defaults
|
|
105
|
+
* to: the miner minimum when it is above the consensus one. Node reads the price a transaction
|
|
106
|
+
* pays as the lower of its `gasPrice` and its fee over its fee gas, so pricing either below the
|
|
107
|
+
* miner minimum gets it refused with `too_low_gas_price_for_miner`.
|
|
108
|
+
* @category transaction builder
|
|
109
|
+
* @param parameters - Parameters a transaction is built against
|
|
110
|
+
*/
|
|
111
|
+
export declare function getFloorGasPrice(parameters: ProtocolParameters): bigint;
|
|
112
|
+
/**
|
|
113
|
+
* Converts the node responses to the shape the transaction builder uses, rejecting values far
|
|
114
|
+
* above the ones the SDK was released with. Not a part of the public api, it is exported for
|
|
115
|
+
* tests — use {@link getCachedProtocolParameters}.
|
|
116
|
+
* @param response - Response of the `/v3/protocol-parameters` endpoint
|
|
117
|
+
* @param nodeSettings - Response of the `/v3/node-settings` endpoint
|
|
118
|
+
*/
|
|
119
|
+
export declare function convertProtocolParameters(response: Awaited<ReturnType<Node['getProtocolParameters']>>, nodeSettings: Awaited<ReturnType<Node['getNodeSettings']>>): ProtocolParameters;
|
|
120
|
+
/**
|
|
121
|
+
* Requests protocol parameters from node, the result is cached per node instance.
|
|
122
|
+
*
|
|
123
|
+
* Falls back to {@link defaultProtocolParameters} for a node that doesn't provide the endpoints,
|
|
124
|
+
* can't be reached, or answers something this SDK release can't read. Rejects only when node
|
|
125
|
+
* reports parameters that would price a transaction far above the SDK release — see
|
|
126
|
+
* {@link ProtocolParametersOption} for the way out of that.
|
|
127
|
+
*
|
|
128
|
+
* The cache is keyed by the `Node` object, so code that constructs a `Node` per request (a
|
|
129
|
+
* serverless handler, an edge worker) requests the parameters again for each one. Keep one `Node`
|
|
130
|
+
* instance per endpoint to get the benefit of the cache.
|
|
131
|
+
* @category transaction builder
|
|
132
|
+
* @param nodeOrProxy - Node to request the parameters from
|
|
133
|
+
*/
|
|
134
|
+
export declare function getCachedProtocolParameters(nodeOrProxy: Node): Promise<ProtocolParameters>;
|