stellar-plus
Version:
beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain
37 lines (36 loc) • 2.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SorobanOpCodes = exports.extractSorobanResultXdrOpErrorCode = void 0;
const stellar_sdk_1 = require("@stellar/stellar-sdk");
const extractSorobanResultXdrOpErrorCode = (resultXdr) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
if (typeof resultXdr === 'string') {
const resultXdrObject = stellar_sdk_1.xdr.TransactionResult.fromXDR(resultXdr, 'base64');
return resultXdrObject.result().results()[0].tr().value().switch().name;
}
try {
if (((_a = resultXdr.result) === null || _a === void 0 ? void 0 : _a.call(resultXdr).results) !== undefined && typeof ((_b = resultXdr.result) === null || _b === void 0 ? void 0 : _b.call(resultXdr).results) === 'function') {
return (_l = (_j = (_g = (_e = (_c = resultXdr.result) === null || _c === void 0 ? void 0 : (_d = _c.call(resultXdr)).results) === null || _e === void 0 ? void 0 : (_f = _e.call(_d)[0]).tr) === null || _g === void 0 ? void 0 : (_h = _g.call(_f)).value) === null || _j === void 0 ? void 0 : (_k = _j.call(_h)).switch) === null || _l === void 0 ? void 0 : _l.call(_k).name;
}
}
catch (error) {
// "Xdr don't have results"
//TODO: Evaluate if we should treat this in some way
}
try {
if (((_m = resultXdr.result) === null || _m === void 0 ? void 0 : _m.call(resultXdr).switch) !== undefined && typeof ((_o = resultXdr.result) === null || _o === void 0 ? void 0 : _o.call(resultXdr).switch) === 'function') {
return (_r = (_p = resultXdr.result) === null || _p === void 0 ? void 0 : (_q = _p.call(resultXdr)).switch) === null || _r === void 0 ? void 0 : _r.call(_q).name;
}
}
catch (error) {
console.log('Fail in decode xdr: %s, Error: %s', resultXdr, error);
return 'fail_in_decode_xdr';
}
return 'not_found';
};
exports.extractSorobanResultXdrOpErrorCode = extractSorobanResultXdrOpErrorCode;
var SorobanOpCodes;
(function (SorobanOpCodes) {
SorobanOpCodes["invokeHostFunctionEntryArchived"] = "invokeHostFunctionEntryArchived";
SorobanOpCodes["restoreFootprintSuccess"] = "restoreFootprintSuccess";
})(SorobanOpCodes || (exports.SorobanOpCodes = SorobanOpCodes = {}));