UNPKG

dpos-offline

Version:

Offline Signing Transactions for DPOS Blockchains

59 lines (58 loc) 2.54 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var ByteBuffer = require("bytebuffer"); var empty = require("is-empty"); var varuint = require("varuint-bitcoin"); var base_rise_1 = require("../base_rise"); var rise_address_1 = require("../rise_address"); var BaseRiseV1Codec = /** @class */ (function (_super) { __extends(BaseRiseV1Codec, _super); function BaseRiseV1Codec() { return _super !== null && _super.apply(this, arguments) || this; } BaseRiseV1Codec.prototype.calcBytes = function (tx) { var assetBytes = this.assetBytes(tx); var bb = new ByteBuffer(1 + 4 + 32 + 32 + 8 + 8 + 64 + 64 + assetBytes.length, true); var recipientV2 = !empty(tx.recipientId) && !/^[0-9]+R$/.test(tx.recipientId); bb.writeByte(tx.type); bb.writeUint32((recipientV2 ? Math.pow(2, 30) : 0) + tx.timestamp); bb.append(tx.senderPubData); if (recipientV2) { var address = rise_address_1.RiseIdsHandler.addressToBytes(tx.recipientId); bb.append(varuint.encode(address.length)); bb.append(address); } else if (empty(tx.recipientId)) { bb.append(Buffer.alloc(8).fill(0)); } else { bb.append(rise_address_1.RiseIdsHandler.addressToBytes(tx.recipientId)); } // tslint:disable-next-line no-string-literal bb['writeLong'](tx.amount); bb.append(assetBytes); bb.flip(); return new Buffer(bb.toBuffer()); }; BaseRiseV1Codec.prototype.fromBytes = function (buff) { throw new Error('V1 transaction types do not support deserializing from bytes'); }; BaseRiseV1Codec.prototype.assetFromBytes = function (buf) { throw new Error('V1 transaction types do not support deserializing from bytes'); }; return BaseRiseV1Codec; }(base_rise_1.BaseRiseCodec)); exports.BaseRiseV1Codec = BaseRiseV1Codec;