@airgap/ethereum 0.13.45-beta.1 → 0.13.45-beta.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/package.json +5 -5
- package/v0/index.js +10 -10
- package/v0/index.js.map +1 -1
- package/v0/protocol/BaseEthereumProtocol.d.ts +0 -1
- package/v0/protocol/BaseEthereumProtocol.js +460 -872
- package/v0/protocol/BaseEthereumProtocol.js.map +1 -1
- package/v0/protocol/EthereumAddress.d.ts +0 -1
- package/v0/protocol/EthereumAddress.js +26 -17
- package/v0/protocol/EthereumAddress.js.map +1 -1
- package/v0/protocol/EthereumClassicProtocol.js +6 -23
- package/v0/protocol/EthereumClassicProtocol.js.map +1 -1
- package/v0/protocol/EthereumCryptoClient.js +66 -125
- package/v0/protocol/EthereumCryptoClient.js.map +1 -1
- package/v0/protocol/EthereumProtocol.js +9 -28
- package/v0/protocol/EthereumProtocol.js.map +1 -1
- package/v0/protocol/EthereumProtocolOptions.d.ts +1 -1
- package/v0/protocol/EthereumProtocolOptions.js +36 -117
- package/v0/protocol/EthereumProtocolOptions.js.map +1 -1
- package/v0/protocol/EthereumRopstenProtocol.js +6 -23
- package/v0/protocol/EthereumRopstenProtocol.js.map +1 -1
- package/v0/protocol/clients/info-clients/EtherscanInfoClient.js +86 -186
- package/v0/protocol/clients/info-clients/EtherscanInfoClient.js.map +1 -1
- package/v0/protocol/clients/info-clients/InfoClient.js +3 -4
- package/v0/protocol/clients/info-clients/InfoClient.js.map +1 -1
- package/v0/protocol/clients/node-clients/AirGapNodeClient.js +126 -298
- package/v0/protocol/clients/node-clients/AirGapNodeClient.js.map +1 -1
- package/v0/protocol/clients/node-clients/NodeClient.js +3 -4
- package/v0/protocol/clients/node-clients/NodeClient.js.map +1 -1
- package/v0/protocol/erc20/ERC20.js +4 -4
- package/v0/protocol/erc20/ERC20.js.map +1 -1
- package/v0/protocol/erc20/GenericERC20.js +161 -300
- package/v0/protocol/erc20/GenericERC20.js.map +1 -1
- package/v0/protocol/utils/utils.js +52 -55
- package/v0/protocol/utils/utils.js.map +1 -1
- package/v0/serializer/validators/transaction-validator.js +23 -31
- package/v0/serializer/validators/transaction-validator.js.map +1 -1
- package/v0/serializer/validators/validators.js +25 -73
- package/v0/serializer/validators/validators.js.map +1 -1
- package/v1/block-explorer/EtherscanBlockExplorer.js +12 -61
- package/v1/block-explorer/EtherscanBlockExplorer.js.map +1 -1
- package/v1/clients/crypto/EthereumCryptoClient.js +69 -124
- package/v1/clients/crypto/EthereumCryptoClient.js.map +1 -1
- package/v1/clients/info/EthereumInfoClient.d.ts +1 -1
- package/v1/clients/info/EthereumInfoClient.js +3 -4
- package/v1/clients/info/EthereumInfoClient.js.map +1 -1
- package/v1/clients/info/EtherscanInfoClient.js +84 -162
- package/v1/clients/info/EtherscanInfoClient.js.map +1 -1
- package/v1/clients/node/HttpEthereumNodeClient.d.ts +2 -2
- package/v1/clients/node/HttpEthereumNodeClient.js +164 -375
- package/v1/clients/node/HttpEthereumNodeClient.js.map +1 -1
- package/v1/data/EthereumAddress.js +29 -20
- package/v1/data/EthereumAddress.js.map +1 -1
- package/v1/index.js +14 -14
- package/v1/index.js.map +1 -1
- package/v1/module/EthereumModule.js +43 -112
- package/v1/module/EthereumModule.js.map +1 -1
- package/v1/module.js +2 -3
- package/v1/module.js.map +1 -1
- package/v1/protocol/EthereumBaseProtocol.js +467 -788
- package/v1/protocol/EthereumBaseProtocol.js.map +1 -1
- package/v1/protocol/EthereumProtocol.js +15 -46
- package/v1/protocol/EthereumProtocol.js.map +1 -1
- package/v1/protocol/erc20/ERC20Protocol.js +213 -360
- package/v1/protocol/erc20/ERC20Protocol.js.map +1 -1
- package/v1/protocol/erc20/ERC20Token.d.ts +1 -1
- package/v1/protocol/erc20/ERC20Token.js +35 -113
- package/v1/protocol/erc20/ERC20Token.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +25 -42
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/serializer-companion.js +71 -148
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.js +14 -17
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
- package/v1/types/crypto.d.ts +1 -1
- package/v1/types/protocol.d.ts +1 -1
- package/v1/types/transaction.d.ts +1 -1
- package/v1/utils/EthereumUtils.js +57 -60
- package/v1/utils/EthereumUtils.js.map +1 -1
- package/v1/utils/key.js +28 -19
- package/v1/utils/key.js.map +1 -1
- package/v1/utils/protocol.js +33 -21
- package/v1/utils/protocol.js.map +1 -1
|
@@ -1,121 +1,56 @@
|
|
|
1
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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (_) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
54
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
55
|
-
if (ar || !(i in from)) {
|
|
56
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
57
|
-
ar[i] = from[i];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
61
|
-
};
|
|
62
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
63
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
64
4
|
};
|
|
65
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
6
|
exports.HttpEthereumNodeClient = exports.EthereumRPCDataTransfer = exports.EthereumRPCDataBalanceOf = exports.EthereumRPCData = exports.EthereumRPCBody = void 0;
|
|
67
7
|
// tslint:disable: max-classes-per-file
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
EthereumRPCBody.prototype.toRPCBody = function () {
|
|
8
|
+
const RPCBody_1 = require("@airgap/coinlib-core/data/RPCBody");
|
|
9
|
+
const axios_0_19_0_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0"));
|
|
10
|
+
const bignumber_1 = require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber");
|
|
11
|
+
const errors_1 = require("@airgap/coinlib-core/errors");
|
|
12
|
+
const coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
|
|
13
|
+
const coinlib_core_1 = require("@airgap/coinlib-core");
|
|
14
|
+
const EthereumUtils_1 = require("../../utils/EthereumUtils");
|
|
15
|
+
class EthereumRPCBody extends RPCBody_1.RPCBody {
|
|
16
|
+
static { this.blockEarliest = 'earliest'; }
|
|
17
|
+
static { this.blockLatest = 'latest'; }
|
|
18
|
+
static { this.blockPending = 'pending'; }
|
|
19
|
+
toRPCBody() {
|
|
81
20
|
return JSON.stringify(this.toJSON());
|
|
82
|
-
}
|
|
83
|
-
|
|
21
|
+
}
|
|
22
|
+
toJSON() {
|
|
84
23
|
return {
|
|
85
24
|
jsonrpc: this.jsonrpc,
|
|
86
25
|
method: this.method,
|
|
87
26
|
params: this.params,
|
|
88
27
|
id: this.id
|
|
89
28
|
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
EthereumRPCBody.blockLatest = 'latest';
|
|
93
|
-
EthereumRPCBody.blockPending = 'pending';
|
|
94
|
-
return EthereumRPCBody;
|
|
95
|
-
}(RPCBody_1.RPCBody));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
96
31
|
exports.EthereumRPCBody = EthereumRPCBody;
|
|
97
|
-
|
|
98
|
-
|
|
32
|
+
class EthereumRPCData {
|
|
33
|
+
// 2 chars = 1 byte hence to get to 32 bytes we need 64 chars
|
|
34
|
+
static { this.parametersLength = 64; }
|
|
35
|
+
constructor(methodSignature) {
|
|
99
36
|
this.methodSignature = methodSignature;
|
|
100
37
|
}
|
|
101
|
-
|
|
102
|
-
|
|
38
|
+
abiEncoded() {
|
|
39
|
+
const hash = EthereumUtils_1.EthereumUtils.sha3(this.methodSignature);
|
|
103
40
|
if (hash === null) {
|
|
104
41
|
return '';
|
|
105
42
|
}
|
|
106
|
-
return
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
var result = value;
|
|
43
|
+
return `0x${hash.slice(2, 10)}`;
|
|
44
|
+
}
|
|
45
|
+
static addLeadingZeroPadding(value, targetLength = EthereumRPCData.parametersLength) {
|
|
46
|
+
let result = value;
|
|
111
47
|
while (result.length < targetLength || result.length % 2 !== 0) {
|
|
112
48
|
result = '0' + result;
|
|
113
49
|
}
|
|
114
50
|
return result;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
var result = value;
|
|
51
|
+
}
|
|
52
|
+
static removeLeadingZeroPadding(value, isAddress = false) {
|
|
53
|
+
let result = value;
|
|
119
54
|
if (isAddress) {
|
|
120
55
|
return value.slice(-40);
|
|
121
56
|
}
|
|
@@ -126,325 +61,179 @@ var EthereumRPCData = /** @class */ (function () {
|
|
|
126
61
|
return result;
|
|
127
62
|
}
|
|
128
63
|
return result;
|
|
129
|
-
}
|
|
130
|
-
|
|
64
|
+
}
|
|
65
|
+
static abiDecoded(value, encodedType) {
|
|
131
66
|
switch (encodedType) {
|
|
132
67
|
case 'bytes':
|
|
133
68
|
if (value.startsWith('0x')) {
|
|
134
69
|
value = value.slice(2);
|
|
135
70
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return buffer.slice(offset + 32, offset + 32 +
|
|
71
|
+
const buffer = Buffer.from(value, 'hex');
|
|
72
|
+
const offset = new bignumber_1.BigNumber(buffer.slice(0, 32).toString('hex'), 16).toNumber();
|
|
73
|
+
const length = new bignumber_1.BigNumber(buffer.slice(offset, offset + 32).toString('hex'), 16).toNumber();
|
|
74
|
+
return buffer.slice(offset + 32, offset + 32 + length).toString('hex');
|
|
140
75
|
default:
|
|
141
76
|
(0, coinlib_core_1.assertNever)(encodedType);
|
|
142
77
|
throw new errors_1.UnsupportedError(coinlib_error_1.Domain.ETHEREUM, 'Unsupported ABI encoded type');
|
|
143
78
|
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
EthereumRPCData.parametersLength = 64;
|
|
147
|
-
return EthereumRPCData;
|
|
148
|
-
}());
|
|
79
|
+
}
|
|
80
|
+
}
|
|
149
81
|
exports.EthereumRPCData = EthereumRPCData;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return _this;
|
|
82
|
+
class EthereumRPCDataBalanceOf extends EthereumRPCData {
|
|
83
|
+
static { this.methodName = 'balanceOf'; }
|
|
84
|
+
constructor(address) {
|
|
85
|
+
super(`${EthereumRPCDataBalanceOf.methodName}(address)`);
|
|
86
|
+
this.address = address;
|
|
156
87
|
}
|
|
157
|
-
|
|
158
|
-
|
|
88
|
+
abiEncoded() {
|
|
89
|
+
let srcAddress = this.address;
|
|
159
90
|
if (srcAddress.startsWith('0x')) {
|
|
160
91
|
srcAddress = srcAddress.slice(2);
|
|
161
92
|
}
|
|
162
|
-
return
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return EthereumRPCDataBalanceOf;
|
|
166
|
-
}(EthereumRPCData));
|
|
93
|
+
return super.abiEncoded() + EthereumRPCData.addLeadingZeroPadding(srcAddress);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
167
96
|
exports.EthereumRPCDataBalanceOf = EthereumRPCDataBalanceOf;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
97
|
+
class EthereumRPCDataTransfer extends EthereumRPCData {
|
|
98
|
+
static { this.methodName = 'transfer'; }
|
|
99
|
+
constructor(toAddressOrData, amount) {
|
|
100
|
+
super(`${EthereumRPCDataTransfer.methodName}(address,uint256)`);
|
|
172
101
|
if (amount) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
102
|
+
const toAddress = toAddressOrData;
|
|
103
|
+
this.recipient = toAddress;
|
|
104
|
+
this.amount = amount;
|
|
176
105
|
}
|
|
177
106
|
else {
|
|
178
|
-
|
|
179
|
-
|
|
107
|
+
const data = toAddressOrData;
|
|
108
|
+
const methodID = super.abiEncoded();
|
|
180
109
|
if (!data.startsWith(methodID)) {
|
|
181
110
|
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.ETHEREUM, 'unexpected method ID');
|
|
182
111
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
112
|
+
const params = data.slice(methodID.length);
|
|
113
|
+
const recipient = EthereumRPCData.removeLeadingZeroPadding(params.slice(0, EthereumRPCData.parametersLength), true);
|
|
114
|
+
const parsedAmount = EthereumRPCData.removeLeadingZeroPadding(params.slice(EthereumRPCData.parametersLength));
|
|
115
|
+
this.recipient = `0x${recipient}`;
|
|
116
|
+
this.amount = `0x${parsedAmount}`;
|
|
188
117
|
}
|
|
189
|
-
return _this;
|
|
190
118
|
}
|
|
191
|
-
|
|
192
|
-
|
|
119
|
+
abiEncoded() {
|
|
120
|
+
let dstAddress = this.recipient;
|
|
193
121
|
if (dstAddress.startsWith('0x')) {
|
|
194
122
|
dstAddress = dstAddress.slice(2);
|
|
195
123
|
}
|
|
196
|
-
|
|
124
|
+
let transferAmount = this.amount;
|
|
197
125
|
if (transferAmount.startsWith('0x')) {
|
|
198
126
|
transferAmount = transferAmount.slice(2);
|
|
199
127
|
}
|
|
200
|
-
return (
|
|
128
|
+
return (super.abiEncoded() +
|
|
201
129
|
EthereumRPCData.addLeadingZeroPadding(dstAddress.toLowerCase()) +
|
|
202
130
|
EthereumRPCData.addLeadingZeroPadding(transferAmount.toLowerCase()));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return EthereumRPCDataTransfer;
|
|
206
|
-
}(EthereumRPCData));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
207
133
|
exports.EthereumRPCDataTransfer = EthereumRPCDataTransfer;
|
|
208
|
-
|
|
209
|
-
|
|
134
|
+
class HttpEthereumNodeClient {
|
|
135
|
+
constructor(baseURL, headers) {
|
|
210
136
|
this.baseURL = baseURL;
|
|
211
137
|
this.headers = headers;
|
|
212
138
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
HttpEthereumNodeClient.prototype.sendSignedTransaction = function (transaction) {
|
|
244
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
245
|
-
var body;
|
|
246
|
-
return __generator(this, function (_a) {
|
|
247
|
-
switch (_a.label) {
|
|
248
|
-
case 0:
|
|
249
|
-
body = new EthereumRPCBody('eth_sendRawTransaction', [transaction]);
|
|
250
|
-
return [4 /*yield*/, this.send(body)];
|
|
251
|
-
case 1: return [2 /*return*/, (_a.sent()).result];
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
};
|
|
256
|
-
HttpEthereumNodeClient.prototype.getTransactionStatus = function (transactionHash) {
|
|
257
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
-
var body, response;
|
|
259
|
-
return __generator(this, function (_a) {
|
|
260
|
-
switch (_a.label) {
|
|
261
|
-
case 0:
|
|
262
|
-
body = new EthereumRPCBody('eth_getTransactionReceipt', [transactionHash]);
|
|
263
|
-
return [4 /*yield*/, this.send(body)];
|
|
264
|
-
case 1:
|
|
265
|
-
response = _a.sent();
|
|
266
|
-
return [2 /*return*/, response.result.status === '0x1' ? { type: 'applied' } : { type: 'failed' }];
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
HttpEthereumNodeClient.prototype.callBalanceOf = function (contractAddress, address) {
|
|
272
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
273
|
-
var body, response;
|
|
274
|
-
return __generator(this, function (_a) {
|
|
275
|
-
switch (_a.label) {
|
|
276
|
-
case 0:
|
|
277
|
-
body = this.balanceOfBody(contractAddress, address);
|
|
278
|
-
return [4 /*yield*/, this.send(body)];
|
|
279
|
-
case 1:
|
|
280
|
-
response = _a.sent();
|
|
281
|
-
return [2 /*return*/, new bignumber_1.BigNumber(response.result)];
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
};
|
|
286
|
-
HttpEthereumNodeClient.prototype.callBalanceOfOnContracts = function (contractAddresses, address) {
|
|
287
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
-
var bodies, responses, result;
|
|
289
|
-
var _this = this;
|
|
290
|
-
return __generator(this, function (_a) {
|
|
291
|
-
switch (_a.label) {
|
|
292
|
-
case 0:
|
|
293
|
-
bodies = contractAddresses.map(function (contractAddress, index) { return _this.balanceOfBody(contractAddress, address, index); });
|
|
294
|
-
return [4 /*yield*/, this.batchSend(bodies)];
|
|
295
|
-
case 1:
|
|
296
|
-
responses = _a.sent();
|
|
297
|
-
result = {};
|
|
298
|
-
responses.forEach(function (response) {
|
|
299
|
-
var _a;
|
|
300
|
-
result[contractAddresses[response.id]] = new bignumber_1.BigNumber((_a = response.result) !== null && _a !== void 0 ? _a : 0);
|
|
301
|
-
});
|
|
302
|
-
return [2 /*return*/, result];
|
|
303
|
-
}
|
|
304
|
-
});
|
|
139
|
+
async fetchBalance(address) {
|
|
140
|
+
const body = new EthereumRPCBody('eth_getBalance', [address, EthereumRPCBody.blockLatest]);
|
|
141
|
+
const response = await this.send(body);
|
|
142
|
+
return new bignumber_1.BigNumber(response.result);
|
|
143
|
+
}
|
|
144
|
+
async fetchTransactionCount(address) {
|
|
145
|
+
const body = new EthereumRPCBody('eth_getTransactionCount', [address, EthereumRPCBody.blockLatest]);
|
|
146
|
+
const response = await this.send(body);
|
|
147
|
+
return new bignumber_1.BigNumber(response.result).toNumber();
|
|
148
|
+
}
|
|
149
|
+
async sendSignedTransaction(transaction) {
|
|
150
|
+
const body = new EthereumRPCBody('eth_sendRawTransaction', [transaction]);
|
|
151
|
+
return (await this.send(body)).result;
|
|
152
|
+
}
|
|
153
|
+
async getTransactionStatus(transactionHash) {
|
|
154
|
+
const body = new EthereumRPCBody('eth_getTransactionReceipt', [transactionHash]);
|
|
155
|
+
const response = await this.send(body);
|
|
156
|
+
return response.result.status === '0x1' ? { type: 'applied' } : { type: 'failed' };
|
|
157
|
+
}
|
|
158
|
+
async callBalanceOf(contractAddress, address) {
|
|
159
|
+
const body = this.balanceOfBody(contractAddress, address);
|
|
160
|
+
const response = await this.send(body);
|
|
161
|
+
return new bignumber_1.BigNumber(response.result);
|
|
162
|
+
}
|
|
163
|
+
async callBalanceOfOnContracts(contractAddresses, address) {
|
|
164
|
+
const bodies = contractAddresses.map((contractAddress, index) => this.balanceOfBody(contractAddress, address, index));
|
|
165
|
+
const responses = await this.batchSend(bodies);
|
|
166
|
+
const result = {};
|
|
167
|
+
responses.forEach((response) => {
|
|
168
|
+
result[contractAddresses[response.id]] = new bignumber_1.BigNumber(response.result ?? 0);
|
|
305
169
|
});
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
balanceOfBody(contractAddress, address, id = 0) {
|
|
173
|
+
const data = new EthereumRPCDataBalanceOf(address);
|
|
310
174
|
return this.contractCallBody(contractAddress, data, [EthereumRPCBody.blockLatest], id);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
response = _a.sent();
|
|
363
|
-
if (!response.result) {
|
|
364
|
-
return [2 /*return*/, undefined];
|
|
365
|
-
}
|
|
366
|
-
result = EthereumRPCData.abiDecoded(response.result, 'bytes');
|
|
367
|
-
return [2 /*return*/, EthereumUtils_1.EthereumUtils.hexToUtf8(result)];
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
};
|
|
372
|
-
HttpEthereumNodeClient.prototype.getContractSymbol = function (contractAddress) {
|
|
373
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
374
|
-
var data, body, response, result;
|
|
375
|
-
return __generator(this, function (_a) {
|
|
376
|
-
switch (_a.label) {
|
|
377
|
-
case 0:
|
|
378
|
-
data = new EthereumRPCData('symbol()');
|
|
379
|
-
body = this.contractCallBody(contractAddress, data, [EthereumRPCBody.blockLatest]);
|
|
380
|
-
return [4 /*yield*/, this.send(body)];
|
|
381
|
-
case 1:
|
|
382
|
-
response = _a.sent();
|
|
383
|
-
if (!response.result) {
|
|
384
|
-
return [2 /*return*/, undefined];
|
|
385
|
-
}
|
|
386
|
-
result = EthereumRPCData.abiDecoded(response.result, 'bytes');
|
|
387
|
-
return [2 /*return*/, EthereumUtils_1.EthereumUtils.hexToUtf8(result)];
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
};
|
|
392
|
-
HttpEthereumNodeClient.prototype.getContractDecimals = function (contractAddress) {
|
|
393
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
394
|
-
var data, body, response;
|
|
395
|
-
return __generator(this, function (_a) {
|
|
396
|
-
switch (_a.label) {
|
|
397
|
-
case 0:
|
|
398
|
-
data = new EthereumRPCData('decimals()');
|
|
399
|
-
body = this.contractCallBody(contractAddress, data, [EthereumRPCBody.blockLatest]);
|
|
400
|
-
return [4 /*yield*/, this.send(body)];
|
|
401
|
-
case 1:
|
|
402
|
-
response = _a.sent();
|
|
403
|
-
if (!response.result) {
|
|
404
|
-
return [2 /*return*/, undefined];
|
|
405
|
-
}
|
|
406
|
-
return [2 /*return*/, EthereumUtils_1.EthereumUtils.hexToNumber(response.result).toNumber()];
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
};
|
|
411
|
-
HttpEthereumNodeClient.prototype.contractCallBody = function (contractAddress, data, extraParams, id, jsonrpc) {
|
|
412
|
-
if (extraParams === void 0) { extraParams = []; }
|
|
413
|
-
return new EthereumRPCBody('eth_call', __spreadArray([{ to: contractAddress, data: data.abiEncoded() }], extraParams, true), id, jsonrpc);
|
|
414
|
-
};
|
|
415
|
-
HttpEthereumNodeClient.prototype.send = function (body) {
|
|
416
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
417
|
-
var response;
|
|
418
|
-
return __generator(this, function (_a) {
|
|
419
|
-
switch (_a.label) {
|
|
420
|
-
case 0: return [4 /*yield*/, axios_0_19_0_1.default.post(this.baseURL, body.toRPCBody(), { headers: this.headers }).catch(function (error) {
|
|
421
|
-
throw new errors_1.NetworkError(coinlib_error_1.Domain.ETHEREUM, error);
|
|
422
|
-
})];
|
|
423
|
-
case 1:
|
|
424
|
-
response = _a.sent();
|
|
425
|
-
return [2 /*return*/, response.data];
|
|
426
|
-
}
|
|
427
|
-
});
|
|
175
|
+
}
|
|
176
|
+
async estimateTransactionGas(fromAddress, toAddress, amount, data, gas) {
|
|
177
|
+
const body = new EthereumRPCBody('eth_estimateGas', [{ from: fromAddress, to: toAddress, gas, value: amount, data }]);
|
|
178
|
+
const response = await this.send(body);
|
|
179
|
+
return new bignumber_1.BigNumber(response.result);
|
|
180
|
+
}
|
|
181
|
+
async estimateTransferGas(contractAddress, fromAddress, toAddress, hexAmount) {
|
|
182
|
+
const data = new EthereumRPCDataTransfer(toAddress, hexAmount);
|
|
183
|
+
const result = this.estimateTransactionGas(fromAddress, contractAddress, undefined, data.abiEncoded());
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
async getGasPrice() {
|
|
187
|
+
const body = new EthereumRPCBody('eth_gasPrice', []);
|
|
188
|
+
const response = await this.send(body);
|
|
189
|
+
return new bignumber_1.BigNumber(response.result);
|
|
190
|
+
}
|
|
191
|
+
async getContractName(contractAddress) {
|
|
192
|
+
const data = new EthereumRPCData('name()');
|
|
193
|
+
const body = this.contractCallBody(contractAddress, data, [EthereumRPCBody.blockLatest]);
|
|
194
|
+
const response = await this.send(body);
|
|
195
|
+
if (!response.result) {
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
const result = EthereumRPCData.abiDecoded(response.result, 'bytes');
|
|
199
|
+
return EthereumUtils_1.EthereumUtils.hexToUtf8(result);
|
|
200
|
+
}
|
|
201
|
+
async getContractSymbol(contractAddress) {
|
|
202
|
+
const data = new EthereumRPCData('symbol()');
|
|
203
|
+
const body = this.contractCallBody(contractAddress, data, [EthereumRPCBody.blockLatest]);
|
|
204
|
+
const response = await this.send(body);
|
|
205
|
+
if (!response.result) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
const result = EthereumRPCData.abiDecoded(response.result, 'bytes');
|
|
209
|
+
return EthereumUtils_1.EthereumUtils.hexToUtf8(result);
|
|
210
|
+
}
|
|
211
|
+
async getContractDecimals(contractAddress) {
|
|
212
|
+
const data = new EthereumRPCData('decimals()');
|
|
213
|
+
const body = this.contractCallBody(contractAddress, data, [EthereumRPCBody.blockLatest]);
|
|
214
|
+
const response = await this.send(body);
|
|
215
|
+
if (!response.result) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
return EthereumUtils_1.EthereumUtils.hexToNumber(response.result).toNumber();
|
|
219
|
+
}
|
|
220
|
+
contractCallBody(contractAddress, data, extraParams = [], id, jsonrpc) {
|
|
221
|
+
return new EthereumRPCBody('eth_call', [{ to: contractAddress, data: data.abiEncoded() }, ...extraParams], id, jsonrpc);
|
|
222
|
+
}
|
|
223
|
+
async send(body) {
|
|
224
|
+
const response = await axios_0_19_0_1.default.post(this.baseURL, body.toRPCBody(), { headers: this.headers }).catch((error) => {
|
|
225
|
+
throw new errors_1.NetworkError(coinlib_error_1.Domain.ETHEREUM, error);
|
|
428
226
|
});
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
.post(this.baseURL, JSON.stringify(bodies.map(function (body) { return body.toJSON(); })), { headers: this.headers })
|
|
437
|
-
.catch(function (error) {
|
|
438
|
-
throw new errors_1.NetworkError(coinlib_error_1.Domain.ETHEREUM, error);
|
|
439
|
-
})];
|
|
440
|
-
case 1:
|
|
441
|
-
response = _a.sent();
|
|
442
|
-
return [2 /*return*/, response.data];
|
|
443
|
-
}
|
|
444
|
-
});
|
|
227
|
+
return response.data;
|
|
228
|
+
}
|
|
229
|
+
async batchSend(bodies) {
|
|
230
|
+
const response = await axios_0_19_0_1.default
|
|
231
|
+
.post(this.baseURL, JSON.stringify(bodies.map((body) => body.toJSON())), { headers: this.headers })
|
|
232
|
+
.catch((error) => {
|
|
233
|
+
throw new errors_1.NetworkError(coinlib_error_1.Domain.ETHEREUM, error);
|
|
445
234
|
});
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
235
|
+
return response.data;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
449
238
|
exports.HttpEthereumNodeClient = HttpEthereumNodeClient;
|
|
450
239
|
//# sourceMappingURL=HttpEthereumNodeClient.js.map
|