@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Encoding","packRecord","unpackRecord","schemas","EntryTag","encodingTag","CallsMtree","CallStateTree","StateTrees","TreesPoi","Poi","packEntry","params","_encodingTag$find$","encoding","find","tag","Bytearray","unpackEntry","encoded","expectedTag","enc","startsWith"],"sources":["../../../../src/tx/builder/entry/index.ts"],"sourcesContent":["import { Encoded, Encoding } from '../../../utils/encoder.js';\nimport { packRecord, unpackRecord } from '../common.js';\nimport { schemas } from './schema.js';\nimport { EntryTag } from './constants.js';\nimport { EntParams, EntUnpacked } from './schema.generated.js';\n\nconst encodingTag = [\n [EntryTag.CallsMtree, Encoding.CallStateTree],\n [EntryTag.StateTrees, Encoding.StateTrees],\n [EntryTag.TreesPoi, Encoding.Poi],\n] as const;\n\nexport function packEntry(params: EntParams & { tag: EntryTag.CallsMtree }): Encoded.CallStateTree;\nexport function packEntry(params: EntParams & { tag: EntryTag.StateTrees }): Encoded.StateTrees;\nexport function packEntry(params: EntParams & { tag: EntryTag.TreesPoi }): Encoded.Poi;\n/**\n * Pack entry\n * @category entry builder\n * @param params - Params of entry\n * @returns Encoded entry\n */\nexport function packEntry(params: EntParams): Encoded.Any;\nexport function packEntry(params: EntParams): Encoded.Any {\n const encoding = encodingTag.find(([tag]) => tag === params.tag)?.[1] ?? Encoding.Bytearray;\n return packRecord(schemas, EntryTag, params, { packEntry }, encoding);\n}\n\nexport function unpackEntry(\n encoded: Encoded.CallStateTree,\n): EntUnpacked & { tag: EntryTag.CallsMtree };\nexport function unpackEntry(\n encoded: Encoded.StateTrees,\n): EntUnpacked & { tag: EntryTag.StateTrees };\nexport function unpackEntry(encoded: Encoded.Poi): EntUnpacked & { tag: EntryTag.TreesPoi };\n/**\n * Unpack entry\n * @category entry builder\n * @param encoded - Encoded entry\n * @param expectedTag - Expected entry type\n * @returns Params of entry\n */\nexport function unpackEntry<T extends EntryTag>(\n encoded: Encoded.Any,\n expectedTag?: T,\n): EntUnpacked & { tag: T };\nexport function unpackEntry(encoded: Encoded.Any, expectedTag?: EntryTag): EntUnpacked {\n expectedTag ??= encodingTag.find(([, enc]) => encoded.startsWith(enc))?.[0];\n return unpackRecord(schemas, EntryTag, encoded, expectedTag, { unpackEntry }) as any;\n}\n"],"mappings":"AAAA,SAAkBA,QAAQ,QAAQ,2BAA2B;AAC7D,SAASC,UAAU,EAAEC,YAAY,QAAQ,cAAc;AACvD,SAASC,OAAO,QAAQ,aAAa;AACrC,SAASC,QAAQ,QAAQ,gBAAgB;
|
|
1
|
+
{"version":3,"file":"index.js","names":["Encoding","packRecord","unpackRecord","schemas","EntryTag","checkParametersUsable","encodingTag","CallsMtree","CallStateTree","StateTrees","TreesPoi","Poi","packEntry","params","_encodingTag$find$","protocolParameters","encoding","find","tag","Bytearray","unpackEntry","encoded","expectedTag","enc","startsWith"],"sources":["../../../../src/tx/builder/entry/index.ts"],"sourcesContent":["import { Encoded, Encoding } from '../../../utils/encoder.js';\nimport { packRecord, unpackRecord } from '../common.js';\nimport { schemas } from './schema.js';\nimport { EntryTag } from './constants.js';\nimport { EntParams, EntUnpacked } from './schema.generated.js';\nimport { checkParametersUsable, ProtocolParametersOption } from '../protocol-parameters.js';\n\nconst encodingTag = [\n [EntryTag.CallsMtree, Encoding.CallStateTree],\n [EntryTag.StateTrees, Encoding.StateTrees],\n [EntryTag.TreesPoi, Encoding.Poi],\n] as const;\n\nexport function packEntry(params: EntParams & { tag: EntryTag.CallsMtree }): Encoded.CallStateTree;\nexport function packEntry(params: EntParams & { tag: EntryTag.StateTrees }): Encoded.StateTrees;\nexport function packEntry(params: EntParams & { tag: EntryTag.TreesPoi }): Encoded.Poi;\n/**\n * Pack entry\n * @category entry builder\n * @param params - Params of entry\n * @returns Encoded entry\n */\nexport function packEntry(params: EntParams): Encoded.Any;\nexport function packEntry(params: EntParams): Encoded.Any {\n // `GaMetaTxAuthData` holds a `gasPrice` priced by them, see the note in `buildTx`\n const { protocolParameters } = params as ProtocolParametersOption;\n if (protocolParameters != null) checkParametersUsable(protocolParameters);\n const encoding = encodingTag.find(([tag]) => tag === params.tag)?.[1] ?? Encoding.Bytearray;\n return packRecord(schemas, EntryTag, params, { packEntry }, encoding);\n}\n\nexport function unpackEntry(\n encoded: Encoded.CallStateTree,\n): EntUnpacked & { tag: EntryTag.CallsMtree };\nexport function unpackEntry(\n encoded: Encoded.StateTrees,\n): EntUnpacked & { tag: EntryTag.StateTrees };\nexport function unpackEntry(encoded: Encoded.Poi): EntUnpacked & { tag: EntryTag.TreesPoi };\n/**\n * Unpack entry\n * @category entry builder\n * @param encoded - Encoded entry\n * @param expectedTag - Expected entry type\n * @returns Params of entry\n */\nexport function unpackEntry<T extends EntryTag>(\n encoded: Encoded.Any,\n expectedTag?: T,\n): EntUnpacked & { tag: T };\nexport function unpackEntry(encoded: Encoded.Any, expectedTag?: EntryTag): EntUnpacked {\n expectedTag ??= encodingTag.find(([, enc]) => encoded.startsWith(enc))?.[0];\n return unpackRecord(schemas, EntryTag, encoded, expectedTag, { unpackEntry }) as any;\n}\n"],"mappings":"AAAA,SAAkBA,QAAQ,QAAQ,2BAA2B;AAC7D,SAASC,UAAU,EAAEC,YAAY,QAAQ,cAAc;AACvD,SAASC,OAAO,QAAQ,aAAa;AACrC,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC,SAASC,qBAAqB,QAAkC,2BAA2B;AAE3F,MAAMC,WAAW,GAAG,CAClB,CAACF,QAAQ,CAACG,UAAU,EAAEP,QAAQ,CAACQ,aAAa,CAAC,EAC7C,CAACJ,QAAQ,CAACK,UAAU,EAAET,QAAQ,CAACS,UAAU,CAAC,EAC1C,CAACL,QAAQ,CAACM,QAAQ,EAAEV,QAAQ,CAACW,GAAG,CAAC,CACzB;;AAKV;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASC,SAASA,CAACC,MAAiB,EAAe;EAAA,IAAAC,kBAAA;EACxD;EACA,MAAM;IAAEC;EAAmB,CAAC,GAAGF,MAAkC;EACjE,IAAIE,kBAAkB,IAAI,IAAI,EAAEV,qBAAqB,CAACU,kBAAkB,CAAC;EACzE,MAAMC,QAAQ,IAAAF,kBAAA,GAAGR,WAAW,CAACW,IAAI,CAAC,CAAC,CAACC,GAAG,CAAC,KAAKA,GAAG,KAAKL,MAAM,CAACK,GAAG,CAAC,GAAG,CAAC,CAAC,cAAAJ,kBAAA,cAAAA,kBAAA,GAAId,QAAQ,CAACmB,SAAS;EAC3F,OAAOlB,UAAU,CAACE,OAAO,EAAEC,QAAQ,EAAES,MAAM,EAAE;IAAED;EAAU,CAAC,EAAEI,QAAQ,CAAC;AACvE;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,OAAO,SAASI,WAAWA,CAACC,OAAoB,EAAEC,WAAsB,EAAe;EACrFA,WAAW,aAAXA,WAAW,cAAXA,WAAW,GAAXA,WAAW,GAAKhB,WAAW,CAACW,IAAI,CAAC,CAAC,GAAGM,GAAG,CAAC,KAAKF,OAAO,CAACG,UAAU,CAACD,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;EAC3E,OAAOrB,YAAY,CAACC,OAAO,EAAEC,QAAQ,EAAEiB,OAAO,EAAEC,WAAW,EAAE;IAAEF;EAAY,CAAC,CAAC;AAC/E","ignoreList":[]}
|
|
@@ -158,7 +158,7 @@ export declare const schemas: readonly [{
|
|
|
158
158
|
id: Encoded.Generic<import("../field-types/address.js").AddressEncodings | Encoding.Bytearray>;
|
|
159
159
|
} : import("../../../apis/node/index.js").NamePointer & {
|
|
160
160
|
id: Encoded.Generic<import("../field-types/address.js").AddressEncodings>;
|
|
161
|
-
}
|
|
161
|
+
}>, params: import("../field-types/interface.js").SerializeAsIsParams) => Buffer[][];
|
|
162
162
|
deserialize: (pointers: Array<[key: Buffer, id: Buffer]>) => Array<AllowRaw extends true ? import("../../../apis/node/index.js").NamePointer & {
|
|
163
163
|
id: Encoded.Generic<import("../field-types/address.js").AddressEncodings | Encoding.Bytearray>;
|
|
164
164
|
} : import("../../../apis/node/index.js").NamePointer & {
|
|
@@ -543,26 +543,26 @@ export declare const schemas: readonly [{
|
|
|
543
543
|
deserialize(buffer: Buffer): Buffer;
|
|
544
544
|
};
|
|
545
545
|
readonly gasPrice: {
|
|
546
|
-
prepare(value: import("../constants.js").Int | undefined, params: {}, { onNode, denomination, }: {
|
|
546
|
+
prepare(value: import("../constants.js").Int | undefined, params: {}, { onNode, denomination, protocolParameters, }: {
|
|
547
547
|
onNode?: import("../../../Node.js").default;
|
|
548
548
|
denomination?: import("../../../index-browser.js").AE_AMOUNT_FORMATS;
|
|
549
|
-
}): Promise<import("../constants.js").Int | undefined>;
|
|
550
|
-
serializeAettos(value
|
|
549
|
+
} & import("../protocol-parameters.js").ProtocolParametersOption): Promise<import("../constants.js").Int | undefined>;
|
|
550
|
+
serializeAettos(value: string | undefined, params: import("../field-types/interface.js").SerializeAsIsParams, { protocolParameters }: import("../protocol-parameters.js").ProtocolParametersOption): string;
|
|
551
551
|
serialize(value: import("../constants.js").Int | undefined, params: {}, { denomination, ...options }: {
|
|
552
552
|
denomination?: import("../../../index-browser.js").AE_AMOUNT_FORMATS;
|
|
553
553
|
}): Buffer;
|
|
554
554
|
deserialize(value: Buffer): string;
|
|
555
555
|
};
|
|
556
556
|
readonly gasLimit: {
|
|
557
|
-
serialize(_value: number | undefined,
|
|
557
|
+
serialize(_value: number | undefined, params: {
|
|
558
558
|
tag: import("../constants.js").Tag;
|
|
559
559
|
rebuildTx: (params: any) => any;
|
|
560
560
|
unpackTx: typeof import("../index.js").unpackTx;
|
|
561
561
|
buildTx: typeof import("../index.js").buildTx;
|
|
562
562
|
_computingGasLimit?: number;
|
|
563
|
-
}, { gasMax }: {
|
|
563
|
+
} & import("../field-types/interface.js").SerializeAsIsParams, { gasMax, protocolParameters, }: {
|
|
564
564
|
gasMax?: number;
|
|
565
|
-
}): Buffer;
|
|
565
|
+
} & import("../protocol-parameters.js").ProtocolParametersOption): Buffer;
|
|
566
566
|
deserialize(value: Buffer): number;
|
|
567
567
|
};
|
|
568
568
|
}, {
|
|
@@ -1009,11 +1009,11 @@ export declare const schemas: readonly [{
|
|
|
1009
1009
|
deserialize(value: Buffer): string;
|
|
1010
1010
|
};
|
|
1011
1011
|
readonly gasPrice: {
|
|
1012
|
-
prepare(value: import("../constants.js").Int | undefined, params: {}, { onNode, denomination, }: {
|
|
1012
|
+
prepare(value: import("../constants.js").Int | undefined, params: {}, { onNode, denomination, protocolParameters, }: {
|
|
1013
1013
|
onNode?: import("../../../Node.js").default;
|
|
1014
1014
|
denomination?: import("../../../index-browser.js").AE_AMOUNT_FORMATS;
|
|
1015
|
-
}): Promise<import("../constants.js").Int | undefined>;
|
|
1016
|
-
serializeAettos(value
|
|
1015
|
+
} & import("../protocol-parameters.js").ProtocolParametersOption): Promise<import("../constants.js").Int | undefined>;
|
|
1016
|
+
serializeAettos(value: string | undefined, params: import("../field-types/interface.js").SerializeAsIsParams, { protocolParameters }: import("../protocol-parameters.js").ProtocolParametersOption): string;
|
|
1017
1017
|
serialize(value: import("../constants.js").Int | undefined, params: {}, { denomination, ...options }: {
|
|
1018
1018
|
denomination?: import("../../../index-browser.js").AE_AMOUNT_FORMATS;
|
|
1019
1019
|
}): Buffer;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Buffer as _Buffer } from "buffer";
|
|
2
2
|
import { Tag, ConsensusProtocolVersion } from '../constants.js';
|
|
3
|
-
import { getProtocolDetails } from './ct-version.js';
|
|
3
|
+
import { getProtocolDetails, isProtocolIndependent } from './ct-version.js';
|
|
4
|
+
function getKind(tag) {
|
|
5
|
+
return Tag.ContractCallTx === tag || Tag.GaMetaTx === tag ? 'contract-call' : 'oracle-call';
|
|
6
|
+
}
|
|
4
7
|
export default {
|
|
5
8
|
_getProtocolDetails(c, tag) {
|
|
6
|
-
|
|
7
|
-
return getProtocolDetails(c, kind).abiVersion;
|
|
9
|
+
return getProtocolDetails(c, getKind(tag)).abiVersion;
|
|
8
10
|
},
|
|
9
11
|
serialize(value, {
|
|
10
12
|
tag
|
|
@@ -21,7 +23,7 @@ export default {
|
|
|
21
23
|
options) {
|
|
22
24
|
if (value != null) return value;
|
|
23
25
|
if (options.consensusProtocolVersion != null) return undefined;
|
|
24
|
-
if (
|
|
26
|
+
if (isProtocolIndependent(getKind(tag))) return undefined;
|
|
25
27
|
if (options.onNode != null) {
|
|
26
28
|
return this._getProtocolDetails((await options.onNode.getNodeInfo()).consensusProtocolVersion, tag);
|
|
27
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi-version.js","names":["Tag","ConsensusProtocolVersion","getProtocolDetails","
|
|
1
|
+
{"version":3,"file":"abi-version.js","names":["Tag","ConsensusProtocolVersion","getProtocolDetails","isProtocolIndependent","getKind","tag","ContractCallTx","GaMetaTx","_getProtocolDetails","c","abiVersion","serialize","value","consensusProtocolVersion","Ceres","result","_Buffer","from","prepare","options","undefined","onNode","getNodeInfo","deserialize","buffer"],"sources":["../../../../src/tx/builder/field-types/abi-version.ts"],"sourcesContent":["import { Tag, ConsensusProtocolVersion, AbiVersion } from '../constants.js';\nimport { getProtocolDetails, isProtocolIndependent } from './ct-version.js';\nimport Node from '../../../Node.js';\n\nfunction getKind(tag: Tag): 'contract-call' | 'oracle-call' {\n return Tag.ContractCallTx === tag || Tag.GaMetaTx === tag ? 'contract-call' : 'oracle-call';\n}\n\nexport default {\n _getProtocolDetails(c: ConsensusProtocolVersion, tag: Tag): AbiVersion {\n return getProtocolDetails(c, getKind(tag)).abiVersion;\n },\n\n serialize(\n value: AbiVersion | undefined,\n { tag }: { tag: Tag },\n {\n consensusProtocolVersion = ConsensusProtocolVersion.Ceres,\n }: { consensusProtocolVersion?: ConsensusProtocolVersion },\n ): Buffer {\n const result = value ?? this._getProtocolDetails(consensusProtocolVersion, tag);\n\n return Buffer.from([result]);\n },\n\n async prepare(\n value: AbiVersion | undefined,\n { tag }: { tag: Tag },\n // TODO: { consensusProtocolVersion: ConsensusProtocolVersion } | { onNode: Node } | {}\n options: { consensusProtocolVersion?: ConsensusProtocolVersion; onNode?: Node },\n ): Promise<AbiVersion | undefined> {\n if (value != null) return value;\n if (options.consensusProtocolVersion != null) return undefined;\n if (isProtocolIndependent(getKind(tag))) return undefined;\n if (options.onNode != null) {\n return this._getProtocolDetails(\n (await options.onNode.getNodeInfo()).consensusProtocolVersion,\n tag,\n );\n }\n return undefined;\n },\n\n deserialize(buffer: Buffer): AbiVersion {\n return buffer[0];\n },\n};\n"],"mappings":";AAAA,SAASA,GAAG,EAAEC,wBAAwB,QAAoB,iBAAiB;AAC3E,SAASC,kBAAkB,EAAEC,qBAAqB,QAAQ,iBAAiB;AAG3E,SAASC,OAAOA,CAACC,GAAQ,EAAmC;EAC1D,OAAOL,GAAG,CAACM,cAAc,KAAKD,GAAG,IAAIL,GAAG,CAACO,QAAQ,KAAKF,GAAG,GAAG,eAAe,GAAG,aAAa;AAC7F;AAEA,eAAe;EACbG,mBAAmBA,CAACC,CAA2B,EAAEJ,GAAQ,EAAc;IACrE,OAAOH,kBAAkB,CAACO,CAAC,EAAEL,OAAO,CAACC,GAAG,CAAC,CAAC,CAACK,UAAU;EACvD,CAAC;EAEDC,SAASA,CACPC,KAA6B,EAC7B;IAAEP;EAAkB,CAAC,EACrB;IACEQ,wBAAwB,GAAGZ,wBAAwB,CAACa;EACG,CAAC,EAClD;IACR,MAAMC,MAAM,GAAGH,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,IAAI,CAACJ,mBAAmB,CAACK,wBAAwB,EAAER,GAAG,CAAC;IAE/E,OAAOW,OAAA,CAAOC,IAAI,CAAC,CAACF,MAAM,CAAC,CAAC;EAC9B,CAAC;EAED,MAAMG,OAAOA,CACXN,KAA6B,EAC7B;IAAEP;EAAkB,CAAC;EACrB;EACAc,OAA+E,EAC9C;IACjC,IAAIP,KAAK,IAAI,IAAI,EAAE,OAAOA,KAAK;IAC/B,IAAIO,OAAO,CAACN,wBAAwB,IAAI,IAAI,EAAE,OAAOO,SAAS;IAC9D,IAAIjB,qBAAqB,CAACC,OAAO,CAACC,GAAG,CAAC,CAAC,EAAE,OAAOe,SAAS;IACzD,IAAID,OAAO,CAACE,MAAM,IAAI,IAAI,EAAE;MAC1B,OAAO,IAAI,CAACb,mBAAmB,CAC7B,CAAC,MAAMW,OAAO,CAACE,MAAM,CAACC,WAAW,CAAC,CAAC,EAAET,wBAAwB,EAC7DR,GACF,CAAC;IACH;IACA,OAAOe,SAAS;EAClB,CAAC;EAEDG,WAAWA,CAACC,MAAc,EAAc;IACtC,OAAOA,MAAM,CAAC,CAAC,CAAC;EAClB;AACF,CAAC","ignoreList":[]}
|
|
@@ -15,12 +15,31 @@ export declare const ProtocolToVmAbi: {
|
|
|
15
15
|
readonly abiVersion: readonly [AbiVersion.NoAbi, AbiVersion.Fate];
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
+
readonly 7: {
|
|
19
|
+
readonly 'contract-create': {
|
|
20
|
+
readonly vmVersion: readonly [VmVersion.Fate3];
|
|
21
|
+
readonly abiVersion: readonly [AbiVersion.Fate];
|
|
22
|
+
};
|
|
23
|
+
readonly 'contract-call': {
|
|
24
|
+
readonly vmVersion: readonly [];
|
|
25
|
+
readonly abiVersion: readonly [AbiVersion.Fate];
|
|
26
|
+
};
|
|
27
|
+
readonly 'oracle-call': {
|
|
28
|
+
readonly vmVersion: readonly [];
|
|
29
|
+
readonly abiVersion: readonly [AbiVersion.NoAbi, AbiVersion.Fate];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
18
32
|
};
|
|
19
33
|
export interface CtVersion {
|
|
20
34
|
vmVersion: VmVersion;
|
|
21
35
|
abiVersion: AbiVersion;
|
|
22
36
|
}
|
|
23
37
|
export declare function getProtocolDetails(protocolVersion: ConsensusProtocolVersion, type: 'contract-create' | 'contract-call' | 'oracle-call'): CtVersion;
|
|
38
|
+
/**
|
|
39
|
+
* Whether all known consensus protocols pick the same versions for `type`, so asking node for its
|
|
40
|
+
* protocol can't change them.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isProtocolIndependent(type: 'contract-create' | 'contract-call' | 'oracle-call'): boolean;
|
|
24
43
|
declare const _default: {
|
|
25
44
|
serialize(value: CtVersion | undefined, params: {}, { consensusProtocolVersion, }: {
|
|
26
45
|
consensusProtocolVersion?: ConsensusProtocolVersion;
|
|
@@ -18,6 +18,20 @@ export const ProtocolToVmAbi = {
|
|
|
18
18
|
vmVersion: [],
|
|
19
19
|
abiVersion: [AbiVersion.NoAbi, AbiVersion.Fate]
|
|
20
20
|
}
|
|
21
|
+
},
|
|
22
|
+
[ConsensusProtocolVersion.Arcus]: {
|
|
23
|
+
'contract-create': {
|
|
24
|
+
vmVersion: [VmVersion.Fate3],
|
|
25
|
+
abiVersion: [AbiVersion.Fate]
|
|
26
|
+
},
|
|
27
|
+
'contract-call': {
|
|
28
|
+
vmVersion: [],
|
|
29
|
+
abiVersion: [AbiVersion.Fate]
|
|
30
|
+
},
|
|
31
|
+
'oracle-call': {
|
|
32
|
+
vmVersion: [],
|
|
33
|
+
abiVersion: [AbiVersion.NoAbi, AbiVersion.Fate]
|
|
34
|
+
}
|
|
21
35
|
}
|
|
22
36
|
};
|
|
23
37
|
export function getProtocolDetails(protocolVersion, type) {
|
|
@@ -28,6 +42,18 @@ export function getProtocolDetails(protocolVersion, type) {
|
|
|
28
42
|
abiVersion: protocol.abiVersion[0]
|
|
29
43
|
};
|
|
30
44
|
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Whether all known consensus protocols pick the same versions for `type`, so asking node for its
|
|
48
|
+
* protocol can't change them.
|
|
49
|
+
*/
|
|
50
|
+
export function isProtocolIndependent(type) {
|
|
51
|
+
const [first, ...others] = Object.keys(ProtocolToVmAbi).map(protocol => getProtocolDetails(+protocol, type));
|
|
52
|
+
return others.every(({
|
|
53
|
+
vmVersion,
|
|
54
|
+
abiVersion
|
|
55
|
+
}) => vmVersion === first.vmVersion && abiVersion === first.abiVersion);
|
|
56
|
+
}
|
|
31
57
|
export default {
|
|
32
58
|
serialize(value, params, {
|
|
33
59
|
consensusProtocolVersion = ConsensusProtocolVersion.Ceres
|
|
@@ -40,7 +66,7 @@ export default {
|
|
|
40
66
|
options) {
|
|
41
67
|
if (value != null) return value;
|
|
42
68
|
if (options.consensusProtocolVersion != null) return undefined;
|
|
43
|
-
if (
|
|
69
|
+
if (isProtocolIndependent('contract-create')) return undefined;
|
|
44
70
|
if (options.onNode != null) {
|
|
45
71
|
return getProtocolDetails((await options.onNode.getNodeInfo()).consensusProtocolVersion, 'contract-create');
|
|
46
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct-version.js","names":["ConsensusProtocolVersion","VmVersion","AbiVersion","ProtocolToVmAbi","Ceres","vmVersion","Fate3","abiVersion","Fate","NoAbi","getProtocolDetails","protocolVersion","type","_protocol$vmVersion$","protocol","Fate2","serialize","value","params","consensusProtocolVersion","_Buffer","from","prepare","options","undefined","
|
|
1
|
+
{"version":3,"file":"ct-version.js","names":["ConsensusProtocolVersion","VmVersion","AbiVersion","ProtocolToVmAbi","Ceres","vmVersion","Fate3","abiVersion","Fate","NoAbi","Arcus","getProtocolDetails","protocolVersion","type","_protocol$vmVersion$","protocol","Fate2","isProtocolIndependent","first","others","Object","keys","map","every","serialize","value","params","consensusProtocolVersion","_Buffer","from","prepare","options","undefined","onNode","getNodeInfo","deserialize","buffer","vm","abi"],"sources":["../../../../src/tx/builder/field-types/ct-version.ts"],"sourcesContent":["import { ConsensusProtocolVersion, VmVersion, AbiVersion } from '../constants.js';\nimport Node from '../../../Node.js';\n\n/*\n * First abi/vm by default\n * @see {@link https://github.com/aeternity/protocol/blob/71cf111/contracts/contract_vms.md#virtual-machines-on-the-æternity-blockchain}\n */\nexport const ProtocolToVmAbi = {\n [ConsensusProtocolVersion.Ceres]: {\n 'contract-create': {\n vmVersion: [VmVersion.Fate3],\n abiVersion: [AbiVersion.Fate],\n },\n 'contract-call': {\n vmVersion: [],\n abiVersion: [AbiVersion.Fate],\n },\n 'oracle-call': {\n vmVersion: [],\n abiVersion: [AbiVersion.NoAbi, AbiVersion.Fate],\n },\n },\n [ConsensusProtocolVersion.Arcus]: {\n 'contract-create': {\n vmVersion: [VmVersion.Fate3],\n abiVersion: [AbiVersion.Fate],\n },\n 'contract-call': {\n vmVersion: [],\n abiVersion: [AbiVersion.Fate],\n },\n 'oracle-call': {\n vmVersion: [],\n abiVersion: [AbiVersion.NoAbi, AbiVersion.Fate],\n },\n },\n} as const;\n\nexport interface CtVersion {\n vmVersion: VmVersion;\n abiVersion: AbiVersion;\n}\n\nexport function getProtocolDetails(\n protocolVersion: ConsensusProtocolVersion,\n type: 'contract-create' | 'contract-call' | 'oracle-call',\n): CtVersion {\n const protocol = ProtocolToVmAbi[protocolVersion][type];\n return {\n vmVersion: protocol.vmVersion[0] ?? VmVersion.Fate2,\n abiVersion: protocol.abiVersion[0],\n };\n}\n\n/**\n * Whether all known consensus protocols pick the same versions for `type`, so asking node for its\n * protocol can't change them.\n */\nexport function isProtocolIndependent(\n type: 'contract-create' | 'contract-call' | 'oracle-call',\n): boolean {\n const [first, ...others] = Object.keys(ProtocolToVmAbi).map((protocol) =>\n getProtocolDetails(+protocol as ConsensusProtocolVersion, type),\n );\n return others.every(\n ({ vmVersion, abiVersion }) => vmVersion === first.vmVersion && abiVersion === first.abiVersion,\n );\n}\n\nexport default {\n serialize(\n value: CtVersion | undefined,\n params: {},\n {\n consensusProtocolVersion = ConsensusProtocolVersion.Ceres,\n }: { consensusProtocolVersion?: ConsensusProtocolVersion },\n ): Buffer {\n value ??= getProtocolDetails(consensusProtocolVersion, 'contract-create');\n\n return Buffer.from([value.vmVersion, 0, value.abiVersion]);\n },\n\n async prepare(\n value: CtVersion | undefined,\n params: {},\n // TODO: { consensusProtocolVersion: ConsensusProtocolVersion } | { onNode: Node } | {}\n options: { consensusProtocolVersion?: ConsensusProtocolVersion; onNode?: Node },\n ): Promise<CtVersion | undefined> {\n if (value != null) return value;\n if (options.consensusProtocolVersion != null) return undefined;\n if (isProtocolIndependent('contract-create')) return undefined;\n if (options.onNode != null) {\n return getProtocolDetails(\n (await options.onNode.getNodeInfo()).consensusProtocolVersion,\n 'contract-create',\n );\n }\n return undefined;\n },\n\n deserialize(buffer: Buffer): CtVersion {\n const [vm, , abi] = buffer;\n return { vmVersion: +vm, abiVersion: +abi };\n },\n};\n"],"mappings":";AAAA,SAASA,wBAAwB,EAAEC,SAAS,EAAEC,UAAU,QAAQ,iBAAiB;AAGjF;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAG;EAC7B,CAACH,wBAAwB,CAACI,KAAK,GAAG;IAChC,iBAAiB,EAAE;MACjBC,SAAS,EAAE,CAACJ,SAAS,CAACK,KAAK,CAAC;MAC5BC,UAAU,EAAE,CAACL,UAAU,CAACM,IAAI;IAC9B,CAAC;IACD,eAAe,EAAE;MACfH,SAAS,EAAE,EAAE;MACbE,UAAU,EAAE,CAACL,UAAU,CAACM,IAAI;IAC9B,CAAC;IACD,aAAa,EAAE;MACbH,SAAS,EAAE,EAAE;MACbE,UAAU,EAAE,CAACL,UAAU,CAACO,KAAK,EAAEP,UAAU,CAACM,IAAI;IAChD;EACF,CAAC;EACD,CAACR,wBAAwB,CAACU,KAAK,GAAG;IAChC,iBAAiB,EAAE;MACjBL,SAAS,EAAE,CAACJ,SAAS,CAACK,KAAK,CAAC;MAC5BC,UAAU,EAAE,CAACL,UAAU,CAACM,IAAI;IAC9B,CAAC;IACD,eAAe,EAAE;MACfH,SAAS,EAAE,EAAE;MACbE,UAAU,EAAE,CAACL,UAAU,CAACM,IAAI;IAC9B,CAAC;IACD,aAAa,EAAE;MACbH,SAAS,EAAE,EAAE;MACbE,UAAU,EAAE,CAACL,UAAU,CAACO,KAAK,EAAEP,UAAU,CAACM,IAAI;IAChD;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I,IAAI,EAAE,OAAOA,KAAK;IAC/B,IAAIM,OAAO,CAACJ,wBAAwB,IAAI,IAAI,EAAE,OAAOK,SAAS;IAC9D,IAAIf,qBAAqB,CAAC,iBAAiB,CAAC,EAAE,OAAOe,SAAS;IAC9D,IAAID,OAAO,CAACE,MAAM,IAAI,IAAI,EAAE;MAC1B,OAAOtB,kBAAkB,CACvB,CAAC,MAAMoB,OAAO,CAACE,MAAM,CAACC,WAAW,CAAC,CAAC,EAAEP,wBAAwB,EAC7D,iBACF,CAAC;IACH;IACA,OAAOK,SAAS;EAClB,CAAC;EAEDG,WAAWA,CAACC,MAAc,EAAa;IACrC,MAAM,CAACC,EAAE,GAAIC,GAAG,CAAC,GAAGF,MAAM;IAC1B,OAAO;MAAE/B,SAAS,EAAE,CAACgC,EAAE;MAAE9B,UAAU,EAAE,CAAC+B;IAAI,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
|
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { Int } from '../constants.js';
|
|
3
|
+
import { ProtocolParameters, ProtocolParametersOption } from '../protocol-parameters.js';
|
|
3
4
|
import coinAmount from './coin-amount.js';
|
|
5
|
+
import { SerializeAsIsParams } from './interface.js';
|
|
4
6
|
import { Encoded } from '../../../utils/encoder.js';
|
|
5
7
|
import type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';
|
|
6
8
|
import Node from '../../../Node.js';
|
|
7
9
|
/**
|
|
8
10
|
* Calculate gas based on tx type and params
|
|
9
11
|
*/
|
|
10
|
-
export declare function buildGas(builtTx: Encoded.Transaction, unpackTx: typeof unpackTxType, buildTx: typeof buildTxType): number;
|
|
11
|
-
export interface SerializeAettosParams {
|
|
12
|
+
export declare function buildGas(builtTx: Encoded.Transaction, unpackTx: typeof unpackTxType, buildTx: typeof buildTxType, protocolParameters: ProtocolParameters): number;
|
|
13
|
+
export interface SerializeAettosParams extends SerializeAsIsParams {
|
|
12
14
|
rebuildTx: (params: any) => Encoded.Transaction;
|
|
13
15
|
unpackTx: typeof unpackTxType;
|
|
14
16
|
buildTx: typeof buildTxType;
|
|
15
17
|
_computingMinFee?: BigNumber;
|
|
16
18
|
}
|
|
17
19
|
declare const _default: {
|
|
18
|
-
prepare(value: Int | undefined, params: {}, { onNode }: {
|
|
20
|
+
prepare(value: Int | undefined, params: {}, { onNode, protocolParameters }: {
|
|
19
21
|
onNode?: Node;
|
|
20
|
-
}): Promise<Int | undefined>;
|
|
21
|
-
serializeAettos(_value: string | undefined,
|
|
22
|
+
} & ProtocolParametersOption): Promise<Int | undefined>;
|
|
23
|
+
serializeAettos(_value: string | undefined, params: SerializeAettosParams, { _canIncreaseFee, protocolParameters, }: {
|
|
22
24
|
_canIncreaseFee?: boolean;
|
|
23
|
-
}): string;
|
|
25
|
+
} & ProtocolParametersOption): string;
|
|
24
26
|
serialize(value: Parameters<typeof coinAmount.serialize>[0], params: Parameters<typeof coinAmount.serialize>[1] & SerializeAettosParams, options: {
|
|
25
27
|
_canIncreaseFee?: boolean;
|
|
26
|
-
} & Parameters<typeof coinAmount.serialize>[2]): Buffer;
|
|
28
|
+
} & ProtocolParametersOption & Parameters<typeof coinAmount.serialize>[2]): Buffer;
|
|
27
29
|
deserialize(value: Buffer): string;
|
|
28
30
|
};
|
|
29
31
|
export default _default;
|
|
@@ -1,72 +1,70 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { ArgumentError, IllegalArgumentError } from '../../../utils/errors.js';
|
|
3
|
-
import {
|
|
2
|
+
import { ArgumentError, IllegalArgumentError, InternalError } from '../../../utils/errors.js';
|
|
3
|
+
import { Tag } from '../constants.js';
|
|
4
|
+
import { defaultProtocolParameters, getFloorGasPrice, maxOf } from '../protocol-parameters.js';
|
|
4
5
|
import uInt from './u-int.js';
|
|
5
6
|
import coinAmount from './coin-amount.js';
|
|
6
7
|
import { getCachedIncreasedGasPrice } from './gas-price.js';
|
|
7
8
|
import { isKeyOfObject } from '../../../utils/other.js';
|
|
9
|
+
import { serializeAsIsParam } from './interface.js';
|
|
8
10
|
import { decode } from '../../../utils/encoder.js';
|
|
9
|
-
const BASE_GAS = 15000;
|
|
10
|
-
const GAS_PER_BYTE = 20;
|
|
11
|
-
const KEY_BLOCK_INTERVAL = 3;
|
|
12
|
-
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
12
|
+
* Get the base gas
|
|
15
13
|
* @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}
|
|
16
|
-
* @param
|
|
14
|
+
* @param txObject - The unpacked transaction
|
|
15
|
+
* @param protocolParameters - The protocol parameters
|
|
17
16
|
* @returns The base gas
|
|
18
|
-
* @example
|
|
19
|
-
* ```js
|
|
20
|
-
* TX_BASE_GAS(Tag.ChannelForceProgressTx) => 30 * 15000
|
|
21
|
-
* ```
|
|
22
17
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
function getTxBaseGas(txObject, protocolParameters) {
|
|
19
|
+
const {
|
|
20
|
+
tag
|
|
21
|
+
} = txObject;
|
|
22
|
+
const byAbiVersion = protocolParameters.contractTxBaseGas[tag];
|
|
23
|
+
if (byAbiVersion != null) {
|
|
24
|
+
var _txObject$ctVersion$a;
|
|
25
|
+
const abiVersion = (_txObject$ctVersion$a = txObject.ctVersion?.abiVersion) !== null && _txObject$ctVersion$a !== void 0 ? _txObject$ctVersion$a : txObject.abiVersion;
|
|
26
|
+
// read only what the checks in `protocol-parameters.ts` iterate, so that the two can't
|
|
27
|
+
// disagree about what the parameters hold — anything inherited is not a base gas
|
|
28
|
+
const gas = Object.prototype.hasOwnProperty.call(byAbiVersion, abiVersion) ? byAbiVersion[abiVersion] : undefined;
|
|
29
|
+
if (gas != null) return gas;
|
|
30
|
+
// node charges the maximum base gas for an abi version it doesn't know
|
|
31
|
+
const knownAbiVersions = Object.values(byAbiVersion);
|
|
32
|
+
// the maximum of nothing is `-Infinity`, fall through to `txBaseGas` instead
|
|
33
|
+
if (knownAbiVersions.length !== 0) return maxOf(knownAbiVersions);
|
|
34
|
+
}
|
|
35
|
+
const gas = protocolParameters.txBaseGas[tag];
|
|
36
|
+
if (gas == null) throw new InternalError(`Base gas of ${Tag[tag]} is not known`);
|
|
37
|
+
return gas;
|
|
38
|
+
}
|
|
37
39
|
|
|
38
40
|
/**
|
|
39
41
|
* Calculate gas for other types of transactions
|
|
40
42
|
* @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}
|
|
41
43
|
* @param txType - The transaction type
|
|
42
44
|
* @param txSize - The transaction size
|
|
43
|
-
* @
|
|
44
|
-
* @
|
|
45
|
-
* @
|
|
45
|
+
* @param parameters - The transaction parameters
|
|
46
|
+
* @param parameters.relativeTtl - The relative ttl
|
|
47
|
+
* @param parameters.innerTxSize - The size of the inner transaction
|
|
48
|
+
* @param protocolParameters - The protocol parameters
|
|
46
49
|
* @returns The other gas
|
|
47
|
-
* @example
|
|
48
|
-
* ```js
|
|
49
|
-
* TX_OTHER_GAS(Tag.OracleRespondTx, 10, { relativeTtl: 12, innerTxSize: 0 })
|
|
50
|
-
* => 10 * 20 + Math.ceil(32000 * 12 / Math.floor(60 * 24 * 365 / 3))
|
|
51
|
-
* ```
|
|
52
50
|
*/
|
|
53
|
-
|
|
51
|
+
function getTxOtherGas(txType, txSize, {
|
|
54
52
|
relativeTtl,
|
|
55
53
|
innerTxSize
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
54
|
+
}, protocolParameters) {
|
|
55
|
+
const {
|
|
56
|
+
gasPerByte
|
|
57
|
+
} = protocolParameters;
|
|
58
|
+
// the inner transaction of a meta transaction pays for its own bytes in its own fee. The
|
|
59
|
+
// deduction is separate from the state gas below: node reporting a state gas fraction for
|
|
60
|
+
// `GaMetaTx`/`PayingForTx` must not cancel it — that would charge the inner transaction twice
|
|
61
|
+
const isMeta = txType === Tag.GaMetaTx || txType === Tag.PayingForTx;
|
|
62
|
+
const sizeGas = (isMeta ? txSize - innerTxSize : txSize) * gasPerByte;
|
|
63
|
+
// oracle transactions pay a state rent for the time their entry occupies the state tree
|
|
64
|
+
const stateGas = protocolParameters.stateGasPerBlock[txType];
|
|
65
|
+
if (stateGas == null) return sizeGas;
|
|
66
|
+
return sizeGas + Math.ceil(stateGas.part * relativeTtl / stateGas.whole);
|
|
67
|
+
}
|
|
70
68
|
function getOracleRelativeTtl(params) {
|
|
71
69
|
const ttlKeys = {
|
|
72
70
|
[Tag.OracleRegisterTx]: 'oracleTtlValue',
|
|
@@ -84,19 +82,25 @@ function getOracleRelativeTtl(params) {
|
|
|
84
82
|
/**
|
|
85
83
|
* Calculate gas based on tx type and params
|
|
86
84
|
*/
|
|
87
|
-
export function buildGas(builtTx, unpackTx, buildTx) {
|
|
85
|
+
export function buildGas(builtTx, unpackTx, buildTx, protocolParameters) {
|
|
88
86
|
const {
|
|
89
87
|
length
|
|
90
88
|
} = decode(builtTx);
|
|
91
89
|
const txObject = unpackTx(builtTx);
|
|
92
90
|
let innerTxSize = 0;
|
|
93
91
|
if (txObject.tag === Tag.GaMetaTx || txObject.tag === Tag.PayingForTx) {
|
|
94
|
-
|
|
92
|
+
// this rebuild only measures the size of an already signed inner transaction, its values are
|
|
93
|
+
// serialized as they are — see `serializeAsIsParam`
|
|
94
|
+
const innerTx = {
|
|
95
|
+
...txObject.tx.encodedTx,
|
|
96
|
+
[serializeAsIsParam]: true
|
|
97
|
+
};
|
|
98
|
+
innerTxSize = decode(buildTx(innerTx)).length;
|
|
95
99
|
}
|
|
96
|
-
return
|
|
100
|
+
return getTxBaseGas(txObject, protocolParameters) + getTxOtherGas(txObject.tag, length, {
|
|
97
101
|
relativeTtl: getOracleRelativeTtl(txObject),
|
|
98
102
|
innerTxSize
|
|
99
|
-
});
|
|
103
|
+
}, protocolParameters);
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
/**
|
|
@@ -104,12 +108,13 @@ export function buildGas(builtTx, unpackTx, buildTx) {
|
|
|
104
108
|
* @category transaction builder
|
|
105
109
|
* @param rebuildTx - Callback to get built transaction with specific fee
|
|
106
110
|
*/
|
|
107
|
-
function calculateMinFee(rebuildTx, unpackTx, buildTx) {
|
|
111
|
+
function calculateMinFee(rebuildTx, unpackTx, buildTx, protocolParameters) {
|
|
112
|
+
const floorGasPrice = new BigNumber(getFloorGasPrice(protocolParameters).toString());
|
|
108
113
|
let fee = new BigNumber(0);
|
|
109
114
|
let previousFee;
|
|
110
115
|
do {
|
|
111
116
|
previousFee = fee;
|
|
112
|
-
fee =
|
|
117
|
+
fee = floorGasPrice.times(buildGas(rebuildTx(fee), unpackTx, buildTx, protocolParameters));
|
|
113
118
|
} while (!fee.eq(previousFee));
|
|
114
119
|
return fee;
|
|
115
120
|
}
|
|
@@ -121,29 +126,33 @@ const gasPricePrefix = '_gas-price:';
|
|
|
121
126
|
export default {
|
|
122
127
|
...coinAmount,
|
|
123
128
|
async prepare(value, params, {
|
|
124
|
-
onNode
|
|
129
|
+
onNode,
|
|
130
|
+
protocolParameters
|
|
125
131
|
}) {
|
|
126
132
|
if (value != null) return value;
|
|
127
133
|
if (onNode == null) {
|
|
128
134
|
throw new ArgumentError('onNode', 'provided (or provide `fee` instead)', onNode);
|
|
129
135
|
}
|
|
130
|
-
const gasPrice = await getCachedIncreasedGasPrice(onNode);
|
|
136
|
+
const gasPrice = await getCachedIncreasedGasPrice(onNode, protocolParameters);
|
|
131
137
|
if (gasPrice === 0n) return undefined;
|
|
132
138
|
return gasPricePrefix + gasPrice;
|
|
133
139
|
},
|
|
134
|
-
serializeAettos(_value, {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
buildTx,
|
|
138
|
-
_computingMinFee
|
|
139
|
-
}, {
|
|
140
|
-
_canIncreaseFee
|
|
140
|
+
serializeAettos(_value, params, {
|
|
141
|
+
_canIncreaseFee,
|
|
142
|
+
protocolParameters = defaultProtocolParameters
|
|
141
143
|
}) {
|
|
144
|
+
const {
|
|
145
|
+
rebuildTx,
|
|
146
|
+
unpackTx,
|
|
147
|
+
buildTx,
|
|
148
|
+
_computingMinFee
|
|
149
|
+
} = params;
|
|
142
150
|
if (_computingMinFee != null) return _computingMinFee.toFixed();
|
|
151
|
+
if (params[serializeAsIsParam] === true && _value != null) return new BigNumber(_value).toFixed();
|
|
143
152
|
const minFee = calculateMinFee(fee => rebuildTx({
|
|
144
153
|
_computingMinFee: fee
|
|
145
|
-
}), unpackTx, buildTx);
|
|
146
|
-
const value = _value?.startsWith(gasPricePrefix) === true ? minFee.dividedBy(
|
|
154
|
+
}), unpackTx, buildTx, protocolParameters);
|
|
155
|
+
const value = _value?.startsWith(gasPricePrefix) === true ? minFee.dividedBy(getFloorGasPrice(protocolParameters).toString()).times(_value.replace(gasPricePrefix, '')) : new BigNumber(_value !== null && _value !== void 0 ? _value : minFee);
|
|
147
156
|
if (minFee.gt(value)) {
|
|
148
157
|
if (_canIncreaseFee === true) return minFee.toFixed();
|
|
149
158
|
throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger than ${minFee}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fee.js","names":["BigNumber","ArgumentError","IllegalArgumentError","MIN_GAS_PRICE","Tag","uInt","coinAmount","getCachedIncreasedGasPrice","isKeyOfObject","decode","BASE_GAS","GAS_PER_BYTE","KEY_BLOCK_INTERVAL","TX_BASE_GAS","txType","_feeFactors","feeFactors","ChannelForceProgressTx","ChannelOffChainTx","ContractCreateTx","ContractCallTx","GaAttachTx","GaMetaTx","PayingForTx","factor","TX_OTHER_GAS","txSize","relativeTtl","innerTxSize","OracleRegisterTx","OracleExtendTx","OracleQueryTx","OracleRespondTx","Math","ceil","floor","getOracleRelativeTtl","params","ttlKeys","tag","buildGas","builtTx","unpackTx","buildTx","length","txObject","tx","encodedTx","calculateMinFee","rebuildTx","fee","previousFee","times","eq","gasPricePrefix","prepare","value","onNode","gasPrice","undefined","serializeAettos","_value","_computingMinFee","_canIncreaseFee","toFixed","minFee","startsWith","dividedBy","replace","gt","toString","serialize","options","call"],"sources":["../../../../src/tx/builder/field-types/fee.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { ArgumentError, IllegalArgumentError } from '../../../utils/errors.js';\nimport { Int, MIN_GAS_PRICE, Tag } from '../constants.js';\nimport uInt from './u-int.js';\nimport coinAmount from './coin-amount.js';\nimport { getCachedIncreasedGasPrice } from './gas-price.js';\nimport { isKeyOfObject } from '../../../utils/other.js';\nimport { decode, Encoded } from '../../../utils/encoder.js';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';\nimport Node from '../../../Node.js';\n\nconst BASE_GAS = 15000;\nconst GAS_PER_BYTE = 20;\nconst KEY_BLOCK_INTERVAL = 3;\n\n/**\n * Calculate the base gas\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txType - The transaction type\n * @returns The base gas\n * @example\n * ```js\n * TX_BASE_GAS(Tag.ChannelForceProgressTx) => 30 * 15000\n * ```\n */\nconst TX_BASE_GAS = (txType: Tag): number => {\n const feeFactors = {\n [Tag.ChannelForceProgressTx]: 30,\n [Tag.ChannelOffChainTx]: 0,\n [Tag.ContractCreateTx]: 5,\n [Tag.ContractCallTx]: 12,\n [Tag.GaAttachTx]: 5,\n [Tag.GaMetaTx]: 5,\n [Tag.PayingForTx]: 1 / 5,\n } as const;\n const factor = feeFactors[txType as keyof typeof feeFactors] ?? 1;\n return factor * BASE_GAS;\n};\n\n/**\n * Calculate gas for other types of transactions\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txType - The transaction type\n * @param txSize - The transaction size\n * @returns parameters - The transaction parameters\n * @returns parameters.relativeTtl - The relative ttl\n * @returns parameters.innerTxSize - The size of the inner transaction\n * @returns The other gas\n * @example\n * ```js\n * TX_OTHER_GAS(Tag.OracleRespondTx, 10, { relativeTtl: 12, innerTxSize: 0 })\n * => 10 * 20 + Math.ceil(32000 * 12 / Math.floor(60 * 24 * 365 / 3))\n * ```\n */\nconst TX_OTHER_GAS = (\n txType: Tag,\n txSize: number,\n { relativeTtl, innerTxSize }: { relativeTtl: number; innerTxSize: number },\n): number => {\n switch (txType) {\n case Tag.OracleRegisterTx:\n case Tag.OracleExtendTx:\n case Tag.OracleQueryTx:\n case Tag.OracleRespondTx:\n return (\n txSize * GAS_PER_BYTE +\n Math.ceil((32000 * relativeTtl) / Math.floor((60 * 24 * 365) / KEY_BLOCK_INTERVAL))\n );\n case Tag.GaMetaTx:\n case Tag.PayingForTx:\n return (txSize - innerTxSize) * GAS_PER_BYTE;\n default:\n return txSize * GAS_PER_BYTE;\n }\n};\n\nfunction getOracleRelativeTtl(params: any): number {\n const ttlKeys = {\n [Tag.OracleRegisterTx]: 'oracleTtlValue',\n [Tag.OracleExtendTx]: 'oracleTtlValue',\n [Tag.OracleQueryTx]: 'queryTtlValue',\n [Tag.OracleRespondTx]: 'responseTtlValue',\n } as const;\n\n const { tag } = params;\n if (!isKeyOfObject(tag, ttlKeys)) return 1;\n return params[ttlKeys[tag]];\n}\n\n/**\n * Calculate gas based on tx type and params\n */\nexport function buildGas(\n builtTx: Encoded.Transaction,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n): number {\n const { length } = decode(builtTx);\n const txObject = unpackTx(builtTx);\n\n let innerTxSize = 0;\n if (txObject.tag === Tag.GaMetaTx || txObject.tag === Tag.PayingForTx) {\n innerTxSize = decode(buildTx(txObject.tx.encodedTx)).length;\n }\n\n return (\n TX_BASE_GAS(txObject.tag) +\n TX_OTHER_GAS(txObject.tag, length, {\n relativeTtl: getOracleRelativeTtl(txObject),\n innerTxSize,\n })\n );\n}\n\n/**\n * Calculate min fee\n * @category transaction builder\n * @param rebuildTx - Callback to get built transaction with specific fee\n */\nfunction calculateMinFee(\n rebuildTx: (value: BigNumber) => Encoded.Transaction,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n): BigNumber {\n let fee = new BigNumber(0);\n let previousFee;\n do {\n previousFee = fee;\n fee = new BigNumber(MIN_GAS_PRICE).times(buildGas(rebuildTx(fee), unpackTx, buildTx));\n } while (!fee.eq(previousFee));\n return fee;\n}\n\n// TODO: Get rid of this workaround. Transaction builder can't accept/return gas price instead of\n// fee because it may get a decimal gas price. So, it should accept the optional `gasPrice` even\n// if it is not a contract-related transaction. And use this `gasPrice` to calculate `fee`.\nconst gasPricePrefix = '_gas-price:';\n\nexport interface SerializeAettosParams {\n rebuildTx: (params: any) => Encoded.Transaction;\n unpackTx: typeof unpackTxType;\n buildTx: typeof buildTxType;\n _computingMinFee?: BigNumber;\n}\n\nexport default {\n ...coinAmount,\n\n async prepare(\n value: Int | undefined,\n params: {},\n { onNode }: { onNode?: Node },\n ): Promise<Int | undefined> {\n if (value != null) return value;\n if (onNode == null) {\n throw new ArgumentError('onNode', 'provided (or provide `fee` instead)', onNode);\n }\n const gasPrice = await getCachedIncreasedGasPrice(onNode);\n if (gasPrice === 0n) return undefined;\n return gasPricePrefix + gasPrice;\n },\n\n serializeAettos(\n _value: string | undefined,\n { rebuildTx, unpackTx, buildTx, _computingMinFee }: SerializeAettosParams,\n { _canIncreaseFee }: { _canIncreaseFee?: boolean },\n ): string {\n if (_computingMinFee != null) return _computingMinFee.toFixed();\n const minFee = calculateMinFee(\n (fee) => rebuildTx({ _computingMinFee: fee }),\n unpackTx,\n buildTx,\n );\n const value =\n _value?.startsWith(gasPricePrefix) === true\n ? minFee.dividedBy(MIN_GAS_PRICE).times(_value.replace(gasPricePrefix, ''))\n : new BigNumber(_value ?? minFee);\n if (minFee.gt(value)) {\n if (_canIncreaseFee === true) return minFee.toFixed();\n throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger than ${minFee}`);\n }\n return value.toFixed();\n },\n\n serialize(\n value: Parameters<typeof coinAmount.serialize>[0],\n params: Parameters<typeof coinAmount.serialize>[1] & SerializeAettosParams,\n options: { _canIncreaseFee?: boolean } & Parameters<typeof coinAmount.serialize>[2],\n ): Buffer {\n if (typeof value === 'string' && value.startsWith(gasPricePrefix)) {\n return uInt.serialize(this.serializeAettos(value, params, options));\n }\n return coinAmount.serialize.call(this, value, params, options);\n },\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,cAAc;AACpC,SAASC,aAAa,EAAEC,oBAAoB,QAAQ,0BAA0B;AAC9E,SAAcC,aAAa,EAAEC,GAAG,QAAQ,iBAAiB;AACzD,OAAOC,IAAI,MAAM,YAAY;AAC7B,OAAOC,UAAU,MAAM,kBAAkB;AACzC,SAASC,0BAA0B,QAAQ,gBAAgB;AAC3D,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,MAAM,QAAiB,2BAA2B;AAI3D,MAAMC,QAAQ,GAAG,KAAK;AACtB,MAAMC,YAAY,GAAG,EAAE;AACvB,MAAMC,kBAAkB,GAAG,CAAC;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAIC,MAAW,IAAa;EAAA,IAAAC,WAAA;EAC3C,MAAMC,UAAU,GAAG;IACjB,CAACZ,GAAG,CAACa,sBAAsB,GAAG,EAAE;IAChC,CAACb,GAAG,CAACc,iBAAiB,GAAG,CAAC;IAC1B,CAACd,GAAG,CAACe,gBAAgB,GAAG,CAAC;IACzB,CAACf,GAAG,CAACgB,cAAc,GAAG,EAAE;IACxB,CAAChB,GAAG,CAACiB,UAAU,GAAG,CAAC;IACnB,CAACjB,GAAG,CAACkB,QAAQ,GAAG,CAAC;IACjB,CAAClB,GAAG,CAACmB,WAAW,GAAG,CAAC,GAAG;EACzB,CAAU;EACV,MAAMC,MAAM,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E,CAAC;IACzF;IACA,OAAOT,KAAK,CAACQ,OAAO,CAAC,CAAC;EACxB,CAAC;EAEDO,SAASA,CACPf,KAAiD,EACjDnB,MAA0E,EAC1EmC,OAAmF,EAC3E;IACR,IAAI,OAAOhB,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACU,UAAU,CAACZ,cAAc,CAAC,EAAE;MACjE,OAAOjD,IAAI,CAACkE,SAAS,CAAC,IAAI,CAACX,eAAe,CAACJ,KAAK,EAAEnB,MAAM,EAAEmC,OAAO,CAAC,CAAC;IACrE;IACA,OAAOlE,UAAU,CAACiE,SAAS,CAACE,IAAI,CAAC,IAAI,EAAEjB,KAAK,EAAEnB,MAAM,EAAEmC,OAAO,CAAC;EAChE;AACF,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fee.js","names":["BigNumber","ArgumentError","IllegalArgumentError","InternalError","Tag","defaultProtocolParameters","getFloorGasPrice","maxOf","uInt","coinAmount","getCachedIncreasedGasPrice","isKeyOfObject","serializeAsIsParam","decode","getTxBaseGas","txObject","protocolParameters","tag","byAbiVersion","contractTxBaseGas","_txObject$ctVersion$a","abiVersion","ctVersion","gas","Object","prototype","hasOwnProperty","call","undefined","knownAbiVersions","values","length","txBaseGas","getTxOtherGas","txType","txSize","relativeTtl","innerTxSize","gasPerByte","isMeta","GaMetaTx","PayingForTx","sizeGas","stateGas","stateGasPerBlock","Math","ceil","part","whole","getOracleRelativeTtl","params","ttlKeys","OracleRegisterTx","OracleExtendTx","OracleQueryTx","OracleRespondTx","buildGas","builtTx","unpackTx","buildTx","innerTx","tx","encodedTx","calculateMinFee","rebuildTx","floorGasPrice","toString","fee","previousFee","times","eq","gasPricePrefix","prepare","value","onNode","gasPrice","serializeAettos","_value","_canIncreaseFee","_computingMinFee","toFixed","minFee","startsWith","dividedBy","replace","gt","serialize","options"],"sources":["../../../../src/tx/builder/field-types/fee.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { ArgumentError, IllegalArgumentError, InternalError } from '../../../utils/errors.js';\nimport { Int, Tag } from '../constants.js';\nimport {\n defaultProtocolParameters,\n getFloorGasPrice,\n maxOf,\n ProtocolParameters,\n ProtocolParametersOption,\n} from '../protocol-parameters.js';\nimport uInt from './u-int.js';\nimport coinAmount from './coin-amount.js';\nimport { getCachedIncreasedGasPrice } from './gas-price.js';\nimport { isKeyOfObject } from '../../../utils/other.js';\nimport { serializeAsIsParam, SerializeAsIsParams } from './interface.js';\nimport { decode, Encoded } from '../../../utils/encoder.js';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index.js';\nimport Node from '../../../Node.js';\n\n/**\n * Get the base gas\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txObject - The unpacked transaction\n * @param protocolParameters - The protocol parameters\n * @returns The base gas\n */\nfunction getTxBaseGas(txObject: any, protocolParameters: ProtocolParameters): number {\n const { tag }: { tag: Tag } = txObject;\n const byAbiVersion = protocolParameters.contractTxBaseGas[tag];\n if (byAbiVersion != null) {\n const abiVersion = txObject.ctVersion?.abiVersion ?? txObject.abiVersion;\n // read only what the checks in `protocol-parameters.ts` iterate, so that the two can't\n // disagree about what the parameters hold — anything inherited is not a base gas\n const gas = Object.prototype.hasOwnProperty.call(byAbiVersion, abiVersion)\n ? byAbiVersion[abiVersion as keyof typeof byAbiVersion]\n : undefined;\n if (gas != null) return gas;\n // node charges the maximum base gas for an abi version it doesn't know\n const knownAbiVersions = Object.values(byAbiVersion);\n // the maximum of nothing is `-Infinity`, fall through to `txBaseGas` instead\n if (knownAbiVersions.length !== 0) return maxOf(knownAbiVersions);\n }\n const gas = protocolParameters.txBaseGas[tag];\n if (gas == null) throw new InternalError(`Base gas of ${Tag[tag]} is not known`);\n return gas;\n}\n\n/**\n * Calculate gas for other types of transactions\n * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}\n * @param txType - The transaction type\n * @param txSize - The transaction size\n * @param parameters - The transaction parameters\n * @param parameters.relativeTtl - The relative ttl\n * @param parameters.innerTxSize - The size of the inner transaction\n * @param protocolParameters - The protocol parameters\n * @returns The other gas\n */\nfunction getTxOtherGas(\n txType: Tag,\n txSize: number,\n { relativeTtl, innerTxSize }: { relativeTtl: number; innerTxSize: number },\n protocolParameters: ProtocolParameters,\n): number {\n const { gasPerByte } = protocolParameters;\n // the inner transaction of a meta transaction pays for its own bytes in its own fee. The\n // deduction is separate from the state gas below: node reporting a state gas fraction for\n // `GaMetaTx`/`PayingForTx` must not cancel it — that would charge the inner transaction twice\n const isMeta = txType === Tag.GaMetaTx || txType === Tag.PayingForTx;\n const sizeGas = (isMeta ? txSize - innerTxSize : txSize) * gasPerByte;\n // oracle transactions pay a state rent for the time their entry occupies the state tree\n const stateGas = protocolParameters.stateGasPerBlock[txType];\n if (stateGas == null) return sizeGas;\n return sizeGas + Math.ceil((stateGas.part * relativeTtl) / stateGas.whole);\n}\n\nfunction getOracleRelativeTtl(params: any): number {\n const ttlKeys = {\n [Tag.OracleRegisterTx]: 'oracleTtlValue',\n [Tag.OracleExtendTx]: 'oracleTtlValue',\n [Tag.OracleQueryTx]: 'queryTtlValue',\n [Tag.OracleRespondTx]: 'responseTtlValue',\n } as const;\n\n const { tag } = params;\n if (!isKeyOfObject(tag, ttlKeys)) return 1;\n return params[ttlKeys[tag]];\n}\n\n/**\n * Calculate gas based on tx type and params\n */\nexport function buildGas(\n builtTx: Encoded.Transaction,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n protocolParameters: ProtocolParameters,\n): number {\n const { length } = decode(builtTx);\n const txObject = unpackTx(builtTx);\n\n let innerTxSize = 0;\n if (txObject.tag === Tag.GaMetaTx || txObject.tag === Tag.PayingForTx) {\n // this rebuild only measures the size of an already signed inner transaction, its values are\n // serialized as they are — see `serializeAsIsParam`\n const innerTx = { ...txObject.tx.encodedTx, [serializeAsIsParam]: true };\n innerTxSize = decode(buildTx(innerTx as Parameters<typeof buildTx>[0])).length;\n }\n\n return (\n getTxBaseGas(txObject, protocolParameters) +\n getTxOtherGas(\n txObject.tag,\n length,\n { relativeTtl: getOracleRelativeTtl(txObject), innerTxSize },\n protocolParameters,\n )\n );\n}\n\n/**\n * Calculate min fee\n * @category transaction builder\n * @param rebuildTx - Callback to get built transaction with specific fee\n */\nfunction calculateMinFee(\n rebuildTx: (value: BigNumber) => Encoded.Transaction,\n unpackTx: typeof unpackTxType,\n buildTx: typeof buildTxType,\n protocolParameters: ProtocolParameters,\n): BigNumber {\n const floorGasPrice = new BigNumber(getFloorGasPrice(protocolParameters).toString());\n let fee = new BigNumber(0);\n let previousFee;\n do {\n previousFee = fee;\n fee = floorGasPrice.times(buildGas(rebuildTx(fee), unpackTx, buildTx, protocolParameters));\n } while (!fee.eq(previousFee));\n return fee;\n}\n\n// TODO: Get rid of this workaround. Transaction builder can't accept/return gas price instead of\n// fee because it may get a decimal gas price. So, it should accept the optional `gasPrice` even\n// if it is not a contract-related transaction. And use this `gasPrice` to calculate `fee`.\nconst gasPricePrefix = '_gas-price:';\n\nexport interface SerializeAettosParams extends SerializeAsIsParams {\n rebuildTx: (params: any) => Encoded.Transaction;\n unpackTx: typeof unpackTxType;\n buildTx: typeof buildTxType;\n _computingMinFee?: BigNumber;\n}\n\nexport default {\n ...coinAmount,\n\n async prepare(\n value: Int | undefined,\n params: {},\n { onNode, protocolParameters }: { onNode?: Node } & ProtocolParametersOption,\n ): Promise<Int | undefined> {\n if (value != null) return value;\n if (onNode == null) {\n throw new ArgumentError('onNode', 'provided (or provide `fee` instead)', onNode);\n }\n const gasPrice = await getCachedIncreasedGasPrice(onNode, protocolParameters);\n if (gasPrice === 0n) return undefined;\n return gasPricePrefix + gasPrice;\n },\n\n serializeAettos(\n _value: string | undefined,\n params: SerializeAettosParams,\n {\n _canIncreaseFee,\n protocolParameters = defaultProtocolParameters,\n }: { _canIncreaseFee?: boolean } & ProtocolParametersOption,\n ): string {\n const { rebuildTx, unpackTx, buildTx, _computingMinFee } = params;\n if (_computingMinFee != null) return _computingMinFee.toFixed();\n if (params[serializeAsIsParam] === true && _value != null)\n return new BigNumber(_value).toFixed();\n const minFee = calculateMinFee(\n (fee) => rebuildTx({ _computingMinFee: fee }),\n unpackTx,\n buildTx,\n protocolParameters,\n );\n const value =\n _value?.startsWith(gasPricePrefix) === true\n ? minFee\n .dividedBy(getFloorGasPrice(protocolParameters).toString())\n .times(_value.replace(gasPricePrefix, ''))\n : new BigNumber(_value ?? minFee);\n if (minFee.gt(value)) {\n if (_canIncreaseFee === true) return minFee.toFixed();\n throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger than ${minFee}`);\n }\n return value.toFixed();\n },\n\n serialize(\n value: Parameters<typeof coinAmount.serialize>[0],\n params: Parameters<typeof coinAmount.serialize>[1] & SerializeAettosParams,\n options: { _canIncreaseFee?: boolean } & ProtocolParametersOption &\n Parameters<typeof coinAmount.serialize>[2],\n ): Buffer {\n if (typeof value === 'string' && value.startsWith(gasPricePrefix)) {\n return uInt.serialize(this.serializeAettos(value, params, options));\n }\n return coinAmount.serialize.call(this, value, params, options);\n },\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,cAAc;AACpC,SAASC,aAAa,EAAEC,oBAAoB,EAAEC,aAAa,QAAQ,0BAA0B;AAC7F,SAAcC,GAAG,QAAQ,iBAAiB;AAC1C,SACEC,yBAAyB,EACzBC,gBAAgB,EAChBC,KAAK,QAGA,2BAA2B;AAClC,OAAOC,IAAI,MAAM,YAAY;AAC7B,OAAOC,UAAU,MAAM,kBAAkB;AACzC,SAASC,0BAA0B,QAAQ,gBAAgB;AAC3D,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,kBAAkB,QAA6B,gBAAgB;AACxE,SAASC,MAAM,QAAiB,2BAA2B;AAI3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,YAAYA,CAACC,QAAa,EAAEC,kBAAsC,EAAU;EACnF,MAAM;IAAEC;EAAkB,CAAC,GAAGF,QAAQ;EACtC,MAAMG,YAAY,GAAGF,kBA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AC,wBAAwBe,MAAM,EAAE,CAAC;IACzF;IACA,OAAOR,KAAK,CAACO,OAAO,CAAC,CAAC;EACxB,CAAC;EAEDM,SAASA,CACPb,KAAiD,EACjDvB,MAA0E,EAC1EqC,OAC4C,EACpC;IACR,IAAI,OAAOd,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACS,UAAU,CAACX,cAAc,CAAC,EAAE;MACjE,OAAO/D,IAAI,CAAC8E,SAAS,CAAC,IAAI,CAACV,eAAe,CAACH,KAAK,EAAEvB,MAAM,EAAEqC,OAAO,CAAC,CAAC;IACrE;IACA,OAAO9E,UAAU,CAAC6E,SAAS,CAAC3D,IAAI,CAAC,IAAI,EAAE8C,KAAK,EAAEvB,MAAM,EAAEqC,OAAO,CAAC;EAChE;AACF,CAAC","ignoreList":[]}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Tag } from '../constants.js';
|
|
2
|
+
import { 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
|
declare const _default: {
|
|
4
|
-
serialize(_value: number | undefined,
|
|
6
|
+
serialize(_value: number | undefined, params: {
|
|
5
7
|
tag: Tag;
|
|
6
8
|
rebuildTx: (params: any) => any;
|
|
7
9
|
unpackTx: typeof unpackTxType;
|
|
8
10
|
buildTx: typeof buildTxType;
|
|
9
11
|
_computingGasLimit?: number;
|
|
10
|
-
}, { gasMax }: {
|
|
12
|
+
} & SerializeAsIsParams, { gasMax, protocolParameters, }: {
|
|
11
13
|
gasMax?: number;
|
|
12
|
-
}): Buffer;
|
|
14
|
+
} & ProtocolParametersOption): Buffer;
|
|
13
15
|
deserialize(value: Buffer): number;
|
|
14
16
|
};
|
|
15
17
|
export default _default;
|