Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions packages/bitcore-wallet-client/lib/paypro.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var $ = require('preconditions').singleton();
const URL = require('url');
var Bitcore = require('bitcore-lib');
var Bitcore_ = {
btc: Bitcore,
Expand All @@ -10,14 +11,23 @@ var PayPro = {};

PayPro._nodeRequest = function(opts, cb) {
opts.agent = false;

var http = opts.httpNode || (opts.proto === 'http' ? require("http") : require("https"));

var fn = opts.method == 'POST' ? 'post' : 'get';
const url = URL.parse(opts.url);
let ropts = {
headers: opts.headers,
method: opts.method || 'GET',
hostname: url.host,
port:url.port || (opts.proto === 'http' ? 80 : 443),
path:url.path,
protocol: url.protocol,
agent: false,
};

http[fn](opts, function(res) {
var req = http.request(ropts, function(res) {
var data = []; // List of Buffer objects


if (res.statusCode != 200)
return cb(new Error('HTTP Request Error: ' + res.statusCode + ' ' + res.statusMessage + ' ' + ( data ? data : '' ) ));

Expand All @@ -29,6 +39,12 @@ PayPro._nodeRequest = function(opts, cb) {
return cb(null, data);
});
});

req.on("error", function(error) {
return cb(error);
});

req.end();
};

PayPro._browserRequest = function(opts, cb) {
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcore-wallet-client/test/paypro.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('paypro', function() {
};

httpNode = {};
httpNode.get = function(opts, cb) {
httpNode.request = function(opts, cb) {
var res = {};
res.statusCode = httpNode.error || 200;
if (httpNode.error == 404)
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcore-wallet-service/lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ Storage.prototype.getTxHistoryCacheV8 = function(walletId, skip, limit, cb) {
if (lastPosition <= 0)
return cb(null, []);

console.log('[storage.js.750:first/lastPosition:]',firstPosition + '/'+lastPosition); //TODO
//console.log('[storage.js.750:first/lastPosition:]',firstPosition + '/'+lastPosition); //TODO

self.db.collection(collections.CACHE).find({
walletId: walletId,
Expand Down
3 changes: 2 additions & 1 deletion packages/bitcore-wallet-service/scripts/v8tool
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Client = require('../lib/blockchainexplorers/v8/client.js');
const coin = 'BCH';
const network = 'mainnet';
const authKey = process.argv[2];
const path = process.argv[3] || 'addresses';

if (!authKey)
throw "provide authKey"
Expand All @@ -32,7 +33,7 @@ let client = new Client({
});


const url = `${baseUrl}/wallet/${pubKey}/addresses`;
const url = `${baseUrl}/wallet/${pubKey}/${path}`;
const signature = client.sign({ method: 'GET', url });
const payload = {};

Expand Down
24 changes: 16 additions & 8 deletions packages/bitcore-wallet/bin/cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var _ = require('lodash');
var url = require('url');
var read = require('read')
var log = require('npmlog');
var Client = require('../../bitcore-wallet-client');
var Client = require('bitcore-wallet-client');
var FileStorage = require('./filestorage');
var sjcl = require('sjcl');

Expand Down Expand Up @@ -93,16 +93,18 @@ Utils.getClient = function(args, opts, cb) {
opts = opts || {};

var filename = args.file || process.env['WALLET_FILE'] || process.env['HOME'] + '/.wallet.dat';
var host = args.host || process.env['BWS_HOST'] || 'https://bws.bitpay.com/bws/api';
var host = args.host || process.env['BWS_HOST'] || 'https://bws.bitpay.com/';

var storage = new FileStorage({
filename: filename,
});

var client = new Client({
baseUrl: host,
baseUrl: url.resolve(host, '/bws/api'),
verbose: args.verbose,
supportStaffWalletId: opts.walletId,
timeout: 20 * 60 * 1000,
//timeout: 1000,
});

storage.load(function(err, walletData) {
Expand Down Expand Up @@ -213,7 +215,7 @@ Utils.findOneTxProposal = function(txps, id) {
if (matches.length > 1) {
console.log('More than one TX Proposals match:' + id);
Utils.renderTxProposals(txps);
program.exit(1);
process.exit(1);
}

return matches[0];
Expand All @@ -232,17 +234,23 @@ Utils.parseAmount = function(text) {
var regex = '^(\\d*(\\.\\d{0,8})?)\\s*(' + _.keys(Utils.UNITS2).join('|') + ')?$';
var match = new RegExp(regex, 'i').exec(text.trim());

if (!match || match.length === 0) throw new Error('Invalid amount');
if (!match || match.length === 0) {
Utils.die('Invalid amount: ' + text);
}

var amount = parseFloat(match[1]);
if (!_.isNumber(amount) || _.isNaN(amount)) throw new Error('Invalid amount');

var unit = (match[3] || 'sat').toLowerCase();
var rate = Utils.UNITS2[unit];
if (!rate) throw new Error('Invalid unit')
if (!rate) {
Utils.die('Invalid unit: ' + unit);
}

var amountSat = parseFloat((amount * rate).toPrecision(12));
if (amountSat != Math.round(amountSat)) throw new Error('Invalid amount');
if (amountSat != Math.round(amountSat)) {
Utils.die('Invalid amount: ' + amount + ' ' + unit);
}

return amountSat;
};
Expand All @@ -251,7 +259,7 @@ Utils.configureCommander = function(program) {
program
.version('0.0.1')
.option('-f, --file <filename>', 'Wallet file')
.option('-h, --host <host>', 'Bitcore Wallet Service URL (eg: http://localhost:3000/bws/api')
.option('-h, --host <host>', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
.option('-v, --verbose', 'be verbose')

return program;
Expand Down
6 changes: 6 additions & 0 deletions packages/bitcore-wallet/bin/wallet-address
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node

var program = require('commander');
var bitcoreCash = require('bitcore-wallet-client').BitcoreCash;
var utils = require('./cli-utils');
program = utils.configureCommander(program);

Expand All @@ -13,6 +14,11 @@ utils.getClient(program, {
}, function(client) {
client.createAddress({}, function(err, x) {
utils.die(err);

if (client.credentials.coin == 'bch') {
x.address = (new bitcoreCash.Address(x.address)).toCashAddress();
}

console.log('* New Address %s ', x.address);
});
});
6 changes: 6 additions & 0 deletions packages/bitcore-wallet/bin/wallet-addresses
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var _ = require('lodash');
var program = require('commander');
var bitcoreCash = require('bitcore-wallet-client').BitcoreCash;
var utils = require('./cli-utils');
program = utils.configureCommander(program);

Expand All @@ -19,6 +20,11 @@ utils.getClient(program, { mustExist: true }, function (client) {
if (x.length > 0) {
console.log('* Addresses:');
_.each(x, function(a) {
if (client.credentials.coin == 'bch') {
a.address = (new bitcoreCash.Address(a.address)).toCashAddress();
}


console.log(' ', a.address);
});
} else {
Expand Down
17 changes: 5 additions & 12 deletions packages/bitcore-wallet/bin/wallet-balance
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,24 @@ var utils = require('./cli-utils');
program = utils.configureCommander(program);
program
.option('-c, --coin <coin>', 'coin (btc/bch)')
.option('-n, --network <network>', 'network of the coin')
.option('-w, --wallet <walletId>', 'wallet id')
.parse(process.argv);


program.option = function(){};;

var args = program.args;


var opts = {};
if (program.coin) {
opts.coin = program.coin;
}

if (program.network) {
opts.network = program.network;
}

if(program.wallet) {
opts.wallet = program.wallet;
opts.coin = program.coin
}

utils.getClient(program, {
mustExist: true
}, function(client) {
client.getBalance(opts, function(err, x) {
utils.die(err);
console.log('* Wallet balance %s (Locked %s)', utils.renderAmount(x.totalAmount, opts.coin), utils.renderAmount(x.lockedAmount, opts.coin));
console.log('* Wallet balance %s (Locked %s)', utils.renderAmount(x.totalAmount), utils.renderAmount(x.lockedAmount));
});
});
1 change: 0 additions & 1 deletion packages/bitcore-wallet/bin/wallet-broadcast
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ program = utils.configureCommander(program);

program
.usage('[options] <txpid>')
.option('--path <path>', 'REQUIRED - Where wallet is stored')
.parse(process.argv);

var args = program.args;
Expand Down
7 changes: 4 additions & 3 deletions packages/bitcore-wallet/bin/wallet-create
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var utils = require('./cli-utils');
program = utils.configureCommander(program);

program
.option('-n, --network <network>', 'Network for the wallet')
.option('-t, --testnet', 'Create a Testnet Wallet')
.option('-p, --password', 'Encrypt wallet. Will ask password interactively')
.option('-c, --coin <coin>', 'coin (btc/bch)')
.usage('[options] <walletName> <m-n> [copayerName] <passphrase>')
Expand All @@ -19,8 +19,8 @@ if (!args[0])
var walletName = args[0];
var copayerName = args[2] || process.env.USER;
var passphrase = args[3];
var network = program.testnet ? 'testnet' : 'livenet';
var coin = program.coin ? program.coin : 'btc';
var network = program.network ? program.network : 'livenet'

var mn;
try {
Expand All @@ -38,9 +38,10 @@ utils.getClient(program, {
language: 'en',
coin: coin,
});

client.createWallet(walletName, copayerName, mn[0], mn[1], {
network: network,
coin: coin
coin: coin,
}, function(err, secret) {
utils.die(err);
console.log(' * ' + _.capitalize(network) + ' Wallet Created.');
Expand Down
6 changes: 4 additions & 2 deletions packages/bitcore-wallet/bin/wallet-genkey
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ program = utils.configureCommander(program);

program
.option('-t, --testnet', 'Create a Testnet Extended Private Key')
.option('-c, --coin <coin>', 'coin (btc/bch)')
.option('-p, --password', 'Encrypt wallet. Will ask password interactively')
.parse(process.argv);

var args = program.args;
var network = program.testnet ? 'testnet' : 'livenet';
var coin = program.coin ? 'btc' : 'bch';
utils.getClient(program, { doNotComplete: true, mustBeNew: true }, function (client) {
client.seedFromRandom(network);
client.seedFromRandom({network:network, coin:coin});
utils.saveClient(program, client, function () {
console.log(' * ' + _.capitalize(network) + ' Extended Private Key Created.');
console.log(' * ' + _.capitalize(network) + '/' + coin + ' Extended Private Key Created.');
console.log(' To operate with the corresponding public keys from a proxy device, please run `wallet-export --nosign` and then on the proxy device `wallet-import`.');
});
});
Loading