UNPKG

@helium/transactions

Version:

Construct and serialize Helium blockchain transaction primatives

57 lines 2.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const proto_1 = __importDefault(require("@helium/proto")); const Transaction_1 = __importDefault(require("./Transaction")); const utils_1 = require("./utils"); class UnstakeValidatorV1 extends Transaction_1.default { constructor(opts) { super(); this.type = 'unstake_validator_v1'; this.address = opts.address; this.owner = opts.owner; this.stakeAmount = opts.stakeAmount; this.stakeReleaseHeight = opts.stakeReleaseHeight; if (opts.fee !== undefined) { this.fee = opts.fee; } else { this.fee = 0; this.fee = this.calculateFee(); } } serialize() { const Txn = proto_1.default.helium.blockchain_txn; const unstakeValidator = this.toProto(); const txn = Txn.create({ unstakeValidator }); return Txn.encode(txn).finish(); } async sign({ owner: ownerKeypair }) { const UnstakeValidator = proto_1.default.helium.blockchain_txn_stake_validator_v1; const unstakeValidator = this.toProto(true); const serialized = UnstakeValidator.encode(unstakeValidator).finish(); const signature = await ownerKeypair.sign(serialized); this.ownerSignature = signature; return this; } toProto(forSigning = false) { const UnstakeValidator = proto_1.default.helium.blockchain_txn_unstake_validator_v1; return UnstakeValidator.create({ address: this.address ? (0, utils_1.toUint8Array)(this.address.bin) : null, owner: this.owner ? (0, utils_1.toUint8Array)(this.owner.bin) : null, stakeAmount: this.stakeAmount, stakeReleaseHeight: this.stakeReleaseHeight, fee: this.fee && this.fee > 0 ? this.fee : null, ownerSignature: this.ownerSignature && !forSigning ? (0, utils_1.toUint8Array)(this.ownerSignature) : null, }); } calculateFee() { this.ownerSignature = utils_1.EMPTY_SIGNATURE; const payload = this.serialize(); return Transaction_1.default.calculateFee(payload); } } exports.default = UnstakeValidatorV1; //# sourceMappingURL=UnstakeValidatorV1.js.map