airgap-coin-lib
Version:
The airgap-coin-lib is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.
56 lines • 2.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var IAirGapTransaction_1 = require("../../../interfaces/IAirGapTransaction");
var CosmosCoin_1 = require("../CosmosCoin");
var CosmosMessage_1 = require("./CosmosMessage");
var CosmosDelegateMessage = /** @class */ (function () {
function CosmosDelegateMessage(delegatorAddress, validatorAddress, amount, undelegate) {
if (undelegate === void 0) { undelegate = false; }
this.delegatorAddress = delegatorAddress;
this.validatorAddress = validatorAddress;
this.amount = amount;
this.type = undelegate ? CosmosMessage_1.CosmosMessageType.Undelegate : CosmosMessage_1.CosmosMessageType.Delegate;
}
CosmosDelegateMessage.prototype.toJSON = function () {
return {
type: this.type.index,
amount: [this.amount.toJSON()],
fromAddress: this.delegatorAddress,
toAddress: this.validatorAddress
};
};
CosmosDelegateMessage.fromJSON = function (json) {
return new CosmosDelegateMessage(json.fromAddress, json.toAddress, CosmosCoin_1.CosmosCoin.fromJSON(json.amount[0]), json.type === CosmosMessage_1.CosmosMessageType.Undelegate.index);
};
CosmosDelegateMessage.prototype.toRPCBody = function () {
return {
type: this.type.value,
value: {
amount: this.amount.toRPCBody(),
delegator_address: this.delegatorAddress,
validator_address: this.validatorAddress
}
};
};
CosmosDelegateMessage.prototype.toAirGapTransaction = function (protocol, fee) {
return {
amount: this.amount.amount,
from: [this.delegatorAddress],
to: [this.validatorAddress],
isInbound: false,
fee: fee,
protocolIdentifier: protocol.identifier,
network: protocol.options.network,
transactionDetails: this.toRPCBody(),
extra: {
type: this.type.index === CosmosMessage_1.CosmosMessageTypeIndex.DELEGATE ? IAirGapTransaction_1.AirGapTransactionType.DELEGATE : IAirGapTransaction_1.AirGapTransactionType.UNDELEGATE
}
};
};
CosmosDelegateMessage.fromRPCBody = function (json) {
return new CosmosDelegateMessage(json.value.delegator_address, json.value.validator_address, CosmosCoin_1.CosmosCoin.fromRPCBody(json.value.amount), json.type === CosmosMessage_1.CosmosMessageType.Undelegate.value);
};
return CosmosDelegateMessage;
}());
exports.CosmosDelegateMessage = CosmosDelegateMessage;
//# sourceMappingURL=CosmosDelegateMessage.js.map