dpos-offline
Version:
Offline Signing Transactions for DPOS Blockchains
67 lines (66 loc) • 2.21 kB
JavaScript
;
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 __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Transforms an object with some Buffers to strings.
* @param obj
* @param maxRecursionLevel
*/
exports.toTransportable = function (obj, maxRecursionLevel) {
var e_1, _a;
if (maxRecursionLevel === void 0) { maxRecursionLevel = 5; }
if (maxRecursionLevel < 0) {
throw new Error('Object cannot be transformed to transport format');
}
if (Array.isArray(obj)) {
return obj.map(function (item) { return exports.toTransportable(item, maxRecursionLevel - 1); });
}
if (Buffer.isBuffer(obj)) {
return obj.toString('hex');
}
if (typeof obj === 'function') {
return undefined;
}
if (typeof obj !== 'object' || obj === null || typeof obj === 'undefined') {
return obj;
}
var toRet = __assign({}, obj);
var keys = Object.keys(obj);
try {
for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
var key = keys_1_1.value;
toRet[key] = exports.toTransportable(toRet[key], maxRecursionLevel - 1);
if (typeof toRet[key] === 'undefined') {
delete toRet[key];
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
}
finally { if (e_1) throw e_1.error; }
}
return toRet;
};