@transak/hedera-transak 1.0.6 → 1.0.7
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/lib/config.js +2 -0
- package/lib/index.js +41 -30
- package/lib/types.d.ts +1 -2
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +5 -4
- package/package.json +2 -1
package/lib/config.js
CHANGED
|
@@ -5,12 +5,14 @@ exports.networks = {
|
|
|
5
5
|
main: {
|
|
6
6
|
transactionLink: hash => `https://hederaexplorer.io/search-details/transaction/${hash}`,
|
|
7
7
|
walletLink: address => `https://hederaexplorer.io/search-details/account/${address}`,
|
|
8
|
+
mirrorNodeUrl: 'https://mainnet-public.mirrornode.hedera.com/api/v1/transactions/',
|
|
8
9
|
networkName: 'mainnet',
|
|
9
10
|
},
|
|
10
11
|
testnet: {
|
|
11
12
|
transactionLink: hash => `https://testnet.hederaexplorer.io/search-details/transaction/${hash}`,
|
|
12
13
|
walletLink: address => `https://testnet.hederaexplorer.io/search-details/account/${address}`,
|
|
13
14
|
networkName: 'testnet',
|
|
15
|
+
mirrorNodeUrl: 'https://testnet.mirrornode.hedera.com/api/v1/transactions/',
|
|
14
16
|
},
|
|
15
17
|
};
|
|
16
18
|
module.exports = { networks: exports.networks };
|
package/lib/index.js
CHANGED
|
@@ -8,6 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
15
|
const config_1 = require("./config");
|
|
12
16
|
const utils_1 = require("./utils");
|
|
13
17
|
const sdk_1 = require("@hashgraph/sdk");
|
|
@@ -109,35 +113,42 @@ function getBalance(network, decimals, privateKey, accountId, tokenId) {
|
|
|
109
113
|
* @returns
|
|
110
114
|
*/
|
|
111
115
|
function getTransaction(txnId, network, privateKey, accountId) {
|
|
112
|
-
var _a, _b, _c;
|
|
113
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
117
|
+
try {
|
|
118
|
+
const { mirrorNodeUrl } = getNetwork(network);
|
|
119
|
+
if (txnId.includes('@')) {
|
|
120
|
+
txnId = (0, utils_1._getTransactionNumber)(txnId);
|
|
121
|
+
}
|
|
122
|
+
const response = yield (0, axios_1.default)({
|
|
123
|
+
method: 'get',
|
|
124
|
+
url: mirrorNodeUrl + txnId,
|
|
125
|
+
headers: {
|
|
126
|
+
accept: 'application/json',
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
const transactionData = response.data.transactions[0];
|
|
130
|
+
return {
|
|
131
|
+
transactionData,
|
|
132
|
+
receipt: {
|
|
133
|
+
date: transactionData.consensus_timestamp,
|
|
134
|
+
gasCostCryptoCurrency: 'HBAR',
|
|
135
|
+
gasCostInCrypto: +(0, utils_1._toDecimal)(transactionData.charged_tx_fee.toString(), 8),
|
|
136
|
+
gasLimit: +(0, utils_1._toDecimal)(transactionData.max_fee.toString(), 8),
|
|
137
|
+
isPending: false,
|
|
138
|
+
isExecuted: true,
|
|
139
|
+
isSuccessful: transactionData.result === 'SUCCESS',
|
|
140
|
+
isFailed: transactionData.result !== 'SUCCESS',
|
|
141
|
+
isInvalid: transactionData.result !== 'SUCCESS',
|
|
142
|
+
network,
|
|
143
|
+
nonce: transactionData.nonce || 0,
|
|
144
|
+
transactionHash: transactionData.transaction_id,
|
|
145
|
+
transactionLink: getTransactionLink(txnId, network),
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
141
152
|
});
|
|
142
153
|
}
|
|
143
154
|
/**
|
|
@@ -180,8 +191,8 @@ function sendTransaction({ to, amount, network, accountId, privateKey, decimals,
|
|
|
180
191
|
network,
|
|
181
192
|
nonce: ((_b = sendTransactionResponse.transactionId.nonce) === null || _b === void 0 ? void 0 : _b.toNumber()) || 0,
|
|
182
193
|
to,
|
|
183
|
-
transactionHash: sendTransactionResponse.transactionId.toString(),
|
|
184
|
-
transactionLink: getTransactionLink(sendTransactionResponse.transactionId.toString(), network),
|
|
194
|
+
transactionHash: (0, utils_1._getTransactionNumber)(sendTransactionResponse.transactionId.toString()),
|
|
195
|
+
transactionLink: getTransactionLink((0, utils_1._getTransactionNumber)(sendTransactionResponse.transactionId.toString()), network),
|
|
185
196
|
},
|
|
186
197
|
};
|
|
187
198
|
});
|
package/lib/types.d.ts
CHANGED
|
@@ -3,13 +3,12 @@ export declare type Network = {
|
|
|
3
3
|
networkName: string;
|
|
4
4
|
transactionLink: (arg0: string) => string;
|
|
5
5
|
walletLink: (arg0: string) => string;
|
|
6
|
+
mirrorNodeUrl: string;
|
|
6
7
|
};
|
|
7
8
|
export declare type GetTransactionResult = {
|
|
8
9
|
transactionData: TransactionRecord;
|
|
9
10
|
receipt: {
|
|
10
|
-
amount: number;
|
|
11
11
|
date: Date | null;
|
|
12
|
-
from: string;
|
|
13
12
|
gasCostCryptoCurrency: string;
|
|
14
13
|
gasCostInCrypto: number;
|
|
15
14
|
gasLimit: number;
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BigNumber } from '@hashgraph/hethers';
|
|
2
2
|
export declare const _toDecimal: (amount: string, decimals: number) => string;
|
|
3
3
|
export declare const _toCrypto: (amount: string, decimals: number) => BigNumber;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const _getTransactionNumber: (txnId: string) => string;
|
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports._getTransactionNumber = exports._toCrypto = exports._toDecimal = void 0;
|
|
4
4
|
const hethers_1 = require("@hashgraph/hethers");
|
|
5
5
|
// converts any units to Hbars
|
|
6
6
|
const _toDecimal = (amount, decimals) => {
|
|
@@ -11,8 +11,9 @@ exports._toDecimal = _toDecimal;
|
|
|
11
11
|
// converts Hbar to tinybar
|
|
12
12
|
const _toCrypto = (amount, decimals) => hethers_1.hethers.utils.parseUnits(amount, decimals);
|
|
13
13
|
exports._toCrypto = _toCrypto;
|
|
14
|
-
const
|
|
14
|
+
const _getTransactionNumber = (txnId) => {
|
|
15
15
|
const [accountId, rest] = txnId.split('@');
|
|
16
|
-
|
|
16
|
+
const [realm, timestamp] = rest.split('.');
|
|
17
|
+
return [accountId, realm, timestamp].join('-');
|
|
17
18
|
};
|
|
18
|
-
exports.
|
|
19
|
+
exports._getTransactionNumber = _getTransactionNumber;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transak/hedera-transak",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"@ethersproject/wordlists": "^5.7.0",
|
|
33
33
|
"@hashgraph/hethers": "^1.2.1",
|
|
34
34
|
"@hashgraph/sdk": "^2.18.1",
|
|
35
|
+
"axios": "^0.27.2",
|
|
35
36
|
"dotenv": "10.0.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|