@aeternity/aepp-sdk 14.1.0 → 15.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.
Files changed (91) hide show
  1. package/dist/aepp-sdk.browser-script.cjs +1 -1
  2. package/dist/aepp-sdk.browser-script.cjs.map +1 -1
  3. package/dist/aepp-sdk.browser.cjs +1 -1
  4. package/dist/aepp-sdk.browser.cjs.map +1 -1
  5. package/dist/aepp-sdk.cjs +10776 -6350
  6. package/dist/aepp-sdk.cjs.map +1 -1
  7. package/es/account/Base.d.ts +6 -1
  8. package/es/account/Base.js.map +1 -1
  9. package/es/account/Generalized.d.ts +1 -1
  10. package/es/account/Generalized.js +7 -1
  11. package/es/account/Generalized.js.map +1 -1
  12. package/es/aens.d.ts +10 -2
  13. package/es/aens.js +10 -2
  14. package/es/aens.js.map +1 -1
  15. package/es/apis/middleware/models/index.js.map +1 -1
  16. package/es/apis/node/models/index.d.ts +405 -79
  17. package/es/apis/node/models/index.js.map +1 -1
  18. package/es/apis/node/models/mappers.d.ts +54 -4
  19. package/es/apis/node/models/mappers.js +1910 -500
  20. package/es/apis/node/models/mappers.js.map +1 -1
  21. package/es/apis/node/node.d.ts +28 -6
  22. package/es/apis/node/node.js +276 -5
  23. package/es/apis/node/node.js.map +1 -1
  24. package/es/channel/Contract.d.ts +5 -0
  25. package/es/channel/Contract.js +8 -2
  26. package/es/channel/Contract.js.map +1 -1
  27. package/es/channel/handlers.js +3 -3
  28. package/es/channel/handlers.js.map +1 -1
  29. package/es/contract/compiler/Cli.js +6 -2
  30. package/es/contract/compiler/Cli.js.map +1 -1
  31. package/es/contract/ga.d.ts +5 -2
  32. package/es/contract/ga.js +53 -21
  33. package/es/contract/ga.js.map +1 -1
  34. package/es/index-browser.d.ts +3 -1
  35. package/es/index-browser.js +2 -1
  36. package/es/index-browser.js.map +1 -1
  37. package/es/tx/builder/constants.d.ts +12 -2
  38. package/es/tx/builder/constants.js +11 -1
  39. package/es/tx/builder/constants.js.map +1 -1
  40. package/es/tx/builder/entry/index.js +6 -0
  41. package/es/tx/builder/entry/index.js.map +1 -1
  42. package/es/tx/builder/entry/schema.d.ts +10 -10
  43. package/es/tx/builder/field-types/ct-version.d.ts +14 -0
  44. package/es/tx/builder/field-types/ct-version.js +14 -0
  45. package/es/tx/builder/field-types/ct-version.js.map +1 -1
  46. package/es/tx/builder/field-types/fee.d.ts +9 -7
  47. package/es/tx/builder/field-types/fee.js +75 -66
  48. package/es/tx/builder/field-types/fee.js.map +1 -1
  49. package/es/tx/builder/field-types/gas-limit.d.ts +5 -3
  50. package/es/tx/builder/field-types/gas-limit.js +25 -14
  51. package/es/tx/builder/field-types/gas-limit.js.map +1 -1
  52. package/es/tx/builder/field-types/gas-price.d.ts +6 -4
  53. package/es/tx/builder/field-types/gas-price.js +87 -21
  54. package/es/tx/builder/field-types/gas-price.js.map +1 -1
  55. package/es/tx/builder/field-types/interface.d.ts +20 -0
  56. package/es/tx/builder/field-types/interface.js +17 -1
  57. package/es/tx/builder/field-types/interface.js.map +1 -1
  58. package/es/tx/builder/field-types/name-fee.d.ts +3 -2
  59. package/es/tx/builder/field-types/name-fee.js +6 -0
  60. package/es/tx/builder/field-types/name-fee.js.map +1 -1
  61. package/es/tx/builder/field-types/pointers.d.ts +2 -1
  62. package/es/tx/builder/field-types/pointers.js +6 -2
  63. package/es/tx/builder/field-types/pointers.js.map +1 -1
  64. package/es/tx/builder/field-types/transaction.d.ts +4 -1
  65. package/es/tx/builder/field-types/transaction.js +18 -3
  66. package/es/tx/builder/field-types/transaction.js.map +1 -1
  67. package/es/tx/builder/field-types/ttl.d.ts +1 -2
  68. package/es/tx/builder/field-types/ttl.js +7 -4
  69. package/es/tx/builder/field-types/ttl.js.map +1 -1
  70. package/es/tx/builder/field-types/with-formatting.d.ts +1 -1
  71. package/es/tx/builder/field-types/with-formatting.js +1 -1
  72. package/es/tx/builder/field-types/with-formatting.js.map +1 -1
  73. package/es/tx/builder/index.d.ts +13 -0
  74. package/es/tx/builder/index.js +92 -5
  75. package/es/tx/builder/index.js.map +1 -1
  76. package/es/tx/builder/protocol-parameters.d.ts +123 -0
  77. package/es/tx/builder/protocol-parameters.js +519 -0
  78. package/es/tx/builder/protocol-parameters.js.map +1 -0
  79. package/es/tx/builder/schema.d.ts +179 -201
  80. package/es/tx/builder/schema.js +5 -1
  81. package/es/tx/builder/schema.js.map +1 -1
  82. package/es/tx/execution-cost.js +5 -5
  83. package/es/tx/execution-cost.js.map +1 -1
  84. package/es/tx/transaction-signer.js +2 -2
  85. package/es/tx/transaction-signer.js.map +1 -1
  86. package/es/tx/validator.js +4 -4
  87. package/es/tx/validator.js.map +1 -1
  88. package/es/utils/wrap-proxy.d.ts +10 -0
  89. package/es/utils/wrap-proxy.js +18 -0
  90. package/es/utils/wrap-proxy.js.map +1 -1
  91. package/package.json +3 -3
@@ -1,27 +1,38 @@
1
1
  import { IllegalArgumentError } from '../../../utils/errors.js';
2
- import { Tag, MAX_AUTH_FUN_GAS } from '../constants.js';
2
+ import { Tag } from '../constants.js';
3
+ import { defaultProtocolParameters, getGasLimitDivisor } from '../protocol-parameters.js';
3
4
  import shortUInt from './short-u-int.js';
4
5
  import { buildGas } from './fee.js';
