meta-contract-debug
Version:
Meta Contract SDK
48 lines (47 loc) • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasProtoFlag = exports.getProtoVersion = exports.getProtoType = exports.getFlag = exports.getHeaderLen = exports.PROTO_TYPE = exports.HEADER_LEN = exports.PROTO_VERSION_OFFSET = exports.PROTO_VERSION_LEN = exports.PROTO_TYPE_OFFSET = exports.PROTO_TYPE_LEN = exports.PROTO_FLAG_OFFSET = exports.PROTO_FLAG_LEN = exports.PROTO_FLAG = exports.PROTO_SUFFIX = void 0;
exports.PROTO_SUFFIX = 5;
exports.PROTO_FLAG = Buffer.from('metacontract'); // 12
exports.PROTO_FLAG_LEN = exports.PROTO_FLAG.length; // 12
exports.PROTO_FLAG_OFFSET = exports.PROTO_FLAG_LEN + exports.PROTO_SUFFIX; // 12 + 5 = 17
exports.PROTO_TYPE_LEN = 4;
exports.PROTO_TYPE_OFFSET = exports.PROTO_FLAG_OFFSET + exports.PROTO_TYPE_LEN; // 17 + 4 = 21
exports.PROTO_VERSION_LEN = 4;
exports.PROTO_VERSION_OFFSET = exports.PROTO_TYPE_OFFSET + exports.PROTO_VERSION_LEN; // 21 + 4 = 25
exports.HEADER_LEN = exports.PROTO_VERSION_OFFSET; // 25
var PROTO_TYPE;
(function (PROTO_TYPE) {
PROTO_TYPE[PROTO_TYPE["FT"] = 1] = "FT";
PROTO_TYPE[PROTO_TYPE["UNIQUE"] = 2] = "UNIQUE";
PROTO_TYPE[PROTO_TYPE["NFT"] = 3] = "NFT";
PROTO_TYPE[PROTO_TYPE["NFT_SELL"] = 65537] = "NFT_SELL";
})(PROTO_TYPE = exports.PROTO_TYPE || (exports.PROTO_TYPE = {}));
function getHeaderLen() {
return exports.HEADER_LEN;
}
exports.getHeaderLen = getHeaderLen;
function getFlag(script) {
return script.slice(script.length - exports.PROTO_FLAG_OFFSET, script.length - exports.PROTO_SUFFIX);
}
exports.getFlag = getFlag;
function getProtoType(script) {
if (script.length < exports.PROTO_TYPE_OFFSET)
return 0;
return script.readUIntLE(script.length - exports.PROTO_TYPE_OFFSET, exports.PROTO_TYPE_LEN);
}
exports.getProtoType = getProtoType;
function getProtoVersion(script) {
if (script.length < exports.PROTO_VERSION_OFFSET)
return 0;
return script.readUIntLE(script.length - exports.PROTO_VERSION_OFFSET, exports.PROTO_VERSION_LEN);
}
exports.getProtoVersion = getProtoVersion;
function hasProtoFlag(script) {
const flag = getFlag(script);
if (flag.compare(exports.PROTO_FLAG) === 0) {
return true;
}
return false;
}
exports.hasProtoFlag = hasProtoFlag;