@gnolang/tm2-js-client 1.0.3 → 1.0.5
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/provider/errors/errors.d.ts +59 -0
- package/bin/provider/errors/errors.js +173 -0
- package/bin/provider/errors/index.d.ts +1 -0
- package/bin/provider/errors/index.js +17 -0
- package/bin/provider/errors/messages.d.ts +19 -0
- package/bin/provider/errors/messages.js +41 -0
- package/bin/provider/index.d.ts +1 -0
- package/bin/provider/index.js +1 -0
- package/bin/provider/jsonrpc/jsonrpc.d.ts +4 -1
- package/bin/provider/jsonrpc/jsonrpc.js +56 -3
- package/bin/provider/jsonrpc/jsonrpc.test.js +55 -23
- package/bin/provider/provider.d.ts +4 -1
- package/bin/provider/types/common.d.ts +7 -1
- package/bin/provider/utility/errors.utility.d.ts +11 -0
- package/bin/provider/utility/errors.utility.js +56 -0
- package/bin/provider/websocket/ws.d.ts +4 -1
- package/bin/provider/websocket/ws.js +57 -4
- package/bin/provider/websocket/ws.test.js +49 -24
- package/bin/wallet/key/key.js +1 -1
- package/bin/wallet/ledger/ledger.js +1 -1
- package/bin/wallet/wallet.js +10 -11
- package/package.json +7 -7
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
declare class TM2Error extends Error {
|
|
2
|
+
log?: string;
|
|
3
|
+
constructor(message: string, log?: string);
|
|
4
|
+
}
|
|
5
|
+
declare class InternalError extends TM2Error {
|
|
6
|
+
constructor(log?: string);
|
|
7
|
+
}
|
|
8
|
+
declare class TxDecodeError extends TM2Error {
|
|
9
|
+
constructor(log?: string);
|
|
10
|
+
}
|
|
11
|
+
declare class InvalidSequenceError extends TM2Error {
|
|
12
|
+
constructor(log?: string);
|
|
13
|
+
}
|
|
14
|
+
declare class UnauthorizedError extends TM2Error {
|
|
15
|
+
constructor(log?: string);
|
|
16
|
+
}
|
|
17
|
+
declare class InsufficientFundsError extends TM2Error {
|
|
18
|
+
constructor(log?: string);
|
|
19
|
+
}
|
|
20
|
+
declare class UnknownRequestError extends TM2Error {
|
|
21
|
+
constructor(log?: string);
|
|
22
|
+
}
|
|
23
|
+
declare class InvalidAddressError extends TM2Error {
|
|
24
|
+
constructor(log?: string);
|
|
25
|
+
}
|
|
26
|
+
declare class UnknownAddressError extends TM2Error {
|
|
27
|
+
constructor(log?: string);
|
|
28
|
+
}
|
|
29
|
+
declare class InvalidPubKeyError extends TM2Error {
|
|
30
|
+
constructor(log?: string);
|
|
31
|
+
}
|
|
32
|
+
declare class InsufficientCoinsError extends TM2Error {
|
|
33
|
+
constructor(log?: string);
|
|
34
|
+
}
|
|
35
|
+
declare class InvalidCoinsError extends TM2Error {
|
|
36
|
+
constructor(log?: string);
|
|
37
|
+
}
|
|
38
|
+
declare class InvalidGasWantedError extends TM2Error {
|
|
39
|
+
constructor(log?: string);
|
|
40
|
+
}
|
|
41
|
+
declare class OutOfGasError extends TM2Error {
|
|
42
|
+
constructor(log?: string);
|
|
43
|
+
}
|
|
44
|
+
declare class MemoTooLargeError extends TM2Error {
|
|
45
|
+
constructor(log?: string);
|
|
46
|
+
}
|
|
47
|
+
declare class InsufficientFeeError extends TM2Error {
|
|
48
|
+
constructor(log?: string);
|
|
49
|
+
}
|
|
50
|
+
declare class TooManySignaturesError extends TM2Error {
|
|
51
|
+
constructor(log?: string);
|
|
52
|
+
}
|
|
53
|
+
declare class NoSignaturesError extends TM2Error {
|
|
54
|
+
constructor(log?: string);
|
|
55
|
+
}
|
|
56
|
+
declare class GasOverflowError extends TM2Error {
|
|
57
|
+
constructor(log?: string);
|
|
58
|
+
}
|
|
59
|
+
export { TM2Error, InternalError, TxDecodeError, InvalidSequenceError, UnauthorizedError, InsufficientFundsError, UnknownRequestError, InvalidAddressError, UnknownAddressError, InvalidPubKeyError, InsufficientCoinsError, InvalidCoinsError, InvalidGasWantedError, OutOfGasError, MemoTooLargeError, InsufficientFeeError, TooManySignaturesError, NoSignaturesError, GasOverflowError, };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.GasOverflowError = exports.NoSignaturesError = exports.TooManySignaturesError = exports.InsufficientFeeError = exports.MemoTooLargeError = exports.OutOfGasError = exports.InvalidGasWantedError = exports.InvalidCoinsError = exports.InsufficientCoinsError = exports.InvalidPubKeyError = exports.UnknownAddressError = exports.InvalidAddressError = exports.UnknownRequestError = exports.InsufficientFundsError = exports.UnauthorizedError = exports.InvalidSequenceError = exports.TxDecodeError = exports.InternalError = exports.TM2Error = void 0;
|
|
19
|
+
var messages_1 = require("./messages");
|
|
20
|
+
var TM2Error = /** @class */ (function (_super) {
|
|
21
|
+
__extends(TM2Error, _super);
|
|
22
|
+
function TM2Error(message, log) {
|
|
23
|
+
var _this = _super.call(this, message) || this;
|
|
24
|
+
_this.log = log;
|
|
25
|
+
return _this;
|
|
26
|
+
}
|
|
27
|
+
return TM2Error;
|
|
28
|
+
}(Error));
|
|
29
|
+
exports.TM2Error = TM2Error;
|
|
30
|
+
var InternalError = /** @class */ (function (_super) {
|
|
31
|
+
__extends(InternalError, _super);
|
|
32
|
+
function InternalError(log) {
|
|
33
|
+
return _super.call(this, messages_1.InternalErrorMessage, log) || this;
|
|
34
|
+
}
|
|
35
|
+
return InternalError;
|
|
36
|
+
}(TM2Error));
|
|
37
|
+
exports.InternalError = InternalError;
|
|
38
|
+
var TxDecodeError = /** @class */ (function (_super) {
|
|
39
|
+
__extends(TxDecodeError, _super);
|
|
40
|
+
function TxDecodeError(log) {
|
|
41
|
+
return _super.call(this, messages_1.TxDecodeErrorMessage, log) || this;
|
|
42
|
+
}
|
|
43
|
+
return TxDecodeError;
|
|
44
|
+
}(TM2Error));
|
|
45
|
+
exports.TxDecodeError = TxDecodeError;
|
|
46
|
+
var InvalidSequenceError = /** @class */ (function (_super) {
|
|
47
|
+
__extends(InvalidSequenceError, _super);
|
|
48
|
+
function InvalidSequenceError(log) {
|
|
49
|
+
return _super.call(this, messages_1.InvalidSequenceErrorMessage, log) || this;
|
|
50
|
+
}
|
|
51
|
+
return InvalidSequenceError;
|
|
52
|
+
}(TM2Error));
|
|
53
|
+
exports.InvalidSequenceError = InvalidSequenceError;
|
|
54
|
+
var UnauthorizedError = /** @class */ (function (_super) {
|
|
55
|
+
__extends(UnauthorizedError, _super);
|
|
56
|
+
function UnauthorizedError(log) {
|
|
57
|
+
return _super.call(this, messages_1.UnauthorizedErrorMessage, log) || this;
|
|
58
|
+
}
|
|
59
|
+
return UnauthorizedError;
|
|
60
|
+
}(TM2Error));
|
|
61
|
+
exports.UnauthorizedError = UnauthorizedError;
|
|
62
|
+
var InsufficientFundsError = /** @class */ (function (_super) {
|
|
63
|
+
__extends(InsufficientFundsError, _super);
|
|
64
|
+
function InsufficientFundsError(log) {
|
|
65
|
+
return _super.call(this, messages_1.InsufficientFundsErrorMessage, log) || this;
|
|
66
|
+
}
|
|
67
|
+
return InsufficientFundsError;
|
|
68
|
+
}(TM2Error));
|
|
69
|
+
exports.InsufficientFundsError = InsufficientFundsError;
|
|
70
|
+
var UnknownRequestError = /** @class */ (function (_super) {
|
|
71
|
+
__extends(UnknownRequestError, _super);
|
|
72
|
+
function UnknownRequestError(log) {
|
|
73
|
+
return _super.call(this, messages_1.UnknownRequestErrorMessage, log) || this;
|
|
74
|
+
}
|
|
75
|
+
return UnknownRequestError;
|
|
76
|
+
}(TM2Error));
|
|
77
|
+
exports.UnknownRequestError = UnknownRequestError;
|
|
78
|
+
var InvalidAddressError = /** @class */ (function (_super) {
|
|
79
|
+
__extends(InvalidAddressError, _super);
|
|
80
|
+
function InvalidAddressError(log) {
|
|
81
|
+
return _super.call(this, messages_1.InvalidAddressErrorMessage, log) || this;
|
|
82
|
+
}
|
|
83
|
+
return InvalidAddressError;
|
|
84
|
+
}(TM2Error));
|
|
85
|
+
exports.InvalidAddressError = InvalidAddressError;
|
|
86
|
+
var UnknownAddressError = /** @class */ (function (_super) {
|
|
87
|
+
__extends(UnknownAddressError, _super);
|
|
88
|
+
function UnknownAddressError(log) {
|
|
89
|
+
return _super.call(this, messages_1.UnknownAddressErrorMessage, log) || this;
|
|
90
|
+
}
|
|
91
|
+
return UnknownAddressError;
|
|
92
|
+
}(TM2Error));
|
|
93
|
+
exports.UnknownAddressError = UnknownAddressError;
|
|
94
|
+
var InvalidPubKeyError = /** @class */ (function (_super) {
|
|
95
|
+
__extends(InvalidPubKeyError, _super);
|
|
96
|
+
function InvalidPubKeyError(log) {
|
|
97
|
+
return _super.call(this, messages_1.InvalidPubKeyErrorMessage, log) || this;
|
|
98
|
+
}
|
|
99
|
+
return InvalidPubKeyError;
|
|
100
|
+
}(TM2Error));
|
|
101
|
+
exports.InvalidPubKeyError = InvalidPubKeyError;
|
|
102
|
+
var InsufficientCoinsError = /** @class */ (function (_super) {
|
|
103
|
+
__extends(InsufficientCoinsError, _super);
|
|
104
|
+
function InsufficientCoinsError(log) {
|
|
105
|
+
return _super.call(this, messages_1.InsufficientCoinsErrorMessage, log) || this;
|
|
106
|
+
}
|
|
107
|
+
return InsufficientCoinsError;
|
|
108
|
+
}(TM2Error));
|
|
109
|
+
exports.InsufficientCoinsError = InsufficientCoinsError;
|
|
110
|
+
var InvalidCoinsError = /** @class */ (function (_super) {
|
|
111
|
+
__extends(InvalidCoinsError, _super);
|
|
112
|
+
function InvalidCoinsError(log) {
|
|
113
|
+
return _super.call(this, messages_1.InvalidCoinsErrorMessage, log) || this;
|
|
114
|
+
}
|
|
115
|
+
return InvalidCoinsError;
|
|
116
|
+
}(TM2Error));
|
|
117
|
+
exports.InvalidCoinsError = InvalidCoinsError;
|
|
118
|
+
var InvalidGasWantedError = /** @class */ (function (_super) {
|
|
119
|
+
__extends(InvalidGasWantedError, _super);
|
|
120
|
+
function InvalidGasWantedError(log) {
|
|
121
|
+
return _super.call(this, messages_1.InvalidGasWantedErrorMessage, log) || this;
|
|
122
|
+
}
|
|
123
|
+
return InvalidGasWantedError;
|
|
124
|
+
}(TM2Error));
|
|
125
|
+
exports.InvalidGasWantedError = InvalidGasWantedError;
|
|
126
|
+
var OutOfGasError = /** @class */ (function (_super) {
|
|
127
|
+
__extends(OutOfGasError, _super);
|
|
128
|
+
function OutOfGasError(log) {
|
|
129
|
+
return _super.call(this, messages_1.OutOfGasErrorMessage, log) || this;
|
|
130
|
+
}
|
|
131
|
+
return OutOfGasError;
|
|
132
|
+
}(TM2Error));
|
|
133
|
+
exports.OutOfGasError = OutOfGasError;
|
|
134
|
+
var MemoTooLargeError = /** @class */ (function (_super) {
|
|
135
|
+
__extends(MemoTooLargeError, _super);
|
|
136
|
+
function MemoTooLargeError(log) {
|
|
137
|
+
return _super.call(this, messages_1.MemoTooLargeErrorMessage, log) || this;
|
|
138
|
+
}
|
|
139
|
+
return MemoTooLargeError;
|
|
140
|
+
}(TM2Error));
|
|
141
|
+
exports.MemoTooLargeError = MemoTooLargeError;
|
|
142
|
+
var InsufficientFeeError = /** @class */ (function (_super) {
|
|
143
|
+
__extends(InsufficientFeeError, _super);
|
|
144
|
+
function InsufficientFeeError(log) {
|
|
145
|
+
return _super.call(this, messages_1.InsufficientFeeErrorMessage, log) || this;
|
|
146
|
+
}
|
|
147
|
+
return InsufficientFeeError;
|
|
148
|
+
}(TM2Error));
|
|
149
|
+
exports.InsufficientFeeError = InsufficientFeeError;
|
|
150
|
+
var TooManySignaturesError = /** @class */ (function (_super) {
|
|
151
|
+
__extends(TooManySignaturesError, _super);
|
|
152
|
+
function TooManySignaturesError(log) {
|
|
153
|
+
return _super.call(this, messages_1.TooManySignaturesErrorMessage, log) || this;
|
|
154
|
+
}
|
|
155
|
+
return TooManySignaturesError;
|
|
156
|
+
}(TM2Error));
|
|
157
|
+
exports.TooManySignaturesError = TooManySignaturesError;
|
|
158
|
+
var NoSignaturesError = /** @class */ (function (_super) {
|
|
159
|
+
__extends(NoSignaturesError, _super);
|
|
160
|
+
function NoSignaturesError(log) {
|
|
161
|
+
return _super.call(this, messages_1.NoSignaturesErrorMessage, log) || this;
|
|
162
|
+
}
|
|
163
|
+
return NoSignaturesError;
|
|
164
|
+
}(TM2Error));
|
|
165
|
+
exports.NoSignaturesError = NoSignaturesError;
|
|
166
|
+
var GasOverflowError = /** @class */ (function (_super) {
|
|
167
|
+
__extends(GasOverflowError, _super);
|
|
168
|
+
function GasOverflowError(log) {
|
|
169
|
+
return _super.call(this, messages_1.GasOverflowErrorMessage, log) || this;
|
|
170
|
+
}
|
|
171
|
+
return GasOverflowError;
|
|
172
|
+
}(TM2Error));
|
|
173
|
+
exports.GasOverflowError = GasOverflowError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './errors';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./errors"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare const InternalErrorMessage = "internal error encountered";
|
|
2
|
+
declare const TxDecodeErrorMessage = "unable to decode tx";
|
|
3
|
+
declare const InvalidSequenceErrorMessage = "invalid sequence";
|
|
4
|
+
declare const UnauthorizedErrorMessage = "signature is unauthorized";
|
|
5
|
+
declare const InsufficientFundsErrorMessage = "insufficient funds";
|
|
6
|
+
declare const UnknownRequestErrorMessage = "unknown request";
|
|
7
|
+
declare const InvalidAddressErrorMessage = "invalid address";
|
|
8
|
+
declare const UnknownAddressErrorMessage = "unknown address";
|
|
9
|
+
declare const InvalidPubKeyErrorMessage = "invalid pubkey";
|
|
10
|
+
declare const InsufficientCoinsErrorMessage = "insufficient coins";
|
|
11
|
+
declare const InvalidCoinsErrorMessage = "invalid coins";
|
|
12
|
+
declare const InvalidGasWantedErrorMessage = "invalid gas wanted";
|
|
13
|
+
declare const OutOfGasErrorMessage = "out of gas";
|
|
14
|
+
declare const MemoTooLargeErrorMessage = "memo too large";
|
|
15
|
+
declare const InsufficientFeeErrorMessage = "insufficient fee";
|
|
16
|
+
declare const TooManySignaturesErrorMessage = "too many signatures";
|
|
17
|
+
declare const NoSignaturesErrorMessage = "no signatures";
|
|
18
|
+
declare const GasOverflowErrorMessage = "gas overflow";
|
|
19
|
+
export { InternalErrorMessage, TxDecodeErrorMessage, InvalidSequenceErrorMessage, UnauthorizedErrorMessage, InsufficientFundsErrorMessage, UnknownRequestErrorMessage, InvalidAddressErrorMessage, UnknownAddressErrorMessage, InvalidPubKeyErrorMessage, InsufficientCoinsErrorMessage, InvalidCoinsErrorMessage, InvalidGasWantedErrorMessage, OutOfGasErrorMessage, MemoTooLargeErrorMessage, InsufficientFeeErrorMessage, TooManySignaturesErrorMessage, NoSignaturesErrorMessage, GasOverflowErrorMessage, };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Errors constructed from:
|
|
3
|
+
// https://github.com/gnolang/gno/blob/master/tm2/pkg/std/errors.go
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.GasOverflowErrorMessage = exports.NoSignaturesErrorMessage = exports.TooManySignaturesErrorMessage = exports.InsufficientFeeErrorMessage = exports.MemoTooLargeErrorMessage = exports.OutOfGasErrorMessage = exports.InvalidGasWantedErrorMessage = exports.InvalidCoinsErrorMessage = exports.InsufficientCoinsErrorMessage = exports.InvalidPubKeyErrorMessage = exports.UnknownAddressErrorMessage = exports.InvalidAddressErrorMessage = exports.UnknownRequestErrorMessage = exports.InsufficientFundsErrorMessage = exports.UnauthorizedErrorMessage = exports.InvalidSequenceErrorMessage = exports.TxDecodeErrorMessage = exports.InternalErrorMessage = void 0;
|
|
6
|
+
var InternalErrorMessage = 'internal error encountered';
|
|
7
|
+
exports.InternalErrorMessage = InternalErrorMessage;
|
|
8
|
+
var TxDecodeErrorMessage = 'unable to decode tx';
|
|
9
|
+
exports.TxDecodeErrorMessage = TxDecodeErrorMessage;
|
|
10
|
+
var InvalidSequenceErrorMessage = 'invalid sequence';
|
|
11
|
+
exports.InvalidSequenceErrorMessage = InvalidSequenceErrorMessage;
|
|
12
|
+
var UnauthorizedErrorMessage = 'signature is unauthorized';
|
|
13
|
+
exports.UnauthorizedErrorMessage = UnauthorizedErrorMessage;
|
|
14
|
+
var InsufficientFundsErrorMessage = 'insufficient funds';
|
|
15
|
+
exports.InsufficientFundsErrorMessage = InsufficientFundsErrorMessage;
|
|
16
|
+
var UnknownRequestErrorMessage = 'unknown request';
|
|
17
|
+
exports.UnknownRequestErrorMessage = UnknownRequestErrorMessage;
|
|
18
|
+
var InvalidAddressErrorMessage = 'invalid address';
|
|
19
|
+
exports.InvalidAddressErrorMessage = InvalidAddressErrorMessage;
|
|
20
|
+
var UnknownAddressErrorMessage = 'unknown address';
|
|
21
|
+
exports.UnknownAddressErrorMessage = UnknownAddressErrorMessage;
|
|
22
|
+
var InvalidPubKeyErrorMessage = 'invalid pubkey';
|
|
23
|
+
exports.InvalidPubKeyErrorMessage = InvalidPubKeyErrorMessage;
|
|
24
|
+
var InsufficientCoinsErrorMessage = 'insufficient coins';
|
|
25
|
+
exports.InsufficientCoinsErrorMessage = InsufficientCoinsErrorMessage;
|
|
26
|
+
var InvalidCoinsErrorMessage = 'invalid coins';
|
|
27
|
+
exports.InvalidCoinsErrorMessage = InvalidCoinsErrorMessage;
|
|
28
|
+
var InvalidGasWantedErrorMessage = 'invalid gas wanted';
|
|
29
|
+
exports.InvalidGasWantedErrorMessage = InvalidGasWantedErrorMessage;
|
|
30
|
+
var OutOfGasErrorMessage = 'out of gas';
|
|
31
|
+
exports.OutOfGasErrorMessage = OutOfGasErrorMessage;
|
|
32
|
+
var MemoTooLargeErrorMessage = 'memo too large';
|
|
33
|
+
exports.MemoTooLargeErrorMessage = MemoTooLargeErrorMessage;
|
|
34
|
+
var InsufficientFeeErrorMessage = 'insufficient fee';
|
|
35
|
+
exports.InsufficientFeeErrorMessage = InsufficientFeeErrorMessage;
|
|
36
|
+
var TooManySignaturesErrorMessage = 'too many signatures';
|
|
37
|
+
exports.TooManySignaturesErrorMessage = TooManySignaturesErrorMessage;
|
|
38
|
+
var NoSignaturesErrorMessage = 'no signatures';
|
|
39
|
+
exports.NoSignaturesErrorMessage = NoSignaturesErrorMessage;
|
|
40
|
+
var GasOverflowErrorMessage = 'gas overflow';
|
|
41
|
+
exports.GasOverflowErrorMessage = GasOverflowErrorMessage;
|
package/bin/provider/index.d.ts
CHANGED
package/bin/provider/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
2
|
import { BlockInfo, BlockResult, ConsensusParams, NetworkInfo, Status } from '../types';
|
|
3
|
+
import { TransactionEndpoint } from '../endpoints';
|
|
3
4
|
import { Tx } from '../../proto';
|
|
4
5
|
/**
|
|
5
6
|
* Provider based on JSON-RPC HTTP requests
|
|
@@ -22,6 +23,8 @@ export declare class JSONRPCProvider implements Provider {
|
|
|
22
23
|
getAccountSequence(address: string, height?: number): Promise<number>;
|
|
23
24
|
getAccountNumber(address: string, height?: number): Promise<number>;
|
|
24
25
|
getStatus(): Promise<Status>;
|
|
25
|
-
sendTransaction(tx: string): Promise<string>;
|
|
26
|
+
sendTransaction(tx: string, endpoint?: TransactionEndpoint.BROADCAST_TX_SYNC | TransactionEndpoint.BROADCAST_TX_COMMIT): Promise<string>;
|
|
27
|
+
private broadcastTxSync;
|
|
28
|
+
private broadcastTxCommit;
|
|
26
29
|
waitForTransaction(hash: string, fromHeight?: number, timeout?: number): Promise<Tx>;
|
|
27
30
|
}
|
|
@@ -40,6 +40,7 @@ exports.JSONRPCProvider = void 0;
|
|
|
40
40
|
var services_1 = require("../../services");
|
|
41
41
|
var utility_1 = require("../utility");
|
|
42
42
|
var endpoints_1 = require("../endpoints");
|
|
43
|
+
var errors_utility_1 = require("../utility/errors.utility");
|
|
43
44
|
/**
|
|
44
45
|
* Provider based on JSON-RPC HTTP requests
|
|
45
46
|
*/
|
|
@@ -192,16 +193,68 @@ var JSONRPCProvider = /** @class */ (function () {
|
|
|
192
193
|
});
|
|
193
194
|
});
|
|
194
195
|
};
|
|
195
|
-
JSONRPCProvider.prototype.sendTransaction = function (tx) {
|
|
196
|
+
JSONRPCProvider.prototype.sendTransaction = function (tx, endpoint) {
|
|
196
197
|
return __awaiter(this, void 0, void 0, function () {
|
|
197
|
-
var
|
|
198
|
+
var queryEndpoint, request;
|
|
199
|
+
return __generator(this, function (_a) {
|
|
200
|
+
queryEndpoint = endpoint
|
|
201
|
+
? endpoint
|
|
202
|
+
: endpoints_1.TransactionEndpoint.BROADCAST_TX_SYNC;
|
|
203
|
+
request = (0, utility_1.newRequest)(queryEndpoint, [tx]);
|
|
204
|
+
if (queryEndpoint == endpoints_1.TransactionEndpoint.BROADCAST_TX_SYNC) {
|
|
205
|
+
return [2 /*return*/, this.broadcastTxSync(request)];
|
|
206
|
+
}
|
|
207
|
+
// The endpoint is a commit broadcast
|
|
208
|
+
// (it waits for the transaction to be committed) to the chain before returning
|
|
209
|
+
return [2 /*return*/, this.broadcastTxCommit(request)];
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
JSONRPCProvider.prototype.broadcastTxSync = function (request) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
215
|
+
var response, errType, log;
|
|
216
|
+
return __generator(this, function (_a) {
|
|
217
|
+
switch (_a.label) {
|
|
218
|
+
case 0: return [4 /*yield*/, services_1.RestService.post(this.baseURL, {
|
|
219
|
+
request: request,
|
|
220
|
+
})];
|
|
221
|
+
case 1:
|
|
222
|
+
response = _a.sent();
|
|
223
|
+
// Check if there is an immediate tx-broadcast error
|
|
224
|
+
// (originating from basic transaction checks like CheckTx)
|
|
225
|
+
if (response.error) {
|
|
226
|
+
errType = response.error.ABCIErrorKey;
|
|
227
|
+
log = response.Log;
|
|
228
|
+
throw (0, errors_utility_1.constructRequestError)(errType, log);
|
|
229
|
+
}
|
|
230
|
+
return [2 /*return*/, response.hash];
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
JSONRPCProvider.prototype.broadcastTxCommit = function (request) {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
237
|
+
var response, check_tx, deliver_tx, errType, log, errType, log;
|
|
198
238
|
return __generator(this, function (_a) {
|
|
199
239
|
switch (_a.label) {
|
|
200
240
|
case 0: return [4 /*yield*/, services_1.RestService.post(this.baseURL, {
|
|
201
|
-
request:
|
|
241
|
+
request: request,
|
|
202
242
|
})];
|
|
203
243
|
case 1:
|
|
204
244
|
response = _a.sent();
|
|
245
|
+
check_tx = response.check_tx, deliver_tx = response.deliver_tx;
|
|
246
|
+
// Check if there is an immediate tx-broadcast error (in CheckTx)
|
|
247
|
+
if (check_tx.ResponseBase.Error) {
|
|
248
|
+
errType = check_tx.ResponseBase.Error.ABCIErrorKey;
|
|
249
|
+
log = check_tx.ResponseBase.Log;
|
|
250
|
+
throw (0, errors_utility_1.constructRequestError)(errType, log);
|
|
251
|
+
}
|
|
252
|
+
// Check if there is a parsing error with the transaction (in DeliverTx)
|
|
253
|
+
if (deliver_tx.ResponseBase.Error) {
|
|
254
|
+
errType = deliver_tx.ResponseBase.Error.ABCIErrorKey;
|
|
255
|
+
log = deliver_tx.ResponseBase.Log;
|
|
256
|
+
throw (0, errors_utility_1.constructRequestError)(errType, log);
|
|
257
|
+
}
|
|
205
258
|
return [2 /*return*/, response.hash];
|
|
206
259
|
}
|
|
207
260
|
});
|
|
@@ -46,6 +46,7 @@ var jest_mock_extended_1 = require("jest-mock-extended");
|
|
|
46
46
|
var proto_1 = require("../../proto");
|
|
47
47
|
var crypto_1 = require("@cosmjs/crypto");
|
|
48
48
|
var endpoints_1 = require("../endpoints");
|
|
49
|
+
var messages_1 = require("../errors/messages");
|
|
49
50
|
jest.mock('axios');
|
|
50
51
|
var mockedAxios = axios_1.default;
|
|
51
52
|
var mockURL = '127.0.0.1:26657';
|
|
@@ -108,26 +109,57 @@ describe('JSON-RPC Provider', function () {
|
|
|
108
109
|
}
|
|
109
110
|
});
|
|
110
111
|
}); });
|
|
111
|
-
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
112
|
+
describe('sendTransaction', function () {
|
|
113
|
+
var validResult = {
|
|
114
|
+
error: null,
|
|
115
|
+
data: null,
|
|
116
|
+
Log: '',
|
|
117
|
+
hash: 'hash123',
|
|
118
|
+
};
|
|
119
|
+
var mockError = '/std.UnauthorizedError';
|
|
120
|
+
var mockLog = 'random error message';
|
|
121
|
+
var invalidResult = {
|
|
122
|
+
error: {
|
|
123
|
+
ABCIErrorKey: mockError,
|
|
124
|
+
},
|
|
125
|
+
data: null,
|
|
126
|
+
Log: mockLog,
|
|
127
|
+
hash: '',
|
|
128
|
+
};
|
|
129
|
+
test.each([
|
|
130
|
+
[validResult, validResult.hash, '', ''],
|
|
131
|
+
[invalidResult, invalidResult.hash, messages_1.UnauthorizedErrorMessage, mockLog], // error out
|
|
132
|
+
])('case %#', function (response, expectedHash, expectedErr, expectedLog) { return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
+
var provider, hash, e_1;
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
switch (_a.label) {
|
|
136
|
+
case 0:
|
|
137
|
+
mockedAxios.post.mockResolvedValue({
|
|
138
|
+
data: (0, utility_1.newResponse)(response),
|
|
139
|
+
});
|
|
140
|
+
_a.label = 1;
|
|
141
|
+
case 1:
|
|
142
|
+
_a.trys.push([1, 3, , 4]);
|
|
143
|
+
provider = new jsonrpc_1.JSONRPCProvider(mockURL);
|
|
144
|
+
return [4 /*yield*/, provider.sendTransaction('encoded tx')];
|
|
145
|
+
case 2:
|
|
146
|
+
hash = _a.sent();
|
|
147
|
+
expect(axios_1.default.post).toHaveBeenCalled();
|
|
148
|
+
expect(hash).toEqual(expectedHash);
|
|
149
|
+
if (expectedErr != '') {
|
|
150
|
+
fail('expected error');
|
|
151
|
+
}
|
|
152
|
+
return [3 /*break*/, 4];
|
|
153
|
+
case 3:
|
|
154
|
+
e_1 = _a.sent();
|
|
155
|
+
expect(e_1.message).toBe(expectedErr);
|
|
156
|
+
expect(e_1.log).toBe(expectedLog);
|
|
157
|
+
return [3 /*break*/, 4];
|
|
158
|
+
case 4: return [2 /*return*/];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}); });
|
|
162
|
+
});
|
|
131
163
|
test('waitForTransaction', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
132
164
|
var emptyBlock, tx, encodedTx, txHash, filledBlock, latestBlock, startBlock, mockStatus, responseMap, provider, receivedTx;
|
|
133
165
|
return __generator(this, function (_a) {
|
|
@@ -337,7 +369,7 @@ describe('JSON-RPC Provider', function () {
|
|
|
337
369
|
],
|
|
338
370
|
['null', 0], // account doesn't exist
|
|
339
371
|
])('case %#', function (response, expected) { return __awaiter(void 0, void 0, void 0, function () {
|
|
340
|
-
var mockABCIResponse, provider, accountNumber,
|
|
372
|
+
var mockABCIResponse, provider, accountNumber, e_2;
|
|
341
373
|
return __generator(this, function (_a) {
|
|
342
374
|
switch (_a.label) {
|
|
343
375
|
case 0:
|
|
@@ -363,8 +395,8 @@ describe('JSON-RPC Provider', function () {
|
|
|
363
395
|
expect(accountNumber).toBe(expected);
|
|
364
396
|
return [3 /*break*/, 4];
|
|
365
397
|
case 3:
|
|
366
|
-
|
|
367
|
-
expect(
|
|
398
|
+
e_2 = _a.sent();
|
|
399
|
+
expect(e_2.message).toContain('account is not initialized');
|
|
368
400
|
return [3 /*break*/, 4];
|
|
369
401
|
case 4: return [2 /*return*/];
|
|
370
402
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BlockInfo, BlockResult, ConsensusParams, NetworkInfo, Status } from './types';
|
|
2
2
|
import { Tx } from '../proto';
|
|
3
|
+
import { TransactionEndpoint } from './endpoints';
|
|
3
4
|
/**
|
|
4
5
|
* Read-only abstraction for accessing blockchain data
|
|
5
6
|
*/
|
|
@@ -68,8 +69,10 @@ export interface Provider {
|
|
|
68
69
|
* The transaction needs to be signed beforehand.
|
|
69
70
|
* Returns the transaction hash
|
|
70
71
|
* @param {string} tx the base64-encoded signed transaction
|
|
72
|
+
* @param {TransactionEndpoint} endpoint the transaction broadcast type (sync / commit).
|
|
73
|
+
* Defaults to broadcast_sync
|
|
71
74
|
*/
|
|
72
|
-
sendTransaction(tx: string): Promise<string>;
|
|
75
|
+
sendTransaction(tx: string, endpoint?: TransactionEndpoint.BROADCAST_TX_SYNC | TransactionEndpoint.BROADCAST_TX_COMMIT): Promise<string>;
|
|
73
76
|
/**
|
|
74
77
|
* Waits for the transaction to be committed on the chain.
|
|
75
78
|
* NOTE: This method will not take in the fromHeight parameter once
|
|
@@ -143,7 +143,7 @@ export interface EndBlock {
|
|
|
143
143
|
export interface BeginBlock {
|
|
144
144
|
ResponseBase: ABCIResponseBase;
|
|
145
145
|
}
|
|
146
|
-
export interface
|
|
146
|
+
export interface BroadcastTxSyncResult {
|
|
147
147
|
error: {
|
|
148
148
|
[key: string]: string;
|
|
149
149
|
} | null;
|
|
@@ -151,4 +151,10 @@ export interface BroadcastTxResult {
|
|
|
151
151
|
Log: string;
|
|
152
152
|
hash: string;
|
|
153
153
|
}
|
|
154
|
+
export interface BroadcastTxCommitResult {
|
|
155
|
+
check_tx: DeliverTx;
|
|
156
|
+
deliver_tx: DeliverTx;
|
|
157
|
+
hash: string;
|
|
158
|
+
height: string;
|
|
159
|
+
}
|
|
154
160
|
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TM2Error } from '../errors';
|
|
2
|
+
/**
|
|
3
|
+
* Constructs the appropriate Tendermint2
|
|
4
|
+
* error based on the error ID.
|
|
5
|
+
* Error IDs retrieved from:
|
|
6
|
+
* https://github.com/gnolang/gno/blob/64f0fd0fa44021a076e1453b1767fbc914ed3b66/tm2/pkg/std/package.go#L20C1-L38
|
|
7
|
+
* @param {string} errorID the proto ID of the error
|
|
8
|
+
* @param {string} [log] the log associated with the error, if any
|
|
9
|
+
* @returns {TM2Error}
|
|
10
|
+
*/
|
|
11
|
+
export declare const constructRequestError: (errorID: string, log?: string) => TM2Error;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constructRequestError = void 0;
|
|
4
|
+
var errors_1 = require("../errors");
|
|
5
|
+
/**
|
|
6
|
+
* Constructs the appropriate Tendermint2
|
|
7
|
+
* error based on the error ID.
|
|
8
|
+
* Error IDs retrieved from:
|
|
9
|
+
* https://github.com/gnolang/gno/blob/64f0fd0fa44021a076e1453b1767fbc914ed3b66/tm2/pkg/std/package.go#L20C1-L38
|
|
10
|
+
* @param {string} errorID the proto ID of the error
|
|
11
|
+
* @param {string} [log] the log associated with the error, if any
|
|
12
|
+
* @returns {TM2Error}
|
|
13
|
+
*/
|
|
14
|
+
var constructRequestError = function (errorID, log) {
|
|
15
|
+
switch (errorID) {
|
|
16
|
+
case '/std.InternalError':
|
|
17
|
+
return new errors_1.InternalError(log);
|
|
18
|
+
case '/std.TxDecodeError':
|
|
19
|
+
return new errors_1.TxDecodeError(log);
|
|
20
|
+
case '/std.InvalidSequenceError':
|
|
21
|
+
return new errors_1.InvalidSequenceError(log);
|
|
22
|
+
case '/std.UnauthorizedError':
|
|
23
|
+
return new errors_1.UnauthorizedError(log);
|
|
24
|
+
case '/std.InsufficientFundsError':
|
|
25
|
+
return new errors_1.InsufficientFundsError(log);
|
|
26
|
+
case '/std.UnknownRequestError':
|
|
27
|
+
return new errors_1.UnknownRequestError(log);
|
|
28
|
+
case '/std.InvalidAddressError':
|
|
29
|
+
return new errors_1.InvalidAddressError(log);
|
|
30
|
+
case '/std.UnknownAddressError':
|
|
31
|
+
return new errors_1.UnknownAddressError(log);
|
|
32
|
+
case '/std.InvalidPubKeyError':
|
|
33
|
+
return new errors_1.InvalidPubKeyError(log);
|
|
34
|
+
case '/std.InsufficientCoinsError':
|
|
35
|
+
return new errors_1.InsufficientCoinsError(log);
|
|
36
|
+
case '/std.InvalidCoinsError':
|
|
37
|
+
return new errors_1.InvalidCoinsError(log);
|
|
38
|
+
case '/std.InvalidGasWantedError':
|
|
39
|
+
return new errors_1.InvalidGasWantedError(log);
|
|
40
|
+
case '/std.OutOfGasError':
|
|
41
|
+
return new errors_1.OutOfGasError(log);
|
|
42
|
+
case '/std.MemoTooLargeError':
|
|
43
|
+
return new errors_1.MemoTooLargeError(log);
|
|
44
|
+
case '/std.InsufficientFeeError':
|
|
45
|
+
return new errors_1.InsufficientFeeError(log);
|
|
46
|
+
case '/std.TooManySignaturesError':
|
|
47
|
+
return new errors_1.TooManySignaturesError(log);
|
|
48
|
+
case '/std.NoSignaturesError':
|
|
49
|
+
return new errors_1.NoSignaturesError(log);
|
|
50
|
+
case '/std.GasOverflowError':
|
|
51
|
+
return new errors_1.GasOverflowError(log);
|
|
52
|
+
default:
|
|
53
|
+
return new errors_1.TM2Error("unknown error: ".concat(errorID), log);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.constructRequestError = constructRequestError;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Provider } from '../provider';
|
|
3
3
|
import { BlockInfo, BlockResult, ConsensusParams, NetworkInfo, RPCRequest, RPCResponse, Status } from '../types';
|
|
4
|
+
import { TransactionEndpoint } from '../endpoints';
|
|
4
5
|
import { Tx } from '../../proto';
|
|
5
6
|
/**
|
|
6
7
|
* Provider based on WS JSON-RPC HTTP requests
|
|
@@ -50,6 +51,8 @@ export declare class WSProvider implements Provider {
|
|
|
50
51
|
getAccountSequence(address: string, height?: number): Promise<number>;
|
|
51
52
|
getAccountNumber(address: string, height?: number): Promise<number>;
|
|
52
53
|
getStatus(): Promise<Status>;
|
|
53
|
-
sendTransaction(tx: string): Promise<string>;
|
|
54
|
+
sendTransaction(tx: string, endpoint?: TransactionEndpoint.BROADCAST_TX_SYNC | TransactionEndpoint.BROADCAST_TX_COMMIT): Promise<string>;
|
|
55
|
+
private broadcastTxSync;
|
|
56
|
+
private broadcastTxCommit;
|
|
54
57
|
waitForTransaction(hash: string, fromHeight?: number, timeout?: number): Promise<Tx>;
|
|
55
58
|
}
|
|
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.WSProvider = void 0;
|
|
40
40
|
var utility_1 = require("../utility");
|
|
41
41
|
var endpoints_1 = require("../endpoints");
|
|
42
|
+
var errors_utility_1 = require("../utility/errors.utility");
|
|
42
43
|
/**
|
|
43
44
|
* Provider based on WS JSON-RPC HTTP requests
|
|
44
45
|
*/
|
|
@@ -282,15 +283,67 @@ var WSProvider = /** @class */ (function () {
|
|
|
282
283
|
});
|
|
283
284
|
});
|
|
284
285
|
};
|
|
285
|
-
WSProvider.prototype.sendTransaction = function (tx) {
|
|
286
|
+
WSProvider.prototype.sendTransaction = function (tx, endpoint) {
|
|
286
287
|
return __awaiter(this, void 0, void 0, function () {
|
|
287
|
-
var
|
|
288
|
+
var queryEndpoint, request;
|
|
289
|
+
return __generator(this, function (_a) {
|
|
290
|
+
queryEndpoint = endpoint
|
|
291
|
+
? endpoint
|
|
292
|
+
: endpoints_1.TransactionEndpoint.BROADCAST_TX_SYNC;
|
|
293
|
+
request = (0, utility_1.newRequest)(queryEndpoint, [tx]);
|
|
294
|
+
if (queryEndpoint == endpoints_1.TransactionEndpoint.BROADCAST_TX_SYNC) {
|
|
295
|
+
return [2 /*return*/, this.broadcastTxSync(request)];
|
|
296
|
+
}
|
|
297
|
+
// The endpoint is a commit broadcast
|
|
298
|
+
// (it waits for the transaction to be committed) to the chain before returning
|
|
299
|
+
return [2 /*return*/, this.broadcastTxCommit(request)];
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
WSProvider.prototype.broadcastTxSync = function (request) {
|
|
304
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
305
|
+
var response, broadcastResponse, errType, log;
|
|
306
|
+
return __generator(this, function (_a) {
|
|
307
|
+
switch (_a.label) {
|
|
308
|
+
case 0: return [4 /*yield*/, this.sendRequest(request)];
|
|
309
|
+
case 1:
|
|
310
|
+
response = _a.sent();
|
|
311
|
+
broadcastResponse = this.parseResponse(response);
|
|
312
|
+
// Check if there is an immediate tx-broadcast error
|
|
313
|
+
// (originating from basic transaction checks like CheckTx)
|
|
314
|
+
if (broadcastResponse.error) {
|
|
315
|
+
errType = broadcastResponse.error.ABCIErrorKey;
|
|
316
|
+
log = broadcastResponse.Log;
|
|
317
|
+
throw (0, errors_utility_1.constructRequestError)(errType, log);
|
|
318
|
+
}
|
|
319
|
+
return [2 /*return*/, broadcastResponse.hash];
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
WSProvider.prototype.broadcastTxCommit = function (request) {
|
|
325
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
326
|
+
var response, broadcastResponse, check_tx, deliver_tx, errType, log, errType, log;
|
|
288
327
|
return __generator(this, function (_a) {
|
|
289
328
|
switch (_a.label) {
|
|
290
|
-
case 0: return [4 /*yield*/, this.sendRequest(
|
|
329
|
+
case 0: return [4 /*yield*/, this.sendRequest(request)];
|
|
291
330
|
case 1:
|
|
292
331
|
response = _a.sent();
|
|
293
|
-
|
|
332
|
+
broadcastResponse = this.parseResponse(response);
|
|
333
|
+
check_tx = broadcastResponse.check_tx, deliver_tx = broadcastResponse.deliver_tx;
|
|
334
|
+
// Check if there is an immediate tx-broadcast error (in CheckTx)
|
|
335
|
+
if (check_tx.ResponseBase.Error) {
|
|
336
|
+
errType = check_tx.ResponseBase.Error.ABCIErrorKey;
|
|
337
|
+
log = check_tx.ResponseBase.Log;
|
|
338
|
+
throw (0, errors_utility_1.constructRequestError)(errType, log);
|
|
339
|
+
}
|
|
340
|
+
// Check if there is a parsing error with the transaction (in DeliverTx)
|
|
341
|
+
if (deliver_tx.ResponseBase.Error) {
|
|
342
|
+
errType = deliver_tx.ResponseBase.Error.ABCIErrorKey;
|
|
343
|
+
log = deliver_tx.ResponseBase.Log;
|
|
344
|
+
throw (0, errors_utility_1.constructRequestError)(errType, log);
|
|
345
|
+
}
|
|
346
|
+
return [2 /*return*/, broadcastResponse.hash];
|
|
294
347
|
}
|
|
295
348
|
});
|
|
296
349
|
});
|
|
@@ -45,6 +45,7 @@ var jest_websocket_mock_1 = __importDefault(require("jest-websocket-mock"));
|
|
|
45
45
|
var proto_1 = require("../../proto");
|
|
46
46
|
var crypto_1 = require("@cosmjs/crypto");
|
|
47
47
|
var endpoints_1 = require("../endpoints");
|
|
48
|
+
var messages_1 = require("../errors/messages");
|
|
48
49
|
describe('WS Provider', function () {
|
|
49
50
|
var wsPort = 8545;
|
|
50
51
|
var wsHost = 'localhost';
|
|
@@ -336,30 +337,54 @@ describe('WS Provider', function () {
|
|
|
336
337
|
}
|
|
337
338
|
});
|
|
338
339
|
}); });
|
|
339
|
-
|
|
340
|
-
var
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
340
|
+
describe('sendTransaction', function () {
|
|
341
|
+
var validResult = {
|
|
342
|
+
error: null,
|
|
343
|
+
data: null,
|
|
344
|
+
Log: '',
|
|
345
|
+
hash: 'hash123',
|
|
346
|
+
};
|
|
347
|
+
var mockError = '/std.UnauthorizedError';
|
|
348
|
+
var mockLog = 'random error message';
|
|
349
|
+
var invalidResult = {
|
|
350
|
+
error: {
|
|
351
|
+
ABCIErrorKey: mockError,
|
|
352
|
+
},
|
|
353
|
+
data: null,
|
|
354
|
+
Log: mockLog,
|
|
355
|
+
hash: '',
|
|
356
|
+
};
|
|
357
|
+
test.each([
|
|
358
|
+
[validResult, validResult.hash, '', ''],
|
|
359
|
+
[invalidResult, invalidResult.hash, messages_1.UnauthorizedErrorMessage, mockLog], // error out
|
|
360
|
+
])('case %#', function (response, expectedHash, expectedErr, expectedLog) { return __awaiter(void 0, void 0, void 0, function () {
|
|
361
|
+
var hash, e_2;
|
|
362
|
+
return __generator(this, function (_a) {
|
|
363
|
+
switch (_a.label) {
|
|
364
|
+
case 0: return [4 /*yield*/, setHandler(response)];
|
|
365
|
+
case 1:
|
|
366
|
+
_a.sent();
|
|
367
|
+
_a.label = 2;
|
|
368
|
+
case 2:
|
|
369
|
+
_a.trys.push([2, 4, , 5]);
|
|
370
|
+
return [4 /*yield*/, wsProvider.sendTransaction('encoded tx')];
|
|
371
|
+
case 3:
|
|
372
|
+
hash = _a.sent();
|
|
373
|
+
expect(hash).toEqual(expectedHash);
|
|
374
|
+
if (expectedErr != '') {
|
|
375
|
+
fail('expected error');
|
|
376
|
+
}
|
|
377
|
+
return [3 /*break*/, 5];
|
|
378
|
+
case 4:
|
|
379
|
+
e_2 = _a.sent();
|
|
380
|
+
expect(e_2.message).toBe(expectedErr);
|
|
381
|
+
expect(e_2.log).toBe(expectedLog);
|
|
382
|
+
return [3 /*break*/, 5];
|
|
383
|
+
case 5: return [2 /*return*/];
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}); });
|
|
387
|
+
});
|
|
363
388
|
var getEmptyBlockInfo = function () {
|
|
364
389
|
var emptyHeader = {
|
|
365
390
|
version: '',
|
package/bin/wallet/key/key.js
CHANGED
|
@@ -60,8 +60,8 @@ var KeySigner = /** @class */ (function () {
|
|
|
60
60
|
* @param {string} addressPrefix the address prefix
|
|
61
61
|
*/
|
|
62
62
|
function KeySigner(privateKey, publicKey, addressPrefix) {
|
|
63
|
-
if (addressPrefix === void 0) { addressPrefix = utility_1.defaultAddressPrefix; }
|
|
64
63
|
var _this = this;
|
|
64
|
+
if (addressPrefix === void 0) { addressPrefix = utility_1.defaultAddressPrefix; }
|
|
65
65
|
this.getAddress = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
66
66
|
return __generator(this, function (_a) {
|
|
67
67
|
return [2 /*return*/, (0, amino_1.pubkeyToAddress)((0, amino_1.encodeSecp256k1Pubkey)(crypto_1.Secp256k1.compressPubkey(this.publicKey)), this.addressPrefix)];
|
|
@@ -51,8 +51,8 @@ var LedgerSigner = /** @class */ (function () {
|
|
|
51
51
|
* @param {string} addressPrefix the address prefix
|
|
52
52
|
*/
|
|
53
53
|
function LedgerSigner(connector, accountIndex, addressPrefix) {
|
|
54
|
-
if (addressPrefix === void 0) { addressPrefix = utility_1.defaultAddressPrefix; }
|
|
55
54
|
var _this = this;
|
|
55
|
+
if (addressPrefix === void 0) { addressPrefix = utility_1.defaultAddressPrefix; }
|
|
56
56
|
this.getAddress = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
57
57
|
var compressedPubKey;
|
|
58
58
|
return __generator(this, function (_a) {
|
package/bin/wallet/wallet.js
CHANGED
|
@@ -70,7 +70,7 @@ var signdoc_1 = require("@cosmjs/amino/build/signdoc");
|
|
|
70
70
|
* Wallet is a single account abstraction
|
|
71
71
|
* that can interact with the blockchain
|
|
72
72
|
*/
|
|
73
|
-
var Wallet =
|
|
73
|
+
var Wallet = /** @class */ (function () {
|
|
74
74
|
function Wallet() {
|
|
75
75
|
var _this = this;
|
|
76
76
|
/**
|
|
@@ -275,14 +275,13 @@ var Wallet = exports.Wallet = /** @class */ (function () {
|
|
|
275
275
|
* @param {AccountWalletOption} options the account options
|
|
276
276
|
*/
|
|
277
277
|
Wallet.createRandom = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
278
|
-
var publicKey, privateKey, wallet;
|
|
279
|
-
var _b;
|
|
278
|
+
var _b, publicKey, privateKey, wallet;
|
|
280
279
|
return __generator(_a, function (_c) {
|
|
281
280
|
switch (_c.label) {
|
|
282
281
|
case 0: return [4 /*yield*/, (0, utility_1.generateKeyPair)((0, bip39_1.entropyToMnemonic)((0, utility_1.generateEntropy)()), 0)];
|
|
283
282
|
case 1:
|
|
284
|
-
|
|
285
|
-
wallet = new
|
|
283
|
+
_b = _c.sent(), publicKey = _b.publicKey, privateKey = _b.privateKey;
|
|
284
|
+
wallet = new _a();
|
|
286
285
|
wallet.signer = new key_1.KeySigner(privateKey, crypto_1.Secp256k1.compressPubkey(publicKey), options === null || options === void 0 ? void 0 : options.addressPrefix);
|
|
287
286
|
return [2 /*return*/, wallet];
|
|
288
287
|
}
|
|
@@ -294,14 +293,13 @@ var Wallet = exports.Wallet = /** @class */ (function () {
|
|
|
294
293
|
* @param {CreateWalletOptions} options the wallet generation options
|
|
295
294
|
*/
|
|
296
295
|
Wallet.fromMnemonic = function (mnemonic, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
297
|
-
var publicKey, privateKey, wallet;
|
|
298
|
-
var _b;
|
|
296
|
+
var _b, publicKey, privateKey, wallet;
|
|
299
297
|
return __generator(_a, function (_c) {
|
|
300
298
|
switch (_c.label) {
|
|
301
299
|
case 0: return [4 /*yield*/, (0, utility_1.generateKeyPair)(mnemonic, options === null || options === void 0 ? void 0 : options.accountIndex)];
|
|
302
300
|
case 1:
|
|
303
|
-
|
|
304
|
-
wallet = new
|
|
301
|
+
_b = _c.sent(), publicKey = _b.publicKey, privateKey = _b.privateKey;
|
|
302
|
+
wallet = new _a();
|
|
305
303
|
wallet.signer = new key_1.KeySigner(privateKey, crypto_1.Secp256k1.compressPubkey(publicKey), options === null || options === void 0 ? void 0 : options.addressPrefix);
|
|
306
304
|
return [2 /*return*/, wallet];
|
|
307
305
|
}
|
|
@@ -319,7 +317,7 @@ var Wallet = exports.Wallet = /** @class */ (function () {
|
|
|
319
317
|
case 0: return [4 /*yield*/, crypto_1.Secp256k1.makeKeypair(privateKey)];
|
|
320
318
|
case 1:
|
|
321
319
|
publicKey = (_b.sent()).pubkey;
|
|
322
|
-
wallet = new
|
|
320
|
+
wallet = new _a();
|
|
323
321
|
wallet.signer = new key_1.KeySigner(privateKey, crypto_1.Secp256k1.compressPubkey(publicKey), options === null || options === void 0 ? void 0 : options.addressPrefix);
|
|
324
322
|
return [2 /*return*/, wallet];
|
|
325
323
|
}
|
|
@@ -332,9 +330,10 @@ var Wallet = exports.Wallet = /** @class */ (function () {
|
|
|
332
330
|
*/
|
|
333
331
|
Wallet.fromLedger = function (connector, options) {
|
|
334
332
|
var _b;
|
|
335
|
-
var wallet = new
|
|
333
|
+
var wallet = new _a();
|
|
336
334
|
wallet.signer = new ledger_1.LedgerSigner(connector, (_b = options === null || options === void 0 ? void 0 : options.accountIndex) !== null && _b !== void 0 ? _b : 0, options === null || options === void 0 ? void 0 : options.addressPrefix);
|
|
337
335
|
return wallet;
|
|
338
336
|
};
|
|
339
337
|
return Wallet;
|
|
340
338
|
}());
|
|
339
|
+
exports.Wallet = Wallet;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gnolang/tm2-js-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Tendermint2 JS / TS Client",
|
|
5
5
|
"main": "./bin/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -33,20 +33,20 @@
|
|
|
33
33
|
"@typescript-eslint/eslint-plugin": "^5.59.5",
|
|
34
34
|
"@typescript-eslint/parser": "^5.59.5",
|
|
35
35
|
"eslint": "^8.40.0",
|
|
36
|
-
"eslint-config-prettier": "^
|
|
37
|
-
"eslint-plugin-prettier": "
|
|
36
|
+
"eslint-config-prettier": "^9.0.0",
|
|
37
|
+
"eslint-plugin-prettier": "5.0.0",
|
|
38
38
|
"jest": "^29.5.0",
|
|
39
39
|
"jest-mock-extended": "^3.0.4",
|
|
40
40
|
"jest-websocket-mock": "^2.4.0",
|
|
41
|
-
"prettier": "^
|
|
41
|
+
"prettier": "^3.0.0",
|
|
42
42
|
"ts-jest": "^29.1.0",
|
|
43
43
|
"ts-proto": "^1.147.2",
|
|
44
44
|
"typescript": "^5.0.4"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@cosmjs/amino": "^0.
|
|
48
|
-
"@cosmjs/crypto": "^0.
|
|
49
|
-
"@cosmjs/ledger-amino": "^0.
|
|
47
|
+
"@cosmjs/amino": "^0.31.0",
|
|
48
|
+
"@cosmjs/crypto": "^0.31.0",
|
|
49
|
+
"@cosmjs/ledger-amino": "^0.31.0",
|
|
50
50
|
"axios": "^1.4.0",
|
|
51
51
|
"long": "^5.2.3",
|
|
52
52
|
"protobufjs": "^7.2.3",
|