emulate getinfo for wallets who copy bitcoin mistakes (#250)

like vertcoin 0.12... for sure its more efficient sigh
This commit is contained in:
Tanariel 2018-03-25 13:09:26 +03:00 committed by Tanguy Pruvot
parent 9c438eeb94
commit 2d0a2df480
2 changed files with 32 additions and 1 deletions

2
.gitignore vendored
View file

@ -18,3 +18,5 @@ web/serverconfig.php
web/assets/
*.rej
*.orig
.idea/*
web/yaamp/.idea/

View file

@ -7,6 +7,7 @@ class WalletRPC {
public $type = 'Bitcoin';
protected $rpc;
protected $rpc_wallet;
protected $hasGetInfo = false;
// cache
protected $account;
@ -42,6 +43,7 @@ class WalletRPC {
default:
$this->type = 'Bitcoin';
$this->rpc = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport, $url);
$this->hasGetInfo = $coin->hasgetinfo;
}
} else {
@ -377,7 +379,34 @@ class WalletRPC {
}
// Bitcoin RPC
switch ($method) {
case 'getinfo':
if ($this->hasGetInfo) {
$res = $this->rpc->__call($method,$params);
} else {
$miningInfo = $this->rpc->getmininginfo();
$res["blocks"] = arraySafeVal($miningInfo,"blocks");
$res["difficulty"] = arraySafeVal($miningInfo,"difficulty");
$res["testnet"] = "main" != arraySafeVal($miningInfo,"chain");
$walletInfo = $this->rpc->getwalletinfo();
$res["walletversion"] = arraySafeVal($walletInfo,"walletversion");
$res["balance"] = arraySafeVal($walletInfo,"balance");
$res["keypoololdest"] = arraySafeVal($walletInfo,"keypoololdest");
$res["keypoolsize"] = arraySafeVal($walletInfo,"keypoolsize");
$res["paytxfee"] = arraySafeVal($walletInfo,"paytxfee");
$networkInfo = $this->rpc->getnetworkinfo();
$res["version"] = arraySafeVal($networkInfo,"version");
$res["protocolversion"] = arraySafeVal($networkInfo,"protocolversion");
$res["timeoffset"] = arraySafeVal($networkInfo,"timeoffset");
$res["connections"] = arraySafeVal($networkInfo,"connections");
// $res["proxy"] = arraySafeVal($networkInfo,"networks")[0]["proxy"];
$res["relayfee"] = arraySafeVal($networkInfo,"relayfee");
}
break;
default:
$res = $this->rpc->__call($method,$params);
}
$this->error = $this->rpc->error;
return $res;
}