@airgap/cosmos 0.13.11-beta.14 → 0.13.11-beta.15
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/LICENSE.md +7 -7
- package/package.json +2 -3
- package/v1/data/CosmosAddress.d.ts +7 -0
- package/v1/data/CosmosAddress.js +29 -0
- package/v1/data/CosmosAddress.js.map +1 -0
- package/v1/data/CosmosCoin.d.ts +19 -0
- package/v1/data/CosmosCoin.js +55 -0
- package/v1/data/CosmosCoin.js.map +1 -0
- package/v1/data/CosmosFee.d.ts +15 -0
- package/v1/data/CosmosFee.js +31 -0
- package/v1/data/CosmosFee.js.map +1 -0
- package/v1/data/transaction/CosmosTransaction.d.ts +36 -0
- package/v1/data/transaction/CosmosTransaction.js +109 -0
- package/v1/data/transaction/CosmosTransaction.js.map +1 -0
- package/v1/data/transaction/message/CosmosDelegateMessage.d.ts +19 -0
- package/v1/data/transaction/message/CosmosDelegateMessage.js +70 -0
- package/v1/data/transaction/message/CosmosDelegateMessage.js.map +1 -0
- package/v1/data/transaction/message/CosmosMessage.d.ts +38 -0
- package/v1/data/transaction/message/CosmosMessage.js +47 -0
- package/v1/data/transaction/message/CosmosMessage.js.map +1 -0
- package/v1/data/transaction/message/CosmosSendMessage.d.ts +19 -0
- package/v1/data/transaction/message/CosmosSendMessage.js +83 -0
- package/v1/data/transaction/message/CosmosSendMessage.js.map +1 -0
- package/v1/data/transaction/message/CosmosWithdrawDelegationRewardMessage.d.ts +23 -0
- package/v1/data/transaction/message/CosmosWithdrawDelegationRewardMessage.js +61 -0
- package/v1/data/transaction/message/CosmosWithdrawDelegationRewardMessage.js.map +1 -0
- package/v1/index.d.ts +6 -2
- package/v1/index.js.map +1 -1
- package/v1/module/CosmosModule.js +1 -1
- package/v1/module/CosmosModule.js.map +1 -1
- package/v1/node/CosmosNodeClient.d.ts +28 -0
- package/v1/node/CosmosNodeClient.js +381 -0
- package/v1/node/CosmosNodeClient.js.map +1 -0
- package/v1/protocol/CosmosCryptoClient.d.ts +8 -0
- package/v1/protocol/CosmosCryptoClient.js +90 -0
- package/v1/protocol/CosmosCryptoClient.js.map +1 -0
- package/v1/protocol/CosmosProtocol.d.ts +47 -10
- package/v1/protocol/CosmosProtocol.js +531 -41
- package/v1/protocol/CosmosProtocol.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +7 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +37 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-cosmos.d.ts +4 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-cosmos.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-cosmos.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-cosmos.d.ts +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-cosmos.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-cosmos.js.map +1 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-cosmos.json +100 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-cosmos.json +19 -0
- package/v1/serializer/v3/serializer-companion.js +7 -7
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validators.d.ts +7 -0
- package/v1/serializer/v3/validators/transaction-validators.js +88 -0
- package/v1/serializer/v3/validators/transaction-validators.js.map +1 -0
- package/v1/types/crypto.d.ts +2 -0
- package/v1/types/crypto.js +3 -0
- package/v1/types/crypto.js.map +1 -0
- package/v1/types/protocol.d.ts +8 -0
- package/v1/types/protocol.js +3 -0
- package/v1/types/protocol.js.map +1 -0
- package/v1/types/rpc.d.ts +286 -0
- package/v1/types/rpc.js +3 -0
- package/v1/types/rpc.js.map +1 -0
- package/v1/types/transaction.d.ts +44 -0
- package/v1/types/transaction.js +10 -0
- package/v1/types/transaction.js.map +1 -0
- package/v1/utils/key.d.ts +3 -0
- package/v1/utils/key.js +20 -0
- package/v1/utils/key.js.map +1 -0
- package/v1/utils/signature.d.ts +2 -0
- package/v1/utils/signature.js +13 -0
- package/v1/utils/signature.js.map +1 -0
- package/v1/utils/transaction.d.ts +1 -0
- package/v1/utils/transaction.js +8 -0
- package/v1/utils/transaction.js.map +1 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CosmosSendMessage = void 0;
|
|
16
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
17
|
+
var IAirGapTransaction_1 = require("@airgap/coinlib-core/interfaces/IAirGapTransaction");
|
|
18
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
19
|
+
var CosmosCoin_1 = require("../../CosmosCoin");
|
|
20
|
+
var CosmosMessage_1 = require("./CosmosMessage");
|
|
21
|
+
var CosmosSendMessage = /** @class */ (function () {
|
|
22
|
+
function CosmosSendMessage(fromAddress, toAddress, amount) {
|
|
23
|
+
this.type = CosmosMessage_1.CosmosMessageType.Send;
|
|
24
|
+
this.fromAddress = fromAddress;
|
|
25
|
+
this.toAddress = toAddress;
|
|
26
|
+
this.amount = amount;
|
|
27
|
+
}
|
|
28
|
+
CosmosSendMessage.prototype.toEncodeObject = function () {
|
|
29
|
+
return {
|
|
30
|
+
typeUrl: this.type.value,
|
|
31
|
+
value: {
|
|
32
|
+
fromAddress: this.fromAddress,
|
|
33
|
+
toAddress: this.toAddress,
|
|
34
|
+
amount: __spreadArray([], this.amount, true)
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
CosmosSendMessage.fromEncodeObject = function (encodeObject) {
|
|
39
|
+
return new CosmosSendMessage(encodeObject.value.fromAddress, encodeObject.value.toAddress, encodeObject.value.amount.map(function (amount) { return new CosmosCoin_1.CosmosCoin(amount.denom, amount.amount); }));
|
|
40
|
+
};
|
|
41
|
+
CosmosSendMessage.prototype.toJSON = function () {
|
|
42
|
+
return {
|
|
43
|
+
type: this.type.index,
|
|
44
|
+
amount: this.amount.map(function (value) { return value.toJSON(); }),
|
|
45
|
+
fromAddress: this.fromAddress,
|
|
46
|
+
toAddress: this.toAddress
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
CosmosSendMessage.fromJSON = function (json) {
|
|
50
|
+
return new CosmosSendMessage(json.fromAddress, json.toAddress, json.amount.map(function (value) { return CosmosCoin_1.CosmosCoin.fromJSON(value); }));
|
|
51
|
+
};
|
|
52
|
+
CosmosSendMessage.prototype.toRPCBody = function () {
|
|
53
|
+
return {
|
|
54
|
+
type: this.type.value,
|
|
55
|
+
value: {
|
|
56
|
+
amount: this.amount.map(function (value) { return value.toRPCBody(); }),
|
|
57
|
+
from_address: this.fromAddress,
|
|
58
|
+
to_address: this.toAddress
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
CosmosSendMessage.prototype.toAirGapTransaction = function (network, fee) {
|
|
63
|
+
return {
|
|
64
|
+
from: [this.fromAddress],
|
|
65
|
+
to: [this.toAddress],
|
|
66
|
+
isInbound: false,
|
|
67
|
+
amount: (0, module_kit_1.newAmount)(this.amount
|
|
68
|
+
.map(function (value) { return new bignumber_1.default(value.amount); })
|
|
69
|
+
.reduce(function (prev, next) { return prev.plus(next); })
|
|
70
|
+
.toString(10), 'blockchain'),
|
|
71
|
+
fee: (0, module_kit_1.newAmount)(fee, 'blockchain'),
|
|
72
|
+
network: network,
|
|
73
|
+
type: IAirGapTransaction_1.AirGapTransactionType.SPEND,
|
|
74
|
+
json: this.toRPCBody()
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
CosmosSendMessage.fromRPCBody = function (json) {
|
|
78
|
+
return new CosmosSendMessage(json.value.from_address, json.value.to_address, json.value.amount.map(function (value) { return CosmosCoin_1.CosmosCoin.fromRPCBody(value); }));
|
|
79
|
+
};
|
|
80
|
+
return CosmosSendMessage;
|
|
81
|
+
}());
|
|
82
|
+
exports.CosmosSendMessage = CosmosSendMessage;
|
|
83
|
+
//# sourceMappingURL=CosmosSendMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CosmosSendMessage.js","sourceRoot":"","sources":["../../../../../src/v1/data/transaction/message/CosmosSendMessage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iHAA0F;AAE1F,yFAA0F;AAC1F,iDAAiE;AAGjE,+CAA6D;AAE7D,iDAAqF;AAErF;IAOE,2BAAY,WAAmB,EAAE,SAAiB,EAAE,MAAoB;QAFxD,SAAI,GAAsB,iCAAiB,CAAC,IAAI,CAAA;QAG9D,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEM,0CAAc,GAArB;QACE,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK;YACxB,KAAK,EAAE;gBACL,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,MAAM,oBAAM,IAAI,CAAC,MAAM,OAAC;aACzB;SACF,CAAA;IACH,CA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A1B,UAA2B,OAA8B,EAAE,GAAW;QACpE,OAAO;YACL,IAAI,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC;YACxB,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC;YACpB,SAAS,EAAE,KAAK;YAEhB,MAAM,EAAE,IAAA,sBAAS,EACf,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,UAAC,KAAiB,IAAK,OAAA,IAAI,mBAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAA3B,CAA2B,CAAC;iBACvD,MAAM,CAAC,UAAC,IAAe,EAAE,IAAe,IAAK,OAAA,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAf,CAAe,CAAC;iBAC7D,QAAQ,CAAC,EAAE,CAAC,EACf,YAAY,CACb;YACD,GAAG,EAAE,IAAA,sBAAS,EAAC,GAAG,EAAE,YAAY,CAAC;YAEjC,OAAO,SAAA;YACP,IAAI,EAAE,0CAAqB,CAAC,KAAK;YACjC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE;SACvB,CAAA;IACH,CAAC;IAEa,6BAAW,GAAzB,UAA0B,IAAS;QACjC,OAAO,IAAI,iBAAiB,CAC1B,IAAI,CAAC,KAAK,CAAC,YAAY,EACvB,IAAI,CAAC,KAAK,CAAC,UAAU,EACrB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,UAAC,KAAU,IAAK,OAAA,uBAAU,CAAC,WAAW,CAAC,KAAK,CAAC,EAA7B,CAA6B,CAAC,CACrE,CAAA;IACH,CAAC;IACH,wBAAC;AAAD,CAAC,AAxFD,IAwFC;AAxFY,8CAAiB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EncodeObject } from '@airgap/coinlib-core/dependencies/src/cosmjs';
|
|
2
|
+
import { AirGapTransaction } from '@airgap/module-kit';
|
|
3
|
+
import { CosmosProtocolNetwork, CosmosUnits } from '../../../types/protocol';
|
|
4
|
+
import { CosmosMessage, CosmosMessageJSON, CosmosMessageType } from './CosmosMessage';
|
|
5
|
+
export declare class CosmosWithdrawDelegationRewardMessage implements CosmosMessage {
|
|
6
|
+
readonly delegatorAddress: string;
|
|
7
|
+
readonly validatorAddress: string;
|
|
8
|
+
readonly type: CosmosMessageType;
|
|
9
|
+
constructor(delegatorAddress: string, validatorAddress: string);
|
|
10
|
+
toEncodeObject(): EncodeObject;
|
|
11
|
+
static fromEncodeObject(encodeObject: EncodeObject): CosmosWithdrawDelegationRewardMessage;
|
|
12
|
+
toAirGapTransaction(network: CosmosProtocolNetwork, fee: string): AirGapTransaction<CosmosUnits>;
|
|
13
|
+
toJSON(): CosmosMessageJSON;
|
|
14
|
+
static fromJSON(json: CosmosMessageJSON): CosmosWithdrawDelegationRewardMessage;
|
|
15
|
+
toRPCBody(): {
|
|
16
|
+
type: string;
|
|
17
|
+
value: {
|
|
18
|
+
delegator_address: string;
|
|
19
|
+
validator_address: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
static fromRPCBody(json: any): CosmosWithdrawDelegationRewardMessage;
|
|
23
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CosmosWithdrawDelegationRewardMessage = void 0;
|
|
4
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
5
|
+
var CosmosMessage_1 = require("./CosmosMessage");
|
|
6
|
+
var CosmosWithdrawDelegationRewardMessage = /** @class */ (function () {
|
|
7
|
+
function CosmosWithdrawDelegationRewardMessage(delegatorAddress, validatorAddress) {
|
|
8
|
+
this.type = CosmosMessage_1.CosmosMessageType.WithdrawDelegationReward;
|
|
9
|
+
this.delegatorAddress = delegatorAddress;
|
|
10
|
+
this.validatorAddress = validatorAddress;
|
|
11
|
+
}
|
|
12
|
+
CosmosWithdrawDelegationRewardMessage.prototype.toEncodeObject = function () {
|
|
13
|
+
return {
|
|
14
|
+
typeUrl: this.type.value,
|
|
15
|
+
value: {
|
|
16
|
+
delegatorAddress: this.delegatorAddress,
|
|
17
|
+
validatorAddress: this.validatorAddress
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
CosmosWithdrawDelegationRewardMessage.fromEncodeObject = function (encodeObject) {
|
|
22
|
+
return new CosmosWithdrawDelegationRewardMessage(encodeObject.value.delegatorAddress, encodeObject.value.validatorAddress);
|
|
23
|
+
};
|
|
24
|
+
CosmosWithdrawDelegationRewardMessage.prototype.toAirGapTransaction = function (network, fee) {
|
|
25
|
+
return {
|
|
26
|
+
from: [this.delegatorAddress],
|
|
27
|
+
to: [this.validatorAddress],
|
|
28
|
+
isInbound: false,
|
|
29
|
+
amount: (0, module_kit_1.newAmount)('0', 'blockchain'),
|
|
30
|
+
fee: (0, module_kit_1.newAmount)(fee, 'blockchain'),
|
|
31
|
+
network: network,
|
|
32
|
+
json: this.toRPCBody()
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
CosmosWithdrawDelegationRewardMessage.prototype.toJSON = function () {
|
|
36
|
+
return {
|
|
37
|
+
type: this.type.index,
|
|
38
|
+
amount: [{ denom: '', amount: '' }],
|
|
39
|
+
fromAddress: this.delegatorAddress,
|
|
40
|
+
toAddress: this.validatorAddress
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
CosmosWithdrawDelegationRewardMessage.fromJSON = function (json) {
|
|
44
|
+
return new CosmosWithdrawDelegationRewardMessage(json.fromAddress, json.toAddress);
|
|
45
|
+
};
|
|
46
|
+
CosmosWithdrawDelegationRewardMessage.prototype.toRPCBody = function () {
|
|
47
|
+
return {
|
|
48
|
+
type: this.type.value,
|
|
49
|
+
value: {
|
|
50
|
+
delegator_address: this.delegatorAddress,
|
|
51
|
+
validator_address: this.validatorAddress
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
CosmosWithdrawDelegationRewardMessage.fromRPCBody = function (json) {
|
|
56
|
+
return new CosmosWithdrawDelegationRewardMessage(json.value.delegator_address, json.value.validator_address);
|
|
57
|
+
};
|
|
58
|
+
return CosmosWithdrawDelegationRewardMessage;
|
|
59
|
+
}());
|
|
60
|
+
exports.CosmosWithdrawDelegationRewardMessage = CosmosWithdrawDelegationRewardMessage;
|
|
61
|
+
//# sourceMappingURL=CosmosWithdrawDelegationRewardMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CosmosWithdrawDelegationRewardMessage.js","sourceRoot":"","sources":["../../../../../src/v1/data/transaction/message/CosmosWithdrawDelegationRewardMessage.ts"],"names":[],"mappings":";;;AACA,iDAAiE;AAIjE,iDAAqF;AAErF;IAKE,+CAAY,gBAAwB,EAAE,gBAAwB;QAF9C,SAAI,GAAsB,iCAAiB,CAAC,wBAAwB,CAAA;QAGlF,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;IAC1C,CAAC;IAEM,8DAAc,GAArB;QACE,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK;YACxB,KAAK,EAAE;gBACL,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;gBACvC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;aACxC;SACF,CAAA;IACH,CAAC;IAEa,sDAAgB,GAA9B,UAA+B,YAA0B;QACvD,OAAO,IAAI,qCAAqC,CAAC,YAAY,CAAC,KAAK,CAAC,gBAAgB,EAAE,YAAY,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAC5H,CAAC;IAEM,mEAAmB,GAA1B,UAA2B,OAA8B,EAAE,GAAW;QACpE,OAAO;YACL,IAAI,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC;YAC7B,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC;YAC3B,SAAS,EAAE,KAAK;YAEhB,MAAM,EAAE,IAAA,sBAAS,EAAC,GAAG,EAAE,YAAY,CAAC;YACpC,GAAG,EAAE,IAAA,sBAAS,EAAC,GAAG,EAAE,YAAY,CAAC;YACjC,OAAO,SAAA;YACP,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE;SACvB,CAAA;IACH,CAAC;IAEM,sDAAM,GAAb;QACE,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK;YACrB,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;YACnC,WAAW,EAAE,IAAI,CAAC,gBAAgB;YAClC,SAAS,EAAE,IAAI,CAAC,gBAAgB;SACjC,CAAA;IACH,CAAC;IAEa,8CAAQ,GAAtB,UAAuB,IAAuB;QAC5C,OAAO,IAAI,qCAAqC,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;IACpF,CAAC;IAEM,yDAAS,GAAhB;QACE,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK;YACrB,KAAK,EAAE;gBACL,iBAAiB,EAAE,IAAI,CAAC,gBAAgB;gBACxC,iBAAiB,EAAE,IAAI,CAAC,gBAAgB;aACzC;SACF,CAAA;IACH,CAAC;IAEa,iDAAW,GAAzB,UAA0B,IAAS;QACjC,OAAO,IAAI,qCAAqC,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;IAC9G,CAAC;IACH,4CAAC;AAAD,CAAC,AA/DD,IA+DC;AA/DY,sFAAqC"}
|
package/v1/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { MintscanBlockExplorer } from './block-explorer/MintscanBlockExplorer';
|
|
2
2
|
import { CosmosModule } from './module/CosmosModule';
|
|
3
|
-
import { CosmosProtocol, createCosmosProtocol, createCosmosProtocolOptions
|
|
3
|
+
import { CosmosProtocol, createCosmosProtocol, createCosmosProtocolOptions } from './protocol/CosmosProtocol';
|
|
4
|
+
import { CosmosCryptoConfiguration } from './types/crypto';
|
|
5
|
+
import { CosmosProtocolNetwork, CosmosProtocolOptions, CosmosUnits } from './types/protocol';
|
|
6
|
+
import { CosmosSignedTransaction, CosmosTransactionCursor, CosmosUnsignedTransaction } from './types/transaction';
|
|
4
7
|
export { CosmosModule };
|
|
5
|
-
export { CosmosProtocol, createCosmosProtocol, createCosmosProtocolOptions
|
|
8
|
+
export { CosmosProtocol, createCosmosProtocol, createCosmosProtocolOptions };
|
|
6
9
|
export { MintscanBlockExplorer };
|
|
10
|
+
export { CosmosCryptoConfiguration, CosmosUnits, CosmosProtocolNetwork, CosmosProtocolOptions, CosmosUnsignedTransaction, CosmosSignedTransaction, CosmosTransactionCursor };
|
package/v1/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":";;;AAAA,gFAA8E;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":";;;AAAA,gFAA8E;AAiBrE,sGAjBA,6CAAqB,OAiBA;AAhB9B,sDAAoD;AAQ3C,6FARA,2BAAY,OAQA;AAPrB,4DAA6G;AAWpF,qGAXA,qCAAoB,OAWA;AAAE,4GAXA,4CAA2B,OAWA"}
|
|
@@ -98,7 +98,7 @@ var CosmosModule = /** @class */ (function () {
|
|
|
98
98
|
case coinlib_core_1.MainProtocolSymbols.COSMOS:
|
|
99
99
|
return (0, CosmosProtocol_1.createCosmosProtocol)({ network: network });
|
|
100
100
|
default:
|
|
101
|
-
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.
|
|
101
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.AETERNITY, "Protocol ".concat(identifier, " not supported."));
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
104
|
return CosmosModule;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CosmosModule.js","sourceRoot":"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EAAA;;;KAChD;IAEY,0CAAmB,GAAhC,UAAiC,UAA8B,EAAE,SAAkB;;;;;gBAC3E,OAAO,GAAgC,MAAA,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,0CAAE,WAAW,CAAC,SAAS,CAAC,CAAA;gBACvG,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,SAAS,EAAE;oBAC/B,MAAM,IAAI,gCAAuB,CAAC,qBAAM,CAAC,MAAM,EAAE,4CAA4C,CAAC,CAAA;iBAC/F;gBAED,sBAAO,IAAI,6CAAqB,EAAE,EAAA;;;KACnC;IAEY,kDAA2B,GAAxC;;;gBACE,sBAAO,IAAI,kDAA2B,EAAE,EAAA;;;KACzC;IAEO,qCAAc,GAAtB,UAAuB,UAA8B,EAAE,OAAyB;QAC9E,QAAQ,UAAU,EAAE;YAClB,KAAK,kCAAmB,CAAC,MAAM;gBAC7B,OAAO,IAAA,qCAAoB,EAAC,EAAE,OAAO,SAAA,EAAE,CAAC,CAAA;YAC1C;gBACE,MAAM,IAAI,gCAAuB,CAAC,qBAAM,CAAC,SAAS,EAAE,mBAAY,UAAU,oBAAiB,CAAC,CAAA;SAC/F;IACH,CAAC;IACH,mBAAC;AAAD,CAAC,AA1CD,IA0CC;AA1CY,oCAAY"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import BigNumber from '@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber';
|
|
2
|
+
import { CosmosAccount, CosmosDelegation, CosmosNodeInfo, CosmosPagedSendTxsResponse, CosmosRewardDetails, CosmosUnbondingDelegation, CosmosValidator } from '../types/rpc';
|
|
3
|
+
export declare class CosmosNodeClient {
|
|
4
|
+
readonly baseURL: string;
|
|
5
|
+
useCORSProxy: boolean;
|
|
6
|
+
constructor(baseURL: string, useCORSProxy?: boolean);
|
|
7
|
+
fetchBalance(address: string): Promise<{
|
|
8
|
+
total: BigNumber;
|
|
9
|
+
available: BigNumber;
|
|
10
|
+
}>;
|
|
11
|
+
fetchSendTransactionsFor(address: string, limit: number, offset: number, isSender?: boolean): Promise<CosmosPagedSendTxsResponse>;
|
|
12
|
+
fetchNodeInfo(): Promise<CosmosNodeInfo>;
|
|
13
|
+
broadcastSignedTransaction(tx_bytes: string): Promise<string>;
|
|
14
|
+
fetchAccount(address: string): Promise<CosmosAccount>;
|
|
15
|
+
fetchDelegations(address: string, filterEmpty?: boolean): Promise<CosmosDelegation[]>;
|
|
16
|
+
fetchTotalDelegatedAmount(address: string): Promise<BigNumber>;
|
|
17
|
+
fetchValidator(address: string): Promise<CosmosValidator>;
|
|
18
|
+
fetchValidators(): Promise<CosmosValidator[]>;
|
|
19
|
+
fetchSelfDelegation(validatorAddress: string): Promise<CosmosDelegation>;
|
|
20
|
+
fetchUnbondingDelegations(delegatorAddress: string): Promise<CosmosUnbondingDelegation[]>;
|
|
21
|
+
fetchTotalUnbondingAmount(address: string): Promise<BigNumber>;
|
|
22
|
+
fetchRewardDetails(delegatorAddress: string): Promise<CosmosRewardDetails[]>;
|
|
23
|
+
fetchTotalReward(delegatorAddress: string): Promise<BigNumber>;
|
|
24
|
+
fetchRewardForDelegation(delegatorAddress: string, validatorAddress: string): Promise<BigNumber>;
|
|
25
|
+
withdrawAllDelegationRewards(delegatorAddress: string, chainID: string, accountNumber: string, sequence: string, gas: BigNumber, fee: BigNumber, memo: string, simulate?: boolean): Promise<string>;
|
|
26
|
+
withdrawDelegationRewards(delegatorAddress: string, validatorAdress: string, chainID: string, accountNumber: string, sequence: string, gas: BigNumber, fee: BigNumber, memo: string, simulate?: boolean): Promise<string>;
|
|
27
|
+
private url;
|
|
28
|
+
}
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.CosmosNodeClient = void 0;
|
|
43
|
+
var index_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0/index"));
|
|
44
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
45
|
+
var CosmosCoin_1 = require("../data/CosmosCoin");
|
|
46
|
+
var CosmosNodeClient = /** @class */ (function () {
|
|
47
|
+
function CosmosNodeClient(baseURL, useCORSProxy) {
|
|
48
|
+
if (useCORSProxy === void 0) { useCORSProxy = false; }
|
|
49
|
+
this.baseURL = baseURL;
|
|
50
|
+
this.useCORSProxy = useCORSProxy;
|
|
51
|
+
}
|
|
52
|
+
CosmosNodeClient.prototype.fetchBalance = function (address) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
+
var response, data, availableBalance, totalBalance;
|
|
55
|
+
return __generator(this, function (_a) {
|
|
56
|
+
switch (_a.label) {
|
|
57
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.url("/bank/balances/".concat(address)))];
|
|
58
|
+
case 1:
|
|
59
|
+
response = _a.sent();
|
|
60
|
+
data = response.data.result;
|
|
61
|
+
if (!(data.length > 0)) return [3 /*break*/, 3];
|
|
62
|
+
availableBalance = CosmosCoin_1.CosmosCoin.sum(CosmosCoin_1.CosmosCoin.fromCoins(data));
|
|
63
|
+
return [4 /*yield*/, Promise.all([
|
|
64
|
+
this.fetchTotalReward(address),
|
|
65
|
+
this.fetchTotalUnbondingAmount(address),
|
|
66
|
+
this.fetchTotalDelegatedAmount(address)
|
|
67
|
+
])];
|
|
68
|
+
case 2:
|
|
69
|
+
totalBalance = (_a.sent()).reduce(function (current, next) { return current.plus(next); }, new bignumber_1.default(availableBalance));
|
|
70
|
+
return [2 /*return*/, {
|
|
71
|
+
total: totalBalance.decimalPlaces(0, bignumber_1.default.ROUND_FLOOR),
|
|
72
|
+
available: availableBalance.decimalPlaces(0, bignumber_1.default.ROUND_FLOOR)
|
|
73
|
+
}];
|
|
74
|
+
case 3: return [2 /*return*/, { total: new bignumber_1.default(0), available: new bignumber_1.default(0) }];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
CosmosNodeClient.prototype.fetchSendTransactionsFor = function (address, limit, offset, isSender) {
|
|
80
|
+
if (isSender === void 0) { isSender = true; }
|
|
81
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
+
var response;
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
switch (_a.label) {
|
|
85
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.url("/cosmos/tx/v1beta1/txs?events=".concat(isSender ? 'transfer.sender' : 'transfer.recipient', "='").concat(address, "'&pagination.limit=").concat(limit, "&pagination.offset=").concat(offset, "&orderBy=ORDER_BY_DESC")))];
|
|
86
|
+
case 1:
|
|
87
|
+
response = _a.sent();
|
|
88
|
+
return [2 /*return*/, response.data];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
CosmosNodeClient.prototype.fetchNodeInfo = function () {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
+
var response, nodeInfo;
|
|
96
|
+
return __generator(this, function (_a) {
|
|
97
|
+
switch (_a.label) {
|
|
98
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.url("/node_info"))];
|
|
99
|
+
case 1:
|
|
100
|
+
response = _a.sent();
|
|
101
|
+
nodeInfo = response.data.node_info;
|
|
102
|
+
return [2 /*return*/, nodeInfo];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
CosmosNodeClient.prototype.broadcastSignedTransaction = function (tx_bytes) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
+
var response;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
112
|
+
case 0: return [4 /*yield*/, index_1.default.post(this.url("/cosmos/tx/v1beta1/txs"), {
|
|
113
|
+
tx_bytes: tx_bytes,
|
|
114
|
+
mode: 'BROADCAST_MODE_ASYNC'
|
|
115
|
+
}, {
|
|
116
|
+
headers: {
|
|
117
|
+
'Content-type': 'application/json'
|
|
118
|
+
}
|
|
119
|
+
})];
|
|
120
|
+
case 1:
|
|
121
|
+
response = _a.sent();
|
|
122
|
+
return [2 /*return*/, response.data.tx_response.txhash];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
CosmosNodeClient.prototype.fetchAccount = function (address) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
+
var response, account;
|
|
130
|
+
return __generator(this, function (_a) {
|
|
131
|
+
switch (_a.label) {
|
|
132
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.url("/auth/accounts/".concat(address)))];
|
|
133
|
+
case 1:
|
|
134
|
+
response = _a.sent();
|
|
135
|
+
account = response.data.result;
|
|
136
|
+
return [2 /*return*/, account];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
CosmosNodeClient.prototype.fetchDelegations = function (address, filterEmpty) {
|
|
142
|
+
if (filterEmpty === void 0) { filterEmpty = true; }
|
|
143
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
144
|
+
var response, delegations;
|
|
145
|
+
return __generator(this, function (_a) {
|
|
146
|
+
switch (_a.label) {
|
|
147
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.url("/staking/delegators/".concat(address, "/delegations")))];
|
|
148
|
+
case 1:
|
|
149
|
+
response = _a.sent();
|
|
150
|
+
if (response.data === null) {
|
|
151
|
+
return [2 /*return*/, []];
|
|
152
|
+
}
|
|
153
|
+
delegations = response.data.result;
|
|
154
|
+
return [2 /*return*/, filterEmpty ? delegations.filter(function (delegation) { return new bignumber_1.default(delegation.balance.amount).gt(0); }) : delegations];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
CosmosNodeClient.prototype.fetchTotalDelegatedAmount = function (address) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
161
|
+
var delegations, balances;
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
switch (_a.label) {
|
|
164
|
+
case 0: return [4 /*yield*/, this.fetchDelegations(address)];
|
|
165
|
+
case 1:
|
|
166
|
+
delegations = _a.sent();
|
|
167
|
+
balances = delegations.map(function (delegation) { return delegation.balance; });
|
|
168
|
+
return [2 /*return*/, CosmosCoin_1.CosmosCoin.sum(CosmosCoin_1.CosmosCoin.fromCoins(balances)).decimalPlaces(0, bignumber_1.default.ROUND_FLOOR)];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
CosmosNodeClient.prototype.fetchValidator = function (address) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
+
var response, validator;
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
switch (_a.label) {
|
|
178
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.url("/staking/validators/".concat(address)))];
|
|
179
|
+
case 1:
|
|
180
|
+
response = _a.sent();
|
|
181
|
+
validator = response.data.result;
|
|
182
|
+
return [2 /*return*/, validator];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
CosmosNodeClient.prototype.fetchValidators = function () {
|
|
188
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
189
|
+
var response, validators;
|
|
190
|
+
return __generator(this, function (_a) {
|
|
191
|
+
switch (_a.label) {
|
|
192
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.url('/staking/validators'))];
|
|
193
|
+
case 1:
|
|
194
|
+
response = _a.sent();
|
|
195
|
+
validators = response.data.result;
|
|
196
|
+
return [2 /*return*/, validators];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
CosmosNodeClient.prototype.fetchSelfDelegation = function (validatorAddress) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
+
var validatorInfo, operatorAddress, response, delegation;
|
|
204
|
+
return __generator(this, function (_a) {
|
|
205
|
+
switch (_a.label) {
|
|
206
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.url("/distribution/validators/".concat(validatorAddress)))];
|
|
207
|
+
case 1:
|
|
208
|
+
validatorInfo = _a.sent();
|
|
209
|
+
operatorAddress = validatorInfo.data.result.operator_address;
|
|
210
|
+
return [4 /*yield*/, index_1.default.get(this.url("/staking/delegators/".concat(operatorAddress, "/delegations/").concat(validatorAddress)))];
|
|
211
|
+
case 2:
|
|
212
|
+
response = _a.sent();
|
|
213
|
+
delegation = response.data.result;
|
|
214
|
+
return [2 /*return*/, delegation];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
CosmosNodeClient.prototype.fetchUnbondingDelegations = function (delegatorAddress) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
+
var response, unbondingDelegations;
|
|
222
|
+
return __generator(this, function (_a) {
|
|
223
|
+
switch (_a.label) {
|
|
224
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.url("/staking/delegators/".concat(delegatorAddress, "/unbonding_delegations")))];
|
|
225
|
+
case 1:
|
|
226
|
+
response = _a.sent();
|
|
227
|
+
unbondingDelegations = response.data.result;
|
|
228
|
+
return [2 /*return*/, unbondingDelegations];
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
CosmosNodeClient.prototype.fetchTotalUnbondingAmount = function (address) {
|
|
234
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
235
|
+
var unbondingDelegations, unbondings;
|
|
236
|
+
return __generator(this, function (_a) {
|
|
237
|
+
switch (_a.label) {
|
|
238
|
+
case 0: return [4 /*yield*/, this.fetchUnbondingDelegations(address)];
|
|
239
|
+
case 1:
|
|
240
|
+
unbondingDelegations = _a.sent();
|
|
241
|
+
if (unbondingDelegations) {
|
|
242
|
+
unbondings = unbondingDelegations.map(function (delegation) { return delegation.entries; }).reduce(function (current, next) { return current.concat(next); }, []);
|
|
243
|
+
return [2 /*return*/, unbondings
|
|
244
|
+
.reduce(function (current, next) { return current.plus(new bignumber_1.default(next.balance)); }, new bignumber_1.default(0))
|
|
245
|
+
.decimalPlaces(0, bignumber_1.default.ROUND_FLOOR)];
|
|
246
|
+
}
|
|
247
|
+
return [2 /*return*/, new bignumber_1.default(0)];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
CosmosNodeClient.prototype.fetchRewardDetails = function (delegatorAddress) {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
254
|
+
return __generator(this, function (_a) {
|
|
255
|
+
return [2 /*return*/, index_1.default.get(this.url("/distribution/delegators/".concat(delegatorAddress, "/rewards")))
|
|
256
|
+
.then(function (response) { var _a; return ((_a = response.data.result.rewards) !== null && _a !== void 0 ? _a : []); })
|
|
257
|
+
.catch(function () { return []; })];
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
CosmosNodeClient.prototype.fetchTotalReward = function (delegatorAddress) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
263
|
+
var totalRewards;
|
|
264
|
+
return __generator(this, function (_a) {
|
|
265
|
+
switch (_a.label) {
|
|
266
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.url("/distribution/delegators/".concat(delegatorAddress, "/rewards")))
|
|
267
|
+
.then(function (response) { return response.data.result.total; })
|
|
268
|
+
.catch(function () { return []; })];
|
|
269
|
+
case 1:
|
|
270
|
+
totalRewards = _a.sent();
|
|
271
|
+
if ((totalRewards === null || totalRewards === void 0 ? void 0 : totalRewards.length) > 0) {
|
|
272
|
+
return [2 /*return*/, CosmosCoin_1.CosmosCoin.sum(CosmosCoin_1.CosmosCoin.fromCoins(totalRewards)).decimalPlaces(0, bignumber_1.default.ROUND_FLOOR)];
|
|
273
|
+
}
|
|
274
|
+
return [2 /*return*/, new bignumber_1.default(0)];
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
CosmosNodeClient.prototype.fetchRewardForDelegation = function (delegatorAddress, validatorAddress) {
|
|
280
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
281
|
+
var totalRewards;
|
|
282
|
+
return __generator(this, function (_a) {
|
|
283
|
+
switch (_a.label) {
|
|
284
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.url("/distribution/delegators/".concat(delegatorAddress, "/rewards/").concat(validatorAddress)))
|
|
285
|
+
.then(function (response) { return response.data.result; })
|
|
286
|
+
.catch(function () { return []; })];
|
|
287
|
+
case 1:
|
|
288
|
+
totalRewards = _a.sent();
|
|
289
|
+
if ((totalRewards === null || totalRewards === void 0 ? void 0 : totalRewards.length) > 0) {
|
|
290
|
+
return [2 /*return*/, CosmosCoin_1.CosmosCoin.sum(CosmosCoin_1.CosmosCoin.fromCoins(totalRewards)).decimalPlaces(0, bignumber_1.default.ROUND_FLOOR)];
|
|
291
|
+
}
|
|
292
|
+
return [2 /*return*/, new bignumber_1.default(0)];
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
CosmosNodeClient.prototype.withdrawAllDelegationRewards = function (delegatorAddress, chainID, accountNumber, sequence, gas, fee, memo, simulate) {
|
|
298
|
+
if (simulate === void 0) { simulate = false; }
|
|
299
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
300
|
+
var body, response;
|
|
301
|
+
return __generator(this, function (_a) {
|
|
302
|
+
switch (_a.label) {
|
|
303
|
+
case 0:
|
|
304
|
+
body = {
|
|
305
|
+
base_req: {
|
|
306
|
+
from: delegatorAddress,
|
|
307
|
+
memo: memo,
|
|
308
|
+
chain_id: chainID,
|
|
309
|
+
account_number: accountNumber,
|
|
310
|
+
sequence: sequence,
|
|
311
|
+
gas: gas.toFixed(),
|
|
312
|
+
gas_adjustment: '1.2',
|
|
313
|
+
fees: [
|
|
314
|
+
{
|
|
315
|
+
denom: 'uatom',
|
|
316
|
+
amount: fee.toFixed()
|
|
317
|
+
}
|
|
318
|
+
],
|
|
319
|
+
simulate: simulate
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
return [4 /*yield*/, index_1.default.post(this.url("/distribution/delegators/".concat(delegatorAddress, "/rewards")), JSON.stringify(body), {
|
|
323
|
+
headers: {
|
|
324
|
+
'Content-type': 'application/json'
|
|
325
|
+
}
|
|
326
|
+
})];
|
|
327
|
+
case 1:
|
|
328
|
+
response = _a.sent();
|
|
329
|
+
return [2 /*return*/, response.data.hash];
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
CosmosNodeClient.prototype.withdrawDelegationRewards = function (delegatorAddress, validatorAdress, chainID, accountNumber, sequence, gas, fee, memo, simulate) {
|
|
335
|
+
if (simulate === void 0) { simulate = false; }
|
|
336
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
337
|
+
var body, response;
|
|
338
|
+
return __generator(this, function (_a) {
|
|
339
|
+
switch (_a.label) {
|
|
340
|
+
case 0:
|
|
341
|
+
body = {
|
|
342
|
+
base_req: {
|
|
343
|
+
from: delegatorAddress,
|
|
344
|
+
memo: memo,
|
|
345
|
+
chain_id: chainID,
|
|
346
|
+
account_number: accountNumber,
|
|
347
|
+
sequence: sequence,
|
|
348
|
+
gas: gas.toFixed(),
|
|
349
|
+
gas_adjustment: '1.2',
|
|
350
|
+
fees: [
|
|
351
|
+
{
|
|
352
|
+
denom: 'uatom',
|
|
353
|
+
amount: fee.toFixed()
|
|
354
|
+
}
|
|
355
|
+
],
|
|
356
|
+
simulate: simulate
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
return [4 /*yield*/, index_1.default.post(this.url("/distribution/delegators/".concat(delegatorAddress, "/rewards/").concat(validatorAdress)), JSON.stringify(body), {
|
|
360
|
+
headers: {
|
|
361
|
+
'Content-type': 'application/json'
|
|
362
|
+
}
|
|
363
|
+
})];
|
|
364
|
+
case 1:
|
|
365
|
+
response = _a.sent();
|
|
366
|
+
return [2 /*return*/, response.data.hash];
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
CosmosNodeClient.prototype.url = function (path) {
|
|
372
|
+
var result = "".concat(this.baseURL).concat(path);
|
|
373
|
+
if (this.useCORSProxy) {
|
|
374
|
+
result = "https://cors-proxy.airgap.prod.gke.papers.tech/proxy?url=".concat(encodeURI(result));
|
|
375
|
+
}
|
|
376
|
+
return result;
|
|
377
|
+
};
|
|
378
|
+
return CosmosNodeClient;
|
|
379
|
+
}());
|
|
380
|
+
exports.CosmosNodeClient = CosmosNodeClient;
|
|
381
|
+
//# sourceMappingURL=CosmosNodeClient.js.map
|