@aeternity/aepp-sdk 13.3.0 → 13.3.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.js +1 -1
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +2 -2
- package/dist/aepp-sdk.js.map +1 -1
- package/es/Node.mjs +1 -1
- package/es/Node.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.mjs +1 -1
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Node.ts +1 -1
- package/src/tx/builder/field-types/gas-price.ts +70 -70
package/es/Node.mjs
CHANGED
|
@@ -76,7 +76,7 @@ export default class Node extends NodeTransformed {
|
|
|
76
76
|
// eslint-disable-next-line constructor-super
|
|
77
77
|
super(url, {
|
|
78
78
|
allowInsecureConnection: true,
|
|
79
|
-
additionalPolicies: [...(ignoreVersion ? [] : [genVersionCheckPolicy('node', getVersion, '6.2.0', '
|
|
79
|
+
additionalPolicies: [...(ignoreVersion ? [] : [genVersionCheckPolicy('node', getVersion, '6.2.0', '8.0.0')]), genRequestQueuesPolicy(), genCombineGetRequestsPolicy(), genRetryOnFailurePolicy(retryCount, retryOverallDelay), genErrorFormatterPolicy(body => [' ', body.reason, body.errorCode == null ? '' : ` (${body.errorCode})`].join(''))],
|
|
80
80
|
...options
|
|
81
81
|
});
|
|
82
82
|
_classPrivateFieldInitSpec(this, _cachedStatusPromise, {
|
package/es/Node.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.mjs","names":["BigNumber","userAgentPolicyName","setClientRequestIdPolicyName","genRequestQueuesPolicy","genCombineGetRequestsPolicy","genErrorFormatterPolicy","genVersionCheckPolicy","genRetryOnFailurePolicy","Node","NodeApi","mapObject","UnsupportedVersionError","ConsensusProtocolVersion","bigIntPropertyNames","numberPropertyNames","_mapData","WeakSet","_encodeArg","_decodeRes","NodeTransformed","constructor","args","_classPrivateMethodInitSpec","sendOperationRequest","operationArguments","operationSpec","key","value","_classPrivateMethodGet","_encodeArg2","call","_decodeRes2","_mapData2","data","transform","Array","isArray","map","d","some","k","bigInt","number","toFixed","toString","BigInt","_cachedStatusPromise","WeakMap","url","ignoreVersion","retryCount","retryOverallDelay","options","getVersion","opts","_getCachedStatus","nodeVersion","allowInsecureConnection","additionalPolicies","body","reason","errorCode","join","_classPrivateFieldInitSpec","writable","pipeline","removePolicy","name","intAsString","_classPrivateFieldGet","getStatus","promise","then","_classPrivateFieldSet","getNetworkId","networkId","getNodeInfo","nodeNetworkId","protocols","topBlockHeight","consensusProtocolVersion","filter","effectiveAtHeight","reduce","acc","p","version","versions","Object","values","el","geVersion","Math","min","ltVersion","max","$host"],"sources":["../src/Node.ts"],"sourcesContent":["// eslint-disable-next-line max-classes-per-file\nimport BigNumber from 'bignumber.js';\nimport { OperationArguments, OperationOptions, OperationSpec } from '@azure/core-client';\nimport { userAgentPolicyName, setClientRequestIdPolicyName } from '@azure/core-rest-pipeline';\nimport {\n genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy,\n genVersionCheckPolicy, genRetryOnFailurePolicy,\n} from './utils/autorest';\nimport { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node';\nimport { mapObject } from './utils/other';\nimport { UnsupportedVersionError } from './utils/errors';\nimport { Encoded } from './utils/encoder';\nimport { ConsensusProtocolVersion } from './tx/builder/constants';\n\nconst bigIntPropertyNames = [\n 'balance', 'queryFee', 'fee', 'amount', 'nameFee', 'channelAmount',\n 'initiatorAmount', 'responderAmount', 'channelReserve', 'initiatorAmountFinal',\n 'responderAmountFinal', 'gasPrice', 'minGasPrice', 'deposit',\n] as const;\n\nconst numberPropertyNames = [\n 'time', 'gas', 'gasUsed', 'nameSalt',\n 'nonce', 'nextNonce', 'height', 'blockHeight', 'topBlockHeight',\n 'ttl', 'nameTtl', 'clientTtl',\n 'inbound', 'outbound', 'peerCount', 'pendingTransactionsCount', 'effectiveAtHeight',\n 'version', 'solutions', 'round', 'minutes', 'utilization', 'difficulty', 'hashrate',\n] as const;\n\nclass NodeTransformed extends NodeApi {\n override async sendOperationRequest(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n ): Promise<any> {\n const args = mapObject(\n operationArguments,\n ([key, value]) => [key, this.#encodeArg(value)],\n ) as OperationArguments;\n return this.#decodeRes(await super.sendOperationRequest(args, operationSpec));\n }\n\n #mapData(data: any, transform: {\n bigInt: (v: any) => any;\n number: (v: any) => any;\n }): unknown {\n if (Array.isArray(data)) return data.map((d) => this.#mapData(d, transform));\n if (data != null && typeof data === 'object') {\n return mapObject(data, ([key, value]) => {\n if (value == null) return [key, value];\n if (bigIntPropertyNames.some((k) => k === key)) return [key, transform.bigInt(value)];\n if (numberPropertyNames.some((k) => k === key)) return [key, transform.number(value)];\n return [key, this.#mapData(value, transform)];\n });\n }\n return data;\n }\n\n #encodeArg(data: any): any {\n return this.#mapData(data, {\n bigInt: (value) => {\n if (value instanceof BigNumber) return value.toFixed();\n return value.toString();\n },\n number: (value) => value.toString(),\n });\n }\n\n #decodeRes(data: any): any {\n return this.#mapData(data, {\n bigInt: (value) => BigInt(value),\n number: (value) => +value,\n });\n }\n}\n\ntype BigIntPropertyNames = typeof bigIntPropertyNames[number];\ntype NumberPropertyNames = typeof numberPropertyNames[number];\ntype PreserveOptional<NewType, OrigType> =\n OrigType extends undefined ? NewType | undefined : NewType;\nexport type TransformNodeType<Type> =\n Type extends (...args: infer Args) => infer Ret\n ? (...args: TransformNodeType<Args>) => TransformNodeType<Ret>\n : Type extends [infer Item, ...infer Rest]\n ? [TransformNodeType<Item>, ...TransformNodeType<Rest>]\n : Type extends Array<infer Item>\n ? Array<TransformNodeType<Item>>\n : Type extends Promise<infer T>\n ? Promise<TransformNodeType<T>>\n : Type extends { [P in any]: any }\n ? {\n [Property in keyof Type]:\n Property extends BigIntPropertyNames\n ? PreserveOptional<bigint, Type[Property]>\n : Property extends NumberPropertyNames\n ? PreserveOptional<number, Type[Property]>\n : Property extends 'txHash'\n ? PreserveOptional<Encoded.TxHash, Type[Property]>\n : Property extends 'bytecode'\n ? PreserveOptional<Encoded.ContractBytearray, Type[Property]>\n : TransformNodeType<Type[Property]>\n }\n : Type;\ntype NodeTransformedApi = new (...args: ConstructorParameters<typeof NodeApi>) => {\n [Name in keyof InstanceType<typeof NodeApi>]:\n Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest'\n ? NodeApi[Name] : TransformNodeType<NodeApi[Name]>\n};\n\ninterface NodeInfo {\n url: string;\n nodeNetworkId: string;\n version: string;\n consensusProtocolVersion: ConsensusProtocolVersion;\n}\n\nexport default class Node extends (NodeTransformed as unknown as NodeTransformedApi) {\n /**\n * @param url - Url for node API\n * @param options - Options\n * @param options.ignoreVersion - Don't ensure that the node is supported\n * @param options.retryCount - Amount of extra requests to do in case of failure\n * @param options.retryOverallDelay - Time in ms to wait between all retries\n */\n constructor(\n url: string,\n {\n ignoreVersion = false, retryCount = 3, retryOverallDelay = 800, ...options\n }: NodeOptionalParams & {\n ignoreVersion?: boolean;\n retryCount?: number;\n retryOverallDelay?: number;\n } = {},\n ) {\n const getVersion = async (opts: OperationOptions): Promise<string> => (\n (await this._getCachedStatus(opts)).nodeVersion\n );\n // eslint-disable-next-line constructor-super\n super(url, {\n allowInsecureConnection: true,\n additionalPolicies: [\n ...ignoreVersion ? [] : [genVersionCheckPolicy('node', getVersion, '6.2.0', '7.0.0')],\n genRequestQueuesPolicy(),\n genCombineGetRequestsPolicy(),\n genRetryOnFailurePolicy(retryCount, retryOverallDelay),\n genErrorFormatterPolicy((body: ErrorModel) => [\n ' ', body.reason, body.errorCode == null ? '' : ` (${body.errorCode})`,\n ].join('')),\n ],\n ...options,\n });\n this.pipeline.removePolicy({ name: userAgentPolicyName });\n this.pipeline.removePolicy({ name: setClientRequestIdPolicyName });\n // TODO: use instead our retry policy\n this.pipeline.removePolicy({ name: 'defaultRetryPolicy' });\n this.intAsString = true;\n }\n\n #cachedStatusPromise?: ReturnType<Node['getStatus']>;\n\n async _getCachedStatus(options?: OperationOptions): ReturnType<Node['getStatus']> {\n if (this.#cachedStatusPromise != null) return this.#cachedStatusPromise;\n return this.getStatus(options);\n }\n\n // eslint-disable-next-line rulesdir/tsdoc-syntax\n /** @ts-expect-error use code generation to create node class? */\n override async getStatus(\n ...args: Parameters<InstanceType<NodeTransformedApi>['getStatus']>\n ): ReturnType<InstanceType<NodeTransformedApi>['getStatus']> {\n const promise = super.getStatus(...args);\n promise.then(() => { this.#cachedStatusPromise = promise; }, () => {});\n return promise;\n }\n\n /**\n * Returns network ID provided by node.\n * This method won't do extra requests on subsequent calls.\n */\n async getNetworkId(): Promise<string> {\n return (await this._getCachedStatus()).networkId;\n }\n\n async getNodeInfo(): Promise<NodeInfo> {\n const {\n nodeVersion,\n networkId: nodeNetworkId,\n protocols,\n topBlockHeight,\n } = await this.getStatus();\n\n const consensusProtocolVersion = protocols\n .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)\n .reduce(\n (acc, p) => (p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc),\n { effectiveAtHeight: -1, version: 0 },\n )\n .version;\n if (ConsensusProtocolVersion[consensusProtocolVersion] == null) {\n const version = consensusProtocolVersion.toString();\n const versions = Object.values(ConsensusProtocolVersion)\n .filter((el) => typeof el === 'number').map((el) => +el);\n const geVersion = Math.min(...versions).toString();\n const ltVersion = (Math.max(...versions) + 1).toString();\n throw new UnsupportedVersionError('consensus protocol', version, geVersion, ltVersion);\n }\n\n return {\n url: this.$host,\n nodeNetworkId,\n version: nodeVersion,\n consensusProtocolVersion,\n };\n }\n}\n"],"mappings":";;;;;;;AAAA;AACA,OAAOA,SAAS,MAAM,cAAc;AAEpC,SAASC,mBAAmB,EAAEC,4BAA4B,QAAQ,2BAA2B;AAAC,SAE5FC,sBA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ACbS,OAAO,EAAE9B,WAAW;MACpBwB;IACF,CAAC;EACH;AACF"}
|
|
1
|
+
{"version":3,"file":"Node.mjs","names":["BigNumber","userAgentPolicyName","setClientRequestIdPolicyName","genRequestQueuesPolicy","genCombineGetRequestsPolicy","genErrorFormatterPolicy","genVersionCheckPolicy","genRetryOnFailurePolicy","Node","NodeApi","mapObject","UnsupportedVersionError","ConsensusProtocolVersion","bigIntPropertyNames","numberPropertyNames","_mapData","WeakSet","_encodeArg","_decodeRes","NodeTransformed","constructor","args","_classPrivateMethodInitSpec","sendOperationRequest","operationArguments","operationSpec","key","value","_classPrivateMethodGet","_encodeArg2","call","_decodeRes2","_mapData2","data","transform","Array","isArray","map","d","some","k","bigInt","number","toFixed","toString","BigInt","_cachedStatusPromise","WeakMap","url","ignoreVersion","retryCount","retryOverallDelay","options","getVersion","opts","_getCachedStatus","nodeVersion","allowInsecureConnection","additionalPolicies","body","reason","errorCode","join","_classPrivateFieldInitSpec","writable","pipeline","removePolicy","name","intAsString","_classPrivateFieldGet","getStatus","promise","then","_classPrivateFieldSet","getNetworkId","networkId","getNodeInfo","nodeNetworkId","protocols","topBlockHeight","consensusProtocolVersion","filter","effectiveAtHeight","reduce","acc","p","version","versions","Object","values","el","geVersion","Math","min","ltVersion","max","$host"],"sources":["../src/Node.ts"],"sourcesContent":["// eslint-disable-next-line max-classes-per-file\nimport BigNumber from 'bignumber.js';\nimport { OperationArguments, OperationOptions, OperationSpec } from '@azure/core-client';\nimport { userAgentPolicyName, setClientRequestIdPolicyName } from '@azure/core-rest-pipeline';\nimport {\n genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy,\n genVersionCheckPolicy, genRetryOnFailurePolicy,\n} from './utils/autorest';\nimport { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node';\nimport { mapObject } from './utils/other';\nimport { UnsupportedVersionError } from './utils/errors';\nimport { Encoded } from './utils/encoder';\nimport { ConsensusProtocolVersion } from './tx/builder/constants';\n\nconst bigIntPropertyNames = [\n 'balance', 'queryFee', 'fee', 'amount', 'nameFee', 'channelAmount',\n 'initiatorAmount', 'responderAmount', 'channelReserve', 'initiatorAmountFinal',\n 'responderAmountFinal', 'gasPrice', 'minGasPrice', 'deposit',\n] as const;\n\nconst numberPropertyNames = [\n 'time', 'gas', 'gasUsed', 'nameSalt',\n 'nonce', 'nextNonce', 'height', 'blockHeight', 'topBlockHeight',\n 'ttl', 'nameTtl', 'clientTtl',\n 'inbound', 'outbound', 'peerCount', 'pendingTransactionsCount', 'effectiveAtHeight',\n 'version', 'solutions', 'round', 'minutes', 'utilization', 'difficulty', 'hashrate',\n] as const;\n\nclass NodeTransformed extends NodeApi {\n override async sendOperationRequest(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n ): Promise<any> {\n const args = mapObject(\n operationArguments,\n ([key, value]) => [key, this.#encodeArg(value)],\n ) as OperationArguments;\n return this.#decodeRes(await super.sendOperationRequest(args, operationSpec));\n }\n\n #mapData(data: any, transform: {\n bigInt: (v: any) => any;\n number: (v: any) => any;\n }): unknown {\n if (Array.isArray(data)) return data.map((d) => this.#mapData(d, transform));\n if (data != null && typeof data === 'object') {\n return mapObject(data, ([key, value]) => {\n if (value == null) return [key, value];\n if (bigIntPropertyNames.some((k) => k === key)) return [key, transform.bigInt(value)];\n if (numberPropertyNames.some((k) => k === key)) return [key, transform.number(value)];\n return [key, this.#mapData(value, transform)];\n });\n }\n return data;\n }\n\n #encodeArg(data: any): any {\n return this.#mapData(data, {\n bigInt: (value) => {\n if (value instanceof BigNumber) return value.toFixed();\n return value.toString();\n },\n number: (value) => value.toString(),\n });\n }\n\n #decodeRes(data: any): any {\n return this.#mapData(data, {\n bigInt: (value) => BigInt(value),\n number: (value) => +value,\n });\n }\n}\n\ntype BigIntPropertyNames = typeof bigIntPropertyNames[number];\ntype NumberPropertyNames = typeof numberPropertyNames[number];\ntype PreserveOptional<NewType, OrigType> =\n OrigType extends undefined ? NewType | undefined : NewType;\nexport type TransformNodeType<Type> =\n Type extends (...args: infer Args) => infer Ret\n ? (...args: TransformNodeType<Args>) => TransformNodeType<Ret>\n : Type extends [infer Item, ...infer Rest]\n ? [TransformNodeType<Item>, ...TransformNodeType<Rest>]\n : Type extends Array<infer Item>\n ? Array<TransformNodeType<Item>>\n : Type extends Promise<infer T>\n ? Promise<TransformNodeType<T>>\n : Type extends { [P in any]: any }\n ? {\n [Property in keyof Type]:\n Property extends BigIntPropertyNames\n ? PreserveOptional<bigint, Type[Property]>\n : Property extends NumberPropertyNames\n ? PreserveOptional<number, Type[Property]>\n : Property extends 'txHash'\n ? PreserveOptional<Encoded.TxHash, Type[Property]>\n : Property extends 'bytecode'\n ? PreserveOptional<Encoded.ContractBytearray, Type[Property]>\n : TransformNodeType<Type[Property]>\n }\n : Type;\ntype NodeTransformedApi = new (...args: ConstructorParameters<typeof NodeApi>) => {\n [Name in keyof InstanceType<typeof NodeApi>]:\n Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest'\n ? NodeApi[Name] : TransformNodeType<NodeApi[Name]>\n};\n\ninterface NodeInfo {\n url: string;\n nodeNetworkId: string;\n version: string;\n consensusProtocolVersion: ConsensusProtocolVersion;\n}\n\nexport default class Node extends (NodeTransformed as unknown as NodeTransformedApi) {\n /**\n * @param url - Url for node API\n * @param options - Options\n * @param options.ignoreVersion - Don't ensure that the node is supported\n * @param options.retryCount - Amount of extra requests to do in case of failure\n * @param options.retryOverallDelay - Time in ms to wait between all retries\n */\n constructor(\n url: string,\n {\n ignoreVersion = false, retryCount = 3, retryOverallDelay = 800, ...options\n }: NodeOptionalParams & {\n ignoreVersion?: boolean;\n retryCount?: number;\n retryOverallDelay?: number;\n } = {},\n ) {\n const getVersion = async (opts: OperationOptions): Promise<string> => (\n (await this._getCachedStatus(opts)).nodeVersion\n );\n // eslint-disable-next-line constructor-super\n super(url, {\n allowInsecureConnection: true,\n additionalPolicies: [\n ...ignoreVersion ? [] : [genVersionCheckPolicy('node', getVersion, '6.2.0', '8.0.0')],\n genRequestQueuesPolicy(),\n genCombineGetRequestsPolicy(),\n genRetryOnFailurePolicy(retryCount, retryOverallDelay),\n genErrorFormatterPolicy((body: ErrorModel) => [\n ' ', body.reason, body.errorCode == null ? '' : ` (${body.errorCode})`,\n ].join('')),\n ],\n ...options,\n });\n this.pipeline.removePolicy({ name: userAgentPolicyName });\n this.pipeline.removePolicy({ name: setClientRequestIdPolicyName });\n // TODO: use instead our retry policy\n this.pipeline.removePolicy({ name: 'defaultRetryPolicy' });\n this.intAsString = true;\n }\n\n #cachedStatusPromise?: ReturnType<Node['getStatus']>;\n\n async _getCachedStatus(options?: OperationOptions): ReturnType<Node['getStatus']> {\n if (this.#cachedStatusPromise != null) return this.#cachedStatusPromise;\n return this.getStatus(options);\n }\n\n // eslint-disable-next-line rulesdir/tsdoc-syntax\n /** @ts-expect-error use code generation to create node class? */\n override async getStatus(\n ...args: Parameters<InstanceType<NodeTransformedApi>['getStatus']>\n ): ReturnType<InstanceType<NodeTransformedApi>['getStatus']> {\n const promise = super.getStatus(...args);\n promise.then(() => { this.#cachedStatusPromise = promise; }, () => {});\n return promise;\n }\n\n /**\n * Returns network ID provided by node.\n * This method won't do extra requests on subsequent calls.\n */\n async getNetworkId(): Promise<string> {\n return (await this._getCachedStatus()).networkId;\n }\n\n async getNodeInfo(): Promise<NodeInfo> {\n const {\n nodeVersion,\n networkId: nodeNetworkId,\n protocols,\n topBlockHeight,\n } = await this.getStatus();\n\n const consensusProtocolVersion = protocols\n .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)\n .reduce(\n (acc, p) => (p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc),\n { effectiveAtHeight: -1, version: 0 },\n )\n .version;\n if (ConsensusProtocolVersion[consensusProtocolVersion] == null) {\n const version = consensusProtocolVersion.toString();\n const versions = Object.values(ConsensusProtocolVersion)\n .filter((el) => typeof el === 'number').map((el) => +el);\n const geVersion = Math.min(...versions).toString();\n const ltVersion = (Math.max(...versions) + 1).toString();\n throw new UnsupportedVersionError('consensus protocol', version, geVersion, ltVersion);\n }\n\n return {\n url: this.$host,\n nodeNetworkId,\n version: nodeVersion,\n consensusProtocolVersion,\n };\n }\n}\n"],"mappings":";;;;;;;AAAA;AACA,OAAOA,SAAS,MAAM,cAAc;AAEpC,SAASC,mBAAmB,EAAEC,4BAA4B,QAAQ,2BAA2B;AAAC,SAE5FC,sBAAsB,EAAEC,2BAA2B,EAAEC,uBAAuB,EAC5EC,qBAAqB,EAAEC,uBAAuB;AAAA,SAEvCC,IAAI,IAAIC,OAAO;AAAA,SACfC,SAAS;AAAA,SACTC,uBAAuB;AAAA,SAEvBC,wBAAwB;AAEjC,MAAMC,mBAAmB,GAAG,CAC1B,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAClE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,sBAAsB,EAC9E,sBAAsB,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,CACpD;AAEV,MAAMC,mBAAmB,GAAG,CAC1B,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EACpC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAC/D,KAAK,EAAE,SAAS,EAAE,WAAW,EAC7B,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,0BAA0B,EAAE,mBAAmB,EACnF,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,CAC3E;AAAC,IAAAC,QAAA,oBAAAC,OAAA;AAAA,IAAAC,UAAA,oBAAAD,OAAA;AAAA,IAAAE,UAAA,oBAAAF,OAAA;AAEX,MAAMG,eAAe,SAASV,OAAO,CAAC;EAAAW,YAAA,GAAAC,IAAA;IAAA,SAAAA,IAAA;IAAAC,2BAAA,OAAAJ,UAAA;IAAAI,2BAAA,OAAAL,UAAA;IAAAK,2BAAA,OAAAP,Q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AACF,IAAI,CAACG,GAAG,CAAC,GAAGR,QAAQ,CAAC,GAAG,CAAC,EAAE3C,QAAQ,CAAC,CAAC;MACxD,MAAM,IAAIjC,uBAAuB,CAAC,oBAAoB,EAAE2E,OAAO,EAAEK,SAAS,EAAEG,SAAS,CAAC;IACxF;IAEA,OAAO;MACL9C,GAAG,EAAE,IAAI,CAACgD,KAAK;MACfnB,aAAa;MACbS,OAAO,EAAE9B,WAAW;MACpBwB;IACF,CAAC;EACH;AACF"}
|
|
@@ -16,7 +16,7 @@ export async function getCachedIncreasedGasPrice(node) {
|
|
|
16
16
|
nodeVersion
|
|
17
17
|
} = await node._getCachedStatus();
|
|
18
18
|
// TODO: remove remove '6.12.0+' check after releasing 6.13.0
|
|
19
|
-
if (!nodeVersion.startsWith('6.12.0+') && !semverSatisfies(nodeVersion, '6.13.0', '
|
|
19
|
+
if (!nodeVersion.startsWith('6.12.0+') && !semverSatisfies(nodeVersion, '6.13.0', '8.0.0')) {
|
|
20
20
|
return 0n;
|
|
21
21
|
}
|
|
22
22
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas-price.mjs","names":["BigNumber","coinAmount","ArgumentError","IllegalArgumentError","MIN_GAS_PRICE","formatAmount","semverSatisfies","gasPriceCache","WeakMap","getCachedIncreasedGasPrice","node","cache","get","time","Date","now","gasPrice","nodeVersion","_getCachedStatus","startsWith","minGasPrice","utilization","getRecentGasPrices","BigInt","toString","times","integerValue","toFixed","maxSafeGasPrice","console","warn","join","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';\nimport { ArgumentError, IllegalArgumentError } from '../../../utils/errors';\nimport { Int, MIN_GAS_PRICE } from '../constants';\nimport Node from '../../../Node';\nimport { AE_AMOUNT_FORMATS, formatAmount } from '../../../utils/amount-formatter';\nimport semverSatisfies from '../../../utils/semver-satisfies';\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 // TODO: remove after requiring node@6.13.0\n const { nodeVersion } = await node._getCachedStatus();\n // TODO: remove remove '6.12.0+' check after releasing 6.13.0\n if (!nodeVersion.startsWith('6.12.0+') && !semverSatisfies(nodeVersion, '6.13.0', '
|
|
1
|
+
{"version":3,"file":"gas-price.mjs","names":["BigNumber","coinAmount","ArgumentError","IllegalArgumentError","MIN_GAS_PRICE","formatAmount","semverSatisfies","gasPriceCache","WeakMap","getCachedIncreasedGasPrice","node","cache","get","time","Date","now","gasPrice","nodeVersion","_getCachedStatus","startsWith","minGasPrice","utilization","getRecentGasPrices","BigInt","toString","times","integerValue","toFixed","maxSafeGasPrice","console","warn","join","set","prepare","value","params","onNode","denomination","undefined","targetDenomination","serializeAettos"],"sources":["../../../../src/tx/builder/field-types/gas-price.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\r\nimport coinAmount from './coin-amount';\r\nimport { ArgumentError, IllegalArgumentError } from '../../../utils/errors';\r\nimport { Int, MIN_GAS_PRICE } from '../constants';\r\nimport Node from '../../../Node';\r\nimport { AE_AMOUNT_FORMATS, formatAmount } from '../../../utils/amount-formatter';\r\nimport semverSatisfies from '../../../utils/semver-satisfies';\r\n\r\nconst gasPriceCache: WeakMap<Node, { time: number; gasPrice: bigint }> = new WeakMap();\r\n\r\nexport async function getCachedIncreasedGasPrice(node: Node): Promise<bigint> {\r\n const cache = gasPriceCache.get(node);\r\n if (cache != null && cache.time > Date.now() - 20 * 1000) {\r\n return cache.gasPrice;\r\n }\r\n\r\n // TODO: remove after requiring node@6.13.0\r\n const { nodeVersion } = await node._getCachedStatus();\r\n // TODO: remove remove '6.12.0+' check after releasing 6.13.0\r\n if (!nodeVersion.startsWith('6.12.0+') && !semverSatisfies(nodeVersion, '6.13.0', '8.0.0')) {\r\n return 0n;\r\n }\r\n\r\n const { minGasPrice, utilization } = (await node.getRecentGasPrices())[0];\r\n let gasPrice = utilization < 70 ? 0n : BigInt(\r\n new BigNumber(minGasPrice.toString()).times(1.01).integerValue().toFixed(),\r\n );\r\n\r\n const maxSafeGasPrice = BigInt(MIN_GAS_PRICE) * 100000n; // max microblock fee is 600ae or 35usd\r\n if (gasPrice > maxSafeGasPrice) {\r\n console.warn([\r\n `Estimated gas price ${gasPrice} exceeds the maximum safe value for unknown reason.`,\r\n `It will be limited to ${maxSafeGasPrice}.`,\r\n 'To overcome this restriction provide `gasPrice`/`fee` in options.',\r\n ].join(' '));\r\n gasPrice = maxSafeGasPrice;\r\n }\r\n\r\n gasPriceCache.set(node, { gasPrice, time: Date.now() });\r\n return gasPrice;\r\n}\r\n\r\n// TODO: use withFormatting after using a single type for coins representation\r\nexport default {\r\n ...coinAmount,\r\n\r\n async prepare(\r\n value: Int | undefined,\r\n params: {},\r\n { onNode, denomination }: {\r\n onNode?: Node;\r\n denomination?: AE_AMOUNT_FORMATS;\r\n },\r\n ): Promise<Int | undefined> {\r\n if (value != null) return value;\r\n if (onNode == null) {\r\n throw new ArgumentError('onNode', 'provided (or provide `gasPrice` instead)', onNode);\r\n }\r\n const gasPrice = await getCachedIncreasedGasPrice(onNode);\r\n if (gasPrice === 0n) return undefined;\r\n return formatAmount(gasPrice, { targetDenomination: denomination });\r\n },\r\n\r\n serializeAettos(value: string | undefined = MIN_GAS_PRICE.toString()): string {\r\n if (+value < MIN_GAS_PRICE) {\r\n throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger than ${MIN_GAS_PRICE}`);\r\n }\r\n return value;\r\n },\r\n};\r\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,cAAc;AAAC,OAC9BC,UAAU;AAAA,SACRC,aAAa,EAAEC,oBAAoB;AAAA,SAC9BC,aAAa;AAAA,SAECC,YAAY;AAAA,OAC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AG,CAACtB,IAAI,EAAE;IAAEM,QAAQ;IAAEH,IAAI,EAAEC,IAAI,CAACC,GAAG,CAAC;EAAE,CAAC,CAAC;EACvD,OAAOC,QAAQ;AACjB;;AAEA;AACA,eAAe;EACb,GAAGf,UAAU;EAEb,MAAMgC,OAAOA,CACXC,KAAsB,EACtBC,MAAU,EACV;IAAEC,MAAM;IAAEC;EAGV,CAAC,EACyB;IAC1B,IAAIH,KAAK,IAAI,IAAI,EAAE,OAAOA,KAAK;IAC/B,IAAIE,MAAM,IAAI,IAAI,EAAE;MAClB,MAAM,IAAIlC,aAAa,CAAC,QAAQ,EAAE,0CAA0C,EAAEkC,MAAM,CAAC;IACvF;IACA,MAAMpB,QAAQ,GAAG,MAAMP,0BAA0B,CAAC2B,MAAM,CAAC;IACzD,IAAIpB,QAAQ,KAAK,EAAE,EAAE,OAAOsB,SAAS;IACrC,OAAOjC,YAAY,CAACW,QAAQ,EAAE;MAAEuB,kBAAkB,EAAEF;IAAa,CAAC,CAAC;EACrE,CAAC;EAEDG,eAAeA,CAACN,KAAyB,GAAG9B,aAAa,CAACoB,QAAQ,CAAC,CAAC,EAAU;IAC5E,IAAI,CAACU,KAAK,GAAG9B,aAAa,EAAE;MAC1B,MAAM,IAAID,oBAAoB,CAAE,aAAY+B,KAAK,CAACV,QAAQ,CAAC,CAAE,wBAAuBpB,aAAc,EAAC,CAAC;IACtG;IACA,OAAO8B,KAAK;EACd;AACF,CAAC"}
|
package/package.json
CHANGED
package/src/Node.ts
CHANGED
|
@@ -137,7 +137,7 @@ export default class Node extends (NodeTransformed as unknown as NodeTransformed
|
|
|
137
137
|
super(url, {
|
|
138
138
|
allowInsecureConnection: true,
|
|
139
139
|
additionalPolicies: [
|
|
140
|
-
...ignoreVersion ? [] : [genVersionCheckPolicy('node', getVersion, '6.2.0', '
|
|
140
|
+
...ignoreVersion ? [] : [genVersionCheckPolicy('node', getVersion, '6.2.0', '8.0.0')],
|
|
141
141
|
genRequestQueuesPolicy(),
|
|
142
142
|
genCombineGetRequestsPolicy(),
|
|
143
143
|
genRetryOnFailurePolicy(retryCount, retryOverallDelay),
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import coinAmount from './coin-amount';
|
|
3
|
-
import { ArgumentError, IllegalArgumentError } from '../../../utils/errors';
|
|
4
|
-
import { Int, MIN_GAS_PRICE } from '../constants';
|
|
5
|
-
import Node from '../../../Node';
|
|
6
|
-
import { AE_AMOUNT_FORMATS, formatAmount } from '../../../utils/amount-formatter';
|
|
7
|
-
import semverSatisfies from '../../../utils/semver-satisfies';
|
|
8
|
-
|
|
9
|
-
const gasPriceCache: WeakMap<Node, { time: number; gasPrice: bigint }> = new WeakMap();
|
|
10
|
-
|
|
11
|
-
export async function getCachedIncreasedGasPrice(node: Node): Promise<bigint> {
|
|
12
|
-
const cache = gasPriceCache.get(node);
|
|
13
|
-
if (cache != null && cache.time > Date.now() - 20 * 1000) {
|
|
14
|
-
return cache.gasPrice;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// TODO: remove after requiring node@6.13.0
|
|
18
|
-
const { nodeVersion } = await node._getCachedStatus();
|
|
19
|
-
// TODO: remove remove '6.12.0+' check after releasing 6.13.0
|
|
20
|
-
if (!nodeVersion.startsWith('6.12.0+') && !semverSatisfies(nodeVersion, '6.13.0', '
|
|
21
|
-
return 0n;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const { minGasPrice, utilization } = (await node.getRecentGasPrices())[0];
|
|
25
|
-
let gasPrice = utilization < 70 ? 0n : BigInt(
|
|
26
|
-
new BigNumber(minGasPrice.toString()).times(1.01).integerValue().toFixed(),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const maxSafeGasPrice = BigInt(MIN_GAS_PRICE) * 100000n; // max microblock fee is 600ae or 35usd
|
|
30
|
-
if (gasPrice > maxSafeGasPrice) {
|
|
31
|
-
console.warn([
|
|
32
|
-
`Estimated gas price ${gasPrice} exceeds the maximum safe value for unknown reason.`,
|
|
33
|
-
`It will be limited to ${maxSafeGasPrice}.`,
|
|
34
|
-
'To overcome this restriction provide `gasPrice`/`fee` in options.',
|
|
35
|
-
].join(' '));
|
|
36
|
-
gasPrice = maxSafeGasPrice;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
gasPriceCache.set(node, { gasPrice, time: Date.now() });
|
|
40
|
-
return gasPrice;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// TODO: use withFormatting after using a single type for coins representation
|
|
44
|
-
export default {
|
|
45
|
-
...coinAmount,
|
|
46
|
-
|
|
47
|
-
async prepare(
|
|
48
|
-
value: Int | undefined,
|
|
49
|
-
params: {},
|
|
50
|
-
{ onNode, denomination }: {
|
|
51
|
-
onNode?: Node;
|
|
52
|
-
denomination?: AE_AMOUNT_FORMATS;
|
|
53
|
-
},
|
|
54
|
-
): Promise<Int | undefined> {
|
|
55
|
-
if (value != null) return value;
|
|
56
|
-
if (onNode == null) {
|
|
57
|
-
throw new ArgumentError('onNode', 'provided (or provide `gasPrice` instead)', onNode);
|
|
58
|
-
}
|
|
59
|
-
const gasPrice = await getCachedIncreasedGasPrice(onNode);
|
|
60
|
-
if (gasPrice === 0n) return undefined;
|
|
61
|
-
return formatAmount(gasPrice, { targetDenomination: denomination });
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
serializeAettos(value: string | undefined = MIN_GAS_PRICE.toString()): string {
|
|
65
|
-
if (+value < MIN_GAS_PRICE) {
|
|
66
|
-
throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger than ${MIN_GAS_PRICE}`);
|
|
67
|
-
}
|
|
68
|
-
return value;
|
|
69
|
-
},
|
|
70
|
-
};
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import coinAmount from './coin-amount';
|
|
3
|
+
import { ArgumentError, IllegalArgumentError } from '../../../utils/errors';
|
|
4
|
+
import { Int, MIN_GAS_PRICE } from '../constants';
|
|
5
|
+
import Node from '../../../Node';
|
|
6
|
+
import { AE_AMOUNT_FORMATS, formatAmount } from '../../../utils/amount-formatter';
|
|
7
|
+
import semverSatisfies from '../../../utils/semver-satisfies';
|
|
8
|
+
|
|
9
|
+
const gasPriceCache: WeakMap<Node, { time: number; gasPrice: bigint }> = new WeakMap();
|
|
10
|
+
|
|
11
|
+
export async function getCachedIncreasedGasPrice(node: Node): Promise<bigint> {
|
|
12
|
+
const cache = gasPriceCache.get(node);
|
|
13
|
+
if (cache != null && cache.time > Date.now() - 20 * 1000) {
|
|
14
|
+
return cache.gasPrice;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// TODO: remove after requiring node@6.13.0
|
|
18
|
+
const { nodeVersion } = await node._getCachedStatus();
|
|
19
|
+
// TODO: remove remove '6.12.0+' check after releasing 6.13.0
|
|
20
|
+
if (!nodeVersion.startsWith('6.12.0+') && !semverSatisfies(nodeVersion, '6.13.0', '8.0.0')) {
|
|
21
|
+
return 0n;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { minGasPrice, utilization } = (await node.getRecentGasPrices())[0];
|
|
25
|
+
let gasPrice = utilization < 70 ? 0n : BigInt(
|
|
26
|
+
new BigNumber(minGasPrice.toString()).times(1.01).integerValue().toFixed(),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const maxSafeGasPrice = BigInt(MIN_GAS_PRICE) * 100000n; // max microblock fee is 600ae or 35usd
|
|
30
|
+
if (gasPrice > maxSafeGasPrice) {
|
|
31
|
+
console.warn([
|
|
32
|
+
`Estimated gas price ${gasPrice} exceeds the maximum safe value for unknown reason.`,
|
|
33
|
+
`It will be limited to ${maxSafeGasPrice}.`,
|
|
34
|
+
'To overcome this restriction provide `gasPrice`/`fee` in options.',
|
|
35
|
+
].join(' '));
|
|
36
|
+
gasPrice = maxSafeGasPrice;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
gasPriceCache.set(node, { gasPrice, time: Date.now() });
|
|
40
|
+
return gasPrice;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// TODO: use withFormatting after using a single type for coins representation
|
|
44
|
+
export default {
|
|
45
|
+
...coinAmount,
|
|
46
|
+
|
|
47
|
+
async prepare(
|
|
48
|
+
value: Int | undefined,
|
|
49
|
+
params: {},
|
|
50
|
+
{ onNode, denomination }: {
|
|
51
|
+
onNode?: Node;
|
|
52
|
+
denomination?: AE_AMOUNT_FORMATS;
|
|
53
|
+
},
|
|
54
|
+
): Promise<Int | undefined> {
|
|
55
|
+
if (value != null) return value;
|
|
56
|
+
if (onNode == null) {
|
|
57
|
+
throw new ArgumentError('onNode', 'provided (or provide `gasPrice` instead)', onNode);
|
|
58
|
+
}
|
|
59
|
+
const gasPrice = await getCachedIncreasedGasPrice(onNode);
|
|
60
|
+
if (gasPrice === 0n) return undefined;
|
|
61
|
+
return formatAmount(gasPrice, { targetDenomination: denomination });
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
serializeAettos(value: string | undefined = MIN_GAS_PRICE.toString()): string {
|
|
65
|
+
if (+value < MIN_GAS_PRICE) {
|
|
66
|
+
throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger than ${MIN_GAS_PRICE}`);
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
},
|
|
70
|
+
};
|