@paradeum/burrow
Version:
TypeScript library that calls a Hyperledger Burrow server over GRPC.
70 lines • 2 kB
JavaScript
;
exports.__esModule = true;
exports.burrowToAbi = exports.abiToBurrow = exports.numberTB = exports.bytesTA = exports.bytesTB = exports.addressTA = exports.addressTB = exports.recApply = void 0;
exports.recApply = function (func, args) {
if (Array.isArray(args)) {
var next = [];
for (var i = 0; i < args.length; i++) {
next.push(exports.recApply(func, args[i]));
}
;
return next;
}
return func(args);
};
exports.addressTB = function (arg) {
return arg.toUpperCase();
};
exports.addressTA = function (arg) {
if (!/^0x/i.test(arg)) {
return '0x' + arg;
}
return arg;
};
exports.bytesTB = function (arg) {
return arg.toString('hex').toUpperCase();
};
exports.bytesTA = function (arg) {
if (typeof (arg) === 'string' && /^0x/i.test(arg)) {
arg = arg.slice(2);
}
return Buffer.from(arg, 'hex');
};
exports.numberTB = function (arg) {
return arg.toNumber();
};
exports.abiToBurrow = function (puts, args) {
var out = [];
for (var i = 0; i < puts.length; i++) {
if (/address/i.test(puts[i])) {
out.push(exports.recApply(exports.addressTB, args[i]));
}
else if (/bytes/i.test(puts[i])) {
out.push(exports.recApply(exports.bytesTB, args[i]));
}
else if (/int/i.test(puts[i])) {
out.push(exports.recApply(exports.numberTB, args[i]));
}
else {
out.push(args[i]);
}
}
return out;
};
exports.burrowToAbi = function (puts, args) {
var out = [];
for (var i = 0; i < puts.length; i++) {
if (/address/i.test(puts[i])) {
out.push(exports.recApply(exports.addressTA, args[i]));
}
else if (/bytes/i.test(puts[i])) {
out.push(exports.recApply(exports.bytesTA, args[i]));
}
else {
out.push(args[i]);
}
}
;
return out;
};
//# sourceMappingURL=convert.js.map