airgap-coin-lib
Version:
The airgap-coin-lib is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.
81 lines • 4.19 kB
JavaScript
;
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 __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var SCALEDecoder_1 = require("../../scale/SCALEDecoder");
var SCALEClass_1 = require("../../scale/type/SCALEClass");
var SCALEInt_1 = require("../../scale/type/SCALEInt");
var SubstrateTransactionMethodArgs_1 = require("./SubstrateTransactionMethodArgs");
var SubstrateTransactionMethod = /** @class */ (function (_super) {
__extends(SubstrateTransactionMethod, _super);
function SubstrateTransactionMethod(moduleIndex, callIndex, args, toAirGapTransactionParts) {
var _this = _super.call(this) || this;
_this.moduleIndex = moduleIndex;
_this.callIndex = callIndex;
_this.args = args;
_this.toAirGapTransactionParts = toAirGapTransactionParts;
_this.scaleFields = __spreadArrays([_this.moduleIndex, _this.callIndex], _this.args.map(function (arg) { return arg[1]; }));
return _this;
}
SubstrateTransactionMethod.create = function (network, type, moduleIndex, callIndex, args) {
var argsFactory = SubstrateTransactionMethodArgs_1.SubstrateTransactionMethodArgsFactory.create(network, type, args);
return new SubstrateTransactionMethod(SCALEInt_1.SCALEInt.from(moduleIndex), SCALEInt_1.SCALEInt.from(callIndex), argsFactory.createFields(), argsFactory.createToAirGapTransactionParts());
};
SubstrateTransactionMethod.decode = function (network, type, raw) {
var decoder = new SCALEDecoder_1.SCALEDecoder(network, raw);
var moduleIndex = decoder.decodeNextInt(8);
var callIndex = decoder.decodeNextInt(8);
var argsDecoder = SubstrateTransactionMethodArgs_1.SubstrateTransactionMethodArgsDecoder.create(type);
var args = decoder.decodeNextObject(function (network, hex) { return argsDecoder.decode(network, hex); });
return {
bytesDecoded: moduleIndex.bytesDecoded + callIndex.bytesDecoded + args.bytesDecoded,
decoded: SubstrateTransactionMethod.create(network, type, moduleIndex.decoded.toNumber(), callIndex.decoded.toNumber(), args.decoded)
};
};
SubstrateTransactionMethod.prototype.toString = function () {
return JSON.stringify(__assign({ moduleIndex: this.moduleIndex.toNumber(), callIndex: this.callIndex.toNumber() }, this.args.reduce(function (prev, _a) {
var _b;
var key = _a[0], value = _a[1];
var valueString = value.toString();
try {
valueString = JSON.parse(valueString);
}
catch (_c) { }
return Object.assign(prev, (_b = {},
_b[key] = valueString,
_b));
}, {})), null, 2);
};
return SubstrateTransactionMethod;
}(SCALEClass_1.SCALEClass));
exports.SubstrateTransactionMethod = SubstrateTransactionMethod;
//# sourceMappingURL=SubstrateTransactionMethod.js.map