Giter Club home page Giter Club logo

Comments (6)

dcousens avatar dcousens commented on July 18, 2024

Could you post your actual code?

from coinselect.

askz avatar askz commented on July 18, 2024

the utxos used are consumed from a coind listunspent command
EDIT: I think the problem is from the fee calculation. Since the coin we are using there got a fixed fee per tx, whatever the size, no feeRate/kb.

const getNewInputsOutputs = (outputsSenderAddress, newAddress, estimatedFeeRate, coin, wallet) => {
  let totalAmount = 0;
  outputsSenderAddress.forEach(output => {
    if (output.amount > 0) {
      totalAmount += sb.toSatoshi(output.amount);
    }
  });

  const targets = [ {
      address: newAddress,
      // value: totalAmount - 49000,
    }
  ];

  if (coin.fee != null) {
    feeRate = 0;
  }

  const utxos = _.map(outputsSenderAddress, (output) => {
    return {
      txId: output.txid,
      vout: output.vout,
      value: sb.toSatoshi(output.amount),
    };
  })

  console.log("Utxos => ", utxos);
  console.log("Targets => ", targets);
  console.log("EstimateFEE => ", estimatedFeeRate);

  let { inputs, outputs, fee } = coinSelect(utxos, targets, estimatedFeeRate);
  console.log("FEE => ", fee);
  console.log("Inputs => ", inputs);
  console.log("outputs => ", outputs)

  if (!inputs || !outputs) {
    return null;
  }

  let finalFee = fee;
  outputs.forEach(output => {
    if (output.address == null) {
      if (coin.fee != null) {
        finalFee = coin.fee;
        output.value -= coin.fee;
      }
      // output.address = wallet.address;
    }
  });

  console.log("Outputs => ", outputs);
  return {
    inputs,
    outputs,
    fee: finalFee
  };
};

from coinselect.

askz avatar askz commented on July 18, 2024

what do you think @dcousens ?

from coinselect.

dcousens avatar dcousens commented on July 18, 2024

feeRate or estimatedFeeRate?

from coinselect.

dcousens avatar dcousens commented on July 18, 2024

Also, if you want a fixed fee, you could set the feeRate to 0 and add a faux output { value: X } that represents your fixed fee.

from coinselect.

dcousens avatar dcousens commented on July 18, 2024

As an example, I can't reproduce this yet.

let coinselect = require('coinselect/split')
let inputs = [
  {
    txId: 'a',
    value: 10000000
  },
  {
    txId: 'b',
    value: 10000000
  },
  {
    txId: 'c',
    value: 10000000
  }
]

let outputs = [
  {
    address: 'me'
  }
]

console.log(coinselect(inputs, outputs, 0))
{ inputs:
   [ { txId: 'a', value: 10000000 },
     { txId: 'b', value: 10000000 },
     { txId: 'c', value: 10000000 } ],
  outputs: [ { address: 'me', value: 30000000 } ],
  fee: 0 }

from coinselect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.