Browse Source

add output amount

activeAddress
Matias Alejo Garcia 10 years ago
parent
commit
3b8873b7a8
  1. 2
      README.md
  2. 2
      bit-wallet/bit-balance
  3. 19
      bit-wallet/bit-status
  4. 35
      bit-wallet/cli-utils.js
  5. 11
      lib/server.js

2
README.md

@ -37,6 +37,8 @@ A Multisig HD Wallet Service, with minimun server trust.
# Spend coins. Amount can be specified in btc, bit or sat (default)
./bit send 1xxxxx 100bit "100 bits to mother"
# You can use 100bit or 0.00001btc or 10000sat. (Set up BIT_UNIT to btc/sat/bit so select output unit).
# List pending TX Proposals
./bit status

2
bit-wallet/bit-balance

@ -13,5 +13,5 @@ var client = utils.getClient(program);
client.getBalance(function(err, x) {
utils.die(err);
console.log('* Wallet balance', x);
console.log('* Wallet balance %s (Locked %s)', utils.renderAmount(x.totalAmount), utils.renderAmount(x.lockedAmount) );
});

19
bit-wallet/bit-status

@ -22,20 +22,7 @@ client.getStatus(function(err, res) {
console.log('* Copayers:', _.pluck(x.copayers,'name').join(', '));
var x = res.balance;
console.log('* Balance %dSAT (Locked: %dSAT)', x.totalAmount, x.lockedAmount);
if (!_.isEmpty(res.pendingTxps)) {
console.log("* TX Proposals:")
_.each(res.pendingTxps, function(x) {
missingSignatures = x.requiredSignatures - _.filter(_.values(x.actions), function (a) { return a.type == 'accept'; }).length;
console.log("\t%s [\"%s\" by %s] %dSAT => %s", utils.shortID(x.id), x.message, x.creatorName, x.amount, x.toAddress);
if (!_.isEmpty(x.actions)) {
console.log('\t\tActions: ', _.map(x.actions, function(a) {
return a.copayerName + ' ' + (a.type == 'accept' ? '✓' : '✗') + (a.comment ? ' (' + a.comment + ')' : '');
}).join('. '));
}
console.log('\t\tMissing signatures: ' + missingSignatures);
});
}
console.log('* Balance %s (Locked: %s)', utils.renderAmount(x.totalAmount), utils.renderAmount(x.lockedAmount));
utils.renderTxProposals(res.pendingTxps);
});

35
bit-wallet/cli-utils.js

@ -99,4 +99,39 @@ Utils.configureCommander = function(program) {
return program;
};
Utils.renderAmount = function(amount) {
var unit = process.env.BIT_UNIT || 'bit';
if (unit === 'SAT') {
// Do nothing
} else if (process.env.BIT_UNIT === 'btc') {
amount = amount / 1e8;
} else {
amount = amount / 100;
}
amount = (parseFloat(amount.toPrecision(12)));
return amount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + ' ' + unit;
};
Utils.renderTxProposals = function(txps) {
if (_.isEmpty(txps))
return;
console.log("* TX Proposals:")
_.each(txps, function(x) {
var missingSignatures = x.requiredSignatures - _.filter(_.values(x.actions), function(a) {
return a.type == 'accept';
}).length;
console.log("\t%s [\"%s\" by %s] %s => %s", Utils.shortID(x.id), x.message, x.creatorName, Utils.renderAmount(x.amount), x.toAddress);
if (!_.isEmpty(x.actions)) {
console.log('\t\tActions: ', _.map(x.actions, function(a) {
return a.copayerName + ' ' + (a.type == 'accept' ? '✓' : '✗') + (a.comment ? ' (' + a.comment + ')' : '');
}).join('. '));
}
console.log('\t\tMissing signatures: ' + missingSignatures);
});
};
module.exports = Utils;

11
lib/server.js

@ -363,7 +363,7 @@ WalletService.prototype._getUtxos = function(cb) {
bc.getUnspentUtxos(addressStrs, function(err, inutxos) {
if (err) return cb(err);
var utxos = _.map(inutxos, function(i) {
return _.pick(i, ['txid', 'vout', 'address', 'scriptPubKey', 'amount', 'satoshis']);
return _.pick(i.toObject(), ['txid', 'vout', 'address', 'scriptPubKey', 'amount', 'satoshis']);
});
self.getPendingTxs({}, function(err, txps) {
if (err) return cb(err);
@ -432,22 +432,28 @@ WalletService.prototype.getBalance = function(opts, cb) {
WalletService.prototype._selectUtxos = function(txp, utxos) {
console.log('[server.js.434:utxos:]',utxos); //TODO
var i = 0;
var total = 0;
var selected = [];
var inputs = _.sortBy(utxos, 'amount');
console.log('[server.js.438:inputs:]',inputs); //TODO
while (i < inputs.length) {
selected.push(inputs[i]);
total += inputs[i].satoshis;
console.log('[server.js.443]'); //TODO
if (total >= txp.amount + Bitcore.Transaction.FEE_PER_KB) {
try {
// Check if there are enough fees
txp.inputs = selected;
console.log('[server.js.449]'); //TODO
var raw = txp.getRawTx();
return;
} catch (ex) {
console.log('[server.js.453:ex:]',ex); //TODO
if (ex.name != 'bitcore.ErrorTransactionFeeError') {
throw ex.message;
}
@ -498,6 +504,7 @@ WalletService.prototype.createTx = function(opts, cb) {
return cb(new ClientError('DUSTAMOUNT', 'Amount below dust threshold'));
self._getUtxos(function(err, utxos) {
console.log('[server.js.506:utxos:]',utxos); //TODO
if (err) return cb(err);
var changeAddress = wallet.createAddress(true);
@ -520,6 +527,7 @@ WalletService.prototype.createTx = function(opts, cb) {
try {
self._selectUtxos(txp, utxos);
} catch (ex) {
console.log('[server.js.523:ex:]',ex); //TODO
return cb(new ClientError(ex));
}
@ -528,6 +536,7 @@ WalletService.prototype.createTx = function(opts, cb) {
txp.inputPaths = _.pluck(txp.inputs, 'path');
console.log('[server.js.530]'); //TODO
self.storage.storeAddressAndWallet(wallet, changeAddress, function(err) {
if (err) return cb(err);

Loading…
Cancel
Save