Browse Source

enable btc, send vin/vout final check

v0.25
pbca26 7 years ago
parent
commit
26ce131c9e
  1. 18
      routes/electrumjs/electrumServers.js
  2. 36
      routes/shepherd/electrum/createtx.js
  3. 2
      routes/shepherd/electrum/listunspent.js
  4. 4
      version
  5. 2
      version_build

18
routes/electrumjs/electrumServers.js

@ -323,16 +323,22 @@ let electrumServers = {
'136.243.45.140:50041'
],
},
/*btc: {
address: 'electrum1.cipig.net',
port: 10000,
btc: {
address: 'e-x.not.fyi',
port: 50001,
proto: 'tcp',
abbr: 'BTC',
serverList: [
'electrum1.cipig.net:10000',
'electrum2.cipig.net:10000'
'mooo.not.fyi:50011',
'e-x.not.fyi:50001',
'vps.hsmiths.com:50001',
'us.electrum.be:50001',
'electrumx.bot.nu:50001',
'btc.asis.io:50001',
'electrum.backplanedns.org:50001',
'electrum.festivaldelhumor.org:50001'
],
},*/
},
btg: {
address: '173.212.225.176',
port: 10052,

36
routes/shepherd/electrum/createtx.js

@ -203,6 +203,7 @@ module.exports = (shepherd) => {
const changeAddress = req.query.change;
const push = req.query.push;
const opreturn = req.query.opreturn;
const btcFee = req.query.btcfee ? Number(req.query.btcfee) : null;
let fee = shepherd.electrumServers[network].txfee;
let value = Number(req.query.value);
let wif = req.query.wif;
@ -215,6 +216,10 @@ module.exports = (shepherd) => {
wif = shepherd.elections.priv;
}
if (btcFee) {
fee = 0;
}
shepherd.log('electrum createrawtx =>', true);
ecl.connect();
@ -274,10 +279,15 @@ module.exports = (shepherd) => {
// default coin selection algo blackjack with fallback to accumulative
// make a first run, calc approx tx fee
// if ins and outs are empty reduce max spend by txfee
const firstRun = shepherd.coinSelect(utxoListFormatted, targets, 0);
const firstRun = shepherd.coinSelect(utxoListFormatted, targets, btcFee ? btcFee : 0);
let inputs = firstRun.inputs;
let outputs = firstRun.outputs;
if (btcFee) {
shepherd.log(`btc fee per byte ${btcFee}`, true);
fee = firstRun.fee;
}
shepherd.log('coinselect res =>', true);
shepherd.log('coinselect inputs =>', true);
shepherd.log(inputs, true);
@ -295,7 +305,7 @@ module.exports = (shepherd) => {
const secondRun = shepherd.coinSelect(utxoListFormatted, targets, 0);
inputs = secondRun.inputs;
outputs = secondRun.outputs;
fee = secondRun.fee;
fee = fee ? fee : secondRun.fee;
shepherd.log('second run coinselect inputs =>', true);
shepherd.log(inputs, true);
@ -309,10 +319,21 @@ module.exports = (shepherd) => {
if (outputs &&
outputs.length === 2) {
_change = outputs[1].value;
_change = outputs[1].value - fee;
}
if (!btcFee &&
_change === 0) {
outputs[0].value = outputs[0].value - fee;
}
if (btcFee) {
value = outputs[0].value;
} else {
if (_change > 0) {
value = outputs[0].value - fee;
}
}
shepherd.log('adjusted outputs, value - default fee =>', true);
shepherd.log(outputs, true);
@ -361,7 +382,7 @@ module.exports = (shepherd) => {
shepherd.log(`estimated fee overhead ${_feeOverhead}`, true);
shepherd.log(`current change amount ${_change} (${_change * 0.00000001}), boosted change amount ${_change + (totalInterest - _feeOverhead)} (${(_change + (totalInterest - _feeOverhead)) * 0.00000001})`, true);
if (_maxSpend === value) {
if (_maxSpend - fee === value) {
_change = totalInterest - _change - _feeOverhead;
if (outputAddress === changeAddress) {
@ -394,6 +415,13 @@ module.exports = (shepherd) => {
shepherd.log(`vin sum ${vinSum} (${vinSum * 0.00000001})`, true);
shepherd.log(`estimatedFee ${_estimatedFee} (${_estimatedFee * 0.00000001})`, true);
// double check no extra fee is applied
shepherd.log(`vin - vout ${vinSum - value - _change}`);
if ((vinSum - value - _change) > fee) {
_change += fee;
shepherd.log(`double fee, increase change by ${fee}`);
}
let _rawtx;

2
routes/shepherd/electrum/listunspent.js

@ -1,3 +1,5 @@
// TODO: watchonly spendable switch
module.exports = (shepherd) => {
shepherd.listunspent = (ecl, address, network, full, verify) => {
let _atLeastOneDecodeTxFailed = false;

4
version

@ -1,3 +1,3 @@
version=0.2.0.28a
type=a-beta
version=0.2.0.28b
type=b-beta
minversion=0.2.0.28

2
version_build

@ -1 +1 @@
0.2.0.28a-beta
0.2.0.28b-beta
Loading…
Cancel
Save