5
- function calculateGasLimitMax(gasMax, rebuildTx, unpackTx, buildTx) {
6
- return gasMax - +buildGas(rebuildTx(gasMax), unpackTx, buildTx);
6
+ import { serializeAsIsParam } from './interface.js';
7
+ function calculateGasLimitMax(gasMax, rebuildTx, unpackTx, buildTx, protocolParameters) {
8
+ return gasMax - +buildGas(rebuildTx(gasMax), unpackTx, buildTx, protocolParameters);
7
9
  }
8
10
  export default {
9
11
  ...shortUInt,
10
- serialize(_value, {
11
- tag,
12
- rebuildTx,
13
- unpackTx,
14
- buildTx,
15
- _computingGasLimit
16
- }, {
17
- gasMax = 6e6
12
+ serialize(_value, params, {
13
+ gasMax,
14
+ protocolParameters = defaultProtocolParameters
18
15
  }) {
16
+ const {
17
+ tag,
18
+ rebuildTx,
19
+ unpackTx,
20
+ buildTx,
21
+ _computingGasLimit
22
+ } = params;
19
23
  if (_computingGasLimit != null) return shortUInt.serialize(_computingGasLimit);
20
- const gasLimitMax = tag === Tag.GaMetaTx ? MAX_AUTH_FUN_GAS : calculateGasLimitMax(gasMax, gasLimit => rebuildTx({
24
+ if (params[serializeAsIsParam] === true && _value != null) return shortUInt.serialize(_value);
25
+ const gasLimitMax = tag === Tag.GaMetaTx ? protocolParameters.maxAuthFunGas : calculateGasLimitMax(gasMax !== null && gasMax !== void 0 ? gasMax : protocolParameters.blockGasLimit, gasLimit => rebuildTx({
21
26
  _computingGasLimit: gasLimit,
22
27
  _canIncreaseFee: true
23
- }), unpackTx, buildTx);
24
- const value = _value !== null && _value !== void 0 ? _value : gasLimitMax;
28
+ }), unpackTx, buildTx, protocolParameters);
29
+ // node raises the ceiling above through the parameter this tag reads, so the value defaulted
30
+ // here is lowered by that raise — see `getGasLimitDivisor`. Only the default: a caller passing
31
+ // `gasLimit`, or capping it with `gasMax`, chose it itself — except on `GaMetaTx`, whose
32
+ // ceiling is `maxAuthFunGas` and never reads `gasMax`
33
+ const capped = gasMax != null && tag !== Tag.GaMetaTx;
34
+ const raise = capped ? 1 : getGasLimitDivisor(protocolParameters, tag);
35
+ const value = _value !== null && _value !== void 0 ? _value : raise > 1 ? Math.floor(gasLimitMax / raise) : gasLimitMax;
25
36
  if (value > gasLimitMax) {
26
37
  throw new IllegalArgumentError(`Gas limit ${value} must be less or equal to ${gasLimitMax}`);
27
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gas-limit.js","names":["IllegalArgumentError","Tag","MAX_AUTH_FUN_GAS","shortUInt","buildGas","calculateGasLimitMax","gasMax","rebuildTx","unpackTx","buildTx","serialize","_value","tag","_computingGasLimit","gasLimitMax","GaMetaTx","gasLimit","_canIncreaseFee","value"],"sources":["../../../../src/tx/builder/field-types/gas-limit.ts"],"sourcesContent":["import { IllegalArgumentError } from '../../../utils/errors.js';\nimport { Tag, MAX_AUTH_FUN_GAS } from '../constants.js';\nimport shortUInt from './short-u-int.js';\nimport { buildGas } from './fee.js';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';\n\nfunction calculateGasLimitMax(\n gasMax: number,\n rebuildTx: (value: number) => any,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n): number {\n return gasMax - +buildGas(rebuildTx(gasMax), unpackTx, buildTx);\n}\n\nexport default {\n ...shortUInt,\n\n serialize(\n _value: number | undefined,\n {\n tag,\n rebuildTx,\n unpackTx,\n buildTx,\n _computingGasLimit,\n }: {\n tag: Tag;\n rebuildTx: (params: any) => any;\n unpackTx: typeof unpackTxType;\n buildTx: typeof buildTxType;\n _computingGasLimit?: number;\n },\n { gasMax = 6e6 }: { gasMax?: number },\n ): Buffer {\n if (_computingGasLimit != null) return shortUInt.serialize(_computingGasLimit);\n\n const gasLimitMax =\n tag === Tag.GaMetaTx\n ? MAX_AUTH_FUN_GAS\n : calculateGasLimitMax(\n gasMax,\n (gasLimit) => rebuildTx({ _computingGasLimit: gasLimit, _canIncreaseFee: true }),\n unpackTx,\n buildTx,\n );\n const value = _value ?? gasLimitMax;\n if (value > gasLimitMax) {\n throw new IllegalArgumentError(`Gas limit ${value} must be less or equal to ${gasLimitMax}`);\n }\n return shortUInt.serialize(value);\n },\n};\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,0BAA0B;AAC/D,SAASC,GAAG,EAAEC,gBAAgB,QAAQ,iBAAiB;AACvD,OAAOC,SAAS,MAAM,kBAAkB;AACxC,SAASC,QAAQ,QAAQ,UAAU;AAGnC,SAASC,oBAAoBA,CAC3BC,MAAc,EACdC,SAAiC,EACjCC,QAA6B,EAC7BC,OAA2B,EACnB;EACR,OAAOH,MAAM,GAAG,CAACF,QAAQ,CAACG,SAAS,CAACD,MAAM,CAAC,EAAEE,QAAQ,EAAEC,OAAO,CAAC;AACjE;AAEA,eAAe;EACb,GAAGN,SAAS;EAEZO,SAASA,CACPC,MAA0B,EAC1B;IACEC,GAAG;IACHL,SAAS;IACTC,QAAQ;IACRC,OAAO;IACPI;EAOF,CAAC,EACD;IAAEP,MAAM,GAAG;EAAyB,CAAC,EAC7B;IACR,IAAIO,kBAAkB,IAAI,IAAI,EAAE,OAAOV,SAAS,CAACO,SAAS,CAACG,kBAAkB,CAAC;IAE9E,MAAMC,WAAW,GACfF,GAAG,KAAKX,GAAG,CAACc,QAAQ,GAChBb,gBAAgB,GAChBG,oBAAoB,CAClBC,MAAM,EACLU,QAAQ,IAAKT,SAAS,CAAC;MAAEM,kBAAkB,EAAEG,QAAQ;MAAEC,eAAe,EAAE;IAAK,CAAC,CAAC,EAChFT,QAAQ,EACRC,OACF,CAAC;IACP,MAAMS,KAAK,GAAGP,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIG,WAAW;IACnC,IAAII,KAAK,GAAGJ,WAAW,EAAE;MACvB,MAAM,IAAId,oBAAoB,CAAC,aAAakB,KAAK,6BAA6BJ,WAAW,EAAE,CAAC;IAC9F;IACA,OAAOX,SAAS,CAACO,SAAS,CAACQ,KAAK,CAAC;EACnC;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"gas-limit.js","names":["IllegalArgumentError","Tag","defaultProtocolParameters","getGasLimitDivisor","shortUInt","buildGas","serializeAsIsParam","calculateGasLimitMax","gasMax","rebuildTx","unpackTx","buildTx","protocolParameters","serialize","_value","params","tag","_computingGasLimit","gasLimitMax","GaMetaTx","maxAuthFunGas","blockGasLimit","gasLimit","_canIncreaseFee","capped","raise","value","Math","floor"],"sources":["../../../../src/tx/builder/field-types/gas-limit.ts"],"sourcesContent":["import { IllegalArgumentError } from '../../../utils/errors.js';\nimport { Tag } from '../constants.js';\nimport {\n defaultProtocolParameters,\n getGasLimitDivisor,\n ProtocolParameters,\n ProtocolParametersOption,\n} from '../protocol-parameters.js';\nimport shortUInt from './short-u-int.js';\nimport { buildGas } from './fee.js';\nimport { serializeAsIsParam, SerializeAsIsParams } from './interface.js';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';\n\nfunction calculateGasLimitMax(\n gasMax: number,\n rebuildTx: (value: number) => any,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n protocolParameters: ProtocolParameters,\n): number {\n return gasMax - +buildGas(rebuildTx(gasMax), unpackTx, buildTx, protocolParameters);\n}\n\nexport default {\n ...shortUInt,\n\n serialize(\n _value: number | undefined,\n params: {\n tag: Tag;\n rebuildTx: (params: any) => any;\n unpackTx: typeof unpackTxType;\n buildTx: typeof buildTxType;\n _computingGasLimit?: number;\n } & SerializeAsIsParams,\n {\n gasMax,\n protocolParameters = defaultProtocolParameters,\n }: { gasMax?: number } & ProtocolParametersOption,\n ): Buffer {\n const { tag, rebuildTx, unpackTx, buildTx, _computingGasLimit } = params;\n if (_computingGasLimit != null) return shortUInt.serialize(_computingGasLimit);\n if (params[serializeAsIsParam] === true && _value != null) return shortUInt.serialize(_value);\n\n const gasLimitMax =\n tag === Tag.GaMetaTx\n ? protocolParameters.maxAuthFunGas\n : calculateGasLimitMax(\n gasMax ?? protocolParameters.blockGasLimit,\n (gasLimit) => rebuildTx({ _computingGasLimit: gasLimit, _canIncreaseFee: true }),\n unpackTx,\n buildTx,\n protocolParameters,\n );\n // node raises the ceiling above through the parameter this tag reads, so the value defaulted\n // here is lowered by that raise — see `getGasLimitDivisor`. Only the default: a caller passing\n // `gasLimit`, or capping it with `gasMax`, chose it itself — except on `GaMetaTx`, whose\n // ceiling is `maxAuthFunGas` and never reads `gasMax`\n const capped = gasMax != null && tag !== Tag.GaMetaTx;\n const raise = capped ? 1 : getGasLimitDivisor(protocolParameters, tag);\n const value = _value ?? (raise > 1 ? Math.floor(gasLimitMax / raise) : gasLimitMax);\n if (value > gasLimitMax) {\n throw new IllegalArgumentError(`Gas limit ${value} must be less or equal to ${gasLimitMax}`);\n }\n return shortUInt.serialize(value);\n },\n};\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,0BAA0B;AAC/D,SA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IQ,GAAG,KAAKf,GAAG,CAACkB,QAAQ;IACrD,MAAMM,KAAK,GAAGD,MAAM,GAAG,CAAC,GAAGrB,kBAAkB,CAACS,kBAAkB,EAAEI,GAAG,CAAC;IACtE,MAAMU,KAAK,GAAGZ,MAAM,aAANA,MAAM,cAANA,MAAM,GAAKW,KAAK,GAAG,CAAC,GAAGE,IAAI,CAACC,KAAK,CAACV,WAAW,GAAGO,KAAK,CAAC,GAAGP,WAAY;IACnF,IAAIQ,KAAK,GAAGR,WAAW,EAAE;MACvB,MAAM,IAAIlB,oBAAoB,CAAC,aAAa0B,KAAK,6BAA6BR,WAAW,EAAE,CAAC;IAC9F;IACA,OAAOd,SAAS,CAACS,SAAS,CAACa,KAAK,CAAC;EACnC;AACF,CAAC","ignoreList":[]}
@@ -1,16 +1,18 @@
1
1
  import { Int } from '../constants.js';
2
+ import { ProtocolParameters, ProtocolParametersOption } from '../protocol-parameters.js';
3
+ import { SerializeAsIsParams } from './interface.js';
2
4
  import Node from '../../../Node.js';
3
5
  import { AE_AMOUNT_FORMATS } from '../../../utils/amount-formatter.js';
4
- export declare function getCachedIncreasedGasPrice(node: Node): Promise<bigint>;
6
+ export declare function getCachedIncreasedGasPrice(nodeOrProxy: Node, parameters?: ProtocolParameters): Promise<bigint>;
5
7
  declare const _default: {
6
- prepare(value: Int | undefined, params: {}, { onNode, denomination, }: {
8
+ prepare(value: Int | undefined, params: {}, { onNode, denomination, protocolParameters, }: {
7
9
  onNode?: Node;
8
10
  /**
9
11
  * @deprecated no replacement implemented yet
10
12
  */
11
13
  denomination?: AE_AMOUNT_FORMATS;
12
- }): Promise<Int | undefined>;
13
- serializeAettos(value?: string | undefined): string;
14
+ } & ProtocolParametersOption): Promise<Int | undefined>;
15
+ serializeAettos(value: string | undefined, params: SerializeAsIsParams, { protocolParameters }: ProtocolParametersOption): string;
14
16
  serialize(value: Int | undefined, params: {}, { denomination, ...options }: {
15
17
  denomination?: AE_AMOUNT_FORMATS;
16
18
  }): Buffer;
@@ -1,28 +1,88 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import coinAmount from './coin-amount.js';
3
3
  import { ArgumentError, IllegalArgumentError } from '../../../utils/errors.js';
4
- import { MIN_GAS_PRICE } from '../constants.js';
4
+ import { defaultProtocolParameters, getCachedProtocolParameters, getGasPriceDivisor } from '../protocol-parameters.js';
5
+ import { serializeAsIsParam } from './interface.js';
6
+ import { unwrapProxy } from '../../../utils/wrap-proxy.js';
5
7
  import { formatAmount } from '../../../utils/amount-formatter.js';
6
8
  const gasPriceCache = new WeakMap();
7
- export async function getCachedIncreasedGasPrice(node) {
8
- const cache = gasPriceCache.get(node);
9
- if (cache != null && cache.time > Date.now() - 20 * 1000) {
10
- return cache.gasPrice;
11
- }
12
- const {
13
- minGasPrice,
14
- utilization
15
- } = (await node.getRecentGasPrices())[0];
16
- let gasPrice = utilization < 70 ? 0n : BigInt(new BigNumber(minGasPrice.toString()).times(1.01).integerValue().toFixed());
17
- const maxSafeGasPrice = BigInt(MIN_GAS_PRICE) * 100000n; // max microblock fee is 600ae or 35usd
18
- if (gasPrice > maxSafeGasPrice) {
19
- console.warn(`Estimated gas price ${gasPrice} exceeds the maximum safe value for unknown reason.` + ` It will be limited to ${maxSafeGasPrice}.` + ' To overcome this restriction provide `gasPrice`/`fee` in options.');
20
- gasPrice = maxSafeGasPrice;
9
+
10
+ // the ceiling is based on the gas price of the SDK release and not on the one node reports, so
11
+ // that node can't raise its own limit — a node asking for more than the ceiling gets an
12
+ // underpriced transaction rather than the user an unbounded fee. Max microblock fee is 600ae or
13
+ // 35usd, counted with the gas of the SDK release — see `getGasPriceDivisor`
14
+ const maxSafeGasPrice = defaultProtocolParameters.minGasPrice * 100000n;
15
+
16
+ /**
17
+ * Gas price the recent demand of the network suggests, cached per node. Depends on the network
18
+ * only — the miner floor is applied by the caller, so that a caller providing its own
19
+ * {@link ProtocolParameters} doesn't put a gas price based on them into a cache others share.
20
+ *
21
+ * The request is cached rather than its result, and this body has no `await` before registering
22
+ * it: `buildTxAsync` prepares fields concurrently, so `fee.prepare` and `gasPrice.prepare` both
23
+ * ask before either could write a result, and sharing the promise keeps that one round trip.
24
+ */
25
+ function getCachedDemandGasPrice(node) {
26
+ const cached = gasPriceCache.get(node);
27
+ if (cached != null && cached.time > Date.now() - 20 * 1000) {
28
+ return cached;
21
29
  }
22
- gasPriceCache.set(node, {
30
+ const gasPrice = (async () => {
31
+ const {
32
+ minGasPrice,
33
+ utilization
34
+ } = (await node.getRecentGasPrices())[0];
35
+ const price = utilization < 70 ? 0n : BigInt(new BigNumber(minGasPrice.toString()).times(1.01).integerValue().toFixed());
36
+ if (price <= maxSafeGasPrice) return price;
37
+ console.warn(`Estimated gas price ${price} exceeds the maximum safe value for unknown reason.` + ` It will be limited to ${maxSafeGasPrice}.` + ' To overcome this restriction provide `gasPrice`/`fee` in options.');
38
+ return maxSafeGasPrice;
39
+ })();
40
+ const entry = {
23
41
  gasPrice,
24
42
  time: Date.now()
43
+ };
44
+ gasPriceCache.set(node, entry);
45
+ gasPrice.then(() => {
46
+ // the interval is about how long the value stays representative, and it starts when the
47
+ // value is known — stamping the request instead would shorten it by the round trip, and on
48
+ // a link slower than the interval every build would open a request of its own
49
+ entry.time = Date.now();
50
+ },
51
+ // a request that failed may succeed on the next transaction built, and a gas price that can't
52
+ // be requested fails the build — unlike `getCachedProtocolParameters`, which caches its
53
+ // failures because it falls back to the parameters of the SDK release and the build goes on
54
+ () => {
55
+ if (gasPriceCache.get(node) === entry) gasPriceCache.delete(node);
25
56
  });
57
+ return entry;
58
+ }
59
+ export async function getCachedIncreasedGasPrice(nodeOrProxy, parameters) {
60
+ const node = unwrapProxy(nodeOrProxy);
61
+ const demandEntry = getCachedDemandGasPrice(node);
62
+ // the caller may have been given the parameters to build against, requesting them from node
63
+ // would both waste a request and ignore the `minMinerGasPrice` it was asked to use
64
+ const [protocolParameters, demandGasPrice] = await Promise.all([parameters !== null && parameters !== void 0 ? parameters : getCachedProtocolParameters(node), demandEntry.gasPrice]);
65
+ let gasPrice = demandGasPrice;
66
+
67
+ // 0n means "the consensus minimum", it is below what the miner of this node accepts
68
+ const minerFloor = protocolParameters.minMinerGasPrice > protocolParameters.minGasPrice ? protocolParameters.minMinerGasPrice : 0n;
69
+ if (gasPrice < minerFloor) gasPrice = minerFloor;
70
+
71
+ // the ceiling goes down by the factor the parameters raise the fee gas by — see
72
+ // `getGasPriceDivisor`. Counted in thousandths so that a hard fork raising the gas a few percent
73
+ // lowers the ceiling a few percent, rather than halving it by rounding the factor up
74
+ const gasRaise = BigInt(Math.ceil(getGasPriceDivisor(protocolParameters) * 1000));
75
+ // this can't cut the miner floor applied above: `checkParametersNotExcessive` bounds the miner
76
+ // minimum times the fee gas raise by `maxRaiseFactor`, and the ceiling is 100 times
77
+ // `maxRaiseFactor` above the minimum gas price, so it stays 100 times above the floor
78
+ const ceiling = maxSafeGasPrice * 1000n / gasRaise;
79
+ if (gasPrice > ceiling) {
80
+ if (gasRaise > 1000n && demandEntry.ceilingWarned !== true) {
81
+ demandEntry.ceilingWarned = true;
82
+ console.warn(`Estimated gas price ${gasPrice} exceeds the maximum safe value ${ceiling} for the` + ' protocol parameters node reports. It will be limited to it, so the transaction may be' + ' not mined while the demand stays above it. To overcome this restriction provide' + ' `gasPrice`/`fee`, or `protocolParameters` in options.');
83
+ }
84
+ gasPrice = ceiling;
85
+ }
26
86
  return gasPrice;
27
87
  }
28
88
 
@@ -31,21 +91,27 @@ export default {
31
91
  ...coinAmount,
32
92
  async prepare(value, params, {
33
93
  onNode,
34
- denomination
94
+ denomination,
95
+ protocolParameters
35
96
  }) {
36
97
  if (value != null) return value;
37
98
  if (onNode == null) {
38
99
  throw new ArgumentError('onNode', 'provided (or provide `gasPrice` instead)', onNode);
39
100
  }
40
- const gasPrice = await getCachedIncreasedGasPrice(onNode);
101
+ const gasPrice = await getCachedIncreasedGasPrice(onNode, protocolParameters);
41
102
  if (gasPrice === 0n) return undefined;
42
103
  return formatAmount(gasPrice, {
43
104
  targetDenomination: denomination
44
105
  });
45
106
  },
46
- serializeAettos(value = MIN_GAS_PRICE.toString()) {
47
- if (+value < MIN_GAS_PRICE) {
48
- throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger than ${MIN_GAS_PRICE}`);
107
+ serializeAettos(value, params, {
108
+ protocolParameters = defaultProtocolParameters
109
+ }) {
110
+ const minGasPrice = protocolParameters.minGasPrice.toString();
111
+ if (value == null) return minGasPrice;
112
+ if (params[serializeAsIsParam] === true) return value;
113
+ if (new BigNumber(value).lt(minGasPrice)) {
114
+ throw new IllegalArgumentError(`Gas price ${value} must be bigger than ${minGasPrice}`);
49
115
  }
50
116
  return value;
51
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gas-price.js","names":["BigNumber","coinAmount","ArgumentError","IllegalArgumentError","MIN_GAS_PRICE","formatAmount","gasPriceCache","WeakMap","getCachedIncreasedGasPrice","node","cache","get","time","Date","now","gasPrice","minGasPrice","utilization","getRecentGasPrices","BigInt","toString","times","integerValue","toFixed","maxSafeGasPrice","console","warn","set","prepare","value","params","onNode","denomination","undefined","targetDenomination","serializeAettos"],"sources":["../../../../src/tx/builder/field-types/gas-price.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport coinAmount from './coin-amount.js';\nimport { ArgumentError, IllegalArgumentError } from '../../../utils/errors.js';\nimport { Int, MIN_GAS_PRICE } from '../constants.js';\nimport Node from '../../../Node.js';\nimport { AE_AMOUNT_FORMATS, formatAmount } from '../../../utils/amount-formatter.js';\n\nconst gasPriceCache: WeakMap<Node, { time: number; gasPrice: bigint }> = new WeakMap();\n\nexport async function getCachedIncreasedGasPrice(node: Node): Promise<bigint> {\n const cache = gasPriceCache.get(node);\n if (cache != null && cache.time > Date.now() - 20 * 1000) {\n return cache.gasPrice;\n }\n\n const { minGasPrice, utilization } = (await node.getRecentGasPrices())[0];\n let gasPrice =\n utilization < 70\n ? 0n\n : BigInt(new BigNumber(minGasPrice.toString()).times(1.01).integerValue().toFixed());\n\n const maxSafeGasPrice = BigInt(MIN_GAS_PRICE) * 100000n; // max microblock fee is 600ae or 35usd\n if (gasPrice > maxSafeGasPrice) {\n console.warn(\n `Estimated gas price ${gasPrice} exceeds the maximum safe value for unknown reason.` +\n ` It will be limited to ${maxSafeGasPrice}.` +\n ' To overcome this restriction provide `gasPrice`/`fee` in options.',\n );\n gasPrice = maxSafeGasPrice;\n }\n\n gasPriceCache.set(node, { gasPrice, time: Date.now() });\n return gasPrice;\n}\n\n// TODO: use withFormatting after using a single type for coins representation\nexport default {\n ...coinAmount,\n\n async prepare(\n value: Int | undefined,\n params: {},\n {\n onNode,\n denomination,\n }: {\n onNode?: Node;\n /**\n * @deprecated no replacement implemented yet\n */\n denomination?: AE_AMOUNT_FORMATS;\n },\n ): Promise<Int | undefined> {\n if (value != null) return value;\n if (onNode == null) {\n throw new ArgumentError('onNode', 'provided (or provide `gasPrice` instead)', onNode);\n }\n const gasPrice = await getCachedIncreasedGasPrice(onNode);\n if (gasPrice === 0n) return undefined;\n return formatAmount(gasPrice, { targetDenomination: denomination });\n },\n\n serializeAettos(value: string | undefined = MIN_GAS_PRICE.toString()): string {\n if (+value < MIN_GAS_PRICE) {\n throw new IllegalArgumentError(\n `Gas price ${value.toString()} must be bigger than ${MIN_GAS_PRICE}`,\n );\n }\n return value;\n },\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,cAAc;AACpC,OAAOC,UAAU,MAAM,kBAAkB;AACzC,SAASC,aAAa,EAAEC,oBAAoB,QAAQ,0BAA0B;AAC9E,SAAcC,aAAa,QAAQ,iBAAiB;AAEpD,SAA4BC,YAAY,QAAQ,oCAAoC;AAEpF,MAAMC,aAAgE,GAAG,IAAIC,OAAO,CAAC,CAAC;AAEtF,OAAO,eAAeC,0BAA0BA,CAACC,IAAU,EAAmB;EAC5E,MAAMC,KAAK,GAAGJ,aAAa,CAACK,GAAG,CAACF,IAAI,CAAC;EACrC,IAAIC,KAAK,IAAI,IAAI,IAAIA,KAAK,C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AAK,EAAE,EAAE,OAAOkB,SAAS;IACrC,OAAO5B,YAAY,CAACU,QAAQ,EAAE;MAAEmB,kBAAkB,EAAEF;IAAa,CAAC,CAAC;EACrE,CAAC;EAEDG,eAAeA,CAACN,KAAyB,GAAGzB,aAAa,CAACgB,QAAQ,CAAC,CAAC,EAAU;IAC5E,IAAI,CAACS,KAAK,GAAGzB,aAAa,EAAE;MAC1B,MAAM,IAAID,oBAAoB,CAC5B,aAAa0B,KAAK,CAACT,QAAQ,CAAC,CAAC,wBAAwBhB,aAAa,EACpE,CAAC;IACH;IACA,OAAOyB,KAAK;EACd;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"gas-price.js","names":["BigNumber","coinAmount","ArgumentError","IllegalArgumentError","defaultProtocolParameters","getCachedProtocolParameters","getGasPriceDivisor","serializeAsIsParam","unwrapProxy","formatAmount","gasPriceCache","WeakMap","maxSafeGasPrice","minGasPrice","getCachedDemandGasPrice","node","cached","get","time","Date","now","gasPrice","utilization","getRecentGasPrices","price","BigInt","toString","times","integerValue","toFixed","console","warn","entry","set","then","delete","getCachedIncreasedGasPrice","nodeOrProxy","parameters","demandEntry","protocolParameters","demandGasPrice","Promise","all","minerFloor","minMinerGasPrice","gasRaise","Math","ceil","ceiling","ceilingWarned","prepare","value","params","onNode","denomination","undefined","targetDenomination","serializeAettos","lt"],"sources":["../../../../src/tx/builder/field-types/gas-price.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport coinAmount from './coin-amount.js';\nimport { ArgumentError, IllegalArgumentError } from '../../../utils/errors.js';\nimport { Int } from '../constants.js';\nimport {\n defaultProtocolParameters,\n getCachedProtocolParameters,\n getGasPriceDivisor,\n ProtocolParameters,\n ProtocolParametersOption,\n} from '../protocol-parameters.js';\nimport { serializeAsIsParam, SerializeAsIsParams } from './interface.js';\nimport { unwrapProxy } from '../../../utils/wrap-proxy.js';\nimport Node from '../../../Node.js';\nimport { AE_AMOUNT_FORMATS, formatAmount } from '../../../utils/amount-formatter.js';\n\ninterface GasPriceCacheEntry {\n time: number;\n gasPrice: Promise<bigint>;\n /**\n * `getCachedIncreasedGasPrice` runs once per field that asks for a gas price — twice per contract\n * transaction, since `fee.prepare` asks as well — while the ceiling it may warn about is a\n * property of the network and of the parameters, not of the field. Warn once per refresh.\n */\n ceilingWarned?: boolean;\n}\nconst gasPriceCache: WeakMap<Node, GasPriceCacheEntry> = new WeakMap();\n\n// the ceiling is based on the gas price of the SDK release and not on the one node reports, so\n// that node can't raise its own limit — a node asking for more than the ceiling gets an\n// underpriced transaction rather than the user an unbounded fee. Max microblock fee is 600ae or\n// 35usd, counted with the gas of the SDK release — see `getGasPriceDivisor`\nconst maxSafeGasPrice = defaultProtocolParameters.minGasPrice * 100000n;\n\n/**\n * Gas price the recent demand of the network suggests, cached per node. Depends on the network\n * only — the miner floor is applied by the caller, so that a caller providing its own\n * {@link ProtocolParameters} doesn't put a gas price based on them into a cache others share.\n *\n * The request is cached rather than its result, and this body has no `await` before registering\n * it: `buildTxAsync` prepares fields concurrently, so `fee.prepare` and `gasPrice.prepare` both\n * ask before either could write a result, and sharing the promise keeps that one round trip.\n */\nfunction getCachedDemandGasPrice(node: Node): GasPriceCacheEntry {\n const cached = gasPriceCache.get(node);\n if (cached != null && cached.time > Date.now() - 20 * 1000) {\n return cached;\n }\n const gasPrice = (async () => {\n const { minGasPrice, utilization } = (await node.getRecentGasPrices())[0];\n const price =\n utilization < 70\n ? 0n\n : BigInt(new BigNumber(minGasPrice.toString()).times(1.01).integerValue().toFixed());\n if (price <= maxSafeGasPrice) return price;\n console.warn(\n `Estimated gas price ${price} exceeds the maximum safe value for unknown reason.` +\n ` It will be limited to ${maxSafeGasPrice}.` +\n ' To overcome this restriction provide `gasPrice`/`fee` in options.',\n );\n return maxSafeGasPrice;\n })();\n const entry: GasPriceCacheEntry = { gasPrice, time: Date.now() };\n gasPriceCache.set(node, entry);\n gasPrice.then(\n () => {\n // the interval is about how long the value stays representative, and it starts when the\n // value is known — stamping the request instead would shorten it by the round trip, and on\n // a link slower than the interval every build would open a request of its own\n entry.time = Date.now();\n },\n // a request that failed may succeed on the next transaction built, and a gas price that can't\n // be requested fails the build — unlike `getCachedProtocolParameters`, which caches its\n // failures because it falls back to the parameters of the SDK release and the build goes on\n () => {\n if (gasPriceCache.get(node) === entry) gasPriceCache.delete(node);\n },\n );\n return entry;\n}\n\nexport async function getCachedIncreasedGasPrice(\n nodeOrProxy: Node,\n parameters?: ProtocolParameters,\n): Promise<bigint> {\n const node = unwrapProxy(nodeOrProxy);\n const demandEntry = getCachedDemandGasPrice(node);\n // the caller may have been given the parameters to build against, requesting them from node\n // would both waste a request and ignore the `minMinerGasPrice` it was asked to use\n const [protocolParameters, demandGasPrice] = await Promise.all([\n parameters ?? getCachedProtocolParameters(node),\n demandEntry.gasPrice,\n ]);\n let gasPrice = demandGasPrice;\n\n // 0n means \"the consensus minimum\", it is below what the miner of this node accepts\n const minerFloor =\n protocolParameters.minMinerGasPrice > protocolParameters.minGasPrice\n ? protocolParameters.minMinerGasPrice\n : 0n;\n if (gasPrice < minerFloor) gasPrice = minerFloor;\n\n // the ceiling goes down by the factor the parameters raise the fee gas by — see\n // `getGasPriceDivisor`. Counted in thousandths so that a hard fork raising the gas a few percent\n // lowers the ceiling a few percent, rather than halving it by rounding the factor up\n const gasRaise = BigInt(Math.ceil(getGasPriceDivisor(protocolParameters) * 1000));\n // this can't cut the miner floor applied above: `checkParametersNotExcessive` bounds the miner\n // minimum times the fee gas raise by `maxRaiseFactor`, and the ceiling is 100 times\n // `maxRaiseFactor` above the minimum gas price, so it stays 100 times above the floor\n const ceiling = (maxSafeGasPrice * 1000n) / gasRaise;\n if (gasPrice > ceiling) {\n if (gasRaise > 1000n && demandEntry.ceilingWarned !== true) {\n demandEntry.ceilingWarned = true;\n console.warn(\n `Estimated gas price ${gasPrice} exceeds the maximum safe value ${ceiling} for the` +\n ' protocol parameters node reports. It will be limited to it, so the transaction may be' +\n ' not mined while the demand stays above it. To overcome this restriction provide' +\n ' `gasPrice`/`fee`, or `protocolParameters` in options.',\n );\n }\n gasPrice = ceiling;\n }\n\n return gasPrice;\n}\n\n// TODO: use withFormatting after using a single type for coins representation\nexport default {\n ...coinAmount,\n\n async prepare(\n value: Int | undefined,\n params: {},\n {\n onNode,\n denomination,\n protocolParameters,\n }: {\n onNode?: Node;\n /**\n * @deprecated no replacement implemented yet\n */\n denomination?: AE_AMOUNT_FORMATS;\n } & ProtocolParametersOption,\n ): Promise<Int | undefined> {\n if (value != null) return value;\n if (onNode == null) {\n throw new ArgumentError('onNode', 'provided (or provide `gasPrice` instead)', onNode);\n }\n const gasPrice = await getCachedIncreasedGasPrice(onNode, protocolParameters);\n if (gasPrice === 0n) return undefined;\n return formatAmount(gasPrice, { targetDenomination: denomination });\n },\n\n serializeAettos(\n value: string | undefined,\n params: SerializeAsIsParams,\n { protocolParameters = defaultProtocolParameters }: ProtocolParametersOption,\n ): string {\n const minGasPrice = protocolParameters.minGasPrice.toString();\n if (value == null) return minGasPrice;\n if (params[serializeAsIsParam] === true) return value;\n if (new BigNumber(value).lt(minGasPrice)) {\n throw new IllegalArgumentError(`Gas price ${value} must be bigger than ${minGasPrice}`);\n }\n return value;\n },\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,cAAc;AACpC,OAAOC,UAAU,MAAM,kBAAkB;AACzC,SAASC,aAAa,EAAEC,oBAAoB,QAAQ,0BAA0B;AAE9E,SACEC,yBAAyB,EACzBC,2BAA2B,EAC3BC,kBAAkB,QAGb,2BAA2B;AAClC,SAASC,kBAAkB,QAA6B,gBAAgB;AACxE,SAASC,WAAW,QAAQ,8BAA8B;AAE1D,SAA4BC,YAAY,QAAQ,oCAAoC;AAYpF,MAAMC,aAAgD,GAAG,IAAIC,OAAO,CAAC,CAAC;;AAEtE;AACA;AACA;AACA;AACA,MAAMC,eAAe,GAAGR,yBAAyB,CAACS,WAAW,GAAG,OAAO;;AAEvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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A,eAAe;EACb,GAAGpB,UAAU;EAEb,MAAMkD,OAAOA,CACXC,KAAsB,EACtBC,MAAU,EACV;IACEC,MAAM;IACNC,YAAY;IACZf;EAOyB,CAAC,EACF;IAC1B,IAAIY,KAAK,IAAI,IAAI,EAAE,OAAOA,KAAK;IAC/B,IAAIE,MAAM,IAAI,IAAI,EAAE;MAClB,MAAM,IAAIpD,aAAa,CAAC,QAAQ,EAAE,0CAA0C,EAAEoD,MAAM,CAAC;IACvF;IACA,MAAMjC,QAAQ,GAAG,MAAMe,0BAA0B,CAACkB,MAAM,EAAEd,kBAAkB,CAAC;IAC7E,IAAInB,QAAQ,KAAK,EAAE,EAAE,OAAOmC,SAAS;IACrC,OAAO/C,YAAY,CAACY,QAAQ,EAAE;MAAEoC,kBAAkB,EAAEF;IAAa,CAAC,CAAC;EACrE,CAAC;EAEDG,eAAeA,CACbN,KAAyB,EACzBC,MAA2B,EAC3B;IAAEb,kBAAkB,GAAGpC;EAAoD,CAAC,EACpE;IACR,MAAMS,WAAW,GAAG2B,kBAAkB,CAAC3B,WAAW,CAACa,QAAQ,CAAC,CAAC;IAC7D,IAAI0B,KAAK,IAAI,IAAI,EAAE,OAAOvC,WAAW;IACrC,IAAIwC,MAAM,CAAC9C,kBAAkB,CAAC,KAAK,IAAI,EAAE,OAAO6C,KAAK;IACrD,IAAI,IAAIpD,SAAS,CAACoD,KAAK,CAAC,CAACO,EAAE,CAAC9C,WAAW,CAAC,EAAE;MACxC,MAAM,IAAIV,oBAAoB,CAAC,aAAaiD,KAAK,wBAAwBvC,WAAW,EAAE,CAAC;IACzF;IACA,OAAOuC,KAAK;EACd;AACF,CAAC","ignoreList":[]}
@@ -1,7 +1,27 @@
1
1
  export type BinaryData = Buffer | Buffer[] | Buffer[][] | Array<[Buffer, Array<[Buffer, Buffer[]]>]>;
2
+ /**
3
+ * Set in the params of a transaction that is re-serialized rather than built — see
4
+ * `rebuildUnpackedTx`. Fields that check their value against the protocol parameters serialize it
5
+ * as it is instead: the transaction already exists, its values may belong to other parameters than
6
+ * the ones this build runs against, and re-checking them would reject a valid transaction that is
7
+ * serialized verbatim anyway.
8
+ *
9
+ * A symbol so that it can't come out of a `JSON.parse`. It is not a trust boundary either way —
10
+ * `protocolParameters` decides what those same checks compare against and is a plain string key,
11
+ * as are `fee`, `gasPrice`, and `gasLimit`.
12
+ */
13
+ export declare const serializeAsIsParam: unique symbol;
14
+ export interface SerializeAsIsParams {
15
+ [serializeAsIsParam]?: boolean;
16
+ }
2
17
  export interface Field {
3
18
  serialize: (value: any, options: any, parameters: any) => BinaryData;
4
19
  prepare?: (value: any, options: any, parameters: any) => Promise<any>;
20
+ /**
21
+ * Set by the fields holding a transaction that may still have to be built — and priced — so that
22
+ * `buildTxAsync` can tell them from the ones holding a plain value. See `genTransactionField`.
23
+ */
24
+ nestedTransaction?: boolean;
5
25
  deserialize: (value: BinaryData, options: any) => any;
6
26
  recursiveType?: boolean;
7
27
  }
@@ -1,2 +1,18 @@
1
- export {};
1
+ // TODO: give `Field` an optional `validate` that `buildTx` runs before `serialize` and
2
+ // `rebuildUnpackedTx` skips, so that a field can't check a value without being asked to. Needs
3
+ // `packRecord` to stop passing params and options through the same channel first — a string key
4
+ // in that channel would be forgeable from `JSON.parse`, which is why this is a symbol — and
5
+ // `fee` to stop sharing its fixpoint between the default and the check [breaking change]
6
+ /**
7
+ * Set in the params of a transaction that is re-serialized rather than built — see
8
+ * `rebuildUnpackedTx`. Fields that check their value against the protocol parameters serialize it
9
+ * as it is instead: the transaction already exists, its values may belong to other parameters than
10
+ * the ones this build runs against, and re-checking them would reject a valid transaction that is
11
+ * serialized verbatim anyway.
12
+ *
13
+ * A symbol so that it can't come out of a `JSON.parse`. It is not a trust boundary either way —
14
+ * `protocolParameters` decides what those same checks compare against and is a plain string key,
15
+ * as are `fee`, `gasPrice`, and `gasLimit`.
16
+ */
17
+ export const serializeAsIsParam = Symbol('serializeAsIs');
2
18
  //# sourceMappingURL=interface.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.js","names":[],"sources":["../../../../src/tx/builder/field-types/interface.ts"],"sourcesContent":["export type BinaryData =\n | Buffer\n | Buffer[]\n | Buffer[][]\n | Array<[Buffer, Array<[Buffer, Buffer[]]>]>;\n\nexport interface Field {\n serialize: (value: any, options: any, parameters: any) => BinaryData;\n prepare?: (value: any, options: any, parameters: any) => Promise<any>;\n deserialize: (value: BinaryData, options: any) => any;\n recursiveType?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"interface.js","names":["serializeAsIsParam","Symbol"],"sources":["../../../../src/tx/builder/field-types/interface.ts"],"sourcesContent":["export type BinaryData =\n | Buffer\n | Buffer[]\n | Buffer[][]\n | Array<[Buffer, Array<[Buffer, Buffer[]]>]>;\n\n// TODO: give `Field` an optional `validate` that `buildTx` runs before `serialize` and\n// `rebuildUnpackedTx` skips, so that a field can't check a value without being asked to. Needs\n// `packRecord` to stop passing params and options through the same channel first — a string key\n// in that channel would be forgeable from `JSON.parse`, which is why this is a symbol — and\n// `fee` to stop sharing its fixpoint between the default and the check [breaking change]\n/**\n * Set in the params of a transaction that is re-serialized rather than built — see\n * `rebuildUnpackedTx`. Fields that check their value against the protocol parameters serialize it\n * as it is instead: the transaction already exists, its values may belong to other parameters than\n * the ones this build runs against, and re-checking them would reject a valid transaction that is\n * serialized verbatim anyway.\n *\n * A symbol so that it can't come out of a `JSON.parse`. It is not a trust boundary either way —\n * `protocolParameters` decides what those same checks compare against and is a plain string key,\n * as are `fee`, `gasPrice`, and `gasLimit`.\n */\nexport const serializeAsIsParam: unique symbol = Symbol('serializeAsIs');\n\nexport interface SerializeAsIsParams {\n [serializeAsIsParam]?: boolean;\n}\n\nexport interface Field {\n serialize: (value: any, options: any, parameters: any) => BinaryData;\n prepare?: (value: any, options: any, parameters: any) => Promise<any>;\n /**\n * Set by the fields holding a transaction that may still have to be built — and priced — so that\n * `buildTxAsync` can tell them from the ones holding a plain value. See `genTransactionField`.\n */\n nestedTransaction?: boolean;\n deserialize: (value: BinaryData, options: any) => any;\n recursiveType?: boolean;\n}\n"],"mappings":"AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,kBAAiC,GAAGC,MAAM,CAAC,eAAe,CAAC","ignoreList":[]}
@@ -1,9 +1,10 @@
1
1
  import coinAmount from './coin-amount.js';
2
+ import { SerializeAsIsParams } from './interface.js';
2
3
  import { AensName, Int } from '../constants.js';
3
4
  declare const _default: {
4
5
  serializeAettos(_value: string | undefined, txFields: {
5
6
  name: AensName;
6
- }): string;
7
+ } & SerializeAsIsParams): string;
7
8
  /**
8
9
  * @param value - AENS name fee
9
10
  * @param txFields - Transaction fields
@@ -11,7 +12,7 @@ declare const _default: {
11
12
  */
12
13
  serialize(value: Int | undefined, txFields: {
13
14
  name: AensName;
14
- } & Parameters<(typeof coinAmount)["serialize"]>[1], parameters: Parameters<(typeof coinAmount)["serialize"]>[2]): Buffer;
15
+ } & SerializeAsIsParams & Parameters<(typeof coinAmount)["serialize"]>[1], parameters: Parameters<(typeof coinAmount)["serialize"]>[2]): Buffer;
15
16
  deserialize(value: Buffer): string;
16
17
  };
17
18
  export default _default;
@@ -2,9 +2,15 @@ import BigNumber from 'bignumber.js';
2
2
  import { getMinimumNameFee } from '../helpers.js';
3
3
  import { InsufficientNameFeeError } from '../../../utils/errors.js';
4
4
  import coinAmount from './coin-amount.js';
5
+ import { serializeAsIsParam } from './interface.js';
5
6
  export default {
6
7
  ...coinAmount,
7
8
  serializeAettos(_value, txFields) {
9
+ // SDK-release table, node reports it as `nameClaimFees` (all zeroes on a protocol that doesn't
10
+ // enforce it) — skipped on re-serialization, see `serializeAsIsParam`
11
+ if (txFields[serializeAsIsParam] === true && _value != null) {
12
+ return new BigNumber(_value).toFixed();
13
+ }
8
14
  const minNameFee = getMinimumNameFee(txFields.name);
9
15
  const value = new BigNumber(_value !== null && _value !== void 0 ? _value : minNameFee);
10
16
  if (minNameFee.gt(value)) throw new InsufficientNameFeeError(value, minNameFee);
@@ -1 +1 @@
1
- {"version":3,"file":"name-fee.js","names":["BigNumber","getMinimumNameFee","InsufficientNameFeeError","coinAmount","serializeAettos","_value","txFields","minNameFee","name","value","gt","toFixed","serialize","parameters","call"],"sources":["../../../../src/tx/builder/field-types/name-fee.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { getMinimumNameFee } from '../helpers.js';\nimport { InsufficientNameFeeError } from '../../../utils/errors.js';\nimport coinAmount from './coin-amount.js';\nimport { AensName, Int } from '../constants.js';\n\nexport default {\n ...coinAmount,\n\n serializeAettos(_value: string | undefined, txFields: { name: AensName }): string {\n const minNameFee = getMinimumNameFee(txFields.name);\n const value = new BigNumber(_value ?? minNameFee);\n if (minNameFee.gt(value)) throw new InsufficientNameFeeError(value, minNameFee);\n return value.toFixed();\n },\n\n /**\n * @param value - AENS name fee\n * @param txFields - Transaction fields\n * @param txFields.name - AENS Name in transaction\n */\n serialize(\n value: Int | undefined,\n txFields: { name: AensName } & Parameters<(typeof coinAmount)['serialize']>[1],\n parameters: Parameters<(typeof coinAmount)['serialize']>[2],\n ): Buffer {\n return coinAmount.serialize.call(this, value, txFields, parameters);\n },\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,cAAc;AACpC,SAASC,iBAAiB,QAAQ,eAAe;AACjD,SAASC,wBAAwB,QAAQ,0BAA0B;AACnE,OAAOC,UAAU,MAAM,kBAAkB;AAGzC,eAAe;EACb,GAAGA,UAAU;EAEbC,eAAeA,CAACC,MAA0B,EAAEC,QAA4B,EAAU;IAChF,MAAMC,UAAU,GAAGN,iBAAiB,CAACK,QAAQ,CAACE,IAAI,CAAC;IACnD,MAAMC,KAAK,GAAG,IAAIT,SAAS,CAACK,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIE,UAAU,CAAC;IACjD,IAAIA,UAAU,CAACG,EAAE,CAACD,KAAK,CAAC,EAAE,MAAM,IAAIP,wBAAwB,CAACO,KAAK,EAAEF,UAAU,CAAC;IAC/E,OAAOE,KAAK,CAACE,OAAO,CAAC,CAAC;EACxB,CAAC;EAED;AACF;AACA;AACA;AACA;EACEC,SAASA,CACPH,KAAsB,EACtBH,QAA8E,EAC9EO,UAA2D,EACnD;IACR,OAAOV,UAAU,CAACS,SAAS,CAACE,IAAI,CAAC,IAAI,EAAEL,KAAK,EAAEH,QAAQ,EAAEO,UAAU,CAAC;EACrE;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"name-fee.js","names":["BigNumber","getMinimumNameFee","InsufficientNameFeeError","coinAmount","serializeAsIsParam","serializeAettos","_value","txFields","toFixed","minNameFee","name","value","gt","serialize","parameters","call"],"sources":["../../../../src/tx/builder/field-types/name-fee.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { getMinimumNameFee } from '../helpers.js';\nimport { InsufficientNameFeeError } from '../../../utils/errors.js';\nimport coinAmount from './coin-amount.js';\nimport { serializeAsIsParam, SerializeAsIsParams } from './interface.js';\nimport { AensName, Int } from '../constants.js';\n\nexport default {\n ...coinAmount,\n\n serializeAettos(\n _value: string | undefined,\n txFields: { name: AensName } & SerializeAsIsParams,\n ): string {\n // SDK-release table, node reports it as `nameClaimFees` (all zeroes on a protocol that doesn't\n // enforce it) — skipped on re-serialization, see `serializeAsIsParam`\n if (txFields[serializeAsIsParam] === true && _value != null) {\n return new BigNumber(_value).toFixed();\n }\n const minNameFee = getMinimumNameFee(txFields.name);\n const value = new BigNumber(_value ?? minNameFee);\n if (minNameFee.gt(value)) throw new InsufficientNameFeeError(value, minNameFee);\n return value.toFixed();\n },\n\n /**\n * @param value - AENS name fee\n * @param txFields - Transaction fields\n * @param txFields.name - AENS Name in transaction\n */\n serialize(\n value: Int | undefined,\n txFields: { name: AensName } & SerializeAsIsParams &\n Parameters<(typeof coinAmount)['serialize']>[1],\n parameters: Parameters<(typeof coinAmount)['serialize']>[2],\n ): Buffer {\n return coinAmount.serialize.call(this, value, txFields, parameters);\n },\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,cAAc;AACpC,SAASC,iBAAiB,QAAQ,eAAe;AACjD,SAASC,wBAAwB,QAAQ,0BAA0B;AACnE,OAAOC,UAAU,MAAM,kBAAkB;AACzC,SAASC,kBAAkB,QAA6B,gBAAgB;AAGxE,eAAe;EACb,GAAGD,UAAU;EAEbE,eAAeA,CACbC,MAA0B,EAC1BC,QAAkD,EAC1C;IACR;IACA;IACA,IAAIA,QAAQ,CAACH,kBAAkB,CAAC,KAAK,IAAI,IAAIE,MAAM,IAAI,IAAI,EAAE;MAC3D,OAAO,IAAIN,SAAS,CAACM,MAAM,CAAC,CAACE,OAAO,CAAC,CAAC;IACxC;IACA,MAAMC,UAAU,GAAGR,iBAAiB,CAACM,QAAQ,CAACG,IAAI,CAAC;IACnD,MAAMC,KAAK,GAAG,IAAIX,SAAS,CAACM,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIG,UAAU,CAAC;IACjD,IAAIA,UAAU,CAACG,EAAE,CAACD,KAAK,CAAC,EAAE,MAAM,IAAIT,wBAAwB,CAACS,KAAK,EAAEF,UAAU,CAAC;IAC/E,OAAOE,KAAK,CAACH,OAAO,CAAC,CAAC;EACxB,CAAC;EAED;AACF;AACA;AACA;AACA;EACEK,SAASA,CACPF,KAAsB,EACtBJ,QACiD,EACjDO,UAA2D,EACnD;IACR,OAAOX,UAAU,CAACU,SAAS,CAACE,IAAI,CAAC,IAAI,EAAEJ,KAAK,EAAEJ,QAAQ,EAAEO,UAAU,CAAC;EACrE;AACF,CAAC","ignoreList":[]}
@@ -1,6 +1,7 @@
1
1
  import { NamePointer as NamePointerString } from '../../../apis/node/index.js';
2
2
  import { Encoded, Encoding } from '../../../utils/encoder.js';
3
3
  import { AddressEncodings } from './address.js';
4
+ import { SerializeAsIsParams } from './interface.js';
4
5
  type NamePointer = NamePointerString & {
5
6
  id: Encoded.Generic<AddressEncodings>;
6
7
  };
@@ -8,7 +9,7 @@ type NamePointerRaw = NamePointerString & {
8
9
  id: Encoded.Generic<AddressEncodings | Encoding.Bytearray>;
9
10
  };
10
11
  declare const _default: <AllowRaw extends boolean>(allowRaw: AllowRaw) => {
11
- serialize: (pointers: Array<AllowRaw extends true ? NamePointerRaw : NamePointer>) => Buffer[][];
12
+ serialize: (pointers: Array<AllowRaw extends true ? NamePointerRaw : NamePointer>, params: SerializeAsIsParams) => Buffer[][];
12
13
  deserialize: (pointers: Array<[key: Buffer, id: Buffer]>) => Array<AllowRaw extends true ? NamePointerRaw : NamePointer>;
13
14
  };
14
15
  export default _default;
@@ -4,6 +4,7 @@ import { Encoding, decode, encode } from '../../../utils/encoder.js';
4
4
  import { isEncoded } from '../../../utils/crypto.js';
5
5
  import { IllegalArgumentError, DecodeError, ArgumentError } from '../../../utils/errors.js';
6
6
  import address, { idTagToEncoding } from './address.js';
7
+ import { serializeAsIsParam } from './interface.js';
7
8
  const ID_TAG = _Buffer.from([1]);
8
9
  const DATA_TAG = _Buffer.from([2]);
9
10
  const DATA_LENGTH_MAX = 1024;
@@ -16,10 +17,13 @@ export default allowRaw => ({
16
17
  * Helper function to build pointers for name update TX
17
18
  * @param pointers - Array of pointers
18
19
  * `([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])`
20
+ * @param params - Transaction params
19
21
  * @returns Serialized pointers array
20
22
  */
21
- serialize(pointers) {
22
- if (pointers.length > 32) {
23
+ serialize(pointers, params) {
24
+ // SDK-release limit, node reports it as `namePointersMaxCount` (omitted on a protocol that
25
+ // imposes no limit) — skipped on re-serialization, see `serializeAsIsParam`
26
+ if (params[serializeAsIsParam] !== true && pointers.length > 32) {
23
27
  throw new IllegalArgumentError(`Expected 32 pointers or less, got ${pointers.length} instead`);
24
28
  }
25
29
  return pointers.map(({
@@ -1 +1 @@
1
- {"version":3,"file":"pointers.js","names":["toBytes","Encoding","decode","encode","isEncoded","IllegalArgumentError","DecodeError","ArgumentError","address","idTagToEncoding","ID_TAG","_Buffer","from","DATA_TAG","DATA_LENGTH_MAX","addressAny","allowRaw","serialize","pointers","length","map","key","id","payload","Bytearray","data","concat","deserialize","bKey","bId","toString","tag","subarray","equals"],"sources":["../../../../src/tx/builder/field-types/pointers.ts"],"sourcesContent":["import { NamePointer as NamePointerString } from '../../../apis/node/index.js';\nimport { toBytes } from '../../../utils/bytes.js';\nimport { Encoded, Encoding, decode, encode } from '../../../utils/encoder.js';\nimport { isEncoded } from '../../../utils/crypto.js';\nimport { IllegalArgumentError, DecodeError, ArgumentError } from '../../../utils/errors.js';\nimport address, { AddressEncodings, idTagToEncoding } from './address.js';\n\nconst ID_TAG = Buffer.from([1]);\nconst DATA_TAG = Buffer.from([2]);\nconst DATA_LENGTH_MAX = 1024;\nconst addressAny = address(...idTagToEncoding);\n\n// TODO: remove after fixing node types\ntype NamePointer = NamePointerString & {\n id: Encoded.Generic<AddressEncodings>;\n};\ntype NamePointerRaw = NamePointerString & {\n id: Encoded.Generic<AddressEncodings | Encoding.Bytearray>;\n};\n\nexport default <AllowRaw extends boolean>(\n allowRaw: AllowRaw,\n): {\n serialize: (pointers: Array<AllowRaw extends true ? NamePointerRaw : NamePointer>) => Buffer[][];\n deserialize: (\n pointers: Array<[key: Buffer, id: Buffer]>,\n ) => Array<AllowRaw extends true ? NamePointerRaw : NamePointer>;\n} => ({\n /**\n * Helper function to build pointers for name update TX\n * @param pointers - Array of pointers\n * `([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])`\n * @returns Serialized pointers array\n */\n serialize(pointers) {\n if (pointers.length > 32) {\n throw new IllegalArgumentError(\n `Expected 32 pointers or less, got ${pointers.length} instead`,\n );\n }\n return pointers.map(({ key, id }) => {\n let payload;\n if (isEncoded(id, ...idTagToEncoding)) {\n payload = [...(allowRaw ? [ID_TAG] : []), addressAny.serialize(id)];\n }\n if (isEncoded(id, Encoding.Bytearray)) {\n const data = decode(id);\n if (data.length > DATA_LENGTH_MAX) {\n throw new ArgumentError(\n 'Raw pointer',\n `shorter than ${DATA_LENGTH_MAX + 1} bytes`,\n `${data.length} bytes`,\n );\n }\n payload = [DATA_TAG, data];\n }\n if (payload == null) throw new DecodeError(`Unknown AENS pointer value: ${id}`);\n return [toBytes(key), Buffer.concat(payload)];\n });\n },\n\n /**\n * Helper function to read pointers from name update TX\n * @param pointers - Array of pointers\n * @returns Deserialize pointer array\n */\n deserialize(pointers) {\n return pointers.map(([bKey, bId]) => {\n if (!allowRaw) return { key: bKey.toString(), id: addressAny.deserialize(bId) };\n const tag = bId.subarray(0, 1);\n const payload = bId.subarray(1);\n let id;\n if (tag.equals(ID_TAG)) id = addressAny.deserialize(payload);\n // TS can't figure out the real type depending on allowRaw\n if (tag.equals(DATA_TAG)) id = encode(payload, Encoding.Bytearray) as Encoded.AccountAddress;\n if (id == null) throw new DecodeError(`Unknown AENS pointer tag: ${tag}`);\n return { key: bKey.toString(), id };\n });\n },\n});\n"],"mappings":";AACA,SAASA,OAAO,QAAQ,yBAAyB;AACjD,SAAkBC,QAAQ,EAAEC,MAAM,EAAEC,MAAM,QAAQ,2BAA2B;AAC7E,SAASC,SAAS,QAAQ,0BAA0B;AACpD,SAASC,oBAAoB,EAAEC,WAAW,EAAEC,aAAa,QAAQ,0BAA0B;AAC3F,OAAOC,OAAO,IAAsBC,eAAe,QAAQ,cAAc;AAEzE,MAAMC,MAAM,GAAGC,OAAA,CAAOC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,MAAMC,QAAQ,GAAGF,OAAA,CAAOC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACjC,MAAME,eAAe,GAAG,IAAI;AAC5B,MAAMC,UAAU,GAAGP,OAAO,CAAC,GAAGC,eAAe,CAAC;;AAE9C;;AAQA,eACEO,QAAkB,KAMd;EACJ;AACF;AACA;AACA;AACA;AACA;EACEC,SAASA,CAACC,QAAQ,EAAE;IAClB,IAAIA,QAAQ,CAACC,MAAM,GAAG,EAAE,EAAE;MACxB,MAAM,IAAId,oBAAoB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AAME,GAAG,GAAGF,GAAG,CAACG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;MAC9B,MAAMT,OAAO,GAAGM,GAAG,CAACG,QAAQ,CAAC,CAAC,CAAC;MAC/B,IAAIV,EAAE;MACN,IAAIS,GAAG,CAACE,MAAM,CAACvB,MAAM,CAAC,EAAEY,EAAE,GAAGP,UAAU,CAACY,WAAW,CAACJ,OAAO,CAAC;MAC5D;MACA,IAAIQ,GAAG,CAACE,MAAM,CAACpB,QAAQ,CAAC,EAAES,EAAE,GAAGnB,MAAM,CAACoB,OAAO,EAAEtB,QAAQ,CAACuB,SAAS,CAA2B;MAC5F,IAAIF,EAAE,IAAI,IAAI,EAAE,MAAM,IAAIhB,WAAW,CAAC,6BAA6ByB,GAAG,EAAE,CAAC;MACzE,OAAO;QAAEV,GAAG,EAAEO,IAAI,CAACE,QAAQ,CAAC,CAAC;QAAER;MAAG,CAAC;IACrC,CAAC,CAAC;EACJ;AACF,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"pointers.js","names":["toBytes","Encoding","decode","encode","isEncoded","IllegalArgumentError","DecodeError","ArgumentError","address","idTagToEncoding","serializeAsIsParam","ID_TAG","_Buffer","from","DATA_TAG","DATA_LENGTH_MAX","addressAny","allowRaw","serialize","pointers","params","length","map","key","id","payload","Bytearray","data","concat","deserialize","bKey","bId","toString","tag","subarray","equals"],"sources":["../../../../src/tx/builder/field-types/pointers.ts"],"sourcesContent":["import { NamePointer as NamePointerString } from '../../../apis/node/index.js';\nimport { toBytes } from '../../../utils/bytes.js';\nimport { Encoded, Encoding, decode, encode } from '../../../utils/encoder.js';\nimport { isEncoded } from '../../../utils/crypto.js';\nimport { IllegalArgumentError, DecodeError, ArgumentError } from '../../../utils/errors.js';\nimport address, { AddressEncodings, idTagToEncoding } from './address.js';\nimport { serializeAsIsParam, SerializeAsIsParams } from './interface.js';\n\nconst ID_TAG = Buffer.from([1]);\nconst DATA_TAG = Buffer.from([2]);\nconst DATA_LENGTH_MAX = 1024;\nconst addressAny = address(...idTagToEncoding);\n\n// TODO: remove after fixing node types\ntype NamePointer = NamePointerString & {\n id: Encoded.Generic<AddressEncodings>;\n};\ntype NamePointerRaw = NamePointerString & {\n id: Encoded.Generic<AddressEncodings | Encoding.Bytearray>;\n};\n\nexport default <AllowRaw extends boolean>(\n allowRaw: AllowRaw,\n): {\n serialize: (\n pointers: Array<AllowRaw extends true ? NamePointerRaw : NamePointer>,\n params: SerializeAsIsParams,\n ) => Buffer[][];\n deserialize: (\n pointers: Array<[key: Buffer, id: Buffer]>,\n ) => Array<AllowRaw extends true ? NamePointerRaw : NamePointer>;\n} => ({\n /**\n * Helper function to build pointers for name update TX\n * @param pointers - Array of pointers\n * `([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])`\n * @param params - Transaction params\n * @returns Serialized pointers array\n */\n serialize(pointers, params) {\n // SDK-release limit, node reports it as `namePointersMaxCount` (omitted on a protocol that\n // imposes no limit) — skipped on re-serialization, see `serializeAsIsParam`\n if (params[serializeAsIsParam] !== true && pointers.length > 32) {\n throw new IllegalArgumentError(\n `Expected 32 pointers or less, got ${pointers.length} instead`,\n );\n }\n return pointers.map(({ key, id }) => {\n let payload;\n if (isEncoded(id, ...idTagToEncoding)) {\n payload = [...(allowRaw ? [ID_TAG] : []), addressAny.serialize(id)];\n }\n if (isEncoded(id, Encoding.Bytearray)) {\n const data = decode(id);\n if (data.length > DATA_LENGTH_MAX) {\n throw new ArgumentError(\n 'Raw pointer',\n `shorter than ${DATA_LENGTH_MAX + 1} bytes`,\n `${data.length} bytes`,\n );\n }\n payload = [DATA_TAG, data];\n }\n if (payload == null) throw new DecodeError(`Unknown AENS pointer value: ${id}`);\n return [toBytes(key), Buffer.concat(payload)];\n });\n },\n\n /**\n * Helper function to read pointers from name update TX\n * @param pointers - Array of pointers\n * @returns Deserialize pointer array\n */\n deserialize(pointers) {\n return pointers.map(([bKey, bId]) => {\n if (!allowRaw) return { key: bKey.toString(), id: addressAny.deserialize(bId) };\n const tag = bId.subarray(0, 1);\n const payload = bId.subarray(1);\n let id;\n if (tag.equals(ID_TAG)) id = addressAny.deserialize(payload);\n // TS can't figure out the real type depending on allowRaw\n if (tag.equals(DATA_TAG)) id = encode(payload, Encoding.Bytearray) as Encoded.AccountAddress;\n if (id == null) throw new DecodeError(`Unknown AENS pointer tag: ${tag}`);\n return { key: bKey.toString(), id };\n });\n },\n});\n"],"mappings":";AACA,SAASA,OAAO,QAAQ,yBAAyB;AACjD,SAAkBC,QAAQ,EAAEC,MAAM,EAAEC,MAAM,QAAQ,2BAA2B;AAC7E,SAASC,SAAS,QAAQ,0BAA0B;AACpD,SAASC,oBAAoB,EAAEC,WAAW,EAAEC,aAAa,QAAQ,0BAA0B;AAC3F,OAAOC,OAAO,IAAsBC,eAAe,QAAQ,cAAc;AACzE,SAASC,kBAAkB,QAA6B,gBAAgB;AAExE,MAAMC,MAAM,GAAGC,OAAA,CAAOC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,MAAMC,QAAQ,GAAGF,OAAA,CAAOC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACjC,MAAME,eAAe,GAAG,IAAI;AAC5B,MAAMC,UAAU,GAAGR,OAAO,CAAC,GAAGC,eAAe,CAAC;;AAE9C;;AAQA,eACEQ,QAAkB,KASd;EACJ;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,SAASA,CAACC,QAAQ,EAAEC,MAAM,EAAE;IAC1B;IACA;IACA,IAAIA,MAAM,CAACV,kBAAkB,CAAC,KAAK,IAAI,IAAIS,QAAQ,CAACE,MAAM,GAAG,EAAE,EAAE;MAC/D,MAAM,IAAIhB,oBAAoB,CAC5B,qCAAqCc,QAAQ,CAACE,MAAM,UACtD,CAAC;IACH;IACA,OAAOF,QAAQ,CAACG,GAAG,CAAC,CAAC;MAAEC,GAAG;MAAEC;IAAG,CAAC,KAAK;MACnC,IAAIC,OAAO;MACX,IAAIrB,SAAS,CAACo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,MAAM,CAACxB,MAAM,CAAC,EAAEa,EAAE,GAAGR,UAAU,CAACa,WAAW,CAACJ,OAAO,CAAC;MAC5D;MACA,IAAIQ,GAAG,CAACE,MAAM,CAACrB,QAAQ,CAAC,EAAEU,EAAE,GAAGrB,MAAM,CAACsB,OAAO,EAAExB,QAAQ,CAACyB,SAAS,CAA2B;MAC5F,IAAIF,EAAE,IAAI,IAAI,EAAE,MAAM,IAAIlB,WAAW,CAAC,6BAA6B2B,GAAG,EAAE,CAAC;MACzE,OAAO;QAAEV,GAAG,EAAEO,IAAI,CAACE,QAAQ,CAAC,CAAC;QAAER;MAAG,CAAC;IACrC,CAAC,CAAC;EACJ;AACF,CAAC,CAAC","ignoreList":[]}
@@ -1,10 +1,13 @@
1
1
  import { Tag } from '../constants.js';
2
+ import type { ProtocolParametersOption } from '../protocol-parameters.js';
3
+ import { SerializeAsIsParams } from './interface.js';
2
4
  import type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';
3
5
  export default function genTransactionField<T extends Tag = Tag>(tag?: T): {
4
6
  serialize: (value: any, options: {
5
7
  buildTx: typeof buildTxType;
6
- }) => Buffer;
8
+ } & ProtocolParametersOption & SerializeAsIsParams) => Buffer;
7
9
  deserialize: (value: Buffer, options: {
8
10
  unpackTx: typeof unpackTxType;
9
11
  }) => any;
12
+ nestedTransaction: true;
10
13
  };
@@ -1,10 +1,14 @@
1
1
  import { Buffer as _Buffer } from "buffer";
2
2
  import { decode, encode, Encoding } from '../../../utils/encoder.js';
3
+ import { serializeAsIsParam } from './interface.js';
3
4
  export default function genTransactionField(tag) {
4
5
  return {
5
- serialize(txParams, {
6
- buildTx
7
- }) {
6
+ nestedTransaction: true,
7
+ serialize(txParams, options) {
8
+ const {
9
+ buildTx,
10
+ protocolParameters
11
+ } = options;
8
12
  if (ArrayBuffer.isView(txParams)) return _Buffer.from(txParams);
9
13
  if (typeof txParams === 'string' && txParams.startsWith('tx_')) {
10
14
  return decode(txParams);
@@ -13,6 +17,17 @@ export default function genTransactionField(tag) {
13
17
  ...txParams,
14
18
  ...(tag != null && {
15
19
  tag
20
+ }),
21
+ // a nested transaction that is not built yet is built against the parameters of the
22
+ // outer one, otherwise it would be priced by the parameters of the SDK release
23
+ ...(protocolParameters != null && {
24
+ protocolParameters
25
+ }),
26
+ // a transaction nested in one that is only re-serialized is re-serialized as well —
27
+ // without this the innermost transaction of a `PayingForTx` wrapping a `GaMetaTx` gets
28
+ // its already fixed values checked against the parameters of the outermost one
29
+ ...(options[serializeAsIsParam] === true && {
30
+ [serializeAsIsParam]: true
16
31
  })
17
32
  }));
18
33
  },
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.js","names":["decode","encode","Encoding","genTransactionField","tag","serialize","txParams","buildTx","ArrayBuffer","isView","_Buffer","from","startsWith","deserialize","buf","unpackTx","Transaction"],"sources":["../../../../src/tx/builder/field-types/transaction.ts"],"sourcesContent":["import { decode, encode, Encoded, Encoding } from '../../../utils/encoder.js';\nimport { Tag } from '../constants.js';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';\n\nexport default function genTransactionField<T extends Tag = Tag>(\n tag?: T,\n): {\n serialize: (\n // TODO: replace with `TxParams & { tag: T }`,\n // but fix TS2502 value is referenced directly or indirectly in its own type annotation\n value: any,\n options: { buildTx: typeof buildTxType },\n ) => Buffer;\n deserialize: (\n value: Buffer,\n options: { unpackTx: typeof unpackTxType },\n // TODO: replace with `TxUnpacked & { tag: T }`,\n // TS2577 Return type annotation circularly references itself\n ) => any;\n} {\n return {\n serialize(txParams, { buildTx }) {\n if (ArrayBuffer.isView(txParams)) return Buffer.from(txParams as any);\n if (typeof txParams === 'string' && txParams.startsWith('tx_')) {\n return decode(txParams as Encoded.Transaction);\n }\n return decode(buildTx({ ...txParams, ...(tag != null && { tag }) }));\n },\n\n deserialize(buf, { unpackTx }) {\n return unpackTx(encode(buf, Encoding.Transaction), tag);\n },\n };\n}\n"],"mappings":";AAAA,SAASA,MAAM,EAAEC,MAAM,EAAWC,QAAQ,QAAQ,2BAA2B;AAI7E,eAAe,SAASC,mBAAmBA,CACzCC,GAAO,EAcP;EACA,OAAO;IACLC,SAASA,CAACC,QAAQ,EAAE;MAAEC;IAAQ,CAAC,EAAE;MAC/B,IAAIC,WAAW,CAACC,MAAM,CAACH,QAAQ,CAAC,EAAE,OAAOI,OAAA,CAAOC,IAAI,CAACL,QAAe,CAAC;MACrE,IAAI,OAAOA,QAAQ,KAAK,QAAQ,IAAIA,QAAQ,CAACM,UAAU,CAAC,KAAK,CAAC,EAAE;QAC9D,OAAOZ,MAAM,CAACM,QAA+B,CAAC;MAChD;MACA,OAAON,MAAM,CAACO,OAAO,CAAC;QAAE,GAAGD,QAAQ;QAAE,IAAIF,GAAG,IAAI,IAAI,IAAI;UAAEA;QAAI,CAAC;MAAE,CAAC,CAAC,CAAC;IACtE,CAAC;IAEDS,WAAWA,CAACC,GAAG,EAAE;MAAEC;IAAS,CAAC,EAAE;MAC7B,OAAOA,QAAQ,CAACd,MAAM,CAACa,GAAG,EAAEZ,QAAQ,CAACc,WAAW,CAAC,EAAEZ,GAAG,CAAC;IACzD;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"transaction.js","names":["decode","encode","Encoding","serializeAsIsParam","genTransactionField","tag","nestedTransaction","serialize","txParams","options","buildTx","protocolParameters","ArrayBuffer","isView","_Buffer","from","startsWith","deserialize","buf","unpackTx","Transaction"],"sources":["../../../../src/tx/builder/field-types/transaction.ts"],"sourcesContent":["import { decode, encode, Encoded, Encoding } from '../../../utils/encoder.js';\nimport { Tag } from '../constants.js';\nimport type { ProtocolParametersOption } from '../protocol-parameters.js';\nimport { serializeAsIsParam, SerializeAsIsParams } from './interface.js';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';\n\nexport default function genTransactionField<T extends Tag = Tag>(\n tag?: T,\n): {\n serialize: (\n // TODO: replace with `TxParams & { tag: T }`,\n // but fix TS2502 value is referenced directly or indirectly in its own type annotation\n value: any,\n options: { buildTx: typeof buildTxType } & ProtocolParametersOption & SerializeAsIsParams,\n ) => Buffer;\n deserialize: (\n value: Buffer,\n options: { unpackTx: typeof unpackTxType },\n // TODO: replace with `TxUnpacked & { tag: T }`,\n // TS2577 Return type annotation circularly references itself\n ) => any;\n nestedTransaction: true;\n} {\n return {\n nestedTransaction: true,\n\n serialize(txParams, options) {\n const { buildTx, protocolParameters } = options;\n if (ArrayBuffer.isView(txParams)) return Buffer.from(txParams as any);\n if (typeof txParams === 'string' && txParams.startsWith('tx_')) {\n return decode(txParams as Encoded.Transaction);\n }\n return decode(\n buildTx({\n ...txParams,\n ...(tag != null && { tag }),\n // a nested transaction that is not built yet is built against the parameters of the\n // outer one, otherwise it would be priced by the parameters of the SDK release\n ...(protocolParameters != null && { protocolParameters }),\n // a transaction nested in one that is only re-serialized is re-serialized as well —\n // without this the innermost transaction of a `PayingForTx` wrapping a `GaMetaTx` gets\n // its already fixed values checked against the parameters of the outermost one\n ...(options[serializeAsIsParam] === true && { [serializeAsIsParam]: true }),\n }),\n );\n },\n\n deserialize(buf, { unpackTx }) {\n return unpackTx(encode(buf, Encoding.Transaction), tag);\n },\n };\n}\n"],"mappings":";AAAA,SAASA,MAAM,EAAEC,MAAM,EAAWC,QAAQ,QAAQ,2BAA2B;AAG7E,SAASC,kBAAkB,QAA6B,gBAAgB;AAGxE,eAAe,SAASC,mBAAmBA,CACzCC,GAAO,EAeP;EACA,OAAO;IACLC,iBAAiB,EAAE,IAAI;IAEvBC,SAASA,CAACC,QAAQ,EAAEC,OAAO,EAAE;MAC3B,MAAM;QAAEC,OAAO;QAAEC;MAAmB,CAAC,GAAGF,OAAO;MAC/C,IAAIG,WAAW,CAACC,MAAM,CAACL,QAAQ,CAAC,EAAE,OAAOM,OAAA,CAAOC,IAAI,CAACP,QAAe,CAAC;MACrE,IAAI,OAAOA,QAAQ,KAAK,QAAQ,IAAIA,QAAQ,CAACQ,UAAU,CAAC,KAAK,CAAC,EAAE;QAC9D,OAAOhB,MAAM,CAACQ,QAA+B,CAAC;MAChD;MACA,OAAOR,MAAM,CACXU,OAAO,CAAC;QACN,GAAGF,QAAQ;QACX,IAAIH,GAAG,IAAI,IAAI,IAAI;UAAEA;QAAI,CAAC,CAAC;QAC3B;QACA;QACA,IAAIM,kBAAkB,IAAI,IAAI,IAAI;UAAEA;QAAmB,CAAC,CAAC;QACzD;QACA;QACA;QACA,IAAIF,OAAO,CAACN,kBAAkB,CAAC,KAAK,IAAI,IAAI;UAAE,CAACA,kBAAkB,GAAG;QAAK,CAAC;MAC5E,CAAC,CACH,CAAC;IACH,CAAC;IAEDc,WAAWA,CAACC,GAAG,EAAE;MAAEC;IAAS,CAAC,EAAE;MAC7B,OAAOA,QAAQ,CAAClB,MAAM,CAACiB,GAAG,EAAEhB,QAAQ,CAACkB,WAAW,CAAC,EAAEf,GAAG,CAAC;IACzD;EACF,CAAC;AACH","ignoreList":[]}
@@ -5,10 +5,9 @@ import { _getPollInterval } from '../../../chain.js';
5
5
  */
6
6
  declare const _default: {
7
7
  serialize(value: number | undefined): Buffer;
8
- prepare(value: number | undefined, params: {}, { onNode, absoluteTtl, _isInternalBuild, ...options }: {
8
+ prepare(value: number | undefined, params: {}, { onNode, absoluteTtl, ...options }: {
9
9
  onNode?: Node;
10
10
  absoluteTtl?: boolean;
11
- _isInternalBuild?: boolean;
12
11
  } & Omit<Parameters<typeof _getPollInterval>[1], "onNode">): Promise<number | undefined>;
13
12
  deserialize(value: Buffer): number;
14
13
  };
@@ -2,6 +2,10 @@ import shortUInt from './short-u-int.js';
2
2
  import { ArgumentError } from '../../../utils/errors.js';
3
3
  import { getHeight } from '../../../chain.js';
4
4
 
5
+ // TODO: restore after the mainnet mining issue is solved, was used via `_isInternalBuild` flag
6
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
+ const DEFAULT_INTERNAL_RELATIVE_TTL = 3;
8
+
5
9
  /**
6
10
  * Time to leave
7
11
  */
@@ -15,16 +19,15 @@ export default {
15
19
  {
16
20
  onNode,
17
21
  absoluteTtl,
18
- _isInternalBuild,
19
22
  ...options
20
23
  }) {
21
- if (absoluteTtl !== true && value !== 0 && (value != null || _isInternalBuild === true)) {
24
+ if (absoluteTtl !== true && value !== 0 && value != null) {
22
25
  if (onNode == null) throw new ArgumentError('onNode', 'provided', onNode);
23
- value = (value !== null && value !== void 0 ? value : 3) + (await getHeight({
26
+ value += await getHeight({
24
27
  ...options,
25
28
  onNode,
26
29
  cached: true
27
- }));
30
+ });
28
31
  }
29
32
  return value;
30
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ttl.js","names":["shortUInt","ArgumentError","getHeight","serialize","value","prepare","params","onNode","absoluteTtl","_isInternalBuild","options","cached"],"sources":["../../../../src/tx/builder/field-types/ttl.ts"],"sourcesContent":["import shortUInt from './short-u-int.js';\nimport Node from '../../../Node.js';\nimport { ArgumentError } from '../../../utils/errors.js';\nimport { _getPollInterval, getHeight } from '../../../chain.js';\n\n/**\n * Time to leave\n */\nexport default {\n ...shortUInt,\n\n serialize(value: number | undefined): Buffer {\n return shortUInt.serialize(value ?? 0);\n },\n\n async prepare(\n value: number | undefined,\n params: {},\n // TODO: { absoluteTtl: true } | { absoluteTtl: false, onNode: Node }\n {\n onNode,\n absoluteTtl,\n _isInternalBuild,\n ...options\n }: {\n onNode?: Node;\n absoluteTtl?: boolean;\n _isInternalBuild?: boolean;\n } & Omit<Parameters<typeof _getPollInterval>[1], 'onNode'>,\n ) {\n if (absoluteTtl !== true && value !== 0 && (value != null || _isInternalBuild === true)) {\n if (onNode == null) throw new ArgumentError('onNode', 'provided', onNode);\n value = (value ?? 3) + (await getHeight({ ...options, onNode, cached: true }));\n }\n return value;\n },\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,kBAAkB;AAExC,SAASC,aAAa,QAAQ,0BAA0B;AACxD,SAA2BC,SAAS,QAAQ,mBAAmB;;AAE/D;AACA;AACA;AACA,eAAe;EACb,GAAGF,SAAS;EAEZG,SAASA,CAACC,KAAyB,EAAU;IAC3C,OAAOJ,SAAS,CAACG,SAAS,CAACC,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,CAAC,CAAC;EACxC,CAAC;EAED,MAAMC,OAAOA,CACXD,KAAyB,EACzBE,MAAU;EACV;EACA;IACEC,MAAM;IACNC,WAAW;IACXC,gBAAgB;IAChB,GAAGC;EAKoD,CAAC,EAC1D;IACA,IAAIF,WAAW,KAAK,IAAI,IAAIJ,KAAK,KAAK,CAAC,KAAKA,KAAK,IAAI,IAAI,IAAIK,gBAAgB,KAAK,IAAI,CAAC,EAAE;MACvF,IAAIF,MAAM,IAAI,IAAI,EAAE,MAAM,IAAIN,aAAa,CAAC,QAAQ,EAAE,UAAU,EAAEM,MAAM,CAAC;MACzEH,KAAK,GAAG,CAACA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,CAAC,KAAK,MAAMF,SAAS,CAAC;QAAE,GAAGQ,OAAO;QAAEH,MAAM;QAAEI,MAAM,EAAE;MAAK,CAAC,CAAC,CAAC;IAChF;IACA,OAAOP,KAAK;EACd;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"ttl.js","names":["shortUInt","ArgumentError","getHeight","DEFAULT_INTERNAL_RELATIVE_TTL","serialize","value","prepare","params","onNode","absoluteTtl","options","cached"],"sources":["../../../../src/tx/builder/field-types/ttl.ts"],"sourcesContent":["import shortUInt from './short-u-int.js';\nimport Node from '../../../Node.js';\nimport { ArgumentError } from '../../../utils/errors.js';\nimport { _getPollInterval, getHeight } from '../../../chain.js';\n\n// TODO: restore after the mainnet mining issue is solved, was used via `_isInternalBuild` flag\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst DEFAULT_INTERNAL_RELATIVE_TTL = 3;\n\n/**\n * Time to leave\n */\nexport default {\n ...shortUInt,\n\n serialize(value: number | undefined): Buffer {\n return shortUInt.serialize(value ?? 0);\n },\n\n async prepare(\n value: number | undefined,\n params: {},\n // TODO: { absoluteTtl: true } | { absoluteTtl: false, onNode: Node }\n {\n onNode,\n absoluteTtl,\n ...options\n }: {\n onNode?: Node;\n absoluteTtl?: boolean;\n } & Omit<Parameters<typeof _getPollInterval>[1], 'onNode'>,\n ) {\n if (absoluteTtl !== true && value !== 0 && value != null) {\n if (onNode == null) throw new ArgumentError('onNode', 'provided', onNode);\n value += await getHeight({ ...options, onNode, cached: true });\n }\n return value;\n },\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,kBAAkB;AAExC,SAASC,aAAa,QAAQ,0BAA0B;AACxD,SAA2BC,SAAS,QAAQ,mBAAmB;;AAE/D;AACA;AACA,MAAMC,6BAA6B,GAAG,CAAC;;AAEvC;AACA;AACA;AACA,eAAe;EACb,GAAGH,SAAS;EAEZI,SAASA,CAACC,KAAyB,EAAU;IAC3C,OAAOL,SAAS,CAACI,SAAS,CAACC,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,CAAC,CAAC;EACxC,CAAC;EAED,MAAMC,OAAOA,CACXD,KAAyB,EACzBE,MAAU;EACV;EACA;IACEC,MAAM;IACNC,WAAW;IACX,GAAGC;EAIoD,CAAC,EAC1D;IACA,IAAID,WAAW,KAAK,IAAI,IAAIJ,KAAK,KAAK,CAAC,IAAIA,KAAK,IAAI,IAAI,EAAE;MACxD,IAAIG,MAAM,IAAI,IAAI,EAAE,MAAM,IAAIP,aAAa,CAAC,QAAQ,EAAE,UAAU,EAAEO,MAAM,CAAC;MACzEH,KAAK,IAAI,MAAMH,SAAS,CAAC;QAAE,GAAGQ,OAAO;QAAEF,MAAM;QAAEG,MAAM,EAAE;MAAK,CAAC,CAAC;IAChE;IACA,OAAON,KAAK;EACd;AACF,CAAC","ignoreList":[]}