@xchainjs/xchain-thorchain 0.19.2 → 0.20.0
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/CHANGELOG.md +28 -0
- package/README.md +11 -1
- package/lib/client.d.ts +24 -4
- package/lib/index.esm.js +76 -6
- package/lib/index.js +76 -6
- package/lib/util.d.ts +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# v.0.20.0 (2021-12-29)
|
|
2
|
+
|
|
3
|
+
## Breaking change
|
|
4
|
+
|
|
5
|
+
- Add stagenet environment handling for `Network` and `BaseXChainClient` to client
|
|
6
|
+
|
|
7
|
+
# v.0.19.5 (2021-11-22)
|
|
8
|
+
|
|
9
|
+
## Add
|
|
10
|
+
|
|
11
|
+
- Provide `transferOffline` method
|
|
12
|
+
|
|
13
|
+
# v.0.19.4 (2021-11-22)
|
|
14
|
+
|
|
15
|
+
## Add
|
|
16
|
+
|
|
17
|
+
- Provide `getPubKey` method to access public key
|
|
18
|
+
|
|
19
|
+
## Change
|
|
20
|
+
|
|
21
|
+
- Make `getPrivKey` method `public` to access private key
|
|
22
|
+
|
|
23
|
+
# v.0.19.3 (2021-10-31)
|
|
24
|
+
|
|
25
|
+
## Update
|
|
26
|
+
|
|
27
|
+
- Use latest `xchain-cosmos@0.13.8` to use `sync` mode for broadcasting txs
|
|
28
|
+
|
|
1
29
|
# v.0.19.2 (2021-09-27)
|
|
2
30
|
|
|
3
31
|
## Fix
|
package/README.md
CHANGED
|
@@ -48,7 +48,17 @@ const client = new Client({ network: Network.Testnet, phrase: 'my secret phrase'
|
|
|
48
48
|
|
|
49
49
|
// get address
|
|
50
50
|
const address = client.getAddress()
|
|
51
|
-
console.log('address:',
|
|
51
|
+
console.log('address:', address) // address: tthor13gym97tmw3axj3hpewdggy2cr288d3qffr8skg
|
|
52
|
+
|
|
53
|
+
// get private key
|
|
54
|
+
const privKey = client.getPrivKey()
|
|
55
|
+
console.log('privKey:', privKey.toBase64()) // privKey: {your-private-key} base64 encoded
|
|
56
|
+
console.log('privKey:', privKey.toBuffer()) // privKey: {your-private-key} as `Buffer`
|
|
57
|
+
|
|
58
|
+
// get public key
|
|
59
|
+
const pubKey = client.getPubKey()
|
|
60
|
+
console.log('pubKey:', pubKey.toBase64()) // pubKey: {your-public-key} base64 encoded
|
|
61
|
+
console.log('pubKey:', pubKey.toBuffer()) // pubKey: {your-public-key} as `Buffer`
|
|
52
62
|
|
|
53
63
|
// get balances
|
|
54
64
|
const balances = await client.getBalance(address)
|
package/lib/client.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Address, Balance, Fees, Network, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, XChainClient, XChainClientParams } from '@xchainjs/xchain-client';
|
|
2
|
-
import { CosmosSDKClient, RPCTxResult } from '@xchainjs/xchain-cosmos';
|
|
2
|
+
import { CosmosSDKClient, RPCTxResult, TxOfflineParams } from '@xchainjs/xchain-cosmos';
|
|
3
3
|
import { Asset } from '@xchainjs/xchain-util';
|
|
4
|
+
import { PrivKey, PubKey } from 'cosmos-client';
|
|
5
|
+
import { StdTx } from 'cosmos-client/x/auth';
|
|
4
6
|
import { ClientUrl, DepositParam, ExplorerUrls, NodeUrl, ThorchainClientParams } from './types';
|
|
5
7
|
/**
|
|
6
8
|
* Interface for custom Thorchain client
|
|
@@ -118,15 +120,26 @@ declare class Client implements ThorchainClient, XChainClient {
|
|
|
118
120
|
*/
|
|
119
121
|
getFullDerivationPath(index: number): string;
|
|
120
122
|
/**
|
|
121
|
-
*
|
|
122
|
-
* Get private key.
|
|
123
|
+
* Get private key
|
|
123
124
|
*
|
|
125
|
+
* @param {number} index the HD wallet index (optional)
|
|
124
126
|
* @returns {PrivKey} The private key generated from the given phrase
|
|
125
127
|
*
|
|
126
128
|
* @throws {"Phrase not set"}
|
|
127
129
|
* Throws an error if phrase has not been set before
|
|
128
130
|
* */
|
|
129
|
-
|
|
131
|
+
getPrivKey(index?: number): PrivKey;
|
|
132
|
+
/**
|
|
133
|
+
* Get public key
|
|
134
|
+
*
|
|
135
|
+
* @param {number} index the HD wallet index (optional)
|
|
136
|
+
*
|
|
137
|
+
* @returns {PubKey} The public key generated from the given phrase
|
|
138
|
+
*
|
|
139
|
+
* @throws {"Phrase not set"}
|
|
140
|
+
* Throws an error if phrase has not been set before
|
|
141
|
+
**/
|
|
142
|
+
getPubKey(index?: number): PubKey;
|
|
130
143
|
/**
|
|
131
144
|
* Get the current address.
|
|
132
145
|
*
|
|
@@ -193,6 +206,13 @@ declare class Client implements ThorchainClient, XChainClient {
|
|
|
193
206
|
* @returns {TxHash} The transaction hash.
|
|
194
207
|
*/
|
|
195
208
|
transfer({ walletIndex, asset, amount, recipient, memo }: TxParams): Promise<TxHash>;
|
|
209
|
+
/**
|
|
210
|
+
* Transfer without broadcast balances with MsgSend
|
|
211
|
+
*
|
|
212
|
+
* @param {TxOfflineParams} params The transfer offline options.
|
|
213
|
+
* @returns {StdTx} The signed transaction.
|
|
214
|
+
*/
|
|
215
|
+
transferOffline({ walletIndex, asset, amount, recipient, memo, from_balance, from_account_number, from_sequence, }: TxOfflineParams): Promise<StdTx>;
|
|
196
216
|
/**
|
|
197
217
|
* Get the fees.
|
|
198
218
|
*
|
package/lib/index.esm.js
CHANGED
|
@@ -191,6 +191,8 @@ var getPrefix = function (network) {
|
|
|
191
191
|
switch (network) {
|
|
192
192
|
case Network.Mainnet:
|
|
193
193
|
return 'thor';
|
|
194
|
+
case Network.Stagenet:
|
|
195
|
+
return 'sthor';
|
|
194
196
|
case Network.Testnet:
|
|
195
197
|
return 'tthor';
|
|
196
198
|
}
|
|
@@ -352,8 +354,12 @@ var getDefaultClientUrl = function () {
|
|
|
352
354
|
node: 'https://testnet.thornode.thorchain.info',
|
|
353
355
|
rpc: 'https://testnet.rpc.thorchain.info',
|
|
354
356
|
},
|
|
357
|
+
_a[Network.Stagenet] = {
|
|
358
|
+
node: 'https://stagenet-thornode.ninerealms.com',
|
|
359
|
+
rpc: 'https://stagenet-rpc.ninerealms.com',
|
|
360
|
+
},
|
|
355
361
|
_a[Network.Mainnet] = {
|
|
356
|
-
node: 'https://thornode.
|
|
362
|
+
node: 'https://thornode.ninerealms.com',
|
|
357
363
|
rpc: 'https://rpc.thorchain.info',
|
|
358
364
|
},
|
|
359
365
|
_a;
|
|
@@ -368,16 +374,19 @@ var getDefaultExplorerUrls = function () {
|
|
|
368
374
|
var _a, _b, _c;
|
|
369
375
|
var root = (_a = {},
|
|
370
376
|
_a[Network.Testnet] = DEFAULT_EXPLORER_URL + "?network=testnet",
|
|
377
|
+
_a[Network.Stagenet] = DEFAULT_EXPLORER_URL + "?network=stagenet",
|
|
371
378
|
_a[Network.Mainnet] = DEFAULT_EXPLORER_URL,
|
|
372
379
|
_a);
|
|
373
380
|
var txUrl = DEFAULT_EXPLORER_URL + "/tx";
|
|
374
381
|
var tx = (_b = {},
|
|
375
382
|
_b[Network.Testnet] = txUrl,
|
|
383
|
+
_b[Network.Stagenet] = txUrl,
|
|
376
384
|
_b[Network.Mainnet] = txUrl,
|
|
377
385
|
_b);
|
|
378
386
|
var addressUrl = DEFAULT_EXPLORER_URL + "/address";
|
|
379
387
|
var address = (_c = {},
|
|
380
388
|
_c[Network.Testnet] = addressUrl,
|
|
389
|
+
_c[Network.Stagenet] = addressUrl,
|
|
381
390
|
_c[Network.Mainnet] = addressUrl,
|
|
382
391
|
_c);
|
|
383
392
|
return {
|
|
@@ -411,6 +420,8 @@ var getExplorerAddressUrl = function (_a) {
|
|
|
411
420
|
switch (network) {
|
|
412
421
|
case Network.Mainnet:
|
|
413
422
|
return url;
|
|
423
|
+
case Network.Stagenet:
|
|
424
|
+
return url + "?network=stagenet";
|
|
414
425
|
case Network.Testnet:
|
|
415
426
|
return url + "?network=testnet";
|
|
416
427
|
}
|
|
@@ -429,6 +440,8 @@ var getExplorerTxUrl = function (_a) {
|
|
|
429
440
|
switch (network) {
|
|
430
441
|
case Network.Mainnet:
|
|
431
442
|
return url;
|
|
443
|
+
case Network.Stagenet:
|
|
444
|
+
return url + "?network=stagenet";
|
|
432
445
|
case Network.Testnet:
|
|
433
446
|
return url + "?network=testnet";
|
|
434
447
|
}
|
|
@@ -453,6 +466,7 @@ var Client = /** @class */ (function () {
|
|
|
453
466
|
var _this = this;
|
|
454
467
|
var _c = _a.network, network = _c === void 0 ? Network.Testnet : _c, phrase = _a.phrase, clientUrl = _a.clientUrl, explorerUrls = _a.explorerUrls, _d = _a.rootDerivationPaths, rootDerivationPaths = _d === void 0 ? (_b = {},
|
|
455
468
|
_b[Network.Mainnet] = "44'/931'/0'/0/",
|
|
469
|
+
_b[Network.Stagenet] = "44'/931'/0'/0/",
|
|
456
470
|
_b[Network.Testnet] = "44'/931'/0'/0/",
|
|
457
471
|
_b) : _d;
|
|
458
472
|
this.phrase = '';
|
|
@@ -653,18 +667,32 @@ var Client = /** @class */ (function () {
|
|
|
653
667
|
return this.rootDerivationPaths[this.network] + ("" + index);
|
|
654
668
|
};
|
|
655
669
|
/**
|
|
656
|
-
*
|
|
657
|
-
* Get private key.
|
|
670
|
+
* Get private key
|
|
658
671
|
*
|
|
672
|
+
* @param {number} index the HD wallet index (optional)
|
|
659
673
|
* @returns {PrivKey} The private key generated from the given phrase
|
|
660
674
|
*
|
|
661
675
|
* @throws {"Phrase not set"}
|
|
662
676
|
* Throws an error if phrase has not been set before
|
|
663
677
|
* */
|
|
664
|
-
Client.prototype.
|
|
678
|
+
Client.prototype.getPrivKey = function (index) {
|
|
665
679
|
if (index === void 0) { index = 0; }
|
|
666
680
|
return this.cosmosClient.getPrivKeyFromMnemonic(this.phrase, this.getFullDerivationPath(index));
|
|
667
681
|
};
|
|
682
|
+
/**
|
|
683
|
+
* Get public key
|
|
684
|
+
*
|
|
685
|
+
* @param {number} index the HD wallet index (optional)
|
|
686
|
+
*
|
|
687
|
+
* @returns {PubKey} The public key generated from the given phrase
|
|
688
|
+
*
|
|
689
|
+
* @throws {"Phrase not set"}
|
|
690
|
+
* Throws an error if phrase has not been set before
|
|
691
|
+
**/
|
|
692
|
+
Client.prototype.getPubKey = function (index) {
|
|
693
|
+
if (index === void 0) { index = 0; }
|
|
694
|
+
return this.getPrivKey(index).getPubKey();
|
|
695
|
+
};
|
|
668
696
|
/**
|
|
669
697
|
* Get the current address.
|
|
670
698
|
*
|
|
@@ -811,7 +839,7 @@ var Client = /** @class */ (function () {
|
|
|
811
839
|
return [4 /*yield*/, buildDepositTx(msgNativeTx, this.getClientUrl().node)];
|
|
812
840
|
case 2:
|
|
813
841
|
unsignedStdTx = _f.sent();
|
|
814
|
-
privateKey = this.
|
|
842
|
+
privateKey = this.getPrivKey(walletIndex);
|
|
815
843
|
accAddress = AccAddress.fromBech32(signer);
|
|
816
844
|
return [4 /*yield*/, this.cosmosClient.signAndBroadcast(unsignedStdTx, privateKey, accAddress)];
|
|
817
845
|
case 3: return [2 /*return*/, (_c = (_b = (_f.sent())) === null || _b === void 0 ? void 0 : _b.txhash) !== null && _c !== void 0 ? _c : ''];
|
|
@@ -844,7 +872,7 @@ var Client = /** @class */ (function () {
|
|
|
844
872
|
throw new Error('insufficient funds');
|
|
845
873
|
}
|
|
846
874
|
return [4 /*yield*/, this.cosmosClient.transfer({
|
|
847
|
-
privkey: this.
|
|
875
|
+
privkey: this.getPrivKey(walletIndex),
|
|
848
876
|
from: this.getAddress(walletIndex),
|
|
849
877
|
to: recipient,
|
|
850
878
|
amount: amount.amount().toString(),
|
|
@@ -865,6 +893,48 @@ var Client = /** @class */ (function () {
|
|
|
865
893
|
});
|
|
866
894
|
});
|
|
867
895
|
};
|
|
896
|
+
/**
|
|
897
|
+
* Transfer without broadcast balances with MsgSend
|
|
898
|
+
*
|
|
899
|
+
* @param {TxOfflineParams} params The transfer offline options.
|
|
900
|
+
* @returns {StdTx} The signed transaction.
|
|
901
|
+
*/
|
|
902
|
+
Client.prototype.transferOffline = function (_a) {
|
|
903
|
+
var _b = _a.walletIndex, walletIndex = _b === void 0 ? 0 : _b, _c = _a.asset, asset = _c === void 0 ? AssetRuneNative : _c, amount = _a.amount, recipient = _a.recipient, memo = _a.memo, _d = _a.from_balance, from_balance = _d === void 0 ? baseAmount('0', DECIMAL) : _d, _e = _a.from_account_number, from_account_number = _e === void 0 ? '0' : _e, _f = _a.from_sequence, from_sequence = _f === void 0 ? '0' : _f;
|
|
904
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
905
|
+
var fee, result;
|
|
906
|
+
return __generator(this, function (_g) {
|
|
907
|
+
switch (_g.label) {
|
|
908
|
+
case 0:
|
|
909
|
+
registerCodecs(getPrefix(this.network));
|
|
910
|
+
return [4 /*yield*/, this.getFees()];
|
|
911
|
+
case 1:
|
|
912
|
+
fee = _g.sent();
|
|
913
|
+
if (from_balance === baseAmount('0', DECIMAL) ||
|
|
914
|
+
from_balance.amount().lt(amount.amount().plus(fee[FeeOption.Average].amount()))) {
|
|
915
|
+
throw new Error('insufficient funds');
|
|
916
|
+
}
|
|
917
|
+
return [4 /*yield*/, this.cosmosClient.transferSignedOffline({
|
|
918
|
+
privkey: this.getPrivKey(walletIndex),
|
|
919
|
+
from: this.getAddress(walletIndex),
|
|
920
|
+
from_account_number: from_account_number,
|
|
921
|
+
from_sequence: from_sequence,
|
|
922
|
+
to: recipient,
|
|
923
|
+
amount: amount.amount().toString(),
|
|
924
|
+
asset: getDenom(asset),
|
|
925
|
+
memo: memo,
|
|
926
|
+
fee: {
|
|
927
|
+
amount: [],
|
|
928
|
+
gas: DEFAULT_GAS_VALUE,
|
|
929
|
+
},
|
|
930
|
+
})];
|
|
931
|
+
case 2:
|
|
932
|
+
result = _g.sent();
|
|
933
|
+
return [2 /*return*/, JSON.parse(codec.toJSONString(result)).value];
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
});
|
|
937
|
+
};
|
|
868
938
|
/**
|
|
869
939
|
* Get the fees.
|
|
870
940
|
*
|
package/lib/index.js
CHANGED
|
@@ -199,6 +199,8 @@ var getPrefix = function (network) {
|
|
|
199
199
|
switch (network) {
|
|
200
200
|
case xchainClient.Network.Mainnet:
|
|
201
201
|
return 'thor';
|
|
202
|
+
case xchainClient.Network.Stagenet:
|
|
203
|
+
return 'sthor';
|
|
202
204
|
case xchainClient.Network.Testnet:
|
|
203
205
|
return 'tthor';
|
|
204
206
|
}
|
|
@@ -360,8 +362,12 @@ var getDefaultClientUrl = function () {
|
|
|
360
362
|
node: 'https://testnet.thornode.thorchain.info',
|
|
361
363
|
rpc: 'https://testnet.rpc.thorchain.info',
|
|
362
364
|
},
|
|
365
|
+
_a[xchainClient.Network.Stagenet] = {
|
|
366
|
+
node: 'https://stagenet-thornode.ninerealms.com',
|
|
367
|
+
rpc: 'https://stagenet-rpc.ninerealms.com',
|
|
368
|
+
},
|
|
363
369
|
_a[xchainClient.Network.Mainnet] = {
|
|
364
|
-
node: 'https://thornode.
|
|
370
|
+
node: 'https://thornode.ninerealms.com',
|
|
365
371
|
rpc: 'https://rpc.thorchain.info',
|
|
366
372
|
},
|
|
367
373
|
_a;
|
|
@@ -376,16 +382,19 @@ var getDefaultExplorerUrls = function () {
|
|
|
376
382
|
var _a, _b, _c;
|
|
377
383
|
var root = (_a = {},
|
|
378
384
|
_a[xchainClient.Network.Testnet] = DEFAULT_EXPLORER_URL + "?network=testnet",
|
|
385
|
+
_a[xchainClient.Network.Stagenet] = DEFAULT_EXPLORER_URL + "?network=stagenet",
|
|
379
386
|
_a[xchainClient.Network.Mainnet] = DEFAULT_EXPLORER_URL,
|
|
380
387
|
_a);
|
|
381
388
|
var txUrl = DEFAULT_EXPLORER_URL + "/tx";
|
|
382
389
|
var tx = (_b = {},
|
|
383
390
|
_b[xchainClient.Network.Testnet] = txUrl,
|
|
391
|
+
_b[xchainClient.Network.Stagenet] = txUrl,
|
|
384
392
|
_b[xchainClient.Network.Mainnet] = txUrl,
|
|
385
393
|
_b);
|
|
386
394
|
var addressUrl = DEFAULT_EXPLORER_URL + "/address";
|
|
387
395
|
var address = (_c = {},
|
|
388
396
|
_c[xchainClient.Network.Testnet] = addressUrl,
|
|
397
|
+
_c[xchainClient.Network.Stagenet] = addressUrl,
|
|
389
398
|
_c[xchainClient.Network.Mainnet] = addressUrl,
|
|
390
399
|
_c);
|
|
391
400
|
return {
|
|
@@ -419,6 +428,8 @@ var getExplorerAddressUrl = function (_a) {
|
|
|
419
428
|
switch (network) {
|
|
420
429
|
case xchainClient.Network.Mainnet:
|
|
421
430
|
return url;
|
|
431
|
+
case xchainClient.Network.Stagenet:
|
|
432
|
+
return url + "?network=stagenet";
|
|
422
433
|
case xchainClient.Network.Testnet:
|
|
423
434
|
return url + "?network=testnet";
|
|
424
435
|
}
|
|
@@ -437,6 +448,8 @@ var getExplorerTxUrl = function (_a) {
|
|
|
437
448
|
switch (network) {
|
|
438
449
|
case xchainClient.Network.Mainnet:
|
|
439
450
|
return url;
|
|
451
|
+
case xchainClient.Network.Stagenet:
|
|
452
|
+
return url + "?network=stagenet";
|
|
440
453
|
case xchainClient.Network.Testnet:
|
|
441
454
|
return url + "?network=testnet";
|
|
442
455
|
}
|
|
@@ -461,6 +474,7 @@ var Client = /** @class */ (function () {
|
|
|
461
474
|
var _this = this;
|
|
462
475
|
var _c = _a.network, network = _c === void 0 ? xchainClient.Network.Testnet : _c, phrase = _a.phrase, clientUrl = _a.clientUrl, explorerUrls = _a.explorerUrls, _d = _a.rootDerivationPaths, rootDerivationPaths = _d === void 0 ? (_b = {},
|
|
463
476
|
_b[xchainClient.Network.Mainnet] = "44'/931'/0'/0/",
|
|
477
|
+
_b[xchainClient.Network.Stagenet] = "44'/931'/0'/0/",
|
|
464
478
|
_b[xchainClient.Network.Testnet] = "44'/931'/0'/0/",
|
|
465
479
|
_b) : _d;
|
|
466
480
|
this.phrase = '';
|
|
@@ -661,18 +675,32 @@ var Client = /** @class */ (function () {
|
|
|
661
675
|
return this.rootDerivationPaths[this.network] + ("" + index);
|
|
662
676
|
};
|
|
663
677
|
/**
|
|
664
|
-
*
|
|
665
|
-
* Get private key.
|
|
678
|
+
* Get private key
|
|
666
679
|
*
|
|
680
|
+
* @param {number} index the HD wallet index (optional)
|
|
667
681
|
* @returns {PrivKey} The private key generated from the given phrase
|
|
668
682
|
*
|
|
669
683
|
* @throws {"Phrase not set"}
|
|
670
684
|
* Throws an error if phrase has not been set before
|
|
671
685
|
* */
|
|
672
|
-
Client.prototype.
|
|
686
|
+
Client.prototype.getPrivKey = function (index) {
|
|
673
687
|
if (index === void 0) { index = 0; }
|
|
674
688
|
return this.cosmosClient.getPrivKeyFromMnemonic(this.phrase, this.getFullDerivationPath(index));
|
|
675
689
|
};
|
|
690
|
+
/**
|
|
691
|
+
* Get public key
|
|
692
|
+
*
|
|
693
|
+
* @param {number} index the HD wallet index (optional)
|
|
694
|
+
*
|
|
695
|
+
* @returns {PubKey} The public key generated from the given phrase
|
|
696
|
+
*
|
|
697
|
+
* @throws {"Phrase not set"}
|
|
698
|
+
* Throws an error if phrase has not been set before
|
|
699
|
+
**/
|
|
700
|
+
Client.prototype.getPubKey = function (index) {
|
|
701
|
+
if (index === void 0) { index = 0; }
|
|
702
|
+
return this.getPrivKey(index).getPubKey();
|
|
703
|
+
};
|
|
676
704
|
/**
|
|
677
705
|
* Get the current address.
|
|
678
706
|
*
|
|
@@ -819,7 +847,7 @@ var Client = /** @class */ (function () {
|
|
|
819
847
|
return [4 /*yield*/, buildDepositTx(msgNativeTx, this.getClientUrl().node)];
|
|
820
848
|
case 2:
|
|
821
849
|
unsignedStdTx = _f.sent();
|
|
822
|
-
privateKey = this.
|
|
850
|
+
privateKey = this.getPrivKey(walletIndex);
|
|
823
851
|
accAddress = cosmosClient.AccAddress.fromBech32(signer);
|
|
824
852
|
return [4 /*yield*/, this.cosmosClient.signAndBroadcast(unsignedStdTx, privateKey, accAddress)];
|
|
825
853
|
case 3: return [2 /*return*/, (_c = (_b = (_f.sent())) === null || _b === void 0 ? void 0 : _b.txhash) !== null && _c !== void 0 ? _c : ''];
|
|
@@ -852,7 +880,7 @@ var Client = /** @class */ (function () {
|
|
|
852
880
|
throw new Error('insufficient funds');
|
|
853
881
|
}
|
|
854
882
|
return [4 /*yield*/, this.cosmosClient.transfer({
|
|
855
|
-
privkey: this.
|
|
883
|
+
privkey: this.getPrivKey(walletIndex),
|
|
856
884
|
from: this.getAddress(walletIndex),
|
|
857
885
|
to: recipient,
|
|
858
886
|
amount: amount.amount().toString(),
|
|
@@ -873,6 +901,48 @@ var Client = /** @class */ (function () {
|
|
|
873
901
|
});
|
|
874
902
|
});
|
|
875
903
|
};
|
|
904
|
+
/**
|
|
905
|
+
* Transfer without broadcast balances with MsgSend
|
|
906
|
+
*
|
|
907
|
+
* @param {TxOfflineParams} params The transfer offline options.
|
|
908
|
+
* @returns {StdTx} The signed transaction.
|
|
909
|
+
*/
|
|
910
|
+
Client.prototype.transferOffline = function (_a) {
|
|
911
|
+
var _b = _a.walletIndex, walletIndex = _b === void 0 ? 0 : _b, _c = _a.asset, asset = _c === void 0 ? xchainUtil.AssetRuneNative : _c, amount = _a.amount, recipient = _a.recipient, memo = _a.memo, _d = _a.from_balance, from_balance = _d === void 0 ? xchainUtil.baseAmount('0', DECIMAL) : _d, _e = _a.from_account_number, from_account_number = _e === void 0 ? '0' : _e, _f = _a.from_sequence, from_sequence = _f === void 0 ? '0' : _f;
|
|
912
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
913
|
+
var fee, result;
|
|
914
|
+
return __generator(this, function (_g) {
|
|
915
|
+
switch (_g.label) {
|
|
916
|
+
case 0:
|
|
917
|
+
registerCodecs(getPrefix(this.network));
|
|
918
|
+
return [4 /*yield*/, this.getFees()];
|
|
919
|
+
case 1:
|
|
920
|
+
fee = _g.sent();
|
|
921
|
+
if (from_balance === xchainUtil.baseAmount('0', DECIMAL) ||
|
|
922
|
+
from_balance.amount().lt(amount.amount().plus(fee[xchainClient.FeeOption.Average].amount()))) {
|
|
923
|
+
throw new Error('insufficient funds');
|
|
924
|
+
}
|
|
925
|
+
return [4 /*yield*/, this.cosmosClient.transferSignedOffline({
|
|
926
|
+
privkey: this.getPrivKey(walletIndex),
|
|
927
|
+
from: this.getAddress(walletIndex),
|
|
928
|
+
from_account_number: from_account_number,
|
|
929
|
+
from_sequence: from_sequence,
|
|
930
|
+
to: recipient,
|
|
931
|
+
amount: amount.amount().toString(),
|
|
932
|
+
asset: getDenom(asset),
|
|
933
|
+
memo: memo,
|
|
934
|
+
fee: {
|
|
935
|
+
amount: [],
|
|
936
|
+
gas: DEFAULT_GAS_VALUE,
|
|
937
|
+
},
|
|
938
|
+
})];
|
|
939
|
+
case 2:
|
|
940
|
+
result = _g.sent();
|
|
941
|
+
return [2 /*return*/, JSON.parse(cosmosClient.codec.toJSONString(result)).value];
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
};
|
|
876
946
|
/**
|
|
877
947
|
* Get the fees.
|
|
878
948
|
*
|
package/lib/util.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export declare const isBroadcastSuccess: (response: unknown) => boolean;
|
|
|
59
59
|
* @returns {string} The address prefix based on the network.
|
|
60
60
|
*
|
|
61
61
|
**/
|
|
62
|
-
export declare const getPrefix: (network: Network) => "thor" | "tthor";
|
|
62
|
+
export declare const getPrefix: (network: Network) => "thor" | "sthor" | "tthor";
|
|
63
63
|
/**
|
|
64
64
|
* Get the chain id.
|
|
65
65
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Custom Thorchain client and utilities used by XChainJS clients",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/big.js": "^6.0.0",
|
|
36
|
-
"@xchainjs/xchain-client": "^0.
|
|
37
|
-
"@xchainjs/xchain-cosmos": "^0.
|
|
36
|
+
"@xchainjs/xchain-client": "^0.11.0",
|
|
37
|
+
"@xchainjs/xchain-cosmos": "^0.15.0",
|
|
38
38
|
"@xchainjs/xchain-crypto": "^0.2.4",
|
|
39
39
|
"@xchainjs/xchain-util": "^0.3.0",
|
|
40
40
|
"axios": "^0.21.0",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@xchainjs/xchain-client": "^0.
|
|
49
|
-
"@xchainjs/xchain-cosmos": "^0.
|
|
48
|
+
"@xchainjs/xchain-client": "^0.11.0",
|
|
49
|
+
"@xchainjs/xchain-cosmos": "^0.15.0",
|
|
50
50
|
"@xchainjs/xchain-crypto": "^0.2.4",
|
|
51
51
|
"@xchainjs/xchain-util": "^0.3.0",
|
|
52
52
|
"axios": "^0.21.0",
|