How to use the bitcore.Transaction.Output 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 / wallet-ts / src / common / contract.ts View on Github external
return;
        }

        // TODO:  "getrawchangeaddres" WTF?
        // const addr = new Address(await getChangeAddress())
        const addr = 'mnopGXXKQdt6mXnwHeRcdWNsaksoqKcvwZ';
        const outScript = Script.buildPublicKeyHashOut(addr);


        // https://bitcoin.org/en/developer-examples#offline-signing
        const refundTx = new Transaction();
        const lockTime = new BufferReader(pushes.lockTime).readUInt32LE();
        refundTx.lockUntilDate(lockTime);

        // TODO: "refund output value of %v is dust"
        let output = Transaction.Output({
            script: outScript,
            satoshis: 0,
        });

        refundTx.addOutput(output);
        const feePerKb = await this.getFeePerKb();
        console.log('Fee per kb:', feePerKb);
        const redeemSerializeSize = Util.EstimateRefundSerializeSize(contract, refundTx.outputs);
        const refundFee = Util.FeeForSerializeSize(feePerKb, redeemSerializeSize) * 100000000;

        const amount = ctTx.outputs[ctTxOutIdx].satoshis - refundFee;

        output = Transaction.Output({
            script: outScript,
            satoshis: amount,
        });
github AltCoinExchange / altcoin-atomic-trading-platform / wallet-ts / src / common / contract.ts View on Github external
const themAddr = new Address(them);

        const contract = this.atomicSwapContract(
          refundAddr.toJSON().hash,
          themAddr.toJSON().hash,
          lockTime,
          secretHash,
        );

        const contractP2SH = Util.NewAddressScriptHash(contract.toHex(), this.configuration.network);
        const contractP2SHPkScript = Script.buildScriptHashOut(contractP2SH);

        const contractTx = new Transaction();
        const value = Math.round(amount * 100000000);
        // console.log(value);
        const output = Transaction.Output({
            script: contractP2SHPkScript,
            satoshis: value,
        });
        contractTx.addOutput(output);

        const transaction: BtcTransaction = new BtcTransaction(this.configuration);
        await transaction.fundTransaction(refundAddr, contractTx);

        // SIGN TRANSACTION
        const signatures = contractTx.getSignatures(privateKey);
        for (const signature of signatures) {
            contractTx.applySignature(signature);
        }

        const contractTxHash = contractTx.hash;
        const contractFee = contractTx._getInputAmount() - contractTx._getOutputAmount();
github AltCoinExchange / altcoin-atomic-trading-platform / legacy / btcatomicswap / dist / contract / build-contract.js View on Github external
return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            PK = PrivateKey.fromWIF(privateKey);
            refundAddr = PK.toPublicKey().toAddress(_config.configuration.network);
            themAddr = new Address(them);
            contract = (0, _atomicSwapContract.atomicSwapContract)(refundAddr.toJSON().hash, themAddr.toJSON().hash, lockTime, secretHash);
            contractP2SH = _addressUtil.AddressUtil.NewAddressScriptHash(contract.toHex(), _config.configuration.network);
            contractP2SHPkScript = Script.buildScriptHashOut(contractP2SH);
            contractTx = new Transaction();
            value = Math.round(amount * 100000000);
            // console.log(value);

            output = Transaction.Output({
              script: contractP2SHPkScript,
              satoshis: value
            });

            contractTx.addOutput(output);

            _context.next = 12;
            return (0, _fundTransaction.fundTransaction)(refundAddr, contractTx);

          case 12:

            //SIGN TRANSACTION
            signitures = contractTx.getSignatures(privateKey);
            _iteratorNormalCompletion = true;
            _didIteratorError = false;
            _iteratorError = undefined;
github AltCoinExchange / altcoin-atomic-trading-platform / wallet-ts / src / common / contract.ts View on Github external
// TODO: "refund output value of %v is dust"
        let output = Transaction.Output({
            script: outScript,
            satoshis: 0,
        });

        refundTx.addOutput(output);
        const feePerKb = await this.getFeePerKb();
        console.log('Fee per kb:', feePerKb);
        const redeemSerializeSize = Util.EstimateRefundSerializeSize(contract, refundTx.outputs);
        const refundFee = Util.FeeForSerializeSize(feePerKb, redeemSerializeSize) * 100000000;

        const amount = ctTx.outputs[ctTxOutIdx].satoshis - refundFee;

        output = Transaction.Output({
            script: outScript,
            satoshis: amount,
        });

        refundTx.removeOutput(0);
        refundTx.addOutput(output);

        const input = Transaction.Input({
            prevTxId: ctTx.id,
            outputIndex: ctTxOutIdx,
            sequenceNumber: 0,
            script: new Script(ctTx.outputs[ctTxOutIdx].script),
        });

        refundTx.uncheckedAddInput(input);
github AltCoinExchange / altcoin-atomic-trading-platform / legacy / btcatomicswap / src / common / build-refund.js View on Github external
}

  // TODO:  "getrawchangeaddres" + erroe
  // const addr = new Address(await getChangeAddress())
  const addr = "mnopGXXKQdt6mXnwHeRcdWNsaksoqKcvwZ"

  const outScript = Script.buildPublicKeyHashOut(addr)


  // https://bitcoin.org/en/developer-examples#offline-signing
  const refundTx = new Transaction()
  const lockTime = new BufferReader(pushes.lockTime).readUInt32LE()
  refundTx.lockUntilDate(lockTime)

  // TODO: "refund output value of %v is dust"
  let output = Transaction.Output({
    script: outScript,
    satoshis: 0
  })

  refundTx.addOutput(output)
  console.log('aaaa');
  const feePerKb = await getFeePerKb()
  console.log('bbbb');
  const redeemSerializeSize = estimateRefundSerializeSize(contract, refundTx.outputs)

  const refundFee = feeForSerializeSize(feePerKb, redeemSerializeSize) * 100000000

  const amount = ctTx.outputs[ctTxOutIdx].satoshis - refundFee

  output = Transaction.Output({
    script: outScript,
github AltCoinExchange / altcoin-atomic-trading-platform / wallet-ts / src / common / contract.ts View on Github external
// TODO: "redeem output value of %v is dust"
        let output = Transaction.Output({
            script: outScript,
            satoshis: 0,
        });

        redeemTx.addOutput(output);

        const feePerKb = await this.getFeePerKb();
        const redeemSerializeSize = Util.EstimateRedeemSerializeSize(contract, redeemTx.outputs);

        const fee = Util.FeeForSerializeSize(feePerKb, redeemSerializeSize) * 100000000;

        const amount = ctTx.outputs[ctTxOutIdx].satoshis - fee;

        output = Transaction.Output({
            script: outScript,
            satoshis: amount
        });

        redeemTx.removeOutput(0);
        redeemTx.addOutput(output);

        const input = Transaction.Input({
            prevTxId: ctTx.id,
            outputIndex: ctTxOutIdx,
            script: new Script(ctTx.outputs[ctTxOutIdx].script)
        });

        redeemTx.uncheckedAddInput(input);
github AltCoinExchange / altcoin-atomic-trading-platform / legacy / btcatomicswap / src / redeem.js View on Github external
// TODO: "redeem output value of %v is dust"
  let output = Transaction.Output({
    script: outScript,
    satoshis: 0,
  })

  redeemTx.addOutput(output)

  const feePerKb = await getFeePerKb()
  const redeemSerializeSize = estimateRedeemSerializeSize(contract, redeemTx.outputs)

  const fee = feeForSerializeSize(feePerKb, redeemSerializeSize) * 100000000

  const amount = ctTx.outputs[ctTxOutIdx].satoshis - fee

  output = Transaction.Output({
    script: outScript,
    satoshis: amount
  })

  redeemTx.removeOutput(0)
  redeemTx.addOutput(output)


  const input = Transaction.Input({
    prevTxId: ctTx.id,
    outputIndex: ctTxOutIdx,
    script: new Script(ctTx.outputs[ctTxOutIdx].script),
  })

  redeemTx.uncheckedAddInput(input)
github AltCoinExchange / altcoin-atomic-trading-platform / legacy / btcatomicswap / src / common / build-refund.js View on Github external
let output = Transaction.Output({
    script: outScript,
    satoshis: 0
  })

  refundTx.addOutput(output)
  console.log('aaaa');
  const feePerKb = await getFeePerKb()
  console.log('bbbb');
  const redeemSerializeSize = estimateRefundSerializeSize(contract, refundTx.outputs)

  const refundFee = feeForSerializeSize(feePerKb, redeemSerializeSize) * 100000000

  const amount = ctTx.outputs[ctTxOutIdx].satoshis - refundFee

  output = Transaction.Output({
    script: outScript,
    satoshis: amount
  })

  refundTx.removeOutput(0)
  refundTx.addOutput(output)


  const input = Transaction.Input({
    prevTxId: ctTx.id,
    outputIndex: ctTxOutIdx,
    sequenceNumber: 0,
    script: new Script(ctTx.outputs[ctTxOutIdx].script)
  })

  refundTx.uncheckedAddInput(input)
github AltCoinExchange / altcoin-atomic-trading-platform / btcatomicswap / dist / build-contract.js View on Github external
console.log('refundAddrH', refundAddrH);
  console.log('hash160(refundAddrH)', (0, _secretHash.hash160)(refundAddrH));
  console.log('them', them);
  console.log('hash160(them)', (0, _secretHash.hash160)(them));

  try {
    var contract = (0, _atomicSwapContract.atomicSwapContract)((0, _secretHash.hash160)(refundAddrH), (0, _secretHash.hash160)(them), lockTime, secretHash);
    console.log('** contract    ', contract.toHex());

    var contractP2SH = contract.toScriptHashOut();

    var feePerKb = await (0, _feePerKb.getFeePerKb)();
    console.log('** feePerKb    ', feePerKb);

    var transaction = new Transaction().fee(+amount);
    var output = Transaction.Output({
      script: contractP2SH,
      satoshis: amount * 100000000
    });
    transaction.addOutput(output);

    try {
      var fundRawTx = await (0, _rawRequest.fundRawTransaction)(transaction.toString(), feePerKb);
      var signedTx = await (0, _signTransaction.signTransaction)(fundRawTx.data.result.hex);
      console.log('** signedTx    ', signedTx.hex);
      return signedTx.hex;
    } catch (fundErr) {
      if (fundErr && fundErr.response) {
        console.log('fundErr', fundErr.response.data, 'fundErr');
      } else {
        console.log('fundErr', fundErr, 'fundErr');
      }