@@ -42,6 +42,7 @@ function __construct($source, $token, $accepted = array('BTC' => 1), $title = fa
42
42
$ this ->btc = new BitcoinRPC (BTC_CONNECT );
43
43
$ this ->xcp = new BitcoinRPC (XCP_CONNECT );
44
44
45
+
45
46
//setup list of transactions to ignore
46
47
$ getIgnore = $ this ->getAll ('ignore_tx ' );
47
48
foreach ($ getIgnore as $ row ){
@@ -251,14 +252,25 @@ protected function getCounterpartySends($vend_token, $accepted = array(), $noFee
251
252
$ fee = round (($ groupQuantity * ($ this ->service_fee / 100 )), 8 );
252
253
}
253
254
}
254
- $ finalQuantity = $ groupQuantity - $ fee ;
255
+ $ finalQuantity = round ( $ groupQuantity - $ fee, 8 ) ;
255
256
$ send_amount = $ finalQuantity * $ rate ;
256
-
257
257
if ($ send_amount < $ this ->min_amount ){
258
+ $ sendThreshold = 0.02 ;
259
+ $ sendDiff = $ this ->min_amount - $ send_amount ;
260
+ $ sendPercent = $ sendDiff / $ this ->min_amount ;
261
+ if ($ sendPercent <= $ sendThreshold ){
262
+ $ send_amount = $ this ->min_amount ;
263
+ }
264
+ else {
258
265
//echo "[".$this->gateway_title."] Not enough ".$send['asset']." funds from ".$send['source'].", waiting (".$groupQuantity." = ".$send_amount.")\n";
259
- continue ;
266
+ continue ;
267
+ }
260
268
}
261
269
270
+
271
+
272
+
273
+
262
274
$ item = array ();
263
275
$ item ['income ' ] = $ grouped [$ send ['source ' ]][$ send ['asset ' ]];
264
276
$ item ['fee ' ] = $ fee ;
@@ -299,7 +311,8 @@ protected function getBitcoinSends($vend_token, $rate, $noFee = false)
299
311
foreach ($ get_api ['data ' ]['txs ' ] as $ tx ){
300
312
if ($ tx ['confirmations ' ] >= $ this ->min_confirms
301
313
AND $ tx ['amount ' ] > 0
302
- AND $ tx ['amount_multisig ' ] == 0 ){
314
+ AND $ tx ['amount_multisig ' ] == 0
315
+ AND $ tx ['amount ' ] != 0.0000543 ){ //temp to filter out counterwallet transactions
303
316
304
317
//check if this transaction has been seen before
305
318
$ checkTx = $ this ->getAll ('transactions ' , array ('type ' => 'gateway_receive ' ,
@@ -439,7 +452,7 @@ protected function vend($sends)
439
452
if ($ balance ['asset ' ] == $ vendAsset ){
440
453
$ found = true ;
441
454
$ divisible = true ;
442
- if (isset ($ this ->accepted [$ vendAsset ])){
455
+ if (isset ($ this ->accepted_info [$ vendAsset ])){
443
456
$ divisible = $ this ->accepted_info [$ vendAsset ]['divisible ' ];
444
457
}
445
458
if ($ divisible ){
@@ -468,7 +481,7 @@ protected function vend($sends)
468
481
//unlock wallet
469
482
try {
470
483
echo "Unlocking wallet \n" ;
471
- $ this ->btc ->walletpassphrase (XCP_WALLET , 300 );
484
+ $ this ->btc ->walletpassphrase (XCP_WALLET , 10000 );
472
485
}
473
486
catch (Exception $ e ){
474
487
throw new Exception ("Could not unlock wallet: " .$ e ->getMessage ()." " .timestamp ()."\n" );
@@ -497,7 +510,18 @@ protected function vend($sends)
497
510
default :
498
511
echo "Sending XCP TX \n" ;
499
512
//send out counterparty tokens
500
- $ quantity = (int )round (round ($ send ['amount ' ], 8 ) * SATOSHI_MOD );
513
+ $ divisible = true ;
514
+ if (isset ($ this ->accepted_info [$ vendAsset ])){
515
+ $ divisible = $ this ->accepted_info [$ vendAsset ]['divisible ' ];
516
+ }
517
+ if ($ divisible ){
518
+ $ quantity = (int )round (round ($ send ['amount ' ], 8 ) * SATOSHI_MOD );
519
+ }
520
+ else {
521
+ $ quantity = floor ($ send ['amount ' ]);
522
+ }
523
+
524
+
501
525
$ sendData = array ('source ' => $ this ->source_address , 'destination ' => $ send ['send_to ' ],
502
526
'asset ' => $ send ['vend_token ' ], 'quantity ' => $ quantity , 'allow_unconfirmed_inputs ' => true ,
503
527
'pubkey ' => $ this ->source_pubkey ,
@@ -507,8 +531,8 @@ protected function vend($sends)
507
531
);
508
532
509
533
$ getRaw = $ this ->xcp ->create_send ($ sendData );
510
- $ sign = $ this ->xcp -> sign_tx ( array ( ' unsigned_tx_hex ' => $ getRaw) );
511
- $ sendTX = $ this ->xcp -> broadcast_tx ( array ( ' signed_tx_hex ' => $ sign) );
534
+ $ sign = $ this ->btc -> signrawtransaction ( $ getRaw );
535
+ $ sendTX = $ this ->btc -> sendrawtransaction ( $ sign[ ' hex ' ] );
512
536
break ;
513
537
}
514
538
}
@@ -634,7 +658,7 @@ protected function autoInflateToken($token, $needed = 0)
634
658
}
635
659
636
660
try {
637
- $ this ->btc ->walletpassphrase (XCP_WALLET , 300 );
661
+ $ this ->btc ->walletpassphrase (XCP_WALLET , 10000 );
638
662
}
639
663
catch (Exception $ e ){
640
664
throw new Exception ("Could not unlock wallet: " .$ e ->getMessage ()."\n" );
@@ -644,8 +668,8 @@ protected function autoInflateToken($token, $needed = 0)
644
668
'asset ' => $ token , 'allow_unconfirmed_inputs ' => true , 'description ' => $ this ->accepted_info [$ token ]['description ' ]);
645
669
646
670
$ getRaw = $ this ->xcp ->create_issuance ($ issueData );
647
- $ sign = $ this ->xcp -> sign_tx ( array ( ' unsigned_tx_hex ' => $ getRaw) );
648
- $ sendTX = $ this ->xcp -> broadcast_tx ( array ( ' signed_tx_hex ' => $ sign));
671
+ $ sign = $ this ->btc -> signrawtransaction ( $ getRaw );
672
+ $ sendTX = $ this ->btc -> sendrawtransaction ( $ sign[ ' hex ' ]);
649
673
650
674
try {
651
675
$ this ->btc ->walletlock ();
@@ -838,8 +862,8 @@ public function refund($send)
838
862
);
839
863
840
864
$ getRaw = $ this ->xcp ->create_send ($ sendData );
841
- $ sign = $ this ->xcp -> sign_tx ( array ( ' unsigned_tx_hex ' => $ getRaw) );
842
- $ sendTX = $ this ->xcp -> broadcast_tx ( array ( ' signed_tx_hex ' => $ sign) );
865
+ $ sign = $ this ->btc -> signrawtransaction ( $ getRaw );
866
+ $ sendTX = $ this ->btc -> sendrawtransaction ( $ sign[ ' hex ' ] );
843
867
}
844
868
845
869
if ($ sendTX ){
0 commit comments