@hiero-ledger/sdk 2.73.1 → 2.74.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/umd.js +279 -96
- package/dist/umd.min.js +3 -3
- package/lib/MirrorNode.cjs +46 -0
- package/lib/MirrorNode.d.ts +16 -0
- package/lib/MirrorNode.js +1 -1
- package/lib/MirrorNode.js.map +1 -1
- package/lib/account/AccountAllowanceApproveTransaction.cjs +11 -5
- package/lib/account/AccountAllowanceApproveTransaction.d.ts +4 -5
- package/lib/account/AccountAllowanceApproveTransaction.js +1 -1
- package/lib/account/AccountAllowanceApproveTransaction.js.map +1 -1
- package/lib/account/AccountId.cjs +4 -4
- package/lib/account/AccountId.js +1 -1
- package/lib/account/AccountId.js.map +1 -1
- package/lib/account/TokenAllowance.cjs +4 -2
- package/lib/account/TokenAllowance.d.ts +4 -2
- package/lib/account/TokenAllowance.js +1 -1
- package/lib/account/TokenAllowance.js.map +1 -1
- package/lib/account/TokenTransferMap.cjs +7 -2
- package/lib/account/TokenTransferMap.d.ts +6 -2
- package/lib/account/TokenTransferMap.js +1 -1
- package/lib/account/TokenTransferMap.js.map +1 -1
- package/lib/client/Client.cjs +20 -3
- package/lib/client/Client.d.ts +17 -3
- package/lib/client/Client.js +1 -1
- package/lib/client/Client.js.map +1 -1
- package/lib/client/MirrorNetwork.cjs +16 -0
- package/lib/client/MirrorNetwork.d.ts +7 -0
- package/lib/client/MirrorNetwork.js +1 -1
- package/lib/client/MirrorNetwork.js.map +1 -1
- package/lib/client/addressbooks/mainnet.cjs +1 -1
- package/lib/client/addressbooks/mainnet.d.ts +1 -1
- package/lib/client/addressbooks/mainnet.js +1 -1
- package/lib/client/addressbooks/mainnet.js.map +1 -1
- package/lib/client/addressbooks/previewnet.cjs +1 -1
- package/lib/client/addressbooks/previewnet.d.ts +1 -1
- package/lib/client/addressbooks/previewnet.js +1 -1
- package/lib/client/addressbooks/previewnet.js.map +1 -1
- package/lib/client/addressbooks/testnet.cjs +1 -1
- package/lib/client/addressbooks/testnet.d.ts +1 -1
- package/lib/client/addressbooks/testnet.js +1 -1
- package/lib/client/addressbooks/testnet.js.map +1 -1
- package/lib/constants/ClientConstants.cjs +4 -1
- package/lib/constants/ClientConstants.d.ts +2 -0
- package/lib/constants/ClientConstants.js +1 -1
- package/lib/constants/ClientConstants.js.map +1 -1
- package/lib/contract/ContractId.cjs +2 -5
- package/lib/contract/ContractId.js +1 -1
- package/lib/contract/ContractId.js.map +1 -1
- package/lib/query/MirrorNodeContractQuery.cjs +16 -9
- package/lib/query/MirrorNodeContractQuery.js +1 -1
- package/lib/query/MirrorNodeContractQuery.js.map +1 -1
- package/lib/token/AbstractTokenTransferTransaction.cjs +12 -8
- package/lib/token/AbstractTokenTransferTransaction.d.ts +14 -11
- package/lib/token/AbstractTokenTransferTransaction.js +1 -1
- package/lib/token/AbstractTokenTransferTransaction.js.map +1 -1
- package/lib/token/AssessedCustomFee.cjs +8 -4
- package/lib/token/AssessedCustomFee.d.ts +8 -5
- package/lib/token/AssessedCustomFee.js +1 -1
- package/lib/token/AssessedCustomFee.js.map +1 -1
- package/lib/token/CustomFixedFee.cjs +8 -4
- package/lib/token/CustomFixedFee.d.ts +8 -5
- package/lib/token/CustomFixedFee.js +1 -1
- package/lib/token/CustomFixedFee.js.map +1 -1
- package/lib/token/PendingAirdropRecord.cjs +7 -2
- package/lib/token/PendingAirdropRecord.d.ts +6 -2
- package/lib/token/PendingAirdropRecord.js +1 -1
- package/lib/token/PendingAirdropRecord.js.map +1 -1
- package/lib/token/TokenAirdropTransaction.cjs +2 -1
- package/lib/token/TokenAirdropTransaction.d.ts +4 -2
- package/lib/token/TokenAirdropTransaction.js.map +1 -1
- package/lib/token/TokenBurnTransaction.cjs +5 -3
- package/lib/token/TokenBurnTransaction.d.ts +6 -4
- package/lib/token/TokenBurnTransaction.js +1 -1
- package/lib/token/TokenBurnTransaction.js.map +1 -1
- package/lib/token/TokenCreateTransaction.cjs +7 -6
- package/lib/token/TokenCreateTransaction.d.ts +8 -8
- package/lib/token/TokenCreateTransaction.js +1 -1
- package/lib/token/TokenCreateTransaction.js.map +1 -1
- package/lib/token/TokenMintTransaction.cjs +5 -4
- package/lib/token/TokenMintTransaction.d.ts +6 -5
- package/lib/token/TokenMintTransaction.js +1 -1
- package/lib/token/TokenMintTransaction.js.map +1 -1
- package/lib/token/TokenTransfer.cjs +3 -2
- package/lib/token/TokenTransfer.d.ts +2 -2
- package/lib/token/TokenTransfer.js +1 -1
- package/lib/token/TokenTransfer.js.map +1 -1
- package/lib/token/TokenWipeTransaction.cjs +5 -3
- package/lib/token/TokenWipeTransaction.d.ts +6 -4
- package/lib/token/TokenWipeTransaction.js +1 -1
- package/lib/token/TokenWipeTransaction.js.map +1 -1
- package/lib/transaction/Transaction.cjs +54 -0
- package/lib/transaction/Transaction.d.ts +10 -0
- package/lib/transaction/Transaction.js +1 -1
- package/lib/transaction/Transaction.js.map +1 -1
- package/lib/util.cjs +25 -0
- package/lib/util.d.ts +8 -0
- package/lib/util.js +1 -1
- package/lib/util.js.map +1 -1
- package/lib/version.js +1 -1
- package/package.json +12 -8
- package/src/MirrorNode.js +49 -0
- package/src/account/AccountAllowanceApproveTransaction.js +11 -11
- package/src/account/AccountId.js +6 -10
- package/src/account/TokenAllowance.js +5 -2
- package/src/account/TokenTransferMap.js +7 -2
- package/src/client/Client.js +20 -3
- package/src/client/MirrorNetwork.js +18 -0
- package/src/client/addressbooks/mainnet.js +1 -1
- package/src/client/addressbooks/previewnet.js +1 -1
- package/src/client/addressbooks/testnet.js +1 -1
- package/src/constants/ClientConstants.js +3 -0
- package/src/contract/ContractId.js +2 -10
- package/src/query/MirrorNodeContractQuery.js +17 -19
- package/src/token/AbstractTokenTransferTransaction.js +12 -8
- package/src/token/AssessedCustomFee.js +8 -5
- package/src/token/CustomFixedFee.js +8 -5
- package/src/token/PendingAirdropRecord.js +7 -2
- package/src/token/TokenAirdropTransaction.js +2 -1
- package/src/token/TokenBurnTransaction.js +5 -3
- package/src/token/TokenCreateTransaction.js +7 -9
- package/src/token/TokenMintTransaction.js +5 -4
- package/src/token/TokenTransfer.js +3 -2
- package/src/token/TokenWipeTransaction.js +5 -3
- package/src/transaction/Transaction.js +63 -0
- package/src/util.js +26 -0
package/lib/MirrorNode.cjs
CHANGED
|
@@ -44,5 +44,51 @@ class MirrorNode extends _ManagedNode.default {
|
|
|
44
44
|
getKey() {
|
|
45
45
|
return this._address.toString();
|
|
46
46
|
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Gets the base URL for this mirror node's REST API.
|
|
50
|
+
*
|
|
51
|
+
* @returns {string} The base URL for the mirror node REST API
|
|
52
|
+
* @throws {Error} When the mirror node has invalid address configuration
|
|
53
|
+
*/
|
|
54
|
+
get mirrorRestApiBaseUrl() {
|
|
55
|
+
const host = this.address.address;
|
|
56
|
+
const port = this.address.port;
|
|
57
|
+
if (!host || !port) {
|
|
58
|
+
throw new Error("Mirror node has invalid address configuration");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// For localhost/127.0.0.1, mirror node gRPC and REST API use different ports
|
|
62
|
+
// gRPC typically uses port 5600, but REST API uses port 5551
|
|
63
|
+
// Note: Contract calls may use port 8545 (handled separately in MirrorNodeContractQuery)
|
|
64
|
+
if (host === "localhost" || host === "127.0.0.1") {
|
|
65
|
+
return `http://${host}:5551/api/v1`;
|
|
66
|
+
}
|
|
67
|
+
const scheme = this._getSchemeFromHostAndPort(host, port);
|
|
68
|
+
return `${scheme}://${host}:${port}/api/v1`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Determines the appropriate scheme (http/https) based on the host and port.
|
|
73
|
+
*
|
|
74
|
+
* @private
|
|
75
|
+
* @param {string} host - The host address
|
|
76
|
+
* @param {number} port - The port number
|
|
77
|
+
* @returns {string} - The scheme ('http' or 'https')
|
|
78
|
+
*/
|
|
79
|
+
_getSchemeFromHostAndPort(host, port) {
|
|
80
|
+
// For localhost and 127.0.0.1, use HTTP scheme
|
|
81
|
+
if (host === "localhost" || host === "127.0.0.1") {
|
|
82
|
+
return "http";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Standard HTTP ports
|
|
86
|
+
if (port === 80) {
|
|
87
|
+
return "http";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// For other ports, assume HTTPS for security
|
|
91
|
+
return "https";
|
|
92
|
+
}
|
|
47
93
|
}
|
|
48
94
|
exports.default = MirrorNode;
|
package/lib/MirrorNode.d.ts
CHANGED
|
@@ -25,6 +25,22 @@ export default class MirrorNode extends ManagedNode<import("./channel/MirrorChan
|
|
|
25
25
|
newNode?: NewNode | undefined;
|
|
26
26
|
cloneNode?: CloneNode | undefined;
|
|
27
27
|
});
|
|
28
|
+
/**
|
|
29
|
+
* Gets the base URL for this mirror node's REST API.
|
|
30
|
+
*
|
|
31
|
+
* @returns {string} The base URL for the mirror node REST API
|
|
32
|
+
* @throws {Error} When the mirror node has invalid address configuration
|
|
33
|
+
*/
|
|
34
|
+
get mirrorRestApiBaseUrl(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Determines the appropriate scheme (http/https) based on the host and port.
|
|
37
|
+
*
|
|
38
|
+
* @private
|
|
39
|
+
* @param {string} host - The host address
|
|
40
|
+
* @param {number} port - The port number
|
|
41
|
+
* @returns {string} - The scheme ('http' or 'https')
|
|
42
|
+
*/
|
|
43
|
+
private _getSchemeFromHostAndPort;
|
|
28
44
|
}
|
|
29
45
|
export type MirrorChannel = import("./channel/MirrorChannel.js").default;
|
|
30
46
|
export type ManagedNodeAddress = import("./ManagedNodeAddress.js").default;
|
package/lib/MirrorNode.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import r from"./ManagedNode.js";class t extends r{constructor(r={}){super(r)}getKey(){return this._address.toString()}get mirrorRestApiBaseUrl(){const r=this.address.address,t=this.address.port;if(!r||!t)throw new Error("Mirror node has invalid address configuration");if("localhost"===r||"127.0.0.1"===r)return`http://${r}:5551/api/v1`;return`${this._getSchemeFromHostAndPort(r,t)}://${r}:${t}/api/v1`}_getSchemeFromHostAndPort(r,t){return"localhost"===r||"127.0.0.1"===r||80===t?"http":"https"}}export{t as default};
|
|
2
2
|
//# sourceMappingURL=MirrorNode.js.map
|
package/lib/MirrorNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MirrorNode.js","sources":["../src/MirrorNode.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport ManagedNode from \"./ManagedNode.js\";\n\n/**\n * @typedef {import(\"./channel/MirrorChannel.js\").default} MirrorChannel\n * @typedef {import(\"./ManagedNodeAddress.js\").default} ManagedNodeAddress\n */\n\n/**\n * @typedef {object} NewNode\n * @property {string} address\n * @property {(address: string, cert?: string) => MirrorChannel} channelInitFunction\n */\n\n/**\n * @typedef {object} CloneNode\n * @property {MirrorNode} node\n * @property {ManagedNodeAddress} address\n */\n\n/**\n * @augments {ManagedNode<MirrorChannel>}\n */\nexport default class MirrorNode extends ManagedNode {\n /**\n * @param {object} props\n * @param {NewNode=} [props.newNode]\n * @param {CloneNode=} [props.cloneNode]\n */\n constructor(props = {}) {\n super(props);\n }\n\n /**\n * @returns {string}\n */\n getKey() {\n return this._address.toString();\n }\n}\n"],"names":["MirrorNode","ManagedNode","constructor","props","super","getKey","this","_address","toString"],"mappings":"gCAwBe,MAAMA,UAAmBC,EAMpC,WAAAC,CAAYC,EAAQ,IAChBC,MAAMD,EACd,CAKI,MAAAE,GACI,OAAOC,KAAKC,SAASC,UAC7B"}
|
|
1
|
+
{"version":3,"file":"MirrorNode.js","sources":["../src/MirrorNode.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport ManagedNode from \"./ManagedNode.js\";\n\n/**\n * @typedef {import(\"./channel/MirrorChannel.js\").default} MirrorChannel\n * @typedef {import(\"./ManagedNodeAddress.js\").default} ManagedNodeAddress\n */\n\n/**\n * @typedef {object} NewNode\n * @property {string} address\n * @property {(address: string, cert?: string) => MirrorChannel} channelInitFunction\n */\n\n/**\n * @typedef {object} CloneNode\n * @property {MirrorNode} node\n * @property {ManagedNodeAddress} address\n */\n\n/**\n * @augments {ManagedNode<MirrorChannel>}\n */\nexport default class MirrorNode extends ManagedNode {\n /**\n * @param {object} props\n * @param {NewNode=} [props.newNode]\n * @param {CloneNode=} [props.cloneNode]\n */\n constructor(props = {}) {\n super(props);\n }\n\n /**\n * @returns {string}\n */\n getKey() {\n return this._address.toString();\n }\n\n /**\n * Gets the base URL for this mirror node's REST API.\n *\n * @returns {string} The base URL for the mirror node REST API\n * @throws {Error} When the mirror node has invalid address configuration\n */\n get mirrorRestApiBaseUrl() {\n const host = this.address.address;\n const port = this.address.port;\n\n if (!host || !port) {\n throw new Error(\"Mirror node has invalid address configuration\");\n }\n\n // For localhost/127.0.0.1, mirror node gRPC and REST API use different ports\n // gRPC typically uses port 5600, but REST API uses port 5551\n // Note: Contract calls may use port 8545 (handled separately in MirrorNodeContractQuery)\n if (host === \"localhost\" || host === \"127.0.0.1\") {\n return `http://${host}:5551/api/v1`;\n }\n\n const scheme = this._getSchemeFromHostAndPort(host, port);\n\n return `${scheme}://${host}:${port}/api/v1`;\n }\n\n /**\n * Determines the appropriate scheme (http/https) based on the host and port.\n *\n * @private\n * @param {string} host - The host address\n * @param {number} port - The port number\n * @returns {string} - The scheme ('http' or 'https')\n */\n _getSchemeFromHostAndPort(host, port) {\n // For localhost and 127.0.0.1, use HTTP scheme\n if (host === \"localhost\" || host === \"127.0.0.1\") {\n return \"http\";\n }\n\n // Standard HTTP ports\n if (port === 80) {\n return \"http\";\n }\n\n // For other ports, assume HTTPS for security\n return \"https\";\n }\n}\n"],"names":["MirrorNode","ManagedNode","constructor","props","super","getKey","this","_address","toString","mirrorRestApiBaseUrl","host","address","port","Error","_getSchemeFromHostAndPort"],"mappings":"gCAwBe,MAAMA,UAAmBC,EAMpC,WAAAC,CAAYC,EAAQ,IAChBC,MAAMD,EACd,CAKI,MAAAE,GACI,OAAOC,KAAKC,SAASC,UAC7B,CAQI,wBAAIC,GACA,MAAMC,EAAOJ,KAAKK,QAAQA,QACpBC,EAAON,KAAKK,QAAQC,KAE1B,IAAKF,IAASE,EACV,MAAM,IAAIC,MAAM,iDAMpB,GAAa,cAATH,GAAiC,cAATA,EACxB,MAAO,UAAUA,gBAKrB,MAAO,GAFQJ,KAAKQ,0BAA0BJ,EAAME,QAE9BF,KAAQE,UACtC,CAUI,yBAAAE,CAA0BJ,EAAME,GAE5B,MAAa,cAATF,GAAiC,cAATA,GAKf,KAATE,EAJO,OASJ,OACf"}
|
|
@@ -9,11 +9,11 @@ var _AccountId = _interopRequireDefault(require("./AccountId.cjs"));
|
|
|
9
9
|
var _ContractId = _interopRequireDefault(require("../contract/ContractId.cjs"));
|
|
10
10
|
var _TokenId = _interopRequireDefault(require("../token/TokenId.cjs"));
|
|
11
11
|
var _NftId = _interopRequireDefault(require("../token/NftId.cjs"));
|
|
12
|
-
var _long = _interopRequireDefault(require("long"));
|
|
13
12
|
var _Hbar = _interopRequireDefault(require("../Hbar.cjs"));
|
|
14
13
|
var _HbarAllowance = _interopRequireDefault(require("./HbarAllowance.cjs"));
|
|
15
14
|
var _TokenAllowance = _interopRequireDefault(require("./TokenAllowance.cjs"));
|
|
16
15
|
var _TokenNftAllowance = _interopRequireDefault(require("./TokenNftAllowance.cjs"));
|
|
16
|
+
var _util = require("../util.cjs");
|
|
17
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
18
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
19
19
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -140,16 +140,19 @@ class AccountAllowanceApproveTransaction extends _Transaction.default {
|
|
|
140
140
|
* @param {TokenId | string} tokenId
|
|
141
141
|
* @param {AccountId | string} ownerAccountId
|
|
142
142
|
* @param {AccountId | ContractId | string} spenderAccountId
|
|
143
|
-
* @param {Long | number} amount
|
|
143
|
+
* @param {Long | number | BigNumber | bigint} amount
|
|
144
144
|
* @returns {AccountAllowanceApproveTransaction}
|
|
145
145
|
*/
|
|
146
146
|
approveTokenAllowance(tokenId, ownerAccountId, spenderAccountId, amount) {
|
|
147
147
|
this._requireNotFrozen();
|
|
148
|
+
|
|
149
|
+
// Convert amount to Long
|
|
150
|
+
const amountLong = (0, _util.convertAmountToLong)(amount);
|
|
148
151
|
this._tokenApprovals.push(new _TokenAllowance.default({
|
|
149
152
|
tokenId: typeof tokenId === "string" ? _TokenId.default.fromString(tokenId) : tokenId,
|
|
150
153
|
spenderAccountId: typeof spenderAccountId === "string" ? _AccountId.default.fromString(spenderAccountId) : spenderAccountId instanceof _ContractId.default ? _AccountId.default.fromEvmAddress(spenderAccountId.shard, spenderAccountId.realm, spenderAccountId.toEvmAddress()) : spenderAccountId,
|
|
151
154
|
ownerAccountId: typeof ownerAccountId === "string" ? _AccountId.default.fromString(ownerAccountId) : ownerAccountId instanceof _ContractId.default ? _AccountId.default.fromEvmAddress(ownerAccountId.shard, ownerAccountId.realm, ownerAccountId.toEvmAddress()) : ownerAccountId,
|
|
152
|
-
amount:
|
|
155
|
+
amount: amountLong
|
|
153
156
|
}));
|
|
154
157
|
return this;
|
|
155
158
|
}
|
|
@@ -158,15 +161,18 @@ class AccountAllowanceApproveTransaction extends _Transaction.default {
|
|
|
158
161
|
* @deprecated - Use `approveTokenAllowance()` instead
|
|
159
162
|
* @param {TokenId | string} tokenId
|
|
160
163
|
* @param {AccountId | string} spenderAccountId
|
|
161
|
-
* @param {Long | number} amount
|
|
164
|
+
* @param {Long | number | BigNumber | bigint} amount
|
|
162
165
|
* @returns {AccountAllowanceApproveTransaction}
|
|
163
166
|
*/
|
|
164
167
|
addTokenAllowance(tokenId, spenderAccountId, amount) {
|
|
165
168
|
this._requireNotFrozen();
|
|
169
|
+
|
|
170
|
+
// Convert amount to Long
|
|
171
|
+
const amountLong = (0, _util.convertAmountToLong)(amount);
|
|
166
172
|
this._tokenApprovals.push(new _TokenAllowance.default({
|
|
167
173
|
tokenId: typeof tokenId === "string" ? _TokenId.default.fromString(tokenId) : tokenId,
|
|
168
174
|
spenderAccountId: typeof spenderAccountId === "string" ? _AccountId.default.fromString(spenderAccountId) : spenderAccountId,
|
|
169
|
-
amount:
|
|
175
|
+
amount: amountLong,
|
|
170
176
|
ownerAccountId: null
|
|
171
177
|
}));
|
|
172
178
|
return this;
|
|
@@ -82,18 +82,18 @@ export default class AccountAllowanceApproveTransaction extends Transaction {
|
|
|
82
82
|
* @param {TokenId | string} tokenId
|
|
83
83
|
* @param {AccountId | string} ownerAccountId
|
|
84
84
|
* @param {AccountId | ContractId | string} spenderAccountId
|
|
85
|
-
* @param {Long | number} amount
|
|
85
|
+
* @param {Long | number | BigNumber | bigint} amount
|
|
86
86
|
* @returns {AccountAllowanceApproveTransaction}
|
|
87
87
|
*/
|
|
88
|
-
approveTokenAllowance(tokenId: TokenId | string, ownerAccountId: AccountId | string, spenderAccountId: AccountId | ContractId | string, amount: Long | number): AccountAllowanceApproveTransaction;
|
|
88
|
+
approveTokenAllowance(tokenId: TokenId | string, ownerAccountId: AccountId | string, spenderAccountId: AccountId | ContractId | string, amount: Long | number | BigNumber | bigint): AccountAllowanceApproveTransaction;
|
|
89
89
|
/**
|
|
90
90
|
* @deprecated - Use `approveTokenAllowance()` instead
|
|
91
91
|
* @param {TokenId | string} tokenId
|
|
92
92
|
* @param {AccountId | string} spenderAccountId
|
|
93
|
-
* @param {Long | number} amount
|
|
93
|
+
* @param {Long | number | BigNumber | bigint} amount
|
|
94
94
|
* @returns {AccountAllowanceApproveTransaction}
|
|
95
95
|
*/
|
|
96
|
-
addTokenAllowance(tokenId: TokenId | string, spenderAccountId: AccountId | string, amount: Long | number): AccountAllowanceApproveTransaction;
|
|
96
|
+
addTokenAllowance(tokenId: TokenId | string, spenderAccountId: AccountId | string, amount: Long | number | BigNumber | bigint): AccountAllowanceApproveTransaction;
|
|
97
97
|
/**
|
|
98
98
|
* @deprecated - Use `approveTokenNftAllowance()` instead
|
|
99
99
|
* @param {NftId | string} nftId
|
|
@@ -186,7 +186,6 @@ import Transaction from "../transaction/Transaction.js";
|
|
|
186
186
|
import HbarAllowance from "./HbarAllowance.js";
|
|
187
187
|
import AccountId from "./AccountId.js";
|
|
188
188
|
import ContractId from "../contract/ContractId.js";
|
|
189
|
-
import Long from "long";
|
|
190
189
|
import Hbar from "../Hbar.js";
|
|
191
190
|
import TokenAllowance from "./TokenAllowance.js";
|
|
192
191
|
import TokenId from "../token/TokenId.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import r,{TRANSACTION_REGISTRY as o}from"../transaction/Transaction.js";import t from"./AccountId.js";import e from"../contract/ContractId.js";import n from"../token/TokenId.js";import s from"../token/NftId.js";import a from"
|
|
1
|
+
import r,{TRANSACTION_REGISTRY as o}from"../transaction/Transaction.js";import t from"./AccountId.js";import e from"../contract/ContractId.js";import n from"../token/TokenId.js";import s from"../token/NftId.js";import a from"../Hbar.js";import l from"./HbarAllowance.js";import p from"./TokenAllowance.js";import i from"./TokenNftAllowance.js";import{convertAmountToLong as c}from"../util.js";class A extends r{constructor(r={}){super(),this._hbarApprovals=null!=r.hbarApprovals?r.hbarApprovals:[],this._tokenApprovals=null!=r.tokenApprovals?r.tokenApprovals:[],this._nftApprovals=null!=r.nftApprovals?r.nftApprovals:[]}static _fromProtobuf(o,t,e,n,s){const a=s[0].cryptoApproveAllowance;return r._fromProtobufTransactions(new A({hbarApprovals:(null!=a.cryptoAllowances?a.cryptoAllowances:[]).map(r=>l._fromProtobuf(r)),tokenApprovals:(null!=a.tokenAllowances?a.tokenAllowances:[]).map(r=>p._fromProtobuf(r)),nftApprovals:(null!=a.nftAllowances?a.nftAllowances:[]).map(r=>i._fromProtobuf(r))}),o,t,e,n,s)}get hbarApprovals(){return this._hbarApprovals}approveHbarAllowance(r,o,n){return this._requireNotFrozen(),this._hbarApprovals.push(new l({spenderAccountId:"string"==typeof o?t.fromString(o):o instanceof e?t.fromEvmAddress(o.shard,o.realm,o.toEvmAddress()):o,ownerAccountId:"string"==typeof r?t.fromString(r):r instanceof e?t.fromEvmAddress(r.shard,r.realm,r.toEvmAddress()):r,amount:n instanceof a?n:new a(n)})),this}addHbarAllowance(r,o){return this._requireNotFrozen(),this._hbarApprovals.push(new l({spenderAccountId:"string"==typeof r?t.fromString(r):r,amount:o instanceof a?o:new a(o),ownerAccountId:null})),this}get tokenApprovals(){return this._tokenApprovals}approveTokenAllowance(r,o,s,a){this._requireNotFrozen();const l=c(a);return this._tokenApprovals.push(new p({tokenId:"string"==typeof r?n.fromString(r):r,spenderAccountId:"string"==typeof s?t.fromString(s):s instanceof e?t.fromEvmAddress(s.shard,s.realm,s.toEvmAddress()):s,ownerAccountId:"string"==typeof o?t.fromString(o):o instanceof e?t.fromEvmAddress(o.shard,o.realm,o.toEvmAddress()):o,amount:l})),this}addTokenAllowance(r,o,e){this._requireNotFrozen();const s=c(e);return this._tokenApprovals.push(new p({tokenId:"string"==typeof r?n.fromString(r):r,spenderAccountId:"string"==typeof o?t.fromString(o):o,amount:s,ownerAccountId:null})),this}addTokenNftAllowance(r,o){return this._approveTokenNftAllowance(r,null,o,null)}get tokenNftApprovals(){return this._nftApprovals}_approveTokenNftAllowance(r,o,n,a){this._requireNotFrozen();const l="string"==typeof r?s.fromString(r):r,p="string"==typeof n?t.fromString(n):n instanceof e?t.fromEvmAddress(n.shard,n.realm,n.toEvmAddress()):n;let c=!1;for(const r of this._nftApprovals)if(0===r.tokenId.compare(l.tokenId)&&null!=r.spenderAccountId&&0===r.spenderAccountId.compare(p)){null!=r.serialNumbers&&r.serialNumbers.push(l.serial),c=!0;break}return c||this._nftApprovals.push(new i({tokenId:l.tokenId,spenderAccountId:p,ownerAccountId:"string"==typeof o?t.fromString(o):o instanceof e?t.fromEvmAddress(o.shard,o.realm,o.toEvmAddress()):o,serialNumbers:[l.serial],allSerials:!1,delegatingSpender:"string"==typeof a?t.fromString(a):a})),this}approveTokenNftAllowance(r,o,t){return this._approveTokenNftAllowance(r,o,t,null)}approveTokenNftAllowanceWithDelegatingSpender(r,o,t,e){return this._approveTokenNftAllowance(r,o,t,e)}_approveAllTokenNftAllowance(r,o,s,a){return this._requireNotFrozen(),this._nftApprovals.push(new i({tokenId:"string"==typeof r?n.fromString(r):r,spenderAccountId:"string"==typeof s?t.fromString(s):s instanceof e?t.fromEvmAddress(s.shard,s.realm,s.toEvmAddress()):s,ownerAccountId:"string"==typeof o?t.fromString(o):o instanceof e?t.fromEvmAddress(o.shard,o.realm,o.toEvmAddress()):o,serialNumbers:null,allSerials:a,delegatingSpender:null})),this}addAllTokenNftAllowance(r,o,t){return this._approveAllTokenNftAllowance(r,o,t,!0)}approveTokenNftAllowanceAllSerials(r,o,t){return this._approveAllTokenNftAllowance(r,o,t,!0)}deleteTokenNftAllowanceAllSerials(r,o,t){return this._approveAllTokenNftAllowance(r,o,t,!1)}_validateChecksums(r){this._hbarApprovals.map(o=>o._validateChecksums(r)),this._tokenApprovals.map(o=>o._validateChecksums(r)),this._nftApprovals.map(o=>o._validateChecksums(r))}_execute(r,o){return r.crypto.approveAllowances(o)}_getTransactionDataCase(){return"cryptoApproveAllowance"}_makeTransactionData(){return{cryptoAllowances:this._hbarApprovals.map(r=>r._toProtobuf()),tokenAllowances:this._tokenApprovals.map(r=>r._toProtobuf()),nftAllowances:this._nftApprovals.map(r=>r._toProtobuf())}}_getLogId(){return`AccountAllowanceApproveTransaction:${this._transactionIds.current.validStart.toString()}`}}o.set("cryptoApproveAllowance",A._fromProtobuf);export{A as default};
|
|
2
2
|
//# sourceMappingURL=AccountAllowanceApproveTransaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountAllowanceApproveTransaction.js","sources":["../../src/account/AccountAllowanceApproveTransaction.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Transaction, {\n TRANSACTION_REGISTRY,\n} from \"../transaction/Transaction.js\";\nimport AccountId from \"./AccountId.js\";\nimport ContractId from \"../contract/ContractId.js\";\nimport TokenId from \"../token/TokenId.js\";\nimport NftId from \"../token/NftId.js\";\nimport Long from \"long\";\nimport Hbar from \"../Hbar.js\";\nimport HbarAllowance from \"./HbarAllowance.js\";\nimport TokenAllowance from \"./TokenAllowance.js\";\nimport TokenNftAllowance from \"./TokenNftAllowance.js\";\n\n/**\n * @namespace proto\n * @typedef {import(\"@hashgraph/proto\").proto.ITransaction} HieroProto.proto.ITransaction\n * @typedef {import(\"@hashgraph/proto\").proto.ISignedTransaction} HieroProto.proto.ISignedTransaction\n * @typedef {import(\"@hashgraph/proto\").proto.TransactionBody} HieroProto.proto.TransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITransactionBody} HieroProto.proto.ITransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITransactionResponse} HieroProto.proto.ITransactionResponse\n * @typedef {import(\"@hashgraph/proto\").proto.ICryptoApproveAllowanceTransactionBody} HieroProto.proto.ICryptoApproveAllowanceTransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.IAccountID} HieroProto.proto.IAccountID\n * @typedef {import(\"@hashgraph/proto\").proto.IContractID} HieroProto.proto.IContractID\n */\n\n/**\n * @typedef {import(\"../channel/Channel.js\").default} Channel\n * @typedef {import(\"../client/Client.js\").default<*, *>} Client\n * @typedef {import(\"../transaction/TransactionId.js\").default} TransactionId\n * @typedef {import(\"bignumber.js\").default} BigNumber\n * @typedef {import(\"../long.js\").LongObject} LongObject\n */\n\n/**\n * Change properties for the given account.\n */\nexport default class AccountAllowanceApproveTransaction extends Transaction {\n /**\n * @param {object} [props]\n * @param {HbarAllowance[]} [props.hbarApprovals]\n * @param {TokenAllowance[]} [props.tokenApprovals]\n * @param {TokenNftAllowance[]} [props.nftApprovals]\n */\n constructor(props = {}) {\n super();\n\n /**\n * @private\n * @type {HbarAllowance[]}\n */\n this._hbarApprovals =\n props.hbarApprovals != null ? props.hbarApprovals : [];\n\n /**\n * @private\n * @type {TokenAllowance[]}\n */\n this._tokenApprovals =\n props.tokenApprovals != null ? props.tokenApprovals : [];\n\n /**\n * @private\n * @type {TokenNftAllowance[]}\n */\n this._nftApprovals =\n props.nftApprovals != null ? props.nftApprovals : [];\n }\n\n /**\n * @internal\n * @param {HieroProto.proto.ITransaction[]} transactions\n * @param {HieroProto.proto.ISignedTransaction[]} signedTransactions\n * @param {TransactionId[]} transactionIds\n * @param {AccountId[]} nodeIds\n * @param {HieroProto.proto.ITransactionBody[]} bodies\n * @returns {AccountAllowanceApproveTransaction}\n */\n static _fromProtobuf(\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n ) {\n const body = bodies[0];\n const allowanceApproval =\n /** @type {HieroProto.proto.ICryptoApproveAllowanceTransactionBody} */ (\n body.cryptoApproveAllowance\n );\n\n return Transaction._fromProtobufTransactions(\n new AccountAllowanceApproveTransaction({\n hbarApprovals: (allowanceApproval.cryptoAllowances != null\n ? allowanceApproval.cryptoAllowances\n : []\n ).map((approval) => HbarAllowance._fromProtobuf(approval)),\n tokenApprovals: (allowanceApproval.tokenAllowances != null\n ? allowanceApproval.tokenAllowances\n : []\n ).map((approval) => TokenAllowance._fromProtobuf(approval)),\n nftApprovals: (allowanceApproval.nftAllowances != null\n ? allowanceApproval.nftAllowances\n : []\n ).map((approval) => TokenNftAllowance._fromProtobuf(approval)),\n }),\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n );\n }\n\n /**\n * @returns {HbarAllowance[]}\n */\n get hbarApprovals() {\n return this._hbarApprovals;\n }\n\n /**\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @param {number | string | Long | LongObject | BigNumber | Hbar} amount\n * @returns {AccountAllowanceApproveTransaction}\n */\n approveHbarAllowance(ownerAccountId, spenderAccountId, amount) {\n this._requireNotFrozen();\n\n this._hbarApprovals.push(\n new HbarAllowance({\n spenderAccountId:\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n spenderAccountId.shard,\n spenderAccountId.realm,\n spenderAccountId.toEvmAddress(),\n )\n : spenderAccountId,\n ownerAccountId:\n typeof ownerAccountId === \"string\"\n ? AccountId.fromString(ownerAccountId)\n : ownerAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n ownerAccountId.shard,\n ownerAccountId.realm,\n ownerAccountId.toEvmAddress(),\n )\n : ownerAccountId,\n amount: amount instanceof Hbar ? amount : new Hbar(amount),\n }),\n );\n\n return this;\n }\n\n /**\n * @deprecated - Use `approveHbarAllowance()` instead\n * @param {AccountId | string} spenderAccountId\n * @param {number | string | Long | LongObject | BigNumber | Hbar} amount\n * @returns {AccountAllowanceApproveTransaction}\n */\n addHbarAllowance(spenderAccountId, amount) {\n this._requireNotFrozen();\n\n this._hbarApprovals.push(\n new HbarAllowance({\n spenderAccountId:\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId,\n amount: amount instanceof Hbar ? amount : new Hbar(amount),\n ownerAccountId: null,\n }),\n );\n\n return this;\n }\n\n /**\n * @returns {TokenAllowance[]}\n */\n get tokenApprovals() {\n return this._tokenApprovals;\n }\n\n /**\n * @param {TokenId | string} tokenId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @param {Long | number} amount\n * @returns {AccountAllowanceApproveTransaction}\n */\n approveTokenAllowance(tokenId, ownerAccountId, spenderAccountId, amount) {\n this._requireNotFrozen();\n\n this._tokenApprovals.push(\n new TokenAllowance({\n tokenId:\n typeof tokenId === \"string\"\n ? TokenId.fromString(tokenId)\n : tokenId,\n spenderAccountId:\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n spenderAccountId.shard,\n spenderAccountId.realm,\n spenderAccountId.toEvmAddress(),\n )\n : spenderAccountId,\n ownerAccountId:\n typeof ownerAccountId === \"string\"\n ? AccountId.fromString(ownerAccountId)\n : ownerAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n ownerAccountId.shard,\n ownerAccountId.realm,\n ownerAccountId.toEvmAddress(),\n )\n : ownerAccountId,\n amount:\n typeof amount === \"number\"\n ? Long.fromNumber(amount)\n : amount,\n }),\n );\n\n return this;\n }\n\n /**\n * @deprecated - Use `approveTokenAllowance()` instead\n * @param {TokenId | string} tokenId\n * @param {AccountId | string} spenderAccountId\n * @param {Long | number} amount\n * @returns {AccountAllowanceApproveTransaction}\n */\n addTokenAllowance(tokenId, spenderAccountId, amount) {\n this._requireNotFrozen();\n\n this._tokenApprovals.push(\n new TokenAllowance({\n tokenId:\n typeof tokenId === \"string\"\n ? TokenId.fromString(tokenId)\n : tokenId,\n spenderAccountId:\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId,\n amount:\n typeof amount === \"number\"\n ? Long.fromNumber(amount)\n : amount,\n ownerAccountId: null,\n }),\n );\n\n return this;\n }\n\n /**\n * @deprecated - Use `approveTokenNftAllowance()` instead\n * @param {NftId | string} nftId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @returns {AccountAllowanceApproveTransaction}\n */\n addTokenNftAllowance(nftId, spenderAccountId) {\n return this._approveTokenNftAllowance(\n nftId,\n null,\n spenderAccountId,\n null,\n );\n }\n\n /**\n * @returns {TokenNftAllowance[]}\n */\n get tokenNftApprovals() {\n return this._nftApprovals;\n }\n\n /**\n * @param {NftId | string} nftId\n * @param {AccountId | string | null} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @param {AccountId | string | null} delegatingSpender\n * @returns {AccountAllowanceApproveTransaction}\n */\n _approveTokenNftAllowance(\n nftId,\n ownerAccountId,\n spenderAccountId,\n delegatingSpender,\n ) {\n this._requireNotFrozen();\n\n const id = typeof nftId === \"string\" ? NftId.fromString(nftId) : nftId;\n const spender =\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n spenderAccountId.shard,\n spenderAccountId.realm,\n spenderAccountId.toEvmAddress(),\n )\n : spenderAccountId;\n let found = false;\n\n for (const allowance of this._nftApprovals) {\n if (\n allowance.tokenId.compare(id.tokenId) === 0 &&\n allowance.spenderAccountId != null &&\n allowance.spenderAccountId.compare(spender) === 0\n ) {\n if (allowance.serialNumbers != null) {\n allowance.serialNumbers.push(id.serial);\n }\n found = true;\n break;\n }\n }\n\n if (!found) {\n this._nftApprovals.push(\n new TokenNftAllowance({\n tokenId: id.tokenId,\n spenderAccountId: spender,\n ownerAccountId:\n typeof ownerAccountId === \"string\"\n ? AccountId.fromString(ownerAccountId)\n : ownerAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n ownerAccountId.shard,\n ownerAccountId.realm,\n ownerAccountId.toEvmAddress(),\n )\n : ownerAccountId,\n serialNumbers: [id.serial],\n allSerials: false,\n delegatingSpender:\n typeof delegatingSpender === \"string\"\n ? AccountId.fromString(delegatingSpender)\n : delegatingSpender,\n }),\n );\n }\n\n return this;\n }\n\n /**\n * @param {NftId | string} nftId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @returns {AccountAllowanceApproveTransaction}\n */\n approveTokenNftAllowance(nftId, ownerAccountId, spenderAccountId) {\n return this._approveTokenNftAllowance(\n nftId,\n ownerAccountId,\n spenderAccountId,\n null,\n );\n }\n\n /**\n * @param {NftId | string} nftId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @param {AccountId | string} delegatingSpender\n * @returns {AccountAllowanceApproveTransaction}\n */\n approveTokenNftAllowanceWithDelegatingSpender(\n nftId,\n ownerAccountId,\n spenderAccountId,\n delegatingSpender,\n ) {\n return this._approveTokenNftAllowance(\n nftId,\n ownerAccountId,\n spenderAccountId,\n delegatingSpender,\n );\n }\n\n /**\n * @param {TokenId | string} tokenId\n * @param {AccountId | string | null} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @param {boolean} allSerials\n * @returns {AccountAllowanceApproveTransaction}\n */\n _approveAllTokenNftAllowance(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n allSerials,\n ) {\n this._requireNotFrozen();\n\n this._nftApprovals.push(\n new TokenNftAllowance({\n tokenId:\n typeof tokenId === \"string\"\n ? TokenId.fromString(tokenId)\n : tokenId,\n spenderAccountId:\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n spenderAccountId.shard,\n spenderAccountId.realm,\n spenderAccountId.toEvmAddress(),\n )\n : spenderAccountId,\n ownerAccountId:\n typeof ownerAccountId === \"string\"\n ? AccountId.fromString(ownerAccountId)\n : ownerAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n ownerAccountId.shard,\n ownerAccountId.realm,\n ownerAccountId.toEvmAddress(),\n )\n : ownerAccountId,\n serialNumbers: null,\n allSerials,\n delegatingSpender: null,\n }),\n );\n\n return this;\n }\n\n /**\n * @deprecated - Use `approveTokenNftAllowanceAllSerials()` instead\n * @param {TokenId | string} tokenId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | string} spenderAccountId\n * @returns {AccountAllowanceApproveTransaction}\n */\n addAllTokenNftAllowance(tokenId, ownerAccountId, spenderAccountId) {\n return this._approveAllTokenNftAllowance(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n true,\n );\n }\n\n /**\n * @param {TokenId | string} tokenId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @returns {AccountAllowanceApproveTransaction}\n */\n approveTokenNftAllowanceAllSerials(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n ) {\n return this._approveAllTokenNftAllowance(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n true,\n );\n }\n\n /**\n * @param {TokenId | string} tokenId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @returns {AccountAllowanceApproveTransaction}\n */\n deleteTokenNftAllowanceAllSerials(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n ) {\n return this._approveAllTokenNftAllowance(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n false,\n );\n }\n\n /**\n * @param {Client} client\n */\n _validateChecksums(client) {\n this._hbarApprovals.map((approval) =>\n approval._validateChecksums(client),\n );\n this._tokenApprovals.map((approval) =>\n approval._validateChecksums(client),\n );\n this._nftApprovals.map((approval) =>\n approval._validateChecksums(client),\n );\n }\n\n /**\n * @override\n * @internal\n * @param {Channel} channel\n * @param {HieroProto.proto.ITransaction} request\n * @returns {Promise<HieroProto.proto.ITransactionResponse>}\n */\n _execute(channel, request) {\n return channel.crypto.approveAllowances(request);\n }\n\n /**\n * @override\n * @protected\n * @returns {NonNullable<HieroProto.proto.TransactionBody[\"data\"]>}\n */\n _getTransactionDataCase() {\n return \"cryptoApproveAllowance\";\n }\n\n /**\n * @override\n * @protected\n * @returns {HieroProto.proto.ICryptoApproveAllowanceTransactionBody}\n */\n _makeTransactionData() {\n return {\n cryptoAllowances: this._hbarApprovals.map((approval) =>\n approval._toProtobuf(),\n ),\n tokenAllowances: this._tokenApprovals.map((approval) =>\n approval._toProtobuf(),\n ),\n nftAllowances: this._nftApprovals.map((approval) =>\n approval._toProtobuf(),\n ),\n };\n }\n\n /**\n * @returns {string}\n */\n _getLogId() {\n const timestamp = /** @type {import(\"../Timestamp.js\").default} */ (\n this._transactionIds.current.validStart\n );\n return `AccountAllowanceApproveTransaction:${timestamp.toString()}`;\n }\n}\n\nTRANSACTION_REGISTRY.set(\n \"cryptoApproveAllowance\",\n // eslint-disable-next-line @typescript-eslint/unbound-method\n AccountAllowanceApproveTransaction._fromProtobuf,\n);\n"],"names":["AccountAllowanceApproveTransaction","Transaction","constructor","props","super","this","_hbarApprovals","hbarApprovals","_tokenApprovals","tokenApprovals","_nftApprovals","nftApprovals","_fromProtobuf","transactions","signedTransactions","transactionIds","nodeIds","bodies","allowanceApproval","_fromProtobufTransactions","cryptoAllowances","map","approval","HbarAllowance","tokenAllowances","TokenAllowance","nftAllowances","TokenNftAllowance","approveHbarAllowance","ownerAccountId","spenderAccountId","amount","_requireNotFrozen","push","AccountId","fromString","ContractId","fromEvmAddress","shard","realm","toEvmAddress","Hbar","addHbarAllowance","approveTokenAllowance","tokenId","TokenId","Long","fromNumber","addTokenAllowance","addTokenNftAllowance","nftId","_approveTokenNftAllowance","tokenNftApprovals","delegatingSpender","id","NftId","spender","found","allowance","compare","serialNumbers","serial","allSerials","approveTokenNftAllowance","approveTokenNftAllowanceWithDelegatingSpender","_approveAllTokenNftAllowance","addAllTokenNftAllowance","approveTokenNftAllowanceAllSerials","deleteTokenNftAllowanceAllSerials","_validateChecksums","client","_execute","channel","request","crypto","approveAllowances","_getTransactionDataCase","_makeTransactionData","_toProtobuf","_getLogId","_transactionIds","current","toString","TRANSACTION_REGISTRY","set"],"mappings":"4WAsCe,MAAMA,UAA2CC,EAO5D,WAAAC,CAAYC,EAAQ,IAChBC,QAMAC,KAAKC,eACsB,MAAvBH,EAAMI,cAAwBJ,EAAMI,cAAgB,GAMxDF,KAAKG,gBACuB,MAAxBL,EAAMM,eAAyBN,EAAMM,eAAiB,GAM1DJ,KAAKK,cACqB,MAAtBP,EAAMQ,aAAuBR,EAAMQ,aAAe,EAC9D,CAWI,oBAAOC,CACHC,EACAC,EACAC,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f,EACAC,GACA,EAEZ,CAQI,iCAAAsC,CACIxB,EACAf,EACAC,GAEA,OAAOzB,KAAK4D,6BACRrB,EACAf,EACAC,GACA,EAEZ,CAKI,kBAAAuC,CAAmBC,GACfjE,KAAKC,eAAee,IAAKC,GACrBA,EAAS+C,mBAAmBC,IAEhCjE,KAAKG,gBAAgBa,IAAKC,GACtBA,EAAS+C,mBAAmBC,IAEhCjE,KAAKK,cAAcW,IAAKC,GACpBA,EAAS+C,mBAAmBC,GAExC,CASI,QAAAC,CAASC,EAASC,GACd,OAAOD,EAAQE,OAAOC,kBAAkBF,EAChD,CAOI,uBAAAG,GACI,MAAO,wBACf,CAOI,oBAAAC,GACI,MAAO,CACHzD,iBAAkBf,KAAKC,eAAee,IAAKC,GACvCA,EAASwD,eAEbtD,gBAAiBnB,KAAKG,gBAAgBa,IAAKC,GACvCA,EAASwD,eAEbpD,cAAerB,KAAKK,cAAcW,IAAKC,GACnCA,EAASwD,eAGzB,CAKI,SAAAC,GAII,MAAO,sCAFH1E,KAAK2E,gBAAgBC,QACxB,WACsDC,YAC/D,EAGAC,EAAqBC,IACjB,yBAEApF,EAAmCY"}
|
|
1
|
+
{"version":3,"file":"AccountAllowanceApproveTransaction.js","sources":["../../src/account/AccountAllowanceApproveTransaction.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Transaction, {\n TRANSACTION_REGISTRY,\n} from \"../transaction/Transaction.js\";\nimport AccountId from \"./AccountId.js\";\nimport ContractId from \"../contract/ContractId.js\";\nimport TokenId from \"../token/TokenId.js\";\nimport NftId from \"../token/NftId.js\";\nimport Hbar from \"../Hbar.js\";\nimport HbarAllowance from \"./HbarAllowance.js\";\nimport TokenAllowance from \"./TokenAllowance.js\";\nimport TokenNftAllowance from \"./TokenNftAllowance.js\";\nimport { convertAmountToLong } from \"../util.js\";\n\n/**\n * @namespace proto\n * @typedef {import(\"@hashgraph/proto\").proto.ITransaction} HieroProto.proto.ITransaction\n * @typedef {import(\"@hashgraph/proto\").proto.ISignedTransaction} HieroProto.proto.ISignedTransaction\n * @typedef {import(\"@hashgraph/proto\").proto.TransactionBody} HieroProto.proto.TransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITransactionBody} HieroProto.proto.ITransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITransactionResponse} HieroProto.proto.ITransactionResponse\n * @typedef {import(\"@hashgraph/proto\").proto.ICryptoApproveAllowanceTransactionBody} HieroProto.proto.ICryptoApproveAllowanceTransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.IAccountID} HieroProto.proto.IAccountID\n * @typedef {import(\"@hashgraph/proto\").proto.IContractID} HieroProto.proto.IContractID\n */\n\n/**\n * @typedef {import(\"../channel/Channel.js\").default} Channel\n * @typedef {import(\"../client/Client.js\").default<*, *>} Client\n * @typedef {import(\"../transaction/TransactionId.js\").default} TransactionId\n * @typedef {import(\"bignumber.js\").default} BigNumber\n * @typedef {import(\"../long.js\").LongObject} LongObject\n */\n\n/**\n * Change properties for the given account.\n */\nexport default class AccountAllowanceApproveTransaction extends Transaction {\n /**\n * @param {object} [props]\n * @param {HbarAllowance[]} [props.hbarApprovals]\n * @param {TokenAllowance[]} [props.tokenApprovals]\n * @param {TokenNftAllowance[]} [props.nftApprovals]\n */\n constructor(props = {}) {\n super();\n\n /**\n * @private\n * @type {HbarAllowance[]}\n */\n this._hbarApprovals =\n props.hbarApprovals != null ? props.hbarApprovals : [];\n\n /**\n * @private\n * @type {TokenAllowance[]}\n */\n this._tokenApprovals =\n props.tokenApprovals != null ? props.tokenApprovals : [];\n\n /**\n * @private\n * @type {TokenNftAllowance[]}\n */\n this._nftApprovals =\n props.nftApprovals != null ? props.nftApprovals : [];\n }\n\n /**\n * @internal\n * @param {HieroProto.proto.ITransaction[]} transactions\n * @param {HieroProto.proto.ISignedTransaction[]} signedTransactions\n * @param {TransactionId[]} transactionIds\n * @param {AccountId[]} nodeIds\n * @param {HieroProto.proto.ITransactionBody[]} bodies\n * @returns {AccountAllowanceApproveTransaction}\n */\n static _fromProtobuf(\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n ) {\n const body = bodies[0];\n const allowanceApproval =\n /** @type {HieroProto.proto.ICryptoApproveAllowanceTransactionBody} */ (\n body.cryptoApproveAllowance\n );\n\n return Transaction._fromProtobufTransactions(\n new AccountAllowanceApproveTransaction({\n hbarApprovals: (allowanceApproval.cryptoAllowances != null\n ? allowanceApproval.cryptoAllowances\n : []\n ).map((approval) => HbarAllowance._fromProtobuf(approval)),\n tokenApprovals: (allowanceApproval.tokenAllowances != null\n ? allowanceApproval.tokenAllowances\n : []\n ).map((approval) => TokenAllowance._fromProtobuf(approval)),\n nftApprovals: (allowanceApproval.nftAllowances != null\n ? allowanceApproval.nftAllowances\n : []\n ).map((approval) => TokenNftAllowance._fromProtobuf(approval)),\n }),\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n );\n }\n\n /**\n * @returns {HbarAllowance[]}\n */\n get hbarApprovals() {\n return this._hbarApprovals;\n }\n\n /**\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @param {number | string | Long | LongObject | BigNumber | Hbar} amount\n * @returns {AccountAllowanceApproveTransaction}\n */\n approveHbarAllowance(ownerAccountId, spenderAccountId, amount) {\n this._requireNotFrozen();\n\n this._hbarApprovals.push(\n new HbarAllowance({\n spenderAccountId:\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n spenderAccountId.shard,\n spenderAccountId.realm,\n spenderAccountId.toEvmAddress(),\n )\n : spenderAccountId,\n ownerAccountId:\n typeof ownerAccountId === \"string\"\n ? AccountId.fromString(ownerAccountId)\n : ownerAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n ownerAccountId.shard,\n ownerAccountId.realm,\n ownerAccountId.toEvmAddress(),\n )\n : ownerAccountId,\n amount: amount instanceof Hbar ? amount : new Hbar(amount),\n }),\n );\n\n return this;\n }\n\n /**\n * @deprecated - Use `approveHbarAllowance()` instead\n * @param {AccountId | string} spenderAccountId\n * @param {number | string | Long | LongObject | BigNumber | Hbar} amount\n * @returns {AccountAllowanceApproveTransaction}\n */\n addHbarAllowance(spenderAccountId, amount) {\n this._requireNotFrozen();\n\n this._hbarApprovals.push(\n new HbarAllowance({\n spenderAccountId:\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId,\n amount: amount instanceof Hbar ? amount : new Hbar(amount),\n ownerAccountId: null,\n }),\n );\n\n return this;\n }\n\n /**\n * @returns {TokenAllowance[]}\n */\n get tokenApprovals() {\n return this._tokenApprovals;\n }\n\n /**\n * @param {TokenId | string} tokenId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @param {Long | number | BigNumber | bigint} amount\n * @returns {AccountAllowanceApproveTransaction}\n */\n approveTokenAllowance(tokenId, ownerAccountId, spenderAccountId, amount) {\n this._requireNotFrozen();\n\n // Convert amount to Long\n const amountLong = convertAmountToLong(amount);\n\n this._tokenApprovals.push(\n new TokenAllowance({\n tokenId:\n typeof tokenId === \"string\"\n ? TokenId.fromString(tokenId)\n : tokenId,\n spenderAccountId:\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n spenderAccountId.shard,\n spenderAccountId.realm,\n spenderAccountId.toEvmAddress(),\n )\n : spenderAccountId,\n ownerAccountId:\n typeof ownerAccountId === \"string\"\n ? AccountId.fromString(ownerAccountId)\n : ownerAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n ownerAccountId.shard,\n ownerAccountId.realm,\n ownerAccountId.toEvmAddress(),\n )\n : ownerAccountId,\n amount: amountLong,\n }),\n );\n\n return this;\n }\n\n /**\n * @deprecated - Use `approveTokenAllowance()` instead\n * @param {TokenId | string} tokenId\n * @param {AccountId | string} spenderAccountId\n * @param {Long | number | BigNumber | bigint} amount\n * @returns {AccountAllowanceApproveTransaction}\n */\n addTokenAllowance(tokenId, spenderAccountId, amount) {\n this._requireNotFrozen();\n\n // Convert amount to Long\n const amountLong = convertAmountToLong(amount);\n\n this._tokenApprovals.push(\n new TokenAllowance({\n tokenId:\n typeof tokenId === \"string\"\n ? TokenId.fromString(tokenId)\n : tokenId,\n spenderAccountId:\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId,\n amount: amountLong,\n ownerAccountId: null,\n }),\n );\n\n return this;\n }\n\n /**\n * @deprecated - Use `approveTokenNftAllowance()` instead\n * @param {NftId | string} nftId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @returns {AccountAllowanceApproveTransaction}\n */\n addTokenNftAllowance(nftId, spenderAccountId) {\n return this._approveTokenNftAllowance(\n nftId,\n null,\n spenderAccountId,\n null,\n );\n }\n\n /**\n * @returns {TokenNftAllowance[]}\n */\n get tokenNftApprovals() {\n return this._nftApprovals;\n }\n\n /**\n * @param {NftId | string} nftId\n * @param {AccountId | string | null} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @param {AccountId | string | null} delegatingSpender\n * @returns {AccountAllowanceApproveTransaction}\n */\n _approveTokenNftAllowance(\n nftId,\n ownerAccountId,\n spenderAccountId,\n delegatingSpender,\n ) {\n this._requireNotFrozen();\n\n const id = typeof nftId === \"string\" ? NftId.fromString(nftId) : nftId;\n const spender =\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n spenderAccountId.shard,\n spenderAccountId.realm,\n spenderAccountId.toEvmAddress(),\n )\n : spenderAccountId;\n let found = false;\n\n for (const allowance of this._nftApprovals) {\n if (\n allowance.tokenId.compare(id.tokenId) === 0 &&\n allowance.spenderAccountId != null &&\n allowance.spenderAccountId.compare(spender) === 0\n ) {\n if (allowance.serialNumbers != null) {\n allowance.serialNumbers.push(id.serial);\n }\n found = true;\n break;\n }\n }\n\n if (!found) {\n this._nftApprovals.push(\n new TokenNftAllowance({\n tokenId: id.tokenId,\n spenderAccountId: spender,\n ownerAccountId:\n typeof ownerAccountId === \"string\"\n ? AccountId.fromString(ownerAccountId)\n : ownerAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n ownerAccountId.shard,\n ownerAccountId.realm,\n ownerAccountId.toEvmAddress(),\n )\n : ownerAccountId,\n serialNumbers: [id.serial],\n allSerials: false,\n delegatingSpender:\n typeof delegatingSpender === \"string\"\n ? AccountId.fromString(delegatingSpender)\n : delegatingSpender,\n }),\n );\n }\n\n return this;\n }\n\n /**\n * @param {NftId | string} nftId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @returns {AccountAllowanceApproveTransaction}\n */\n approveTokenNftAllowance(nftId, ownerAccountId, spenderAccountId) {\n return this._approveTokenNftAllowance(\n nftId,\n ownerAccountId,\n spenderAccountId,\n null,\n );\n }\n\n /**\n * @param {NftId | string} nftId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @param {AccountId | string} delegatingSpender\n * @returns {AccountAllowanceApproveTransaction}\n */\n approveTokenNftAllowanceWithDelegatingSpender(\n nftId,\n ownerAccountId,\n spenderAccountId,\n delegatingSpender,\n ) {\n return this._approveTokenNftAllowance(\n nftId,\n ownerAccountId,\n spenderAccountId,\n delegatingSpender,\n );\n }\n\n /**\n * @param {TokenId | string} tokenId\n * @param {AccountId | string | null} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @param {boolean} allSerials\n * @returns {AccountAllowanceApproveTransaction}\n */\n _approveAllTokenNftAllowance(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n allSerials,\n ) {\n this._requireNotFrozen();\n\n this._nftApprovals.push(\n new TokenNftAllowance({\n tokenId:\n typeof tokenId === \"string\"\n ? TokenId.fromString(tokenId)\n : tokenId,\n spenderAccountId:\n typeof spenderAccountId === \"string\"\n ? AccountId.fromString(spenderAccountId)\n : spenderAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n spenderAccountId.shard,\n spenderAccountId.realm,\n spenderAccountId.toEvmAddress(),\n )\n : spenderAccountId,\n ownerAccountId:\n typeof ownerAccountId === \"string\"\n ? AccountId.fromString(ownerAccountId)\n : ownerAccountId instanceof ContractId\n ? AccountId.fromEvmAddress(\n ownerAccountId.shard,\n ownerAccountId.realm,\n ownerAccountId.toEvmAddress(),\n )\n : ownerAccountId,\n serialNumbers: null,\n allSerials,\n delegatingSpender: null,\n }),\n );\n\n return this;\n }\n\n /**\n * @deprecated - Use `approveTokenNftAllowanceAllSerials()` instead\n * @param {TokenId | string} tokenId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | string} spenderAccountId\n * @returns {AccountAllowanceApproveTransaction}\n */\n addAllTokenNftAllowance(tokenId, ownerAccountId, spenderAccountId) {\n return this._approveAllTokenNftAllowance(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n true,\n );\n }\n\n /**\n * @param {TokenId | string} tokenId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @returns {AccountAllowanceApproveTransaction}\n */\n approveTokenNftAllowanceAllSerials(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n ) {\n return this._approveAllTokenNftAllowance(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n true,\n );\n }\n\n /**\n * @param {TokenId | string} tokenId\n * @param {AccountId | string} ownerAccountId\n * @param {AccountId | ContractId | string} spenderAccountId\n * @returns {AccountAllowanceApproveTransaction}\n */\n deleteTokenNftAllowanceAllSerials(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n ) {\n return this._approveAllTokenNftAllowance(\n tokenId,\n ownerAccountId,\n spenderAccountId,\n false,\n );\n }\n\n /**\n * @param {Client} client\n */\n _validateChecksums(client) {\n this._hbarApprovals.map((approval) =>\n approval._validateChecksums(client),\n );\n this._tokenApprovals.map((approval) =>\n approval._validateChecksums(client),\n );\n this._nftApprovals.map((approval) =>\n approval._validateChecksums(client),\n );\n }\n\n /**\n * @override\n * @internal\n * @param {Channel} channel\n * @param {HieroProto.proto.ITransaction} request\n * @returns {Promise<HieroProto.proto.ITransactionResponse>}\n */\n _execute(channel, request) {\n return channel.crypto.approveAllowances(request);\n }\n\n /**\n * @override\n * @protected\n * @returns {NonNullable<HieroProto.proto.TransactionBody[\"data\"]>}\n */\n _getTransactionDataCase() {\n return \"cryptoApproveAllowance\";\n }\n\n /**\n * @override\n * @protected\n * @returns {HieroProto.proto.ICryptoApproveAllowanceTransactionBody}\n */\n _makeTransactionData() {\n return {\n cryptoAllowances: this._hbarApprovals.map((approval) =>\n approval._toProtobuf(),\n ),\n tokenAllowances: this._tokenApprovals.map((approval) =>\n approval._toProtobuf(),\n ),\n nftAllowances: this._nftApprovals.map((approval) =>\n approval._toProtobuf(),\n ),\n };\n }\n\n /**\n * @returns {string}\n */\n _getLogId() {\n const timestamp = /** @type {import(\"../Timestamp.js\").default} */ (\n this._transactionIds.current.validStart\n );\n return `AccountAllowanceApproveTransaction:${timestamp.toString()}`;\n }\n}\n\nTRANSACTION_REGISTRY.set(\n \"cryptoApproveAllowance\",\n // eslint-disable-next-line @typescript-eslint/unbound-method\n AccountAllowanceApproveTransaction._fromProtobuf,\n);\n"],"names":["AccountAllowanceApproveTransaction","Transaction","constructor","props","super","this","_hbarApprovals","hbarApprovals","_tokenApprovals","tokenApprovals","_nftApprovals","nftApprovals","_fromProtobuf","transactions","signedTransactions","transactionIds","nodeIds","bodies","allowanceApproval","_fromProtobufTransactions","cryptoAllowances","map","approval","HbarAllowance","tokenAllowances","TokenAllowance","nftAllowances","TokenNftAllowance","approveHbarAllowance","ownerAccountId","spenderAccountId","amount","_requireNotFrozen","push","AccountId","fromString","ContractId","fromEvmAddress","shard","realm","toEvmAddress","Hbar","addHbarAllowance","approveTokenAllowance","tokenId","amountLong","convertAmountToLong","TokenId","addTokenAllowance","addTokenNftAllowance","nftId","_approveTokenNftAllowance","tokenNftApprovals","delegatingSpender","id","NftId","spender","found","allowance","compare","serialNumbers","serial","allSerials","approveTokenNftAllowance","approveTokenNftAllowanceWithDelegatingSpender","_approveAllTokenNftAllowance","addAllTokenNftAllowance","approveTokenNftAllowanceAllSerials","deleteTokenNftAllowanceAllSerials","_validateChecksums","client","_execute","channel","request","crypto","approveAllowances","_getTransactionDataCase","_makeTransactionData","_toProtobuf","_getLogId","_transactionIds","current","toString","TRANSACTION_REGISTRY","set"],"mappings":"yYAsCe,MAAMA,UAA2CC,EAO5D,WAAAC,CAAYC,EAAQ,IAChBC,QAMAC,KAAKC,eACsB,MAAvBH,EAAMI,cAAwBJ,EAAMI,cAAgB,GAMxDF,KAAKG,gBACuB,MAAxBL,EAAMM,eAAyBN,EAAMM,eAAiB,GAM1DJ,KAAKK,cACqB,MAAtBP,EAAMQ,aAAuBR,EAAMQ,aAAe,EAC9D,CAWI,oBAAOC,CACHC,EACAC,EACAC,EACAC,EACAC,GAEA,MACMC,EADOD,EAAO,GAIf,uBAEL,OAAOhB,EAAYkB,0BACf,IAAInB,EAAmC,CACnCO,eAAsD,MAAtCW,EAAkBE,iBAC5BF,EAAkBE,iBAClB,IACJC,IAAKC,GAAaC,EAAcX,cAAcU,IAChDb,gBAAsD,MAArCS,EAAkBM,gBAC7BN,EAAkBM,gBAClB,IACJH,IAAKC,GAAaG,EAAeb,cAAcU,IACjDX,cAAkD,MAAnCO,EAAkBQ,cAC3BR,EAAkBQ,cAClB,IACJL,IAAKC,GAAaK,EAAkBf,cAAcU,MAExDT,EACAC,EACAC,EACAC,EACAC,EAEZ,CAKI,iBAAIV,GACA,OAAOF,KAAKC,cACpB,CAQI,oBAAAsB,CAAqBC,EAAgBC,EAAkBC,GA6BnD,OA5BA1B,KAAK2B,oBAEL3B,KAAKC,eAAe2B,KAChB,IAAIV,EAAc,CACdO,iBACgC,iBAArBA,EACDI,EAAUC,WAAWL,GACrBA,aAA4BM,EAC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,sCAFH1E,KAAK2E,gBAAgBC,QACxB,WACsDC,YAC/D,EAGAC,EAAqBC,IACjB,yBAEApF,EAAmCY"}
|
|
@@ -153,13 +153,13 @@ class AccountId {
|
|
|
153
153
|
if (this.evmAddress === null) {
|
|
154
154
|
throw new Error("field `evmAddress` should not be null");
|
|
155
155
|
}
|
|
156
|
-
const
|
|
156
|
+
const mirrorRestApiBaseUrl = client.mirrorRestApiBaseUrl;
|
|
157
|
+
const url = `${mirrorRestApiBaseUrl}/accounts/${this.evmAddress.toString()}`;
|
|
157
158
|
await new Promise(resolve => {
|
|
158
159
|
setTimeout(resolve, 3000);
|
|
159
160
|
});
|
|
160
161
|
|
|
161
162
|
/* eslint-disable */
|
|
162
|
-
const url = `https://${mirrorUrl}/api/v1/accounts/${this.evmAddress.toString()}`;
|
|
163
163
|
const response = await fetch(url);
|
|
164
164
|
const data = await response.json();
|
|
165
165
|
const mirrorAccountId = data.account;
|
|
@@ -178,13 +178,13 @@ class AccountId {
|
|
|
178
178
|
if (this.num === null) {
|
|
179
179
|
throw new Error("field `num` should not be null");
|
|
180
180
|
}
|
|
181
|
-
const
|
|
181
|
+
const mirrorRestApiBaseUrl = client.mirrorRestApiBaseUrl;
|
|
182
|
+
const url = `${mirrorRestApiBaseUrl}/accounts/${this.num.toString()}`;
|
|
182
183
|
await new Promise(resolve => {
|
|
183
184
|
setTimeout(resolve, 3000);
|
|
184
185
|
});
|
|
185
186
|
|
|
186
187
|
/* eslint-disable */
|
|
187
|
-
const url = `https://${mirrorUrl}/api/v1/accounts/${this.num.toString()}`;
|
|
188
188
|
const response = await fetch(url);
|
|
189
189
|
const data = await response.json();
|
|
190
190
|
const mirrorAccountId = data.evm_address;
|
package/lib/account/AccountId.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import s from"long";import{constructor as t,fromStringSplitter as e,fromEvmAddress as r,validateChecksum as i,fromSolidityAddress as n,toSolidityAddress as l,toEvmAddress as a,toStringWithChecksum as o}from"../EntityIdHelper.js";import*as m from"@hashgraph/proto";import u from"../Key.js";import h from"../PublicKey.js";import d from"../Cache.js";import c from"../EvmAddress.js";import{decode as f}from"../encoding/hex.js";import{isLongZeroAddress as v}from"../util.js";class y{constructor(s,e,r,i,n){const l=t(s,e,r);this.shard=l.shard,this.realm=l.realm,this.num=l.num,this.aliasKey=null!=i?i:null,this.evmAddress=null!=n?n:null,this._checksum=null}static fromString(t){let r,i,n=s.ZERO,l=s.ZERO,a=s.ZERO;if(t.startsWith("0x")&&42==t.length||40==t.length)i=c.fromString(t);else{const o=e(t);if(Number.isNaN(o.shard)||Number.isNaN(o.realm))throw new Error("invalid format for entity ID");null!=o.shard&&(n=s.fromString(o.shard)),null!=o.realm&&(l=s.fromString(o.realm)),o.numOrHex.length<20?a=s.fromString(o.numOrHex):40==o.numOrHex.length?i=c.fromString(o.numOrHex):r=h.fromString(o.numOrHex)}return new y(n,l,a,r,i)}static fromEvmAddress(s,t,e){const i="string"==typeof e?c.fromString(e):e,[n,l,a,o]=r(s,t,i.toString());return new y(n,l,a,void 0,o||void 0)}static fromEvmPublicAddress(s){return new y(0,0,0,void 0,s)}static _fromProtobuf(s){let t,e;return null!=s.alias&&(20===s.alias.length?e=c.fromBytes(s.alias):t=u._fromProtobufKey(m.proto.Key.decode(s.alias))),t instanceof h||(t=void 0),new y(null!=s.shardNum?s.shardNum:0,null!=s.realmNum?s.realmNum:0,null!=s.accountNum?s.accountNum:0,t,e)}get checksum(){return this._checksum}getEvmAddress(){return this.evmAddress}async populateAccountNum(t){if(null===this.evmAddress)throw new Error("field `evmAddress` should not be null");const e=`${t.mirrorRestApiBaseUrl}/accounts/${this.evmAddress.toString()}`;await new Promise(s=>{setTimeout(s,3e3)});const r=await fetch(e),i=(await r.json()).account;return this.num=s.fromString(i.slice(i.lastIndexOf(".")+1)),this}async populateAccountEvmAddress(s){if(null===this.num)throw new Error("field `num` should not be null");const t=`${s.mirrorRestApiBaseUrl}/accounts/${this.num.toString()}`;await new Promise(s=>{setTimeout(s,3e3)});const e=await fetch(t),r=(await e.json()).evm_address;return this.evmAddress=c.fromString(r),this}validate(s){console.warn("Deprecated: Use `validateChecksum` instead"),this.validateChecksum(s)}validateChecksum(s){if(null!=this.aliasKey)throw new Error("cannot calculate checksum with an account ID that has a aliasKey");i(this.shard,this.realm,this.num,this._checksum,s)}static fromBytes(s){return y._fromProtobuf(m.proto.AccountID.decode(s))}static fromSolidityAddress(s){return v(f(s))?new y(...n(s)):this.fromEvmAddress(0,0,s)}toSolidityAddress(){return null!=this.evmAddress?this.evmAddress.toString():null!=this.aliasKey&&"secp256k1"==this.aliasKey._key._type?this.aliasKey.toEvmAddress():l([this.shard,this.realm,this.num])}toEvmAddress(){return null!=this.evmAddress?a(this.evmAddress.toBytes()):a(this.num)}_toProtobuf(){let t=null;null!=this.aliasKey?t=m.proto.Key.encode(this.aliasKey._toProtobufKey()).finish():null!=this.evmAddress&&(t=this.evmAddress._bytes);const e=this.num.eq(s.fromBigInt(0n))&&t;return t?{alias:e?t:null,accountNum:e?null:this.num,shardNum:this.shard,realmNum:this.realm}:{alias:null,accountNum:this.num,shardNum:this.shard,realmNum:this.realm}}toBytes(){return m.proto.AccountID.encode(this._toProtobuf()).finish()}toString(){let s=this.num.toString();return null!=this.aliasKey?s=this.aliasKey.toString():null!=this.evmAddress&&(s=this.evmAddress.toString()),`${this.shard.toString()}.${this.realm.toString()}.${s}`}toStringWithChecksum(s){if(null!=this.aliasKey)throw new Error("cannot calculate checksum with an account ID that has a aliasKey");return o(this.toString(),s)}equals(s){let t=!1;return null!=this.aliasKey&&null!=s.aliasKey?t=this.aliasKey.equals(s.aliasKey):null!=this.evmAddress&&null!=s.evmAddress?t=this.evmAddress.equals(s.evmAddress):null==this.aliasKey&&null==s.aliasKey&&null==this.evmAddress&&null==s.evmAddress&&(t=this.num.eq(s.num)),this.shard.eq(s.shard)&&this.realm.eq(s.realm)&&t}clone(){const s=new y(this);return s._checksum=this._checksum,s.aliasKey=this.aliasKey,s.evmAddress=this.evmAddress,s}compare(s){let t=this.shard.compare(s.shard);if(0!=t)return t;if(t=this.realm.compare(s.realm),0!=t)return t;if(null!=this.aliasKey&&null!=s.aliasKey){const t=this.aliasKey.toString(),e=s.aliasKey.toString();return t>e?1:t<e?-1:0}if(null!=this.evmAddress&&null!=s.evmAddress){const t=this.evmAddress.toString(),e=s.evmAddress.toString();return t>e?1:t<e?-1:0}return null==this.aliasKey&&null==s.aliasKey&&null==this.evmAddress&&null==s.evmAddress?this.num.compare(s.num):1}}d.setAccountIdConstructor((t,e,r)=>new y(t,e,s.ZERO,r));export{y as default};
|
|
2
2
|
//# sourceMappingURL=AccountId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountId.js","sources":["../../src/account/AccountId.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Long from \"long\";\nimport * as EntityIdHelper from \"../EntityIdHelper.js\";\nimport * as HieroProto from \"@hashgraph/proto\";\nimport Key from \"../Key.js\";\nimport PublicKey from \"../PublicKey.js\";\nimport CACHE from \"../Cache.js\";\nimport EvmAddress from \"../EvmAddress.js\";\nimport * as hex from \".././encoding/hex.js\";\nimport { isLongZeroAddress } from \"../util.js\";\n\n/**\n * @typedef {import(\"../client/Client.js\").default<*, *>} Client\n */\n\n/**\n * The ID for a crypto-currency account on Hedera.\n */\nexport default class AccountId {\n /**\n * @param {number | Long | import(\"../EntityIdHelper\").IEntityId} props\n * @param {(number | Long)=} realm\n * @param {(number | Long)=} num\n * @param {(PublicKey)=} aliasKey\n * @param {(EvmAddress)=} evmAddress\n */\n constructor(props, realm, num, aliasKey, evmAddress) {\n const result = EntityIdHelper.constructor(props, realm, num);\n\n this.shard = result.shard;\n this.realm = result.realm;\n this.num = result.num;\n this.aliasKey = aliasKey != null ? aliasKey : null;\n this.evmAddress = evmAddress != null ? evmAddress : null;\n\n /**\n * @type {string | null}\n */\n this._checksum = null;\n }\n\n /**\n * @description Accepts the following formats as string:\n * - as stand alone nubmers\n * - as shard.realm.num\n * - as shard.realm.hex (wo 0x prefix)\n * - hex (w/wo 0x prefix)\n * @param {string} text\n * @returns {AccountId}\n */\n static fromString(text) {\n let shard = Long.ZERO;\n let realm = Long.ZERO;\n let num = Long.ZERO;\n let aliasKey = undefined;\n let evmAddress = undefined;\n\n if ((text.startsWith(\"0x\") && text.length == 42) || text.length == 40) {\n evmAddress = EvmAddress.fromString(text);\n } else {\n const result = EntityIdHelper.fromStringSplitter(text);\n\n if (Number.isNaN(result.shard) || Number.isNaN(result.realm)) {\n throw new Error(\"invalid format for entity ID\");\n }\n\n if (result.shard != null) shard = Long.fromString(result.shard);\n if (result.realm != null) realm = Long.fromString(result.realm);\n\n if (result.numOrHex.length < 20) {\n num = Long.fromString(result.numOrHex);\n } else if (result.numOrHex.length == 40) {\n evmAddress = EvmAddress.fromString(result.numOrHex);\n } else {\n aliasKey = PublicKey.fromString(result.numOrHex);\n }\n }\n\n return new AccountId(shard, realm, num, aliasKey, evmAddress);\n }\n\n /**\n * @description This handles both long-zero format and evm address format addresses.\n * If an actual evm address is passed, please use `AccountId.populateAccountNum(client)` method\n * to get the actual `num` value, since there is no cryptographic relation to the evm address\n * and cannot be populated directly\n * @param {Long | number} shard\n * @param {Long | number} realm\n * @param {EvmAddress | string} evmAddress\n * @returns {AccountId}\n */\n static fromEvmAddress(shard, realm, evmAddress) {\n const evmAddressObj =\n typeof evmAddress === \"string\"\n ? EvmAddress.fromString(evmAddress)\n : evmAddress;\n\n const [shardLong, realmLong, num, address] =\n EntityIdHelper.fromEvmAddress(\n shard,\n realm,\n evmAddressObj.toString(),\n );\n\n return new AccountId(\n shardLong,\n realmLong,\n num,\n undefined,\n address || undefined,\n );\n }\n\n /**\n * @deprecated - Use `fromEvmAddress` instead\n * @summary Accepts an evm address only as `EvmAddress` type\n * @param {EvmAddress} evmAddress\n * @returns {AccountId}\n */\n static fromEvmPublicAddress(evmAddress) {\n return new AccountId(0, 0, 0, undefined, evmAddress);\n }\n\n /**\n * @internal\n * @param {HieroProto.proto.IAccountID} id\n * @returns {AccountId}\n */\n static _fromProtobuf(id) {\n let aliasKey = undefined;\n let evmAddress = undefined;\n\n if (id.alias != null) {\n if (id.alias.length === 20) {\n evmAddress = EvmAddress.fromBytes(id.alias);\n } else {\n aliasKey = Key._fromProtobufKey(\n HieroProto.proto.Key.decode(id.alias),\n );\n }\n }\n\n if (!(aliasKey instanceof PublicKey)) {\n aliasKey = undefined;\n }\n\n return new AccountId(\n id.shardNum != null ? id.shardNum : 0,\n id.realmNum != null ? id.realmNum : 0,\n id.accountNum != null ? id.accountNum : 0,\n aliasKey,\n evmAddress,\n );\n }\n\n /**\n * @returns {string | null}\n */\n get checksum() {\n return this._checksum;\n }\n\n /**\n * @returns {?EvmAddress}\n */\n getEvmAddress() {\n return this.evmAddress;\n }\n\n /**\n * @description Gets the actual `num` field of the `AccountId` from the Mirror Node.\n * Should be used after generating `AccountId.fromEvmAddress()` because it sets the `num` field to `0`\n * automatically since there is no connection between the `num` and the `evmAddress`\n * @param {Client} client\n * @returns {Promise<AccountId>}\n */\n async populateAccountNum(client) {\n if (this.evmAddress === null) {\n throw new Error(\"field `evmAddress` should not be null\");\n }\n const mirrorUrl = client.mirrorNetwork[0].slice(\n 0,\n client.mirrorNetwork[0].indexOf(\":\"),\n );\n\n await new Promise((resolve) => {\n setTimeout(resolve, 3000);\n });\n\n /* eslint-disable */\n const url = `https://${mirrorUrl}/api/v1/accounts/${this.evmAddress.toString()}`;\n const response = await fetch(url);\n const data = await response.json();\n const mirrorAccountId = data.account;\n\n this.num = Long.fromString(\n mirrorAccountId.slice(mirrorAccountId.lastIndexOf(\".\") + 1),\n );\n /* eslint-enable */\n\n return this;\n }\n\n /**\n * @description Populates `evmAddress` field of the `AccountId` extracted from the Mirror Node.\n * @param {Client} client\n * @returns {Promise<AccountId>}\n */\n async populateAccountEvmAddress(client) {\n if (this.num === null) {\n throw new Error(\"field `num` should not be null\");\n }\n const mirrorUrl = client.mirrorNetwork[0].slice(\n 0,\n client.mirrorNetwork[0].indexOf(\":\"),\n );\n\n await new Promise((resolve) => {\n setTimeout(resolve, 3000);\n });\n\n /* eslint-disable */\n const url = `https://${mirrorUrl}/api/v1/accounts/${this.num.toString()}`;\n const response = await fetch(url);\n const data = await response.json();\n const mirrorAccountId = data.evm_address;\n\n this.evmAddress = EvmAddress.fromString(mirrorAccountId);\n /* eslint-enable */\n\n return this;\n }\n\n /**\n * @deprecated - Use `validateChecksum` instead\n * @param {Client} client\n */\n validate(client) {\n console.warn(\"Deprecated: Use `validateChecksum` instead\");\n this.validateChecksum(client);\n }\n\n /**\n * @param {Client} client\n */\n validateChecksum(client) {\n if (this.aliasKey != null) {\n throw new Error(\n \"cannot calculate checksum with an account ID that has a aliasKey\",\n );\n }\n\n EntityIdHelper.validateChecksum(\n this.shard,\n this.realm,\n this.num,\n this._checksum,\n client,\n );\n }\n\n /**\n * @param {Uint8Array} bytes\n * @returns {AccountId}\n */\n static fromBytes(bytes) {\n return AccountId._fromProtobuf(\n HieroProto.proto.AccountID.decode(bytes),\n );\n }\n\n /**\n * @deprecated - Use `fromEvmAddress` instead\n * @param {string} address\n * @returns {AccountId}\n */\n static fromSolidityAddress(address) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n if (isLongZeroAddress(hex.decode(address))) {\n return new AccountId(\n ...EntityIdHelper.fromSolidityAddress(address),\n );\n } else {\n return this.fromEvmAddress(0, 0, address);\n }\n }\n\n /**\n * @description Statically compute the EVM address. Use only with non-native EVM accounts.\n * @deprecated - Use `toEvmAddress` instead\n * If the account is EVM-native, the EVM address depends on the public key and is not directly related to the account ID.\n * @returns {string}\n */\n toSolidityAddress() {\n if (this.evmAddress != null) {\n return this.evmAddress.toString();\n } else if (\n this.aliasKey != null &&\n this.aliasKey._key._type == \"secp256k1\"\n ) {\n return this.aliasKey.toEvmAddress();\n } else {\n return EntityIdHelper.toSolidityAddress([\n this.shard,\n this.realm,\n this.num,\n ]);\n }\n }\n\n /**\n * @returns {string} EVM-compatible address representation of the entity\n */\n toEvmAddress() {\n if (this.evmAddress != null) {\n return EntityIdHelper.toEvmAddress(this.evmAddress.toBytes());\n }\n\n return EntityIdHelper.toEvmAddress(this.num);\n }\n\n //TODO remove the comments after we get to HIP-631\n /**\n * @internal\n * @returns {HieroProto.proto.IAccountID}\n */\n _toProtobuf() {\n let alias = null;\n //let evmAddress = null;\n\n if (this.aliasKey != null) {\n alias = HieroProto.proto.Key.encode(\n this.aliasKey._toProtobufKey(),\n ).finish();\n } else if (this.evmAddress != null) {\n alias = this.evmAddress._bytes;\n }\n\n /* if (this.evmAddress != null) {\n evmAddress = this.evmAddress._bytes;\n } */\n\n const isHollowAccount = this.num.eq(Long.fromBigInt(0n)) && alias;\n\n if (alias) {\n return {\n alias: isHollowAccount ? alias : null,\n accountNum: isHollowAccount ? null : this.num,\n shardNum: this.shard,\n realmNum: this.realm,\n };\n }\n return {\n alias: null,\n accountNum: this.num,\n shardNum: this.shard,\n realmNum: this.realm,\n };\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n return HieroProto.proto.AccountID.encode(this._toProtobuf()).finish();\n }\n\n /**\n * @returns {string}\n */\n toString() {\n let account = this.num.toString();\n\n if (this.aliasKey != null) {\n account = this.aliasKey.toString();\n } else if (this.evmAddress != null) {\n account = this.evmAddress.toString();\n }\n\n return `${this.shard.toString()}.${this.realm.toString()}.${account}`;\n }\n\n /**\n * @param {Client} client\n * @returns {string}\n */\n toStringWithChecksum(client) {\n if (this.aliasKey != null) {\n throw new Error(\n \"cannot calculate checksum with an account ID that has a aliasKey\",\n );\n }\n\n return EntityIdHelper.toStringWithChecksum(this.toString(), client);\n }\n\n /**\n * @param {this} other\n * @returns {boolean}\n */\n equals(other) {\n let account = false;\n\n if (this.aliasKey != null && other.aliasKey != null) {\n account = this.aliasKey.equals(other.aliasKey);\n } else if (this.evmAddress != null && other.evmAddress != null) {\n account = this.evmAddress.equals(other.evmAddress);\n } else if (\n this.aliasKey == null &&\n other.aliasKey == null &&\n this.evmAddress == null &&\n other.evmAddress == null\n ) {\n account = this.num.eq(other.num);\n }\n\n return (\n this.shard.eq(other.shard) && this.realm.eq(other.realm) && account\n );\n }\n\n /**\n * @returns {AccountId}\n */\n clone() {\n const id = new AccountId(this);\n id._checksum = this._checksum;\n id.aliasKey = this.aliasKey;\n id.evmAddress = this.evmAddress;\n return id;\n }\n\n /**\n * @param {AccountId} other\n * @returns {number}\n */\n compare(other) {\n let comparison = this.shard.compare(other.shard);\n if (comparison != 0) {\n return comparison;\n }\n\n comparison = this.realm.compare(other.realm);\n if (comparison != 0) {\n return comparison;\n }\n\n if (this.aliasKey != null && other.aliasKey != null) {\n const t = this.aliasKey.toString();\n const o = other.aliasKey.toString();\n\n if (t > o) {\n return 1;\n } else if (t < o) {\n return -1;\n } else {\n return 0;\n }\n } else if (this.evmAddress != null && other.evmAddress != null) {\n const t = this.evmAddress.toString();\n const o = other.evmAddress.toString();\n\n if (t > o) {\n return 1;\n } else if (t < o) {\n return -1;\n } else {\n return 0;\n }\n } else if (\n this.aliasKey == null &&\n other.aliasKey == null &&\n this.evmAddress == null &&\n other.evmAddress == null\n ) {\n return this.num.compare(other.num);\n } else {\n return 1;\n }\n }\n}\n\nCACHE.setAccountIdConstructor(\n (shard, realm, key) => new AccountId(shard, realm, Long.ZERO, key),\n);\n"],"names":["AccountId","constructor","props","realm","num","aliasKey","evmAddress","result","EntityIdHelper.constructor","this","shard","_checksum","fromString","text","Long","ZERO","startsWith","length","EvmAddress","EntityIdHelper.fromStringSplitter","Number","isNaN","Error","numOrHex","PublicKey","fromEvmAddress","evmAddressObj","shardLong","realmLong","address","EntityIdHelper.fromEvmAddress","toString","undefined","fromEvmPublicAddress","_fromProtobuf","id","alias","fromBytes","Key","_fromProtobufKey","HieroProto","proto","decode","shardNum","realmNum","accountNum","checksum","getEvmAddress","populateAccountNum","client","mirrorUrl","mirrorNetwork","slice","indexOf","Promise","resolve","setTimeout","url","response","fetch","mirrorAccountId","json","account","lastIndexOf","populateAccountEvmAddress","evm_address","validate","console","warn","validateChecksum","EntityIdHelper.validateChecksum","bytes","AccountID","fromSolidityAddress","isLongZeroAddress","hex.decode","EntityIdHelper.fromSolidityAddress","toSolidityAddress","_key","_type","toEvmAddress","EntityIdHelper.toSolidityAddress","EntityIdHelper.toEvmAddress","toBytes","_toProtobuf","encode","_toProtobufKey","finish","_bytes","isHollowAccount","eq","fromBigInt","toStringWithChecksum","EntityIdHelper.toStringWithChecksum","equals","other","clone","compare","comparison","t","o","CACHE","setAccountIdConstructor","key"],"mappings":"sdAmBe,MAAMA,EAQjB,WAAAC,CAAYC,EAAOC,EAAOC,EAAKC,EAAUC,GACrC,MAAMC,EAASC,EAA2BN,EAAOC,EAAOC,GAExDK,KAAKC,MAAQH,EAAOG,MACpBD,KAAKN,MAAQI,EAAOJ,MACpBM,KAAKL,IAAMG,EAAOH,IAClBK,KAAKJ,SAAuB,MAAZA,EAAmBA,EAAW,KAC9CI,KAAKH,WAA2B,MAAdA,EAAqBA,EAAa,KAKpDG,KAAKE,UAAY,IACzB,CAWI,iBAAOC,CAAWC,GACd,IAGIR,EACAC,EAJAI,EAAQI,EAAKC,KACbZ,EAAQW,EAAKC,KACbX,EAAMU,EAAKC,KAIf,GAAKF,EAAKG,WAAW,OAAwB,IAAfH,EAAKI,QAAgC,IAAfJ,EAAKI,OACrDX,EAAaY,EAAWN,WAAWC,OAChC,CACH,MAAMN,EAASY,EAAkCN,GAEjD,GAAIO,OAAOC,MAAMd,EAAOG,QAAUU,OAAOC,MAAMd,EAAOJ,OAClD,MAAM,IAAImB,MAAM,gCAGA,MAAhBf,EAAOG,QAAeA,EAAQI,EAAKF,WAAWL,EAAOG,QACrC,MAAhBH,EAAOJ,QAAeA,EAAQW,EAAKF,WAAWL,EAAOJ,QAErDI,EAAOgB,SAASN,OAAS,GACzBb,EAAMU,EAAKF,WAAWL,EAAOgB,UACI,IAA1BhB,EAAOgB,SAASN,OACvB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AccountId.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Long from \"long\";\nimport * as EntityIdHelper from \"../EntityIdHelper.js\";\nimport * as HieroProto from \"@hashgraph/proto\";\nimport Key from \"../Key.js\";\nimport PublicKey from \"../PublicKey.js\";\nimport CACHE from \"../Cache.js\";\nimport EvmAddress from \"../EvmAddress.js\";\nimport * as hex from \".././encoding/hex.js\";\nimport { isLongZeroAddress } from \"../util.js\";\n\n/**\n * @typedef {import(\"../client/Client.js\").default<*, *>} Client\n */\n\n/**\n * The ID for a crypto-currency account on Hedera.\n */\nexport default class AccountId {\n /**\n * @param {number | Long | import(\"../EntityIdHelper\").IEntityId} props\n * @param {(number | Long)=} realm\n * @param {(number | Long)=} num\n * @param {(PublicKey)=} aliasKey\n * @param {(EvmAddress)=} evmAddress\n */\n constructor(props, realm, num, aliasKey, evmAddress) {\n const result = EntityIdHelper.constructor(props, realm, num);\n\n this.shard = result.shard;\n this.realm = result.realm;\n this.num = result.num;\n this.aliasKey = aliasKey != null ? aliasKey : null;\n this.evmAddress = evmAddress != null ? evmAddress : null;\n\n /**\n * @type {string | null}\n */\n this._checksum = null;\n }\n\n /**\n * @description Accepts the following formats as string:\n * - as stand alone nubmers\n * - as shard.realm.num\n * - as shard.realm.hex (wo 0x prefix)\n * - hex (w/wo 0x prefix)\n * @param {string} text\n * @returns {AccountId}\n */\n static fromString(text) {\n let shard = Long.ZERO;\n let realm = Long.ZERO;\n let num = Long.ZERO;\n let aliasKey = undefined;\n let evmAddress = undefined;\n\n if ((text.startsWith(\"0x\") && text.length == 42) || text.length == 40) {\n evmAddress = EvmAddress.fromString(text);\n } else {\n const result = EntityIdHelper.fromStringSplitter(text);\n\n if (Number.isNaN(result.shard) || Number.isNaN(result.realm)) {\n throw new Error(\"invalid format for entity ID\");\n }\n\n if (result.shard != null) shard = Long.fromString(result.shard);\n if (result.realm != null) realm = Long.fromString(result.realm);\n\n if (result.numOrHex.length < 20) {\n num = Long.fromString(result.numOrHex);\n } else if (result.numOrHex.length == 40) {\n evmAddress = EvmAddress.fromString(result.numOrHex);\n } else {\n aliasKey = PublicKey.fromString(result.numOrHex);\n }\n }\n\n return new AccountId(shard, realm, num, aliasKey, evmAddress);\n }\n\n /**\n * @description This handles both long-zero format and evm address format addresses.\n * If an actual evm address is passed, please use `AccountId.populateAccountNum(client)` method\n * to get the actual `num` value, since there is no cryptographic relation to the evm address\n * and cannot be populated directly\n * @param {Long | number} shard\n * @param {Long | number} realm\n * @param {EvmAddress | string} evmAddress\n * @returns {AccountId}\n */\n static fromEvmAddress(shard, realm, evmAddress) {\n const evmAddressObj =\n typeof evmAddress === \"string\"\n ? EvmAddress.fromString(evmAddress)\n : evmAddress;\n\n const [shardLong, realmLong, num, address] =\n EntityIdHelper.fromEvmAddress(\n shard,\n realm,\n evmAddressObj.toString(),\n );\n\n return new AccountId(\n shardLong,\n realmLong,\n num,\n undefined,\n address || undefined,\n );\n }\n\n /**\n * @deprecated - Use `fromEvmAddress` instead\n * @summary Accepts an evm address only as `EvmAddress` type\n * @param {EvmAddress} evmAddress\n * @returns {AccountId}\n */\n static fromEvmPublicAddress(evmAddress) {\n return new AccountId(0, 0, 0, undefined, evmAddress);\n }\n\n /**\n * @internal\n * @param {HieroProto.proto.IAccountID} id\n * @returns {AccountId}\n */\n static _fromProtobuf(id) {\n let aliasKey = undefined;\n let evmAddress = undefined;\n\n if (id.alias != null) {\n if (id.alias.length === 20) {\n evmAddress = EvmAddress.fromBytes(id.alias);\n } else {\n aliasKey = Key._fromProtobufKey(\n HieroProto.proto.Key.decode(id.alias),\n );\n }\n }\n\n if (!(aliasKey instanceof PublicKey)) {\n aliasKey = undefined;\n }\n\n return new AccountId(\n id.shardNum != null ? id.shardNum : 0,\n id.realmNum != null ? id.realmNum : 0,\n id.accountNum != null ? id.accountNum : 0,\n aliasKey,\n evmAddress,\n );\n }\n\n /**\n * @returns {string | null}\n */\n get checksum() {\n return this._checksum;\n }\n\n /**\n * @returns {?EvmAddress}\n */\n getEvmAddress() {\n return this.evmAddress;\n }\n\n /**\n * @description Gets the actual `num` field of the `AccountId` from the Mirror Node.\n * Should be used after generating `AccountId.fromEvmAddress()` because it sets the `num` field to `0`\n * automatically since there is no connection between the `num` and the `evmAddress`\n * @param {Client} client\n * @returns {Promise<AccountId>}\n */\n async populateAccountNum(client) {\n if (this.evmAddress === null) {\n throw new Error(\"field `evmAddress` should not be null\");\n }\n const mirrorRestApiBaseUrl = client.mirrorRestApiBaseUrl;\n\n const url = `${mirrorRestApiBaseUrl}/accounts/${this.evmAddress.toString()}`;\n\n await new Promise((resolve) => {\n setTimeout(resolve, 3000);\n });\n\n /* eslint-disable */\n const response = await fetch(url);\n const data = await response.json();\n const mirrorAccountId = data.account;\n\n this.num = Long.fromString(\n mirrorAccountId.slice(mirrorAccountId.lastIndexOf(\".\") + 1),\n );\n /* eslint-enable */\n\n return this;\n }\n\n /**\n * @description Populates `evmAddress` field of the `AccountId` extracted from the Mirror Node.\n * @param {Client} client\n * @returns {Promise<AccountId>}\n */\n async populateAccountEvmAddress(client) {\n if (this.num === null) {\n throw new Error(\"field `num` should not be null\");\n }\n const mirrorRestApiBaseUrl = client.mirrorRestApiBaseUrl;\n\n const url = `${mirrorRestApiBaseUrl}/accounts/${this.num.toString()}`;\n\n await new Promise((resolve) => {\n setTimeout(resolve, 3000);\n });\n\n /* eslint-disable */\n const response = await fetch(url);\n const data = await response.json();\n const mirrorAccountId = data.evm_address;\n\n this.evmAddress = EvmAddress.fromString(mirrorAccountId);\n /* eslint-enable */\n\n return this;\n }\n\n /**\n * @deprecated - Use `validateChecksum` instead\n * @param {Client} client\n */\n validate(client) {\n console.warn(\"Deprecated: Use `validateChecksum` instead\");\n this.validateChecksum(client);\n }\n\n /**\n * @param {Client} client\n */\n validateChecksum(client) {\n if (this.aliasKey != null) {\n throw new Error(\n \"cannot calculate checksum with an account ID that has a aliasKey\",\n );\n }\n\n EntityIdHelper.validateChecksum(\n this.shard,\n this.realm,\n this.num,\n this._checksum,\n client,\n );\n }\n\n /**\n * @param {Uint8Array} bytes\n * @returns {AccountId}\n */\n static fromBytes(bytes) {\n return AccountId._fromProtobuf(\n HieroProto.proto.AccountID.decode(bytes),\n );\n }\n\n /**\n * @deprecated - Use `fromEvmAddress` instead\n * @param {string} address\n * @returns {AccountId}\n */\n static fromSolidityAddress(address) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n if (isLongZeroAddress(hex.decode(address))) {\n return new AccountId(\n ...EntityIdHelper.fromSolidityAddress(address),\n );\n } else {\n return this.fromEvmAddress(0, 0, address);\n }\n }\n\n /**\n * @description Statically compute the EVM address. Use only with non-native EVM accounts.\n * @deprecated - Use `toEvmAddress` instead\n * If the account is EVM-native, the EVM address depends on the public key and is not directly related to the account ID.\n * @returns {string}\n */\n toSolidityAddress() {\n if (this.evmAddress != null) {\n return this.evmAddress.toString();\n } else if (\n this.aliasKey != null &&\n this.aliasKey._key._type == \"secp256k1\"\n ) {\n return this.aliasKey.toEvmAddress();\n } else {\n return EntityIdHelper.toSolidityAddress([\n this.shard,\n this.realm,\n this.num,\n ]);\n }\n }\n\n /**\n * @returns {string} EVM-compatible address representation of the entity\n */\n toEvmAddress() {\n if (this.evmAddress != null) {\n return EntityIdHelper.toEvmAddress(this.evmAddress.toBytes());\n }\n\n return EntityIdHelper.toEvmAddress(this.num);\n }\n\n //TODO remove the comments after we get to HIP-631\n /**\n * @internal\n * @returns {HieroProto.proto.IAccountID}\n */\n _toProtobuf() {\n let alias = null;\n //let evmAddress = null;\n\n if (this.aliasKey != null) {\n alias = HieroProto.proto.Key.encode(\n this.aliasKey._toProtobufKey(),\n ).finish();\n } else if (this.evmAddress != null) {\n alias = this.evmAddress._bytes;\n }\n\n /* if (this.evmAddress != null) {\n evmAddress = this.evmAddress._bytes;\n } */\n\n const isHollowAccount = this.num.eq(Long.fromBigInt(0n)) && alias;\n\n if (alias) {\n return {\n alias: isHollowAccount ? alias : null,\n accountNum: isHollowAccount ? null : this.num,\n shardNum: this.shard,\n realmNum: this.realm,\n };\n }\n return {\n alias: null,\n accountNum: this.num,\n shardNum: this.shard,\n realmNum: this.realm,\n };\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n return HieroProto.proto.AccountID.encode(this._toProtobuf()).finish();\n }\n\n /**\n * @returns {string}\n */\n toString() {\n let account = this.num.toString();\n\n if (this.aliasKey != null) {\n account = this.aliasKey.toString();\n } else if (this.evmAddress != null) {\n account = this.evmAddress.toString();\n }\n\n return `${this.shard.toString()}.${this.realm.toString()}.${account}`;\n }\n\n /**\n * @param {Client} client\n * @returns {string}\n */\n toStringWithChecksum(client) {\n if (this.aliasKey != null) {\n throw new Error(\n \"cannot calculate checksum with an account ID that has a aliasKey\",\n );\n }\n\n return EntityIdHelper.toStringWithChecksum(this.toString(), client);\n }\n\n /**\n * @param {this} other\n * @returns {boolean}\n */\n equals(other) {\n let account = false;\n\n if (this.aliasKey != null && other.aliasKey != null) {\n account = this.aliasKey.equals(other.aliasKey);\n } else if (this.evmAddress != null && other.evmAddress != null) {\n account = this.evmAddress.equals(other.evmAddress);\n } else if (\n this.aliasKey == null &&\n other.aliasKey == null &&\n this.evmAddress == null &&\n other.evmAddress == null\n ) {\n account = this.num.eq(other.num);\n }\n\n return (\n this.shard.eq(other.shard) && this.realm.eq(other.realm) && account\n );\n }\n\n /**\n * @returns {AccountId}\n */\n clone() {\n const id = new AccountId(this);\n id._checksum = this._checksum;\n id.aliasKey = this.aliasKey;\n id.evmAddress = this.evmAddress;\n return id;\n }\n\n /**\n * @param {AccountId} other\n * @returns {number}\n */\n compare(other) {\n let comparison = this.shard.compare(other.shard);\n if (comparison != 0) {\n return comparison;\n }\n\n comparison = this.realm.compare(other.realm);\n if (comparison != 0) {\n return comparison;\n }\n\n if (this.aliasKey != null && other.aliasKey != null) {\n const t = this.aliasKey.toString();\n const o = other.aliasKey.toString();\n\n if (t > o) {\n return 1;\n } else if (t < o) {\n return -1;\n } else {\n return 0;\n }\n } else if (this.evmAddress != null && other.evmAddress != null) {\n const t = this.evmAddress.toString();\n const o = other.evmAddress.toString();\n\n if (t > o) {\n return 1;\n } else if (t < o) {\n return -1;\n } else {\n return 0;\n }\n } else if (\n this.aliasKey == null &&\n other.aliasKey == null &&\n this.evmAddress == null &&\n other.evmAddress == null\n ) {\n return this.num.compare(other.num);\n } else {\n return 1;\n }\n }\n}\n\nCACHE.setAccountIdConstructor(\n (shard, realm, key) => new AccountId(shard, realm, Long.ZERO, key),\n);\n"],"names":["AccountId","constructor","props","realm","num","aliasKey","evmAddress","result","EntityIdHelper.constructor","this","shard","_checksum","fromString","text","Long","ZERO","startsWith","length","EvmAddress","EntityIdHelper.fromStringSplitter","Number","isNaN","Error","numOrHex","PublicKey","fromEvmAddress","evmAddressObj","shardLong","realmLong","address","EntityIdHelper.fromEvmAddress","toString","undefined","fromEvmPublicAddress","_fromProtobuf","id","alias","fromBytes","Key","_fromProtobufKey","HieroProto","proto","decode","shardNum","realmNum","accountNum","checksum","getEvmAddress","populateAccountNum","client","url","mirrorRestApiBaseUrl","Promise","resolve","setTimeout","response","fetch","mirrorAccountId","json","account","slice","lastIndexOf","populateAccountEvmAddress","evm_address","validate","console","warn","validateChecksum","EntityIdHelper.validateChecksum","bytes","AccountID","fromSolidityAddress","isLongZeroAddress","hex.decode","EntityIdHelper.fromSolidityAddress","toSolidityAddress","_key","_type","toEvmAddress","EntityIdHelper.toSolidityAddress","EntityIdHelper.toEvmAddress","toBytes","_toProtobuf","encode","_toProtobufKey","finish","_bytes","isHollowAccount","eq","fromBigInt","toStringWithChecksum","EntityIdHelper.toStringWithChecksum","equals","other","clone","compare","comparison","t","o","CACHE","setAccountIdConstructor","key"],"mappings":"sdAmBe,MAAMA,EAQjB,WAAAC,CAAYC,EAAOC,EAAOC,EAAKC,EAAUC,GACrC,MAAMC,EAASC,EAA2BN,EAAOC,EAAOC,GAExDK,KAAKC,MAAQH,EAAOG,MACpBD,KAAKN,MAAQI,EAAOJ,MACpBM,KAAKL,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B,WAEzB,OAAIkE,EAAIC,EACG,EACAD,EAAIC,GACF,EAEF,CAEvB,CAAe,GAAuB,MAAnBzF,KAAKH,YAA0C,MAApBuF,EAAMvF,WAAoB,CAC5D,MAAM2F,EAAIxF,KAAKH,WAAWyB,WACpBmE,EAAIL,EAAMvF,WAAWyB,WAE3B,OAAIkE,EAAIC,EACG,EACAD,EAAIC,GACF,EAEF,CAEvB,CAAe,OACc,MAAjBzF,KAAKJ,UACa,MAAlBwF,EAAMxF,UACa,MAAnBI,KAAKH,YACe,MAApBuF,EAAMvF,WAECG,KAAKL,IAAI2F,QAAQF,EAAMzF,KAEvB,CAEnB,EAGA+F,EAAMC,wBACF,CAAC1F,EAAOP,EAAOkG,IAAQ,IAAIrG,EAAUU,EAAOP,EAAOW,EAAKC,KAAMsF"}
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _TokenId = _interopRequireDefault(require("../token/TokenId.cjs"));
|
|
8
8
|
var _AccountId = _interopRequireDefault(require("./AccountId.cjs"));
|
|
9
9
|
var _long = _interopRequireDefault(require("long"));
|
|
10
|
+
var _util = require("../util.cjs");
|
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
13
|
|
|
@@ -20,6 +21,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* @typedef {import("../client/Client.js").default<*, *>} Client
|
|
24
|
+
* @typedef {import("bignumber.js").default} BigNumber
|
|
23
25
|
*/
|
|
24
26
|
|
|
25
27
|
/**
|
|
@@ -36,7 +38,7 @@ class TokenAllowance {
|
|
|
36
38
|
* @param {TokenId} props.tokenId
|
|
37
39
|
* @param {AccountId | null} props.spenderAccountId
|
|
38
40
|
* @param {AccountId | null} props.ownerAccountId
|
|
39
|
-
* @param {Long | null} props.amount
|
|
41
|
+
* @param {Long | number | BigNumber | bigint | null} props.amount
|
|
40
42
|
*/
|
|
41
43
|
constructor(props) {
|
|
42
44
|
/**
|
|
@@ -67,7 +69,7 @@ class TokenAllowance {
|
|
|
67
69
|
*
|
|
68
70
|
* @readonly
|
|
69
71
|
*/
|
|
70
|
-
this.amount = props.amount;
|
|
72
|
+
this.amount = props.amount != null ? (0, _util.convertAmountToLong)(props.amount) : null;
|
|
71
73
|
Object.freeze(this);
|
|
72
74
|
}
|
|
73
75
|
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* @typedef {import("../client/Client.js").default<*, *>} Client
|
|
10
|
+
* @typedef {import("bignumber.js").default} BigNumber
|
|
10
11
|
*/
|
|
11
12
|
/**
|
|
12
13
|
* Represents a token allowance granted to a spender account by an owner account.
|
|
@@ -35,13 +36,13 @@ export default class TokenAllowance {
|
|
|
35
36
|
* @param {TokenId} props.tokenId
|
|
36
37
|
* @param {AccountId | null} props.spenderAccountId
|
|
37
38
|
* @param {AccountId | null} props.ownerAccountId
|
|
38
|
-
* @param {Long | null} props.amount
|
|
39
|
+
* @param {Long | number | BigNumber | bigint | null} props.amount
|
|
39
40
|
*/
|
|
40
41
|
constructor(props: {
|
|
41
42
|
tokenId: TokenId;
|
|
42
43
|
spenderAccountId: AccountId | null;
|
|
43
44
|
ownerAccountId: AccountId | null;
|
|
44
|
-
amount: Long | null;
|
|
45
|
+
amount: Long | number | BigNumber | bigint | null;
|
|
45
46
|
});
|
|
46
47
|
/**
|
|
47
48
|
* The token that the allowance pertains to.
|
|
@@ -88,6 +89,7 @@ export namespace HieroProto {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
export type Client = import("../client/Client.js").default<any, any>;
|
|
92
|
+
export type BigNumber = import("bignumber.js").default;
|
|
91
93
|
import TokenId from "../token/TokenId.js";
|
|
92
94
|
import AccountId from "./AccountId.js";
|
|
93
95
|
import Long from "long";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import o from"../token/TokenId.js";import t from"./AccountId.js";import n from"long";class
|
|
1
|
+
import o from"../token/TokenId.js";import t from"./AccountId.js";import n from"long";import{convertAmountToLong as e}from"../util.js";class u{constructor(o){this.tokenId=o.tokenId,this.spenderAccountId=o.spenderAccountId,this.ownerAccountId=o.ownerAccountId,this.amount=null!=o.amount?e(o.amount):null,Object.freeze(this)}static _fromProtobuf(e){return new u({tokenId:o._fromProtobuf(e.tokenId),spenderAccountId:t._fromProtobuf(e.spender),ownerAccountId:null!=e.owner?t._fromProtobuf(e.owner):null,amount:null!=e.amount?n.fromValue(e.amount):null})}static _fromGrantedProtobuf(e,r){return new u({tokenId:o._fromProtobuf(e.tokenId),spenderAccountId:t._fromProtobuf(e.spender),ownerAccountId:r,amount:null!=e.amount?n.fromValue(e.amount):null})}_toProtobuf(){return{tokenId:this.tokenId._toProtobuf(),spender:null!=this.spenderAccountId?this.spenderAccountId._toProtobuf():null,owner:null!=this.ownerAccountId?this.ownerAccountId._toProtobuf():null,amount:this.amount}}_validateChecksums(o){this.tokenId.validateChecksum(o),null!=this.ownerAccountId&&this.ownerAccountId.validateChecksum(o),null!=this.spenderAccountId&&this.spenderAccountId.validateChecksum(o)}}export{u as default};
|
|
2
2
|
//# sourceMappingURL=TokenAllowance.js.map
|