@gnolang/tm2-js-client 1.2.2 → 1.2.3
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/bin/proto/google/protobuf/any.d.ts +20 -14
- package/bin/proto/google/protobuf/any.js +29 -44
- package/bin/proto/tm2/abci.d.ts +37 -0
- package/bin/proto/tm2/abci.js +265 -0
- package/bin/proto/tm2/tx.d.ts +16 -36
- package/bin/proto/tm2/tx.js +79 -93
- package/bin/provider/jsonrpc/jsonrpc.d.ts +1 -1
- package/bin/provider/jsonrpc/jsonrpc.js +24 -3
- package/bin/provider/jsonrpc/jsonrpc.test.js +36 -4
- package/bin/provider/utility/provider.utility.d.ts +8 -1
- package/bin/provider/utility/provider.utility.js +32 -3
- package/bin/provider/utility/requests.utility.d.ts +2 -0
- package/bin/provider/utility/requests.utility.js +6 -1
- package/bin/provider/websocket/ws.d.ts +1 -1
- package/bin/provider/websocket/ws.js +27 -2
- package/bin/provider/websocket/ws.test.js +49 -4
- package/package.json +4 -4
package/bin/proto/tm2/tx.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
|
+
// versions:
|
|
4
|
+
// protoc-gen-ts_proto v2.2.0
|
|
5
|
+
// protoc v5.29.0
|
|
6
|
+
// source: tm2/tx.proto
|
|
2
7
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
9
|
};
|
|
5
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
11
|
exports.PubKeySecp256k1 = exports.TxSignature = exports.TxFee = exports.Tx = exports.protobufPackage = void 0;
|
|
7
12
|
/* eslint-disable */
|
|
13
|
+
var wire_1 = require("@bufbuild/protobuf/wire");
|
|
8
14
|
var long_1 = __importDefault(require("long"));
|
|
9
|
-
var minimal_1 = __importDefault(require("protobufjs/minimal"));
|
|
10
15
|
var any_1 = require("../google/protobuf/any");
|
|
11
16
|
exports.protobufPackage = 'tm2.tx';
|
|
12
17
|
function createBaseTx() {
|
|
@@ -14,17 +19,17 @@ function createBaseTx() {
|
|
|
14
19
|
}
|
|
15
20
|
exports.Tx = {
|
|
16
21
|
encode: function (message, writer) {
|
|
17
|
-
if (writer === void 0) { writer =
|
|
22
|
+
if (writer === void 0) { writer = new wire_1.BinaryWriter(); }
|
|
18
23
|
for (var _i = 0, _a = message.messages; _i < _a.length; _i++) {
|
|
19
24
|
var v = _a[_i];
|
|
20
|
-
any_1.Any.encode(v, writer.uint32(10).fork()).
|
|
25
|
+
any_1.Any.encode(v, writer.uint32(10).fork()).join();
|
|
21
26
|
}
|
|
22
27
|
if (message.fee !== undefined) {
|
|
23
|
-
exports.TxFee.encode(message.fee, writer.uint32(18).fork()).
|
|
28
|
+
exports.TxFee.encode(message.fee, writer.uint32(18).fork()).join();
|
|
24
29
|
}
|
|
25
30
|
for (var _b = 0, _c = message.signatures; _b < _c.length; _b++) {
|
|
26
31
|
var v = _c[_b];
|
|
27
|
-
exports.TxSignature.encode(v, writer.uint32(26).fork()).
|
|
32
|
+
exports.TxSignature.encode(v, writer.uint32(26).fork()).join();
|
|
28
33
|
}
|
|
29
34
|
if (message.memo !== '') {
|
|
30
35
|
writer.uint32(34).string(message.memo);
|
|
@@ -32,77 +37,71 @@ exports.Tx = {
|
|
|
32
37
|
return writer;
|
|
33
38
|
},
|
|
34
39
|
decode: function (input, length) {
|
|
35
|
-
var reader = input instanceof
|
|
40
|
+
var reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
|
|
36
41
|
var end = length === undefined ? reader.len : reader.pos + length;
|
|
37
42
|
var message = createBaseTx();
|
|
38
43
|
while (reader.pos < end) {
|
|
39
44
|
var tag = reader.uint32();
|
|
40
45
|
switch (tag >>> 3) {
|
|
41
46
|
case 1:
|
|
42
|
-
if (tag
|
|
47
|
+
if (tag !== 10) {
|
|
43
48
|
break;
|
|
44
49
|
}
|
|
45
50
|
message.messages.push(any_1.Any.decode(reader, reader.uint32()));
|
|
46
51
|
continue;
|
|
47
52
|
case 2:
|
|
48
|
-
if (tag
|
|
53
|
+
if (tag !== 18) {
|
|
49
54
|
break;
|
|
50
55
|
}
|
|
51
56
|
message.fee = exports.TxFee.decode(reader, reader.uint32());
|
|
52
57
|
continue;
|
|
53
58
|
case 3:
|
|
54
|
-
if (tag
|
|
59
|
+
if (tag !== 26) {
|
|
55
60
|
break;
|
|
56
61
|
}
|
|
57
62
|
message.signatures.push(exports.TxSignature.decode(reader, reader.uint32()));
|
|
58
63
|
continue;
|
|
59
64
|
case 4:
|
|
60
|
-
if (tag
|
|
65
|
+
if (tag !== 34) {
|
|
61
66
|
break;
|
|
62
67
|
}
|
|
63
68
|
message.memo = reader.string();
|
|
64
69
|
continue;
|
|
65
70
|
}
|
|
66
|
-
if ((tag & 7)
|
|
71
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
67
72
|
break;
|
|
68
73
|
}
|
|
69
|
-
reader.
|
|
74
|
+
reader.skip(tag & 7);
|
|
70
75
|
}
|
|
71
76
|
return message;
|
|
72
77
|
},
|
|
73
78
|
fromJSON: function (object) {
|
|
74
79
|
return {
|
|
75
|
-
messages: Array.isArray(object === null || object === void 0 ? void 0 : object.messages)
|
|
80
|
+
messages: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.messages)
|
|
76
81
|
? object.messages.map(function (e) { return any_1.Any.fromJSON(e); })
|
|
77
82
|
: [],
|
|
78
83
|
fee: isSet(object.fee) ? exports.TxFee.fromJSON(object.fee) : undefined,
|
|
79
|
-
signatures: Array.isArray(object === null || object === void 0 ? void 0 : object.signatures)
|
|
84
|
+
signatures: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.signatures)
|
|
80
85
|
? object.signatures.map(function (e) { return exports.TxSignature.fromJSON(e); })
|
|
81
86
|
: [],
|
|
82
|
-
memo: isSet(object.memo) ? String(object.memo) : '',
|
|
87
|
+
memo: isSet(object.memo) ? globalThis.String(object.memo) : '',
|
|
83
88
|
};
|
|
84
89
|
},
|
|
85
90
|
toJSON: function (message) {
|
|
91
|
+
var _a, _b;
|
|
86
92
|
var obj = {};
|
|
87
|
-
if (message.messages) {
|
|
88
|
-
obj.messages = message.messages.map(function (e) {
|
|
89
|
-
return e ? any_1.Any.toJSON(e) : undefined;
|
|
90
|
-
});
|
|
93
|
+
if ((_a = message.messages) === null || _a === void 0 ? void 0 : _a.length) {
|
|
94
|
+
obj.messages = message.messages.map(function (e) { return any_1.Any.toJSON(e); });
|
|
91
95
|
}
|
|
92
|
-
|
|
93
|
-
obj.
|
|
96
|
+
if (message.fee !== undefined) {
|
|
97
|
+
obj.fee = exports.TxFee.toJSON(message.fee);
|
|
94
98
|
}
|
|
95
|
-
message.
|
|
96
|
-
|
|
97
|
-
if (message.signatures) {
|
|
98
|
-
obj.signatures = message.signatures.map(function (e) {
|
|
99
|
-
return e ? exports.TxSignature.toJSON(e) : undefined;
|
|
100
|
-
});
|
|
99
|
+
if ((_b = message.signatures) === null || _b === void 0 ? void 0 : _b.length) {
|
|
100
|
+
obj.signatures = message.signatures.map(function (e) { return exports.TxSignature.toJSON(e); });
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
obj.
|
|
102
|
+
if (message.memo !== undefined) {
|
|
103
|
+
obj.memo = message.memo;
|
|
104
104
|
}
|
|
105
|
-
message.memo !== undefined && (obj.memo = message.memo);
|
|
106
105
|
return obj;
|
|
107
106
|
},
|
|
108
107
|
create: function (base) {
|
|
@@ -127,9 +126,9 @@ function createBaseTxFee() {
|
|
|
127
126
|
}
|
|
128
127
|
exports.TxFee = {
|
|
129
128
|
encode: function (message, writer) {
|
|
130
|
-
if (writer === void 0) { writer =
|
|
131
|
-
if (!message.gasWanted.
|
|
132
|
-
writer.uint32(8).sint64(message.gasWanted);
|
|
129
|
+
if (writer === void 0) { writer = new wire_1.BinaryWriter(); }
|
|
130
|
+
if (!message.gasWanted.equals(long_1.default.ZERO)) {
|
|
131
|
+
writer.uint32(8).sint64(message.gasWanted.toString());
|
|
133
132
|
}
|
|
134
133
|
if (message.gasFee !== '') {
|
|
135
134
|
writer.uint32(18).string(message.gasFee);
|
|
@@ -137,29 +136,29 @@ exports.TxFee = {
|
|
|
137
136
|
return writer;
|
|
138
137
|
},
|
|
139
138
|
decode: function (input, length) {
|
|
140
|
-
var reader = input instanceof
|
|
139
|
+
var reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
|
|
141
140
|
var end = length === undefined ? reader.len : reader.pos + length;
|
|
142
141
|
var message = createBaseTxFee();
|
|
143
142
|
while (reader.pos < end) {
|
|
144
143
|
var tag = reader.uint32();
|
|
145
144
|
switch (tag >>> 3) {
|
|
146
145
|
case 1:
|
|
147
|
-
if (tag
|
|
146
|
+
if (tag !== 8) {
|
|
148
147
|
break;
|
|
149
148
|
}
|
|
150
|
-
message.gasWanted = reader.sint64();
|
|
149
|
+
message.gasWanted = long_1.default.fromString(reader.sint64().toString());
|
|
151
150
|
continue;
|
|
152
151
|
case 2:
|
|
153
|
-
if (tag
|
|
152
|
+
if (tag !== 18) {
|
|
154
153
|
break;
|
|
155
154
|
}
|
|
156
155
|
message.gasFee = reader.string();
|
|
157
156
|
continue;
|
|
158
157
|
}
|
|
159
|
-
if ((tag & 7)
|
|
158
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
160
159
|
break;
|
|
161
160
|
}
|
|
162
|
-
reader.
|
|
161
|
+
reader.skip(tag & 7);
|
|
163
162
|
}
|
|
164
163
|
return message;
|
|
165
164
|
},
|
|
@@ -168,14 +167,17 @@ exports.TxFee = {
|
|
|
168
167
|
gasWanted: isSet(object.gasWanted)
|
|
169
168
|
? long_1.default.fromValue(object.gasWanted)
|
|
170
169
|
: long_1.default.ZERO,
|
|
171
|
-
gasFee: isSet(object.gasFee) ? String(object.gasFee) : '',
|
|
170
|
+
gasFee: isSet(object.gasFee) ? globalThis.String(object.gasFee) : '',
|
|
172
171
|
};
|
|
173
172
|
},
|
|
174
173
|
toJSON: function (message) {
|
|
175
174
|
var obj = {};
|
|
176
|
-
message.gasWanted !== undefined
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
if (message.gasWanted !== undefined) {
|
|
176
|
+
obj.gasWanted = (message.gasWanted || long_1.default.ZERO).toString();
|
|
177
|
+
}
|
|
178
|
+
if (message.gasFee !== undefined) {
|
|
179
|
+
obj.gasFee = message.gasFee;
|
|
180
|
+
}
|
|
179
181
|
return obj;
|
|
180
182
|
},
|
|
181
183
|
create: function (base) {
|
|
@@ -193,13 +195,13 @@ exports.TxFee = {
|
|
|
193
195
|
},
|
|
194
196
|
};
|
|
195
197
|
function createBaseTxSignature() {
|
|
196
|
-
return { pubKey: undefined, signature: new Uint8Array() };
|
|
198
|
+
return { pubKey: undefined, signature: new Uint8Array(0) };
|
|
197
199
|
}
|
|
198
200
|
exports.TxSignature = {
|
|
199
201
|
encode: function (message, writer) {
|
|
200
|
-
if (writer === void 0) { writer =
|
|
202
|
+
if (writer === void 0) { writer = new wire_1.BinaryWriter(); }
|
|
201
203
|
if (message.pubKey !== undefined) {
|
|
202
|
-
any_1.Any.encode(message.pubKey, writer.uint32(10).fork()).
|
|
204
|
+
any_1.Any.encode(message.pubKey, writer.uint32(10).fork()).join();
|
|
203
205
|
}
|
|
204
206
|
if (message.signature.length !== 0) {
|
|
205
207
|
writer.uint32(18).bytes(message.signature);
|
|
@@ -207,29 +209,29 @@ exports.TxSignature = {
|
|
|
207
209
|
return writer;
|
|
208
210
|
},
|
|
209
211
|
decode: function (input, length) {
|
|
210
|
-
var reader = input instanceof
|
|
212
|
+
var reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
|
|
211
213
|
var end = length === undefined ? reader.len : reader.pos + length;
|
|
212
214
|
var message = createBaseTxSignature();
|
|
213
215
|
while (reader.pos < end) {
|
|
214
216
|
var tag = reader.uint32();
|
|
215
217
|
switch (tag >>> 3) {
|
|
216
218
|
case 1:
|
|
217
|
-
if (tag
|
|
219
|
+
if (tag !== 10) {
|
|
218
220
|
break;
|
|
219
221
|
}
|
|
220
222
|
message.pubKey = any_1.Any.decode(reader, reader.uint32());
|
|
221
223
|
continue;
|
|
222
224
|
case 2:
|
|
223
|
-
if (tag
|
|
225
|
+
if (tag !== 18) {
|
|
224
226
|
break;
|
|
225
227
|
}
|
|
226
228
|
message.signature = reader.bytes();
|
|
227
229
|
continue;
|
|
228
230
|
}
|
|
229
|
-
if ((tag & 7)
|
|
231
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
230
232
|
break;
|
|
231
233
|
}
|
|
232
|
-
reader.
|
|
234
|
+
reader.skip(tag & 7);
|
|
233
235
|
}
|
|
234
236
|
return message;
|
|
235
237
|
},
|
|
@@ -238,15 +240,17 @@ exports.TxSignature = {
|
|
|
238
240
|
pubKey: isSet(object.pubKey) ? any_1.Any.fromJSON(object.pubKey) : undefined,
|
|
239
241
|
signature: isSet(object.signature)
|
|
240
242
|
? bytesFromBase64(object.signature)
|
|
241
|
-
: new Uint8Array(),
|
|
243
|
+
: new Uint8Array(0),
|
|
242
244
|
};
|
|
243
245
|
},
|
|
244
246
|
toJSON: function (message) {
|
|
245
247
|
var obj = {};
|
|
246
|
-
message.pubKey !== undefined
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
248
|
+
if (message.pubKey !== undefined) {
|
|
249
|
+
obj.pubKey = any_1.Any.toJSON(message.pubKey);
|
|
250
|
+
}
|
|
251
|
+
if (message.signature !== undefined) {
|
|
252
|
+
obj.signature = base64FromBytes(message.signature);
|
|
253
|
+
}
|
|
250
254
|
return obj;
|
|
251
255
|
},
|
|
252
256
|
create: function (base) {
|
|
@@ -259,51 +263,52 @@ exports.TxSignature = {
|
|
|
259
263
|
object.pubKey !== undefined && object.pubKey !== null
|
|
260
264
|
? any_1.Any.fromPartial(object.pubKey)
|
|
261
265
|
: undefined;
|
|
262
|
-
message.signature = (_a = object.signature) !== null && _a !== void 0 ? _a : new Uint8Array();
|
|
266
|
+
message.signature = (_a = object.signature) !== null && _a !== void 0 ? _a : new Uint8Array(0);
|
|
263
267
|
return message;
|
|
264
268
|
},
|
|
265
269
|
};
|
|
266
270
|
function createBasePubKeySecp256k1() {
|
|
267
|
-
return { key: new Uint8Array() };
|
|
271
|
+
return { key: new Uint8Array(0) };
|
|
268
272
|
}
|
|
269
273
|
exports.PubKeySecp256k1 = {
|
|
270
274
|
encode: function (message, writer) {
|
|
271
|
-
if (writer === void 0) { writer =
|
|
275
|
+
if (writer === void 0) { writer = new wire_1.BinaryWriter(); }
|
|
272
276
|
if (message.key.length !== 0) {
|
|
273
277
|
writer.uint32(10).bytes(message.key);
|
|
274
278
|
}
|
|
275
279
|
return writer;
|
|
276
280
|
},
|
|
277
281
|
decode: function (input, length) {
|
|
278
|
-
var reader = input instanceof
|
|
282
|
+
var reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
|
|
279
283
|
var end = length === undefined ? reader.len : reader.pos + length;
|
|
280
284
|
var message = createBasePubKeySecp256k1();
|
|
281
285
|
while (reader.pos < end) {
|
|
282
286
|
var tag = reader.uint32();
|
|
283
287
|
switch (tag >>> 3) {
|
|
284
288
|
case 1:
|
|
285
|
-
if (tag
|
|
289
|
+
if (tag !== 10) {
|
|
286
290
|
break;
|
|
287
291
|
}
|
|
288
292
|
message.key = reader.bytes();
|
|
289
293
|
continue;
|
|
290
294
|
}
|
|
291
|
-
if ((tag & 7)
|
|
295
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
292
296
|
break;
|
|
293
297
|
}
|
|
294
|
-
reader.
|
|
298
|
+
reader.skip(tag & 7);
|
|
295
299
|
}
|
|
296
300
|
return message;
|
|
297
301
|
},
|
|
298
302
|
fromJSON: function (object) {
|
|
299
303
|
return {
|
|
300
|
-
key: isSet(object.key) ? bytesFromBase64(object.key) : new Uint8Array(),
|
|
304
|
+
key: isSet(object.key) ? bytesFromBase64(object.key) : new Uint8Array(0),
|
|
301
305
|
};
|
|
302
306
|
},
|
|
303
307
|
toJSON: function (message) {
|
|
304
308
|
var obj = {};
|
|
305
|
-
message.key !== undefined
|
|
306
|
-
|
|
309
|
+
if (message.key !== undefined) {
|
|
310
|
+
obj.key = base64FromBytes(message.key);
|
|
311
|
+
}
|
|
307
312
|
return obj;
|
|
308
313
|
},
|
|
309
314
|
create: function (base) {
|
|
@@ -312,31 +317,16 @@ exports.PubKeySecp256k1 = {
|
|
|
312
317
|
fromPartial: function (object) {
|
|
313
318
|
var _a;
|
|
314
319
|
var message = createBasePubKeySecp256k1();
|
|
315
|
-
message.key = (_a = object.key) !== null && _a !== void 0 ? _a : new Uint8Array();
|
|
320
|
+
message.key = (_a = object.key) !== null && _a !== void 0 ? _a : new Uint8Array(0);
|
|
316
321
|
return message;
|
|
317
322
|
},
|
|
318
323
|
};
|
|
319
|
-
var tsProtoGlobalThis = (function () {
|
|
320
|
-
if (typeof globalThis !== 'undefined') {
|
|
321
|
-
return globalThis;
|
|
322
|
-
}
|
|
323
|
-
if (typeof self !== 'undefined') {
|
|
324
|
-
return self;
|
|
325
|
-
}
|
|
326
|
-
if (typeof window !== 'undefined') {
|
|
327
|
-
return window;
|
|
328
|
-
}
|
|
329
|
-
if (typeof global !== 'undefined') {
|
|
330
|
-
return global;
|
|
331
|
-
}
|
|
332
|
-
throw 'Unable to locate global object';
|
|
333
|
-
})();
|
|
334
324
|
function bytesFromBase64(b64) {
|
|
335
|
-
if (
|
|
336
|
-
return Uint8Array.from(
|
|
325
|
+
if (globalThis.Buffer) {
|
|
326
|
+
return Uint8Array.from(globalThis.Buffer.from(b64, 'base64'));
|
|
337
327
|
}
|
|
338
328
|
else {
|
|
339
|
-
var bin =
|
|
329
|
+
var bin = globalThis.atob(b64);
|
|
340
330
|
var arr = new Uint8Array(bin.length);
|
|
341
331
|
for (var i = 0; i < bin.length; ++i) {
|
|
342
332
|
arr[i] = bin.charCodeAt(i);
|
|
@@ -345,21 +335,17 @@ function bytesFromBase64(b64) {
|
|
|
345
335
|
}
|
|
346
336
|
}
|
|
347
337
|
function base64FromBytes(arr) {
|
|
348
|
-
if (
|
|
349
|
-
return
|
|
338
|
+
if (globalThis.Buffer) {
|
|
339
|
+
return globalThis.Buffer.from(arr).toString('base64');
|
|
350
340
|
}
|
|
351
341
|
else {
|
|
352
342
|
var bin_1 = [];
|
|
353
343
|
arr.forEach(function (byte) {
|
|
354
|
-
bin_1.push(String.fromCharCode(byte));
|
|
344
|
+
bin_1.push(globalThis.String.fromCharCode(byte));
|
|
355
345
|
});
|
|
356
|
-
return
|
|
346
|
+
return globalThis.btoa(bin_1.join(''));
|
|
357
347
|
}
|
|
358
348
|
}
|
|
359
|
-
if (minimal_1.default.util.Long !== long_1.default) {
|
|
360
|
-
minimal_1.default.util.Long = long_1.default;
|
|
361
|
-
minimal_1.default.configure();
|
|
362
|
-
}
|
|
363
349
|
function isSet(value) {
|
|
364
350
|
return value !== null && value !== undefined;
|
|
365
351
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Tx } from '../../proto';
|
|
1
2
|
import { Provider } from '../provider';
|
|
2
3
|
import { BlockInfo, BlockResult, BroadcastTransactionMap, ConsensusParams, NetworkInfo, Status, TxResult } from '../types';
|
|
3
|
-
import { Tx } from '../../proto';
|
|
4
4
|
/**
|
|
5
5
|
* Provider based on JSON-RPC HTTP requests
|
|
6
6
|
*/
|
|
@@ -37,10 +37,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.JSONRPCProvider = void 0;
|
|
40
|
-
var
|
|
40
|
+
var proto_1 = require("../../proto");
|
|
41
41
|
var services_1 = require("../../services");
|
|
42
|
-
var utility_1 = require("../utility");
|
|
43
42
|
var endpoints_1 = require("../endpoints");
|
|
43
|
+
var types_1 = require("../types");
|
|
44
|
+
var utility_1 = require("../utility");
|
|
44
45
|
var errors_utility_1 = require("../utility/errors.utility");
|
|
45
46
|
/**
|
|
46
47
|
* Provider based on JSON-RPC HTTP requests
|
|
@@ -54,7 +55,27 @@ var JSONRPCProvider = /** @class */ (function () {
|
|
|
54
55
|
this.baseURL = baseURL;
|
|
55
56
|
}
|
|
56
57
|
JSONRPCProvider.prototype.estimateGas = function (tx) {
|
|
57
|
-
return
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var encodedTx, abciResponse, simulateResult;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
encodedTx = (0, utility_1.uint8ArrayToBase64)(proto_1.Tx.encode(tx).finish());
|
|
64
|
+
return [4 /*yield*/, services_1.RestService.post(this.baseURL, {
|
|
65
|
+
request: (0, utility_1.newRequest)(endpoints_1.ABCIEndpoint.ABCI_QUERY, [
|
|
66
|
+
".app/simulate",
|
|
67
|
+
"".concat(encodedTx),
|
|
68
|
+
'0', // Height; not supported > 0 for now
|
|
69
|
+
false,
|
|
70
|
+
]),
|
|
71
|
+
})];
|
|
72
|
+
case 1:
|
|
73
|
+
abciResponse = _a.sent();
|
|
74
|
+
simulateResult = (0, utility_1.extractSimulateFromResponse)(abciResponse);
|
|
75
|
+
return [2 /*return*/, simulateResult.gasUsed.toInt()];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
58
79
|
};
|
|
59
80
|
JSONRPCProvider.prototype.getBalance = function (address, denomination, height) {
|
|
60
81
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -39,19 +39,51 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
var
|
|
42
|
+
var crypto_1 = require("@cosmjs/crypto");
|
|
43
43
|
var axios_1 = __importDefault(require("axios"));
|
|
44
|
-
var jsonrpc_1 = require("./jsonrpc");
|
|
45
|
-
var utility_1 = require("../utility");
|
|
46
44
|
var jest_mock_extended_1 = require("jest-mock-extended");
|
|
45
|
+
var long_1 = __importDefault(require("long"));
|
|
47
46
|
var proto_1 = require("../../proto");
|
|
48
|
-
var crypto_1 = require("@cosmjs/crypto");
|
|
49
47
|
var endpoints_1 = require("../endpoints");
|
|
50
48
|
var messages_1 = require("../errors/messages");
|
|
49
|
+
var types_1 = require("../types");
|
|
50
|
+
var utility_1 = require("../utility");
|
|
51
|
+
var jsonrpc_1 = require("./jsonrpc");
|
|
51
52
|
jest.mock('axios');
|
|
52
53
|
var mockedAxios = axios_1.default;
|
|
53
54
|
var mockURL = '127.0.0.1:26657';
|
|
54
55
|
describe('JSON-RPC Provider', function () {
|
|
56
|
+
test('estimateGas', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
57
|
+
var tx, expectedEstimation, mockABCIResponse, provider, estimation;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
switch (_a.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
tx = proto_1.Tx.fromJSON({
|
|
62
|
+
signatures: [],
|
|
63
|
+
fee: {
|
|
64
|
+
gasFee: '',
|
|
65
|
+
gasWanted: new long_1.default(0),
|
|
66
|
+
},
|
|
67
|
+
messages: [],
|
|
68
|
+
memo: '',
|
|
69
|
+
});
|
|
70
|
+
expectedEstimation = 44900;
|
|
71
|
+
mockABCIResponse = (0, jest_mock_extended_1.mock)();
|
|
72
|
+
mockABCIResponse.response.Value =
|
|
73
|
+
'CiMiIW1zZzowLHN1Y2Nlc3M6dHJ1ZSxsb2c6LGV2ZW50czpbXRCAiXoYyL0F';
|
|
74
|
+
mockedAxios.post.mockResolvedValue({
|
|
75
|
+
data: (0, utility_1.newResponse)(mockABCIResponse),
|
|
76
|
+
});
|
|
77
|
+
provider = new jsonrpc_1.JSONRPCProvider(mockURL);
|
|
78
|
+
return [4 /*yield*/, provider.estimateGas(tx)];
|
|
79
|
+
case 1:
|
|
80
|
+
estimation = _a.sent();
|
|
81
|
+
expect(axios_1.default.post).toHaveBeenCalled();
|
|
82
|
+
expect(estimation).toEqual(expectedEstimation);
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}); });
|
|
55
87
|
test('getNetwork', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
88
|
var mockInfo, provider, info;
|
|
57
89
|
return __generator(this, function (_a) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Provider } from '../provider';
|
|
2
1
|
import { Tx } from '../../proto';
|
|
2
|
+
import { ResponseDeliverTx } from '../../proto/tm2/abci';
|
|
3
|
+
import { Provider } from '../provider';
|
|
4
|
+
import { ABCIResponse } from '../types';
|
|
3
5
|
/**
|
|
4
6
|
* Extracts the specific balance denomination from the ABCI response
|
|
5
7
|
* @param {string | null} abciData the base64-encoded ABCI data
|
|
@@ -16,6 +18,11 @@ export declare const extractSequenceFromResponse: (abciData: string | null) => n
|
|
|
16
18
|
* @param {string | null} abciData the base64-encoded ABCI data
|
|
17
19
|
*/
|
|
18
20
|
export declare const extractAccountNumberFromResponse: (abciData: string | null) => number;
|
|
21
|
+
/**
|
|
22
|
+
* Extracts the simulate transaction response from the ABCI response value
|
|
23
|
+
* @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message
|
|
24
|
+
*/
|
|
25
|
+
export declare const extractSimulateFromResponse: (abciResponse: ABCIResponse | null) => ResponseDeliverTx;
|
|
19
26
|
/**
|
|
20
27
|
* Waits for the transaction to be committed to a block in the chain
|
|
21
28
|
* of the specified provider. This helper does a search for incoming blocks
|
|
@@ -36,10 +36,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.waitForTransaction = exports.extractAccountNumberFromResponse = exports.extractSequenceFromResponse = exports.extractBalanceFromResponse = void 0;
|
|
40
|
-
var requests_utility_1 = require("./requests.utility");
|
|
41
|
-
var proto_1 = require("../../proto");
|
|
39
|
+
exports.waitForTransaction = exports.extractSimulateFromResponse = exports.extractAccountNumberFromResponse = exports.extractSequenceFromResponse = exports.extractBalanceFromResponse = void 0;
|
|
42
40
|
var crypto_1 = require("@cosmjs/crypto");
|
|
41
|
+
var proto_1 = require("../../proto");
|
|
42
|
+
var abci_1 = require("../../proto/tm2/abci");
|
|
43
|
+
var types_1 = require("../types");
|
|
44
|
+
var errors_utility_1 = require("./errors.utility");
|
|
45
|
+
var requests_utility_1 = require("./requests.utility");
|
|
43
46
|
/**
|
|
44
47
|
* Extracts the specific balance denomination from the ABCI response
|
|
45
48
|
* @param {string | null} abciData the base64-encoded ABCI data
|
|
@@ -112,6 +115,32 @@ var extractAccountNumberFromResponse = function (abciData) {
|
|
|
112
115
|
}
|
|
113
116
|
};
|
|
114
117
|
exports.extractAccountNumberFromResponse = extractAccountNumberFromResponse;
|
|
118
|
+
/**
|
|
119
|
+
* Extracts the simulate transaction response from the ABCI response value
|
|
120
|
+
* @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message
|
|
121
|
+
*/
|
|
122
|
+
var extractSimulateFromResponse = function (abciResponse) {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
// Make sure the response is initialized
|
|
125
|
+
if (!abciResponse) {
|
|
126
|
+
throw new Error('abci data is not initialized');
|
|
127
|
+
}
|
|
128
|
+
var error = (_b = (_a = abciResponse.response) === null || _a === void 0 ? void 0 : _a.ResponseBase) === null || _b === void 0 ? void 0 : _b.Error;
|
|
129
|
+
if (error && error[types_1.ABCIErrorKey]) {
|
|
130
|
+
throw (0, errors_utility_1.constructRequestError)(error[types_1.ABCIErrorKey]);
|
|
131
|
+
}
|
|
132
|
+
var value = abciResponse.response.Value;
|
|
133
|
+
if (!value) {
|
|
134
|
+
throw new Error('abci data is not initialized');
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
return (0, requests_utility_1.parseProto)(value, abci_1.ResponseDeliverTx.decode);
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
throw new Error('unable to parse simulate response');
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
exports.extractSimulateFromResponse = extractSimulateFromResponse;
|
|
115
144
|
/**
|
|
116
145
|
* Waits for the transaction to be committed to a block in the chain
|
|
117
146
|
* of the specified provider. This helper does a search for incoming blocks
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BinaryReader } from '@bufbuild/protobuf/wire';
|
|
1
2
|
import { RPCError, RPCRequest, RPCResponse } from '../types';
|
|
2
3
|
/**
|
|
3
4
|
* Creates a new JSON-RPC 2.0 request
|
|
@@ -16,6 +17,7 @@ export declare const newResponse: <Result>(result?: Result, error?: RPCError) =>
|
|
|
16
17
|
* @param {string} data the base64-encoded JSON
|
|
17
18
|
*/
|
|
18
19
|
export declare const parseABCI: <Result>(data: string) => Result;
|
|
20
|
+
export declare const parseProto: <T>(data: string, decodeFn: (input: BinaryReader | Uint8Array, length?: number) => T) => T;
|
|
19
21
|
/**
|
|
20
22
|
* Converts a string into base64 representation
|
|
21
23
|
* @param {string} str the raw string
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uint8ArrayToBase64 = exports.base64ToUint8Array = exports.stringToBase64 = exports.parseABCI = exports.newResponse = exports.newRequest = void 0;
|
|
3
|
+
exports.uint8ArrayToBase64 = exports.base64ToUint8Array = exports.stringToBase64 = exports.parseProto = exports.parseABCI = exports.newResponse = exports.newRequest = void 0;
|
|
4
4
|
var uuid_1 = require("uuid");
|
|
5
5
|
// The version of the supported JSON-RPC protocol
|
|
6
6
|
var standardVersion = '2.0';
|
|
@@ -47,6 +47,11 @@ var parseABCI = function (data) {
|
|
|
47
47
|
return parsedData;
|
|
48
48
|
};
|
|
49
49
|
exports.parseABCI = parseABCI;
|
|
50
|
+
var parseProto = function (data, decodeFn) {
|
|
51
|
+
var protoData = decodeFn(Buffer.from(data, 'base64'));
|
|
52
|
+
return protoData;
|
|
53
|
+
};
|
|
54
|
+
exports.parseProto = parseProto;
|
|
50
55
|
/**
|
|
51
56
|
* Converts a string into base64 representation
|
|
52
57
|
* @param {string} str the raw string
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Tx } from '../../proto';
|
|
1
2
|
import { Provider } from '../provider';
|
|
2
3
|
import { BlockInfo, BlockResult, BroadcastTransactionMap, ConsensusParams, NetworkInfo, RPCRequest, RPCResponse, Status, TxResult } from '../types';
|
|
3
|
-
import { Tx } from '../../proto';
|
|
4
4
|
/**
|
|
5
5
|
* Provider based on WS JSON-RPC HTTP requests
|
|
6
6
|
*/
|