@firmachain/firma-js 0.2.26 → 0.2.29
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.
|
@@ -6,6 +6,7 @@ export declare class FirmaBankService {
|
|
|
6
6
|
private readonly config;
|
|
7
7
|
constructor(config: FirmaConfig);
|
|
8
8
|
getGasEstimationSend(wallet: FirmaWalletService, targetAddress: string, amount: number, txMisc?: TxMisc): Promise<number>;
|
|
9
|
+
getGasEstimationSendToken(wallet: FirmaWalletService, targetAddress: string, tokenID: string, amount: number, decimal: number, txMisc?: TxMisc): Promise<number>;
|
|
9
10
|
sendToken(wallet: FirmaWalletService, targetAddress: string, tokenID: string, amount: number, decimal: number, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
|
|
10
11
|
send(wallet: FirmaWalletService, targetAddress: string, amount: number, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
|
|
11
12
|
getTokenBalanceList(address: string): Promise<Token[]>;
|
|
@@ -65,10 +65,10 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
67
|
};
|
|
68
|
-
FirmaBankService.prototype.
|
|
68
|
+
FirmaBankService.prototype.getGasEstimationSendToken = function (wallet, targetAddress, tokenID, amount, decimal, txMisc) {
|
|
69
69
|
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
70
70
|
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
-
var txRaw,
|
|
71
|
+
var txRaw, error_2;
|
|
72
72
|
return __generator(this, function (_a) {
|
|
73
73
|
switch (_a.label) {
|
|
74
74
|
case 0:
|
|
@@ -76,8 +76,7 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
76
76
|
return [4 /*yield*/, this.getSignedTxSend(wallet, targetAddress, tokenID, FirmaUtil_1.FirmaUtil.getUTokenStringFromToken(amount, decimal), txMisc)];
|
|
77
77
|
case 1:
|
|
78
78
|
txRaw = _a.sent();
|
|
79
|
-
|
|
80
|
-
return [4 /*yield*/, bankTxClient.broadcast(txRaw)];
|
|
79
|
+
return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
|
|
81
80
|
case 2: return [2 /*return*/, _a.sent()];
|
|
82
81
|
case 3:
|
|
83
82
|
error_2 = _a.sent();
|
|
@@ -88,7 +87,7 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
88
87
|
});
|
|
89
88
|
});
|
|
90
89
|
};
|
|
91
|
-
FirmaBankService.prototype.
|
|
90
|
+
FirmaBankService.prototype.sendToken = function (wallet, targetAddress, tokenID, amount, decimal, txMisc) {
|
|
92
91
|
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
93
92
|
return __awaiter(this, void 0, void 0, function () {
|
|
94
93
|
var txRaw, bankTxClient, error_3;
|
|
@@ -96,7 +95,7 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
96
95
|
switch (_a.label) {
|
|
97
96
|
case 0:
|
|
98
97
|
_a.trys.push([0, 3, , 4]);
|
|
99
|
-
return [4 /*yield*/, this.getSignedTxSend(wallet, targetAddress,
|
|
98
|
+
return [4 /*yield*/, this.getSignedTxSend(wallet, targetAddress, tokenID, FirmaUtil_1.FirmaUtil.getUTokenStringFromToken(amount, decimal), txMisc)];
|
|
100
99
|
case 1:
|
|
101
100
|
txRaw = _a.sent();
|
|
102
101
|
bankTxClient = new bank_1.BankTxClient(wallet, this.config.rpcAddress);
|
|
@@ -111,9 +110,32 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
111
110
|
});
|
|
112
111
|
});
|
|
113
112
|
};
|
|
113
|
+
FirmaBankService.prototype.send = function (wallet, targetAddress, amount, txMisc) {
|
|
114
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
var txRaw, bankTxClient, error_4;
|
|
117
|
+
return __generator(this, function (_a) {
|
|
118
|
+
switch (_a.label) {
|
|
119
|
+
case 0:
|
|
120
|
+
_a.trys.push([0, 3, , 4]);
|
|
121
|
+
return [4 /*yield*/, this.getSignedTxSend(wallet, targetAddress, this.config.denom, FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amount), txMisc)];
|
|
122
|
+
case 1:
|
|
123
|
+
txRaw = _a.sent();
|
|
124
|
+
bankTxClient = new bank_1.BankTxClient(wallet, this.config.rpcAddress);
|
|
125
|
+
return [4 /*yield*/, bankTxClient.broadcast(txRaw)];
|
|
126
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
127
|
+
case 3:
|
|
128
|
+
error_4 = _a.sent();
|
|
129
|
+
FirmaUtil_1.FirmaUtil.printLog(error_4);
|
|
130
|
+
throw error_4;
|
|
131
|
+
case 4: return [2 /*return*/];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
114
136
|
FirmaBankService.prototype.getTokenBalanceList = function (address) {
|
|
115
137
|
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
-
var bankQueryClient, result, tokenList, i,
|
|
138
|
+
var bankQueryClient, result, tokenList, i, error_5;
|
|
117
139
|
return __generator(this, function (_a) {
|
|
118
140
|
switch (_a.label) {
|
|
119
141
|
case 0:
|
|
@@ -131,9 +153,9 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
131
153
|
}
|
|
132
154
|
return [2 /*return*/, tokenList];
|
|
133
155
|
case 2:
|
|
134
|
-
|
|
135
|
-
FirmaUtil_1.FirmaUtil.printLog(
|
|
136
|
-
throw
|
|
156
|
+
error_5 = _a.sent();
|
|
157
|
+
FirmaUtil_1.FirmaUtil.printLog(error_5);
|
|
158
|
+
throw error_5;
|
|
137
159
|
case 3: return [2 /*return*/];
|
|
138
160
|
}
|
|
139
161
|
});
|
|
@@ -141,7 +163,7 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
141
163
|
};
|
|
142
164
|
FirmaBankService.prototype.getTokenBalance = function (address, tokenID) {
|
|
143
165
|
return __awaiter(this, void 0, void 0, function () {
|
|
144
|
-
var bankQueryClient, result,
|
|
166
|
+
var bankQueryClient, result, error_6;
|
|
145
167
|
return __generator(this, function (_a) {
|
|
146
168
|
switch (_a.label) {
|
|
147
169
|
case 0:
|
|
@@ -152,9 +174,9 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
152
174
|
result = _a.sent();
|
|
153
175
|
return [2 /*return*/, result.amount];
|
|
154
176
|
case 2:
|
|
155
|
-
|
|
156
|
-
FirmaUtil_1.FirmaUtil.printLog(
|
|
157
|
-
throw
|
|
177
|
+
error_6 = _a.sent();
|
|
178
|
+
FirmaUtil_1.FirmaUtil.printLog(error_6);
|
|
179
|
+
throw error_6;
|
|
158
180
|
case 3: return [2 /*return*/];
|
|
159
181
|
}
|
|
160
182
|
});
|
|
@@ -162,7 +184,7 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
162
184
|
};
|
|
163
185
|
FirmaBankService.prototype.getBalance = function (address) {
|
|
164
186
|
return __awaiter(this, void 0, void 0, function () {
|
|
165
|
-
var bankQueryClient, result,
|
|
187
|
+
var bankQueryClient, result, error_7;
|
|
166
188
|
return __generator(this, function (_a) {
|
|
167
189
|
switch (_a.label) {
|
|
168
190
|
case 0:
|
|
@@ -173,9 +195,9 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
173
195
|
result = _a.sent();
|
|
174
196
|
return [2 /*return*/, result.amount];
|
|
175
197
|
case 2:
|
|
176
|
-
|
|
177
|
-
FirmaUtil_1.FirmaUtil.printLog(
|
|
178
|
-
throw
|
|
198
|
+
error_7 = _a.sent();
|
|
199
|
+
FirmaUtil_1.FirmaUtil.printLog(error_7);
|
|
200
|
+
throw error_7;
|
|
179
201
|
case 3: return [2 /*return*/];
|
|
180
202
|
}
|
|
181
203
|
});
|
|
@@ -184,7 +206,7 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
184
206
|
FirmaBankService.prototype.getSignedTxSend = function (wallet, targetAddress, denom, amount, txMisc) {
|
|
185
207
|
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
186
208
|
return __awaiter(this, void 0, void 0, function () {
|
|
187
|
-
var bankTxClient, address, sendAmount, message,
|
|
209
|
+
var bankTxClient, address, sendAmount, message, error_8;
|
|
188
210
|
return __generator(this, function (_a) {
|
|
189
211
|
switch (_a.label) {
|
|
190
212
|
case 0:
|
|
@@ -198,9 +220,9 @@ var FirmaBankService = /** @class */ (function () {
|
|
|
198
220
|
return [4 /*yield*/, bankTxClient.sign([message], FirmaUtil_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
|
|
199
221
|
case 2: return [2 /*return*/, _a.sent()];
|
|
200
222
|
case 3:
|
|
201
|
-
|
|
202
|
-
FirmaUtil_1.FirmaUtil.printLog(
|
|
203
|
-
throw
|
|
223
|
+
error_8 = _a.sent();
|
|
224
|
+
FirmaUtil_1.FirmaUtil.printLog(error_8);
|
|
225
|
+
throw error_8;
|
|
204
226
|
case 4: return [2 /*return*/];
|
|
205
227
|
}
|
|
206
228
|
});
|
package/dist/sdk/FirmaUtil.js
CHANGED
|
@@ -68,7 +68,7 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
68
68
|
var fct = Number.parseFloat(tokenAmount);
|
|
69
69
|
var decimalMutiplyer = Math.pow(10, decimal);
|
|
70
70
|
var big = fct * decimalMutiplyer;
|
|
71
|
-
return big.
|
|
71
|
+
return big.toFixed(0);
|
|
72
72
|
};
|
|
73
73
|
FirmaUtil.getTokenStringFromUTokenStr = function (uTokenAmount, decimal) {
|
|
74
74
|
var ufct = Number.parseInt(uTokenAmount);
|
|
@@ -78,12 +78,13 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
78
78
|
FirmaUtil.getUTokenStringFromToken = function (tokenAmount, decimal) {
|
|
79
79
|
var decimalMutiplyer = Math.pow(10, decimal);
|
|
80
80
|
var big = tokenAmount * decimalMutiplyer;
|
|
81
|
-
return big.
|
|
81
|
+
return big.toFixed(0);
|
|
82
82
|
};
|
|
83
83
|
FirmaUtil.getUTokenFromToken = function (tokenAmount, decimal) {
|
|
84
84
|
var decimalMutiplyer = Math.pow(10, decimal);
|
|
85
85
|
var big = tokenAmount * decimalMutiplyer;
|
|
86
|
-
|
|
86
|
+
var newBig = big.toFixed(0);
|
|
87
|
+
return Number.parseInt(newBig);
|
|
87
88
|
};
|
|
88
89
|
FirmaUtil.getTokenStringFromUToken = function (uTokenAmount, decimal) {
|
|
89
90
|
var decimalMutiplyer = Math.pow(10, decimal);
|