@@ -2,7 +2,7 @@ var _ = require('lodash');
2
2
var url = require ( 'url' ) ;
3
3
var read = require ( 'read' )
4
4
var log = require ( 'npmlog' ) ;
5
- var Client = require ( '../../ bitcore-wallet-client' ) ;
5
+ var Client = require ( 'bitcore-wallet-client' ) ;
6
6
var FileStorage = require ( './filestorage' ) ;
7
7
var sjcl = require ( 'sjcl' ) ;
8
8
@@ -93,16 +93,18 @@ Utils.getClient = function(args, opts, cb) {
93
93
opts = opts || { } ;
94
94
95
95
var filename = args . file || process . env [ 'WALLET_FILE' ] || process . env [ 'HOME' ] + '/.wallet.dat' ;
96
- var host = args . host || process . env [ 'BWS_HOST' ] || 'https://bws.bitpay.com/bws/api ' ;
96
+ var host = args . host || process . env [ 'BWS_HOST' ] || 'https://bws.bitpay.com/' ;
97
97
98
98
var storage = new FileStorage ( {
99
99
filename : filename ,
100
100
} ) ;
101
101
102
102
var client = new Client ( {
103
- baseUrl : host ,
103
+ baseUrl : url . resolve ( host , '/bws/api' ) ,
104
104
verbose : args . verbose ,
105
105
supportStaffWalletId : opts . walletId ,
106
+ timeout : 20 * 60 * 1000 ,
107
+ //timeout: 1000,
106
108
} ) ;
107
109
108
110
storage . load ( function ( err , walletData ) {
@@ -213,7 +215,7 @@ Utils.findOneTxProposal = function(txps, id) {
213
215
if ( matches . length > 1 ) {
214
216
console . log ( 'More than one TX Proposals match:' + id ) ;
215
217
Utils . renderTxProposals ( txps ) ;
216
- program . exit ( 1 ) ;
218
+ process . exit ( 1 ) ;
217
219
}
218
220
219
221
return matches [ 0 ] ;
@@ -232,17 +234,23 @@ Utils.parseAmount = function(text) {
232
234
var regex = '^(\\d*(\\.\\d{0,8})?)\\s*(' + _ . keys ( Utils . UNITS2 ) . join ( '|' ) + ')?$' ;
233
235
var match = new RegExp ( regex , 'i' ) . exec ( text . trim ( ) ) ;
234
236
235
- if ( ! match || match . length === 0 ) throw new Error ( 'Invalid amount' ) ;
237
+ if ( ! match || match . length === 0 ) {
238
+ Utils . die ( 'Invalid amount: ' + text ) ;
239
+ }
236
240
237
241
var amount = parseFloat ( match [ 1 ] ) ;
238
242
if ( ! _ . isNumber ( amount ) || _ . isNaN ( amount ) ) throw new Error ( 'Invalid amount' ) ;
239
243
240
244
var unit = ( match [ 3 ] || 'sat' ) . toLowerCase ( ) ;
241
245
var rate = Utils . UNITS2 [ unit ] ;
242
- if ( ! rate ) throw new Error ( 'Invalid unit' )
246
+ if ( ! rate ) {
247
+ Utils . die ( 'Invalid unit: ' + unit ) ;
248
+ }
243
249
244
250
var amountSat = parseFloat ( ( amount * rate ) . toPrecision ( 12 ) ) ;
245
- if ( amountSat != Math . round ( amountSat ) ) throw new Error ( 'Invalid amount' ) ;
251
+ if ( amountSat != Math . round ( amountSat ) ) {
252
+ Utils . die ( 'Invalid amount: ' + amount + ' ' + unit ) ;
253
+ }
246
254
247
255
return amountSat ;
248
256
} ;
@@ -251,7 +259,7 @@ Utils.configureCommander = function(program) {
251
259
program
252
260
. version ( '0.0.1' )
253
261
. option ( '-f, --file <filename>' , 'Wallet file' )
254
- . option ( '-h, --host <host>' , 'Bitcore Wallet Service URL (eg: http://localhost:3000/bws /api' )
262
+ . option ( '-h, --host <host>' , 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay /api' )
255
263
. option ( '-v, --verbose' , 'be verbose' )
256
264
257
265
return program ;
0 commit comments