UNPKG

airgap-coin-lib

Version:

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

59 lines 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var bignumber_1 = require("../../../dependencies/src/bignumber.js-9.0.0/bignumber"); var IAirGapTransaction_1 = require("../../../interfaces/IAirGapTransaction"); var CosmosCoin_1 = require("../CosmosCoin"); var CosmosMessage_1 = require("./CosmosMessage"); var CosmosSendMessage = /** @class */ (function () { function CosmosSendMessage(fromAddress, toAddress, amount) { this.type = CosmosMessage_1.CosmosMessageType.Send; this.fromAddress = fromAddress; this.toAddress = toAddress; this.amount = amount; } CosmosSendMessage.prototype.toJSON = function () { return { type: this.type.index, amount: this.amount.map(function (value) { return value.toJSON(); }), fromAddress: this.fromAddress, toAddress: this.toAddress }; }; CosmosSendMessage.fromJSON = function (json) { return new CosmosSendMessage(json.fromAddress, json.toAddress, json.amount.map(function (value) { return CosmosCoin_1.CosmosCoin.fromJSON(value); })); }; CosmosSendMessage.prototype.toRPCBody = function () { return { type: this.type.value, value: { amount: this.amount.map(function (value) { return value.toRPCBody(); }), from_address: this.fromAddress, to_address: this.toAddress } }; }; CosmosSendMessage.prototype.toAirGapTransaction = function (protocol, fee) { return { amount: this.amount .map(function (value) { return new bignumber_1.default(value.amount); }) .reduce(function (prev, next) { return prev.plus(next); }) .toString(10), to: [this.toAddress], from: [this.fromAddress], isInbound: false, fee: fee, protocolIdentifier: protocol.identifier, network: protocol.options.network, transactionDetails: this.toRPCBody(), extra: { type: IAirGapTransaction_1.AirGapTransactionType.SPEND } }; }; CosmosSendMessage.fromRPCBody = function (json) { return new CosmosSendMessage(json.value.from_address, json.value.to_address, json.value.amount.map(function (value) { return CosmosCoin_1.CosmosCoin.fromRPCBody(value); })); }; return CosmosSendMessage; }()); exports.CosmosSendMessage = CosmosSendMessage; //# sourceMappingURL=CosmosSendMessage.js.map