UNPKG

airgap-coin-lib

Version:

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

73 lines 3.71 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 SCALEDecoder_1 = require("../scale/SCALEDecoder"); var SCALEClass_1 = require("../scale/type/SCALEClass"); var SCALEHash_1 = require("../scale/type/SCALEHash"); var SCALEInt_1 = require("../scale/type/SCALEInt"); var SubstrateTransactionMethod_1 = require("./method/SubstrateTransactionMethod"); var SubstrateTransactionPayload = /** @class */ (function (_super) { __extends(SubstrateTransactionPayload, _super); function SubstrateTransactionPayload(method, era, nonce, tip, specVersion, transactionVersion, genesisHash, blockHash) { var _this = _super.call(this) || this; _this.method = method; _this.era = era; _this.nonce = nonce; _this.tip = tip; _this.specVersion = specVersion; _this.transactionVersion = transactionVersion; _this.genesisHash = genesisHash; _this.blockHash = blockHash; _this.scaleFields = [ _this.method, _this.era, _this.nonce, _this.tip, _this.specVersion, _this.transactionVersion, _this.genesisHash, _this.blockHash ]; return _this; } SubstrateTransactionPayload.create = function (transaction, config) { return new SubstrateTransactionPayload(transaction.method, transaction.era, transaction.nonce, transaction.tip, SCALEInt_1.SCALEInt.from(config.specVersion, 32), SCALEInt_1.SCALEInt.from(config.transactionVersion, 32), SCALEHash_1.SCALEHash.from(config.genesisHash), SCALEHash_1.SCALEHash.from(transaction.era.isMortal ? config.lastHash : config.genesisHash)); }; SubstrateTransactionPayload.decode = function (network, type, hex) { var decoder = new SCALEDecoder_1.SCALEDecoder(network, hex); var method = decoder.decodeNextObject(function (network, hex) { return SubstrateTransactionMethod_1.SubstrateTransactionMethod.decode(network, type, hex); }); var era = decoder.decodeNextEra(); var nonce = decoder.decodeNextCompactInt(); var tip = decoder.decodeNextCompactInt(); var specVersion = decoder.decodeNextInt(32); var transactionVersion = decoder.decodeNextInt(32); var genesisHash = decoder.decodeNextHash(256); var blockHash = decoder.decodeNextHash(256); return { bytesDecoded: method.bytesDecoded + era.bytesDecoded + nonce.bytesDecoded + tip.bytesDecoded + specVersion.bytesDecoded + transactionVersion.bytesDecoded + genesisHash.bytesDecoded + blockHash.bytesDecoded, decoded: new SubstrateTransactionPayload(method.decoded, era.decoded, nonce.decoded, tip.decoded, specVersion.decoded, transactionVersion.decoded, genesisHash.decoded, blockHash.decoded) }; }; return SubstrateTransactionPayload; }(SCALEClass_1.SCALEClass)); exports.SubstrateTransactionPayload = SubstrateTransactionPayload; //# sourceMappingURL=SubstrateTransactionPayload.js.map