UNPKG

airgap-coin-lib

Version:

The airgap-coin-lib is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.

91 lines 4.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var bignumber_1 = require("../../dependencies/src/bignumber.js-9.0.0/bignumber"); var CosmosDelegateMessage_1 = require("./cosmos-message/CosmosDelegateMessage"); var CosmosMessage_1 = require("./cosmos-message/CosmosMessage"); var CosmosSendMessage_1 = require("./cosmos-message/CosmosSendMessage"); var CosmosWithdrawDelegationRewardMessage_1 = require("./cosmos-message/CosmosWithdrawDelegationRewardMessage"); var CosmosFee_1 = require("./CosmosFee"); var CosmosTransaction = /** @class */ (function () { function CosmosTransaction(messages, fee, memo, chainID, accountNumber, sequence) { this.messages = messages; this.fee = fee; this.memo = memo; this.chainID = chainID; this.accountNumber = accountNumber; this.sequence = sequence; } CosmosTransaction.prototype.toJSON = function () { return { accountNumber: this.accountNumber, chainID: this.chainID, fee: this.fee.toJSON(), memo: this.memo, messages: this.messages.map(function (value) { return value.toJSON(); }), sequence: this.sequence }; }; CosmosTransaction.prototype.toRPCBody = function () { return { account_number: this.accountNumber, chain_id: this.chainID, fee: this.fee.toRPCBody(), memo: this.memo, msgs: this.messages.map(function (value) { return value.toRPCBody(); }), sequence: this.sequence }; }; CosmosTransaction.prototype.toAirGapTransactions = function (protocol) { var _this = this; var fee = this.fee.amount.map(function (value) { return new bignumber_1.default(value.amount); }).reduce(function (prev, next) { return prev.plus(next); }); return this.messages .map(function (message) { return message.toAirGapTransaction(protocol, fee.toString(10)); }) .map(function (tx) { if (!tx.transactionDetails) { tx.transactionDetails = {}; } tx.transactionDetails.accountNumber = _this.accountNumber; tx.transactionDetails.chainID = _this.chainID; tx.transactionDetails.memo = _this.memo; tx.transactionDetails.sequence = _this.sequence; return tx; }); }; CosmosTransaction.fromJSON = function (json) { var messages = json.transaction.messages.map(function (value) { var type = value.type; switch (type) { case CosmosMessage_1.CosmosMessageType.Send.index: return CosmosSendMessage_1.CosmosSendMessage.fromJSON(value); case CosmosMessage_1.CosmosMessageType.Delegate.index: case CosmosMessage_1.CosmosMessageType.Undelegate.index: return CosmosDelegateMessage_1.CosmosDelegateMessage.fromJSON(value); case CosmosMessage_1.CosmosMessageType.WithdrawDelegationReward.index: return CosmosWithdrawDelegationRewardMessage_1.CosmosWithdrawDelegationRewardMessage.fromJSON(value); default: throw new Error('Unknown message'); } }); return new CosmosTransaction(messages, CosmosFee_1.CosmosFee.fromJSON(json.transaction.fee), json.transaction.memo, json.transaction.chainID, json.transaction.accountNumber, json.transaction.sequence); }; CosmosTransaction.fromRPCBody = function (json) { var messages = json.msgs.map(function (value) { var type = value.type; switch (type) { case CosmosMessage_1.CosmosMessageType.Send.value: return CosmosSendMessage_1.CosmosSendMessage.fromRPCBody(value); case CosmosMessage_1.CosmosMessageType.Delegate.value: case CosmosMessage_1.CosmosMessageType.Undelegate.value: return CosmosDelegateMessage_1.CosmosDelegateMessage.fromRPCBody(value); case CosmosMessage_1.CosmosMessageType.WithdrawDelegationReward.value: return CosmosWithdrawDelegationRewardMessage_1.CosmosWithdrawDelegationRewardMessage.fromRPCBody(value); default: throw new Error('Unknown message'); } }); return new CosmosTransaction(messages, CosmosFee_1.CosmosFee.fromRPCBody(json.fee), json.memo, json.chain_id, json.account_number, json.sequence); }; return CosmosTransaction; }()); exports.CosmosTransaction = CosmosTransaction; //# sourceMappingURL=CosmosTransaction.js.map