How to use the bitcore.Opcode.OP_ELSE function in bitcore

To help you get started, we’ve selected a few bitcore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AltCoinExchange / altcoin-atomic-trading-platform / btcatomicswap / dist / contract / extract-atomic-swap-contract.js View on Github external
var extractAtomicSwapContract = exports.extractAtomicSwapContract = function extractAtomicSwapContract(ct) {
  var contract = new Script(ct);
  var pops = contract.toString().split(' ');
  var opCodes = pops.filter(function (opcode) {
    return opcode.indexOf('0x') === -1;
  });

  var isAtomicSwap = new Opcode(opCodes[0]).toString() === new Opcode(Opcode.OP_IF).toString() && new Opcode(opCodes[1]).toString() === new Opcode(Opcode.OP_RIPEMD160).toString() && parseInt(opCodes[2]) === 20 && new Opcode(opCodes[3]).toString() === new Opcode(Opcode.OP_EQUALVERIFY).toString() && new Opcode(opCodes[4]).toString() === new Opcode(Opcode.OP_DUP).toString() && new Opcode(opCodes[5]).toString() === new Opcode(Opcode.OP_HASH160).toString() && parseInt(opCodes[6]) === 20 && new Opcode(opCodes[7]).toString() === new Opcode(Opcode.OP_ELSE).toString() && parseInt(opCodes[8]) && new Opcode(opCodes[9]).toString() === new Opcode(Opcode.OP_CHECKLOCKTIMEVERIFY).toString() && new Opcode(opCodes[10]).toString() === new Opcode(Opcode.OP_DROP).toString() && new Opcode(opCodes[11]).toString() === new Opcode(Opcode.OP_DUP).toString() && new Opcode(opCodes[12]).toString() === new Opcode(Opcode.OP_HASH160).toString() && parseInt(opCodes[13]) === 20 && new Opcode(opCodes[14]).toString() === new Opcode(Opcode.OP_ENDIF).toString() && new Opcode(opCodes[15]).toString() === new Opcode(Opcode.OP_EQUALVERIFY).toString() && new Opcode(opCodes[16]).toString() === new Opcode(Opcode.OP_CHECKSIG).toString();

  if (!isAtomicSwap) {
    console.error('contract is not an atomic swap script!');
    return;
  }

  var data = pops.filter(function (opcode) {
    return opcode.indexOf('0x') !== -1;
  });

  var secretHash = data[0];
  var recipientHash = data[1];
  var lockTime = data[2].replace('0x', '');
  var refundHash160 = data[3];

  return {
github AltCoinExchange / altcoin-atomic-trading-platform / btcatomicswap / dist / extract-atomic-swap-contract.js View on Github external
var extractAtomicSwapContract = exports.extractAtomicSwapContract = function extractAtomicSwapContract(ct) {
  var contract = new Script(ct);
  var pops = contract.toString().split(' ');
  var opCodes = pops.filter(function (opcode) {
    return opcode.indexOf('0x') === -1;
  });

  var isAtomicSwap = new Opcode(opCodes[0]).toString() === new Opcode(Opcode.OP_IF).toString() && new Opcode(opCodes[1]).toString() === new Opcode(Opcode.OP_RIPEMD160).toString() && parseInt(opCodes[2]) === 20 && new Opcode(opCodes[3]).toString() === new Opcode(Opcode.OP_EQUALVERIFY).toString() && new Opcode(opCodes[4]).toString() === new Opcode(Opcode.OP_DUP).toString() && new Opcode(opCodes[5]).toString() === new Opcode(Opcode.OP_HASH160).toString() && parseInt(opCodes[6]) === 20 && new Opcode(opCodes[7]).toString() === new Opcode(Opcode.OP_ELSE).toString() && parseInt(opCodes[8]) === 5 && new Opcode(opCodes[9]).toString() === new Opcode(Opcode.OP_CHECKLOCKTIMEVERIFY).toString() && new Opcode(opCodes[10]).toString() === new Opcode(Opcode.OP_DROP).toString() && new Opcode(opCodes[11]).toString() === new Opcode(Opcode.OP_DUP).toString() && new Opcode(opCodes[12]).toString() === new Opcode(Opcode.OP_HASH160).toString() && parseInt(opCodes[13]) === 20 && new Opcode(opCodes[14]).toString() === new Opcode(Opcode.OP_ENDIF).toString() && new Opcode(opCodes[15]).toString() === new Opcode(Opcode.OP_EQUALVERIFY).toString() && new Opcode(opCodes[16]).toString() === new Opcode(Opcode.OP_CHECKSIG).toString();

  if (!isAtomicSwap) {
    console.error('contract is not an atomic swap script!');
    return;
  }

  var data = pops.filter(function (opcode) {
    return opcode.indexOf('0x') !== -1;
  });

  var secretHash = data[0];
  var recipientHash = data[1];
  var lockTime = data[2].replace('0x', '');
  var refundHash160 = data[3];

  return {
github AltCoinExchange / altcoin-atomic-trading-platform / legacy / btcatomicswap / src / contract / extract-atomic-swap-contract.js View on Github external
export const extractAtomicSwapContract = (ct) => {
  const contract = new Script(ct);
  const pops = contract.toString().split(' ');
  const opCodes = pops.filter(opcode => opcode.indexOf('0x') === -1);

  const isAtomicSwap =
    (new Opcode(opCodes[0]).toString() === new Opcode(Opcode.OP_IF).toString()) &&
    (new Opcode(opCodes[1]).toString() === new Opcode(Opcode.OP_RIPEMD160).toString()) &&
    (parseInt(opCodes[2]) === 20) &&
    (new Opcode(opCodes[3]).toString() === new Opcode(Opcode.OP_EQUALVERIFY).toString()) &&
    (new Opcode(opCodes[4]).toString() === new Opcode(Opcode.OP_DUP).toString()) &&
    (new Opcode(opCodes[5]).toString() === new Opcode(Opcode.OP_HASH160).toString()) &&
    (parseInt(opCodes[6]) === 20) &&
    (new Opcode(opCodes[7]).toString() === new Opcode(Opcode.OP_ELSE).toString()) &&
    (parseInt(opCodes[8])) &&
    (new Opcode(opCodes[9]).toString() === new Opcode(Opcode.OP_CHECKLOCKTIMEVERIFY).toString()) &&
    (new Opcode(opCodes[10]).toString() === new Opcode(Opcode.OP_DROP).toString()) &&
    (new Opcode(opCodes[11]).toString() === new Opcode(Opcode.OP_DUP).toString()) &&
    (new Opcode(opCodes[12]).toString() === new Opcode(Opcode.OP_HASH160).toString()) &&
    (parseInt(opCodes[13]) === 20) &&
    (new Opcode(opCodes[14]).toString() === new Opcode(Opcode.OP_ENDIF).toString()) &&
    (new Opcode(opCodes[15]).toString() === new Opcode(Opcode.OP_EQUALVERIFY).toString()) &&
    (new Opcode(opCodes[16]).toString() === new Opcode(Opcode.OP_CHECKSIG).toString());

  if (!isAtomicSwap) {
    console.error('contract is not an atomic swap script!')
    return;
  }

  const data = pops.filter(opcode => opcode.indexOf('0x') !== -1);
github AltCoinExchange / altcoin-atomic-trading-platform / wallet-ts / src / common / contract.ts View on Github external
private extractAtomicSwapContract(ct: any) {
        const contract = new Script(ct);
        const pops = contract.toString().split(' ');
        const opCodes = pops.filter(opcode => opcode.indexOf('0x') === -1);

        const isAtomicSwap =
          (new Opcode(opCodes[0]).toString() === new Opcode(Opcode.OP_IF).toString()) &&
          (new Opcode(opCodes[1]).toString() === new Opcode(Opcode.OP_RIPEMD160).toString()) &&
          (parseInt(opCodes[2]) === 20) &&
          (new Opcode(opCodes[3]).toString() === new Opcode(Opcode.OP_EQUALVERIFY).toString()) &&
          (new Opcode(opCodes[4]).toString() === new Opcode(Opcode.OP_DUP).toString()) &&
          (new Opcode(opCodes[5]).toString() === new Opcode(Opcode.OP_HASH160).toString()) &&
          (parseInt(opCodes[6]) === 20) &&
          (new Opcode(opCodes[7]).toString() === new Opcode(Opcode.OP_ELSE).toString()) &&
          (parseInt(opCodes[8])) &&
          (new Opcode(opCodes[9]).toString() === new Opcode(Opcode.OP_CHECKLOCKTIMEVERIFY).toString()) &&
          (new Opcode(opCodes[10]).toString() === new Opcode(Opcode.OP_DROP).toString()) &&
          (new Opcode(opCodes[11]).toString() === new Opcode(Opcode.OP_DUP).toString()) &&
          (new Opcode(opCodes[12]).toString() === new Opcode(Opcode.OP_HASH160).toString()) &&
          (parseInt(opCodes[13]) === 20) &&
          (new Opcode(opCodes[14]).toString() === new Opcode(Opcode.OP_ENDIF).toString()) &&
          (new Opcode(opCodes[15]).toString() === new Opcode(Opcode.OP_EQUALVERIFY).toString()) &&
          (new Opcode(opCodes[16]).toString() === new Opcode(Opcode.OP_CHECKSIG).toString());

        if (!isAtomicSwap) {
            console.error('contract is not an atomic swap script!');
            return;
        }

        const data = pops.filter(opcode => opcode.indexOf('0x') !== -1);
github AltCoinExchange / altcoin-atomic-trading-platform / legacy / btcatomicswap / src / contract / atomic-swap-contract.js View on Github external
number = 0xFFFFFFFF + number + 1;
    }

    return number.toString(16).toUpperCase();
  };

  const script = new Script();
  script.add(Opcode.OP_IF);
  script.add(Opcode.OP_RIPEMD160);
  script.add(new Buffer(secretHash, 'hex'));
  script.add(Opcode.OP_EQUALVERIFY);
  script.add(Opcode.OP_DUP);
  script.add(Opcode.OP_HASH160);
  script.add(new Buffer(pkhThem, 'hex'));

  script.add(Opcode.OP_ELSE);
  script.add(new Buffer(decimalToHexString(conv(lockTime)[0]), 'hex'));
  script.add('OP_CHECKLOCKTIMEVERIFY');
  script.add(Opcode.OP_DROP);
  script.add(Opcode.OP_DUP);
  script.add(Opcode.OP_HASH160);
  script.add(new Buffer(refundAddress, 'hex'));

  script.add(Opcode.OP_ENDIF);

  script.add(Opcode.OP_EQUALVERIFY);
  script.add(Opcode.OP_CHECKSIG);
  return script;
};
github AltCoinExchange / altcoin-atomic-trading-platform / btcatomicswap / src / contract / atomic-swap-contract.js View on Github external
export const atomicSwapContract = (refundAddress, pkhThem, lockTime, secretHash) => {
  const script = new Script();
  script.add(Opcode.OP_IF);
  script.add(Opcode.OP_RIPEMD160);
  script.add(Buffer.from(secretHash));
  script.add(Opcode.OP_EQUALVERIFY);
  script.add(Opcode.OP_DUP);
  script.add(Opcode.OP_HASH160);
  script.add(Buffer.from(pkhThem));

  script.add(Opcode.OP_ELSE);
  script.add(Buffer.from(String(lockTime)));
  script.add('OP_CHECKLOCKTIMEVERIFY');
  script.add(Opcode.OP_DROP);
  script.add(Opcode.OP_DUP);
  script.add(Opcode.OP_HASH160);
  script.add(Buffer.from(refundAddress));

  script.add(Opcode.OP_ENDIF);

  script.add(Opcode.OP_EQUALVERIFY);
  script.add(Opcode.OP_CHECKSIG);
  return script;
};
github AltCoinExchange / altcoin-atomic-trading-platform / wallet-ts / src / common / contract.ts View on Github external
number = 0xFFFFFFFF + number + 1;
            }

            return number.toString(16).toUpperCase();
        };

        const script = new Script();
        script.add(Opcode.OP_IF);
            script.add(Opcode.OP_RIPEMD160);
            script.add(new Buffer(secretHash, 'hex'));
            script.add(Opcode.OP_EQUALVERIFY);
            script.add(Opcode.OP_DUP);
            script.add(Opcode.OP_HASH160);
            script.add(new Buffer(pkhThem, 'hex'));

        script.add(Opcode.OP_ELSE);
            script.add(new Buffer(decimalToHexString(conv(lockTime)[0]), 'hex'));
            script.add('OP_CHECKLOCKTIMEVERIFY');
            script.add(Opcode.OP_DROP);
            script.add(Opcode.OP_DUP);
            script.add(Opcode.OP_HASH160);
            script.add(new Buffer(refundAddress, 'hex'));

        script.add(Opcode.OP_ENDIF);

        script.add(Opcode.OP_EQUALVERIFY);
        script.add(Opcode.OP_CHECKSIG);
        return script;
    }
}
github AltCoinExchange / altcoin-atomic-trading-platform / btcatomicswap / dist / contract / atomic-swap-contract.js View on Github external
number = 0xFFFFFFFF + number + 1;
    }

    return number.toString(16).toUpperCase();
  };

  var script = new Script();
  script.add(Opcode.OP_IF);
  script.add(Opcode.OP_RIPEMD160);
  script.add(new Buffer(secretHash, 'hex'));
  script.add(Opcode.OP_EQUALVERIFY);
  script.add(Opcode.OP_DUP);
  script.add(Opcode.OP_HASH160);
  script.add(new Buffer(pkhThem, 'hex'));

  script.add(Opcode.OP_ELSE);
  script.add(new Buffer(decimalToHexString(conv(lockTime)[0]), 'hex'));
  script.add('OP_CHECKLOCKTIMEVERIFY');
  script.add(Opcode.OP_DROP);
  script.add(Opcode.OP_DUP);
  script.add(Opcode.OP_HASH160);
  script.add(new Buffer(refundAddress, 'hex'));

  script.add(Opcode.OP_ENDIF);

  script.add(Opcode.OP_EQUALVERIFY);
  script.add(Opcode.OP_CHECKSIG);
  return script;
};
github AltCoinExchange / altcoin-atomic-trading-platform / btcatomicswap / dist / atomic-swap-contract.js View on Github external
var atomicSwapContract = exports.atomicSwapContract = function atomicSwapContract(refundAddress, pkhThem, lockTime, secretHash) {
  var script = new Script();
  script.add(Opcode.OP_IF);
  script.add(Opcode.OP_RIPEMD160);
  script.add(new Buffer(secretHash, 'hex'));
  script.add(Opcode.OP_EQUALVERIFY);
  script.add(Opcode.OP_DUP);
  script.add(Opcode.OP_HASH160);
  script.add(new Buffer(pkhThem, 'hex'));

  script.add(Opcode.OP_ELSE);
  script.add(new Buffer(String(lockTime), 'hex'));
  script.add('OP_CHECKLOCKTIMEVERIFY');
  script.add(Opcode.OP_DROP);
  script.add(Opcode.OP_DUP);
  script.add(Opcode.OP_HASH160);
  script.add(new Buffer(refundAddress, 'hex'));

  script.add(Opcode.OP_ENDIF);

  script.add(Opcode.OP_EQUALVERIFY);
  script.add(Opcode.OP_CHECKSIG);
  return script;
};