Skip to content

Commit ec492af

Browse files
committed
fixed some issues and removed leftover debug code
1 parent 7269d6a commit ec492af

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

crypto-gateway.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
require_once('conf/config.php');
88
include(FRAMEWORK_PATH.'/functions.php');
99

10+
1011
if(!isset($argv[1])){
1112
//load it up!
1213
echo "Constructing gateway system\n";

lib/BitcoinRPC.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function sendfromaddress($address, $amount, $to, $fee = 0.00001)
199199
}
200200

201201
if($totalFound < ($amount + $fee)){
202-
throw new Exception('Insufficient funds at this address (need '.(($amount + fee) - $totalFound));
202+
throw new Exception('Insufficient funds at this address (need '.(($amount + $fee) - $totalFound).')');
203203
}
204204

205205
$rawInputs = array();

lib/Gateway.php

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function __construct($source, $token, $accepted = array('BTC' => 1), $title = fa
4242
$this->btc = new BitcoinRPC(BTC_CONNECT);
4343
$this->xcp = new BitcoinRPC(XCP_CONNECT);
4444

45+
4546
//setup list of transactions to ignore
4647
$getIgnore = $this->getAll('ignore_tx');
4748
foreach($getIgnore as $row){
@@ -251,14 +252,25 @@ protected function getCounterpartySends($vend_token, $accepted = array(), $noFee
251252
$fee = round(($groupQuantity * ($this->service_fee / 100)), 8);
252253
}
253254
}
254-
$finalQuantity = $groupQuantity - $fee;
255+
$finalQuantity = round($groupQuantity - $fee, 8);
255256
$send_amount = $finalQuantity * $rate;
256-
257257
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{
258265
//echo "[".$this->gateway_title."] Not enough ".$send['asset']." funds from ".$send['source'].", waiting (".$groupQuantity." = ".$send_amount.")\n";
259-
continue;
266+
continue;
267+
}
260268
}
261269

270+
271+
272+
273+
262274
$item = array();
263275
$item['income'] = $grouped[$send['source']][$send['asset']];
264276
$item['fee'] = $fee;
@@ -299,7 +311,8 @@ protected function getBitcoinSends($vend_token, $rate, $noFee = false)
299311
foreach($get_api['data']['txs'] as $tx){
300312
if($tx['confirmations'] >= $this->min_confirms
301313
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
303316

304317
//check if this transaction has been seen before
305318
$checkTx = $this->getAll('transactions', array('type' => 'gateway_receive',
@@ -439,7 +452,7 @@ protected function vend($sends)
439452
if($balance['asset'] == $vendAsset){
440453
$found = true;
441454
$divisible = true;
442-
if(isset($this->accepted[$vendAsset])){
455+
if(isset($this->accepted_info[$vendAsset])){
443456
$divisible = $this->accepted_info[$vendAsset]['divisible'];
444457
}
445458
if($divisible){
@@ -468,7 +481,7 @@ protected function vend($sends)
468481
//unlock wallet
469482
try{
470483
echo "Unlocking wallet\n";
471-
$this->btc->walletpassphrase(XCP_WALLET, 300);
484+
$this->btc->walletpassphrase(XCP_WALLET, 10000);
472485
}
473486
catch(Exception $e){
474487
throw new Exception("Could not unlock wallet: ".$e->getMessage()." ".timestamp()."\n");
@@ -497,7 +510,18 @@ protected function vend($sends)
497510
default:
498511
echo "Sending XCP TX\n";
499512
//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+
501525
$sendData = array('source' => $this->source_address, 'destination' => $send['send_to'],
502526
'asset' => $send['vend_token'], 'quantity' => $quantity, 'allow_unconfirmed_inputs' => true,
503527
'pubkey' => $this->source_pubkey,
@@ -507,8 +531,8 @@ protected function vend($sends)
507531
);
508532

509533
$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']);
512536
break;
513537
}
514538
}
@@ -634,7 +658,7 @@ protected function autoInflateToken($token, $needed = 0)
634658
}
635659

636660
try{
637-
$this->btc->walletpassphrase(XCP_WALLET, 300);
661+
$this->btc->walletpassphrase(XCP_WALLET, 10000);
638662
}
639663
catch(Exception $e){
640664
throw new Exception("Could not unlock wallet: ".$e->getMessage()."\n");
@@ -644,8 +668,8 @@ protected function autoInflateToken($token, $needed = 0)
644668
'asset' => $token, 'allow_unconfirmed_inputs' => true, 'description' => $this->accepted_info[$token]['description']);
645669

646670
$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']);
649673

650674
try{
651675
$this->btc->walletlock();
@@ -838,8 +862,8 @@ public function refund($send)
838862
);
839863

840864
$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']);
843867
}
844868

845869
if($sendTX){

0 commit comments

Comments
 (0)