"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.utxo_ensure_data = exports.utxo_check_expect_block_out_of_range = exports.utxo_check_expect_empty = exports.WordToOpcode = void 0;
const utils_1 = require("./utils");
/**
 * Opcode words to their opcodes
 * @dev https://en.bitcoin.it/wiki/Script
 * from https://github.com/bitcoin/bitcoin/blob/22139f6e83a2bedd2dad9f280567d2c76c54252f/src/script/script.h#LL69C16-L69C16
 */
var WordToOpcode;
(function (WordToOpcode) {
    // push value
    WordToOpcode[WordToOpcode["OP_0"] = 0] = "OP_0";
    WordToOpcode[WordToOpcode["OP_FALSE"] = 0] = "OP_FALSE";
    WordToOpcode[WordToOpcode["OP_PUSHDATA1"] = 76] = "OP_PUSHDATA1";
    WordToOpcode[WordToOpcode["OP_PUSHDATA2"] = 77] = "OP_PUSHDATA2";
    WordToOpcode[WordToOpcode["OP_PUSHDATA4"] = 78] = "OP_PUSHDATA4";
    WordToOpcode[WordToOpcode["OP_1NEGATE"] = 79] = "OP_1NEGATE";
    WordToOpcode[WordToOpcode["OP_RESERVED"] = 80] = "OP_RESERVED";
    WordToOpcode[WordToOpcode["OP_1"] = 81] = "OP_1";
    WordToOpcode[WordToOpcode["OP_TRUE"] = 81] = "OP_TRUE";
    WordToOpcode[WordToOpcode["OP_2"] = 82] = "OP_2";
    WordToOpcode[WordToOpcode["OP_3"] = 83] = "OP_3";
    WordToOpcode[WordToOpcode["OP_4"] = 84] = "OP_4";
    WordToOpcode[WordToOpcode["OP_5"] = 85] = "OP_5";
    WordToOpcode[WordToOpcode["OP_6"] = 86] = "OP_6";
    WordToOpcode[WordToOpcode["OP_7"] = 87] = "OP_7";
    WordToOpcode[WordToOpcode["OP_8"] = 88] = "OP_8";
    WordToOpcode[WordToOpcode["OP_9"] = 89] = "OP_9";
    WordToOpcode[WordToOpcode["OP_10"] = 90] = "OP_10";
    WordToOpcode[WordToOpcode["OP_11"] = 91] = "OP_11";
    WordToOpcode[WordToOpcode["OP_12"] = 92] = "OP_12";
    WordToOpcode[WordToOpcode["OP_13"] = 93] = "OP_13";
    WordToOpcode[WordToOpcode["OP_14"] = 94] = "OP_14";
    WordToOpcode[WordToOpcode["OP_15"] = 95] = "OP_15";
    WordToOpcode[WordToOpcode["OP_16"] = 96] = "OP_16";
    // control
    WordToOpcode[WordToOpcode["OP_NOP"] = 97] = "OP_NOP";
    WordToOpcode[WordToOpcode["OP_VER"] = 98] = "OP_VER";
    WordToOpcode[WordToOpcode["OP_IF"] = 99] = "OP_IF";
    WordToOpcode[WordToOpcode["OP_NOTIF"] = 100] = "OP_NOTIF";
    WordToOpcode[WordToOpcode["OP_VERIF"] = 101] = "OP_VERIF";
    WordToOpcode[WordToOpcode["OP_VERNOTIF"] = 102] = "OP_VERNOTIF";
    WordToOpcode[WordToOpcode["OP_ELSE"] = 103] = "OP_ELSE";
    WordToOpcode[WordToOpcode["OP_ENDIF"] = 104] = "OP_ENDIF";
    WordToOpcode[WordToOpcode["OP_VERIFY"] = 105] = "OP_VERIFY";
    WordToOpcode[WordToOpcode["OP_RETURN"] = 106] = "OP_RETURN";
    // stack ops
    WordToOpcode[WordToOpcode["OP_TOALTSTACK"] = 107] = "OP_TOALTSTACK";
    WordToOpcode[WordToOpcode["OP_FROMALTSTACK"] = 108] = "OP_FROMALTSTACK";
    WordToOpcode[WordToOpcode["OP_2DROP"] = 109] = "OP_2DROP";
    WordToOpcode[WordToOpcode["OP_2DUP"] = 110] = "OP_2DUP";
    WordToOpcode[WordToOpcode["OP_3DUP"] = 111] = "OP_3DUP";
    WordToOpcode[WordToOpcode["OP_2OVER"] = 112] = "OP_2OVER";
    WordToOpcode[WordToOpcode["OP_2ROT"] = 113] = "OP_2ROT";
    WordToOpcode[WordToOpcode["OP_2SWAP"] = 114] = "OP_2SWAP";
    WordToOpcode[WordToOpcode["OP_IFDUP"] = 115] = "OP_IFDUP";
    WordToOpcode[WordToOpcode["OP_DEPTH"] = 116] = "OP_DEPTH";
    WordToOpcode[WordToOpcode["OP_DROP"] = 117] = "OP_DROP";
    WordToOpcode[WordToOpcode["OP_DUP"] = 118] = "OP_DUP";
    WordToOpcode[WordToOpcode["OP_NIP"] = 119] = "OP_NIP";
    WordToOpcode[WordToOpcode["OP_OVER"] = 120] = "OP_OVER";
    WordToOpcode[WordToOpcode["OP_PICK"] = 121] = "OP_PICK";
    WordToOpcode[WordToOpcode["OP_ROLL"] = 122] = "OP_ROLL";
    WordToOpcode[WordToOpcode["OP_ROT"] = 123] = "OP_ROT";
    WordToOpcode[WordToOpcode["OP_SWAP"] = 124] = "OP_SWAP";
    WordToOpcode[WordToOpcode["OP_TUCK"] = 125] = "OP_TUCK";
    // splice ops
    WordToOpcode[WordToOpcode["OP_CAT"] = 126] = "OP_CAT";
    WordToOpcode[WordToOpcode["OP_SUBSTR"] = 127] = "OP_SUBSTR";
    WordToOpcode[WordToOpcode["OP_LEFT"] = 128] = "OP_LEFT";
    WordToOpcode[WordToOpcode["OP_RIGHT"] = 129] = "OP_RIGHT";
    WordToOpcode[WordToOpcode["OP_SIZE"] = 130] = "OP_SIZE";
    // bit logic
    WordToOpcode[WordToOpcode["OP_INVERT"] = 131] = "OP_INVERT";
    WordToOpcode[WordToOpcode["OP_AND"] = 132] = "OP_AND";
    WordToOpcode[WordToOpcode["OP_OR"] = 133] = "OP_OR";
    WordToOpcode[WordToOpcode["OP_XOR"] = 134] = "OP_XOR";
    WordToOpcode[WordToOpcode["OP_EQUAL"] = 135] = "OP_EQUAL";
    WordToOpcode[WordToOpcode["OP_EQUALVERIFY"] = 136] = "OP_EQUALVERIFY";
    WordToOpcode[WordToOpcode["OP_RESERVED1"] = 137] = "OP_RESERVED1";
    WordToOpcode[WordToOpcode["OP_RESERVED2"] = 138] = "OP_RESERVED2";
    // numeric
    WordToOpcode[WordToOpcode["OP_1ADD"] = 139] = "OP_1ADD";
    WordToOpcode[WordToOpcode["OP_1SUB"] = 140] = "OP_1SUB";
    WordToOpcode[WordToOpcode["OP_2MUL"] = 141] = "OP_2MUL";
    WordToOpcode[WordToOpcode["OP_2DIV"] = 142] = "OP_2DIV";
    WordToOpcode[WordToOpcode["OP_NEGATE"] = 143] = "OP_NEGATE";
    WordToOpcode[WordToOpcode["OP_ABS"] = 144] = "OP_ABS";
    WordToOpcode[WordToOpcode["OP_NOT"] = 145] = "OP_NOT";
    WordToOpcode[WordToOpcode["OP_0NOTEQUAL"] = 146] = "OP_0NOTEQUAL";
    WordToOpcode[WordToOpcode["OP_ADD"] = 147] = "OP_ADD";
    WordToOpcode[WordToOpcode["OP_SUB"] = 148] = "OP_SUB";
    WordToOpcode[WordToOpcode["OP_MUL"] = 149] = "OP_MUL";
    WordToOpcode[WordToOpcode["OP_DIV"] = 150] = "OP_DIV";
    WordToOpcode[WordToOpcode["OP_MOD"] = 151] = "OP_MOD";
    WordToOpcode[WordToOpcode["OP_LSHIFT"] = 152] = "OP_LSHIFT";
    WordToOpcode[WordToOpcode["OP_RSHIFT"] = 153] = "OP_RSHIFT";
    WordToOpcode[WordToOpcode["OP_BOOLAND"] = 154] = "OP_BOOLAND";
    WordToOpcode[WordToOpcode["OP_BOOLOR"] = 155] = "OP_BOOLOR";
    WordToOpcode[WordToOpcode["OP_NUMEQUAL"] = 156] = "OP_NUMEQUAL";
    WordToOpcode[WordToOpcode["OP_NUMEQUALVERIFY"] = 157] = "OP_NUMEQUALVERIFY";
    WordToOpcode[WordToOpcode["OP_NUMNOTEQUAL"] = 158] = "OP_NUMNOTEQUAL";
    WordToOpcode[WordToOpcode["OP_LESSTHAN"] = 159] = "OP_LESSTHAN";
    WordToOpcode[WordToOpcode["OP_GREATERTHAN"] = 160] = "OP_GREATERTHAN";
    WordToOpcode[WordToOpcode["OP_LESSTHANOREQUAL"] = 161] = "OP_LESSTHANOREQUAL";
    WordToOpcode[WordToOpcode["OP_GREATERTHANOREQUAL"] = 162] = "OP_GREATERTHANOREQUAL";
    WordToOpcode[WordToOpcode["OP_MIN"] = 163] = "OP_MIN";
    WordToOpcode[WordToOpcode["OP_MAX"] = 164] = "OP_MAX";
    WordToOpcode[WordToOpcode["OP_WITHIN"] = 165] = "OP_WITHIN";
    // crypto
    WordToOpcode[WordToOpcode["OP_RIPEMD160"] = 166] = "OP_RIPEMD160";
    WordToOpcode[WordToOpcode["OP_SHA1"] = 167] = "OP_SHA1";
    WordToOpcode[WordToOpcode["OP_SHA256"] = 168] = "OP_SHA256";
    WordToOpcode[WordToOpcode["OP_HASH160"] = 169] = "OP_HASH160";
    WordToOpcode[WordToOpcode["OP_HASH256"] = 170] = "OP_HASH256";
    WordToOpcode[WordToOpcode["OP_CODESEPARATOR"] = 171] = "OP_CODESEPARATOR";
    WordToOpcode[WordToOpcode["OP_CHECKSIG"] = 172] = "OP_CHECKSIG";
    WordToOpcode[WordToOpcode["OP_CHECKSIGVERIFY"] = 173] = "OP_CHECKSIGVERIFY";
    WordToOpcode[WordToOpcode["OP_CHECKMULTISIG"] = 174] = "OP_CHECKMULTISIG";
    WordToOpcode[WordToOpcode["OP_CHECKMULTISIGVERIFY"] = 175] = "OP_CHECKMULTISIGVERIFY";
    // expansion
    WordToOpcode[WordToOpcode["OP_NOP1"] = 176] = "OP_NOP1";
    WordToOpcode[WordToOpcode["OP_CHECKLOCKTIMEVERIFY"] = 177] = "OP_CHECKLOCKTIMEVERIFY";
    WordToOpcode[WordToOpcode["OP_NOP2"] = 177] = "OP_NOP2";
    WordToOpcode[WordToOpcode["OP_CHECKSEQUENCEVERIFY"] = 178] = "OP_CHECKSEQUENCEVERIFY";
    WordToOpcode[WordToOpcode["OP_NOP3"] = 178] = "OP_NOP3";
    WordToOpcode[WordToOpcode["OP_NOP4"] = 179] = "OP_NOP4";
    WordToOpcode[WordToOpcode["OP_NOP5"] = 180] = "OP_NOP5";
    WordToOpcode[WordToOpcode["OP_NOP6"] = 181] = "OP_NOP6";
    WordToOpcode[WordToOpcode["OP_NOP7"] = 182] = "OP_NOP7";
    WordToOpcode[WordToOpcode["OP_NOP8"] = 183] = "OP_NOP8";
    WordToOpcode[WordToOpcode["OP_NOP9"] = 184] = "OP_NOP9";
    WordToOpcode[WordToOpcode["OP_NOP10"] = 185] = "OP_NOP10";
    // Opcode added by BIP 342 (Tapscript)
    WordToOpcode[WordToOpcode["OP_CHECKSIGADD"] = 186] = "OP_CHECKSIGADD";
    WordToOpcode[WordToOpcode["OP_INVALIDOPCODE"] = 255] = "OP_INVALIDOPCODE";
})(WordToOpcode = exports.WordToOpcode || (exports.WordToOpcode = {}));
////////////////////////////
//// MCC Error handling ////
////////////////////////////
/**
 * Check if return error code is -5 (can't find transaction)
 * @param data
 * @returns
 */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function utxo_check_expect_empty(data) {
    if (!data || !data.error || !data.error.code) {
        return false;
    }
    if (data.error.code && data.error.code === -5) {
        return true;
    }
    else {
        return false;
    }
}
exports.utxo_check_expect_empty = utxo_check_expect_empty;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function utxo_check_expect_block_out_of_range(data) {
    if (data && data.error && data.error.code) {
        if (data.error.code === -8) {
            return true;
        }
        if (data.error.code === -1) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        return false;
    }
}
exports.utxo_check_expect_block_out_of_range = utxo_check_expect_block_out_of_range;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function utxo_ensure_data(data) {
    if (data === null || data === void 0 ? void 0 : data.error) {
        throw (0, utils_1.MccError)(data);
    }
}
exports.utxo_ensure_data = utxo_ensure_data;
//# sourceMappingURL=utxoUtils.js.map