Compare commits
199 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95021a636d | ||
|
|
15844fa580 | ||
|
|
2a4c674bec | ||
|
|
6b8e2e21c0 | ||
|
|
7b484b2539 | ||
|
|
657350c603 | ||
|
|
7b9df611be | ||
|
|
e15de7b9f0 | ||
|
|
8e11ad314b | ||
|
|
62de55deb6 | ||
|
|
8fc4acad3c | ||
|
|
ea2df3dfa6 | ||
|
|
726262a561 | ||
|
|
6f4b091068 | ||
|
|
9e9c3951b3 | ||
|
|
bf668f4327 | ||
| 57cf6faf21 | |||
|
|
248fb0cc54 | ||
|
|
2f09d9e065 | ||
|
|
a5356346e6 | ||
|
|
0d2bd3b419 | ||
|
|
f966d6e0ff | ||
|
|
79a5fd4e28 | ||
|
|
0e4da0cb11 | ||
|
|
f7b507cec5 | ||
|
|
cd873b537f | ||
|
|
16d205ff06 | ||
|
|
e56c9b25ce | ||
|
|
8a9715f306 | ||
|
|
96beabf954 | ||
|
|
afca393e75 | ||
|
|
73be045de9 | ||
|
|
09d3dd51ba | ||
|
|
66310e5679 | ||
|
|
26243a60f8 | ||
|
|
82ed34bb92 | ||
|
|
ecad33e761 | ||
|
|
89dfd2d547 | ||
|
|
c4aa35b692 | ||
|
|
0b9ad9c537 | ||
|
|
3e5481a41a | ||
|
|
1d0378ffef | ||
|
|
1a30d8e915 | ||
|
|
7501d217e9 | ||
|
|
c2752a740a | ||
|
|
ababb65c1d | ||
|
|
0d99c67605 | ||
|
|
8854a29a23 | ||
|
|
67748de103 | ||
|
|
8adab781a1 | ||
|
|
67e02cb498 | ||
|
|
61c0c11160 | ||
|
|
046d4e7b39 | ||
|
|
d89cc480d7 | ||
|
|
1533d78978 | ||
|
|
468ec7fb1d | ||
|
|
a9f62b8d6d | ||
|
|
2d05a8334b | ||
|
|
ce9af721f7 | ||
|
|
b8119df9fe | ||
|
|
55348cc945 | ||
|
|
bb22e45d40 | ||
|
|
2ffd1de928 | ||
|
|
a64d349a15 | ||
|
|
7efc49336b | ||
|
|
f744778b1d | ||
|
|
ce82b38e84 | ||
|
|
95687ea257 | ||
|
|
d2a5c13106 | ||
|
|
e36b43246b | ||
|
|
8303376372 | ||
|
|
ac4822d507 | ||
|
|
008edc848a | ||
|
|
65c392c084 | ||
|
|
00b6464c3c | ||
|
|
4697718bdc | ||
|
|
51a5d9ad3c | ||
|
|
b1c72ddaf6 | ||
|
|
a563b8656a | ||
|
|
59fe17fcc9 | ||
|
|
a60938ae45 | ||
|
|
a017b2d0ba | ||
|
|
11fe75c102 | ||
|
|
77be0a2716 | ||
|
|
7cbe87e8cd | ||
|
|
858621bb0c | ||
| e81acf2f46 | |||
|
|
2d293c81c9 | ||
|
|
27a62b0fd2 | ||
|
|
55816af407 | ||
|
|
f86ececf92 | ||
|
|
b77018de6f | ||
|
|
246c84c91c | ||
|
|
c2b32207f4 | ||
|
|
41223f5a87 | ||
|
|
e9768b0d10 | ||
|
|
b3729a9895 | ||
|
|
027b36fce8 | ||
|
|
c9a1e60b57 | ||
|
|
05ec0a1b38 | ||
|
|
751ca8dd19 | ||
|
|
c5142655a7 | ||
|
|
cab1ed3ea8 | ||
|
|
99e5c412de | ||
|
|
1baba2ab3a | ||
|
|
b3bec0961b | ||
|
|
5dced856e2 | ||
|
|
7e28ce9246 | ||
|
|
9791689a10 | ||
|
|
489f048438 | ||
|
|
cbe27cf45a | ||
|
|
bda11255ed | ||
|
|
471d88e3cc | ||
|
|
837254e21b | ||
|
|
d1af58ccf9 | ||
|
|
12fa045ba3 | ||
|
|
d03cd9e9f6 | ||
|
|
f700c3a1c7 | ||
|
|
f564e7efa1 | ||
|
|
fd8be6aa1a | ||
|
|
8cf132e1ba | ||
|
|
df3dc61885 | ||
|
|
0e902d3e87 | ||
|
|
55c2ccc12c | ||
|
|
0d181f5512 | ||
|
|
cf6811d5c0 | ||
|
|
d3d20f596b | ||
|
|
54c9d063be | ||
|
|
be078f910f | ||
|
|
6252d4e3fe | ||
|
|
90fb711d2a | ||
|
|
271815e731 | ||
|
|
1a8b491fba | ||
|
|
d6235f4121 | ||
|
|
dacd9420a1 | ||
|
|
7e11df5a28 | ||
|
|
88f50fcae1 | ||
|
|
3251f98ebf | ||
|
|
98dba661b1 | ||
|
|
ca9e95e7af | ||
|
|
5bbbca15a9 | ||
|
|
4c79b7f460 | ||
|
|
5906372fc0 | ||
|
|
30c76cab5c | ||
|
|
e70d422da5 | ||
|
|
754017f634 | ||
|
|
4aeff314bb | ||
|
|
c25ccfe064 | ||
|
|
5fbb3c3ac2 | ||
|
|
d6c6d3420e | ||
|
|
e389988bda | ||
|
|
c8a8d3b9d0 | ||
|
|
3f42a53991 | ||
|
|
6383aade6e | ||
|
|
17acd5830e | ||
|
|
f33402382b | ||
|
|
3ddc0dd90e | ||
|
|
33587258a8 | ||
|
|
49df2cf71f | ||
|
|
975e602088 | ||
|
|
6483f377b5 | ||
|
|
843d1d0fef | ||
|
|
91f6e1f5d4 | ||
|
|
33aa9cb6c5 | ||
|
|
29c27c426e | ||
|
|
2202811745 | ||
|
|
30f35944ea | ||
|
|
7146cfd3c0 | ||
|
|
024042abab | ||
|
|
0b73adb3d8 | ||
|
|
a03484adee | ||
|
|
99f17a3e7d | ||
|
|
3549da461d | ||
|
|
616dde11ea | ||
|
|
31f5ff0bd1 | ||
|
|
3cad1162ef | ||
|
|
7a83f1ab10 | ||
|
|
b974dc4c9a | ||
|
|
55a1dc750c | ||
|
|
4b47d0d88e | ||
|
|
6a6005ca4c | ||
|
|
9dd74285f7 | ||
|
|
788f438114 | ||
|
|
f3e430fee5 | ||
|
|
faf8cc05f7 | ||
|
|
de732ee7f9 | ||
|
|
74190d40ba | ||
|
|
65e801989d | ||
|
|
d688423d3e | ||
|
|
ffc87d69bf | ||
|
|
2a49e6c70a | ||
|
|
6c8bc7b97c | ||
|
|
7efb4df493 | ||
|
|
beff53e938 | ||
|
|
5ca54479a7 | ||
|
|
547cac4afb | ||
|
|
bc9c945646 | ||
|
|
8be4270e16 | ||
|
|
971c385042 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
include/config.inc.php
|
||||
/include/config.inc.php
|
||||
/composer.lock
|
||||
|
||||
22
.travis.yml
Normal file
22
.travis.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
dist: trusty
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 7.2
|
||||
- 7.3
|
||||
- nightly
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: nightly
|
||||
|
||||
## Cache composer
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
before_script:
|
||||
- travis_retry composer update --no-interaction --prefer-dist
|
||||
|
||||
script:
|
||||
- vendor/bin/phpcs -l --standard=psr2 . include
|
||||
224
api.php
224
api.php
@@ -23,6 +23,8 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
header('Content-Type: application/json');
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} /api.php 01. Basic Information
|
||||
@@ -65,8 +67,10 @@ OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
* }
|
||||
*/
|
||||
|
||||
require_once("include/init.inc.php");
|
||||
error_reporting(0);
|
||||
use Arionum\Blacklist;
|
||||
|
||||
require_once __DIR__.'/include/init.inc.php';
|
||||
|
||||
$ip = san_ip($_SERVER['REMOTE_ADDR']);
|
||||
$ip = filter_var($ip, FILTER_VALIDATE_IP);
|
||||
|
||||
@@ -160,6 +164,7 @@ if ($q == "getAddress") {
|
||||
*/
|
||||
|
||||
$account = $data['account'];
|
||||
$public_key = san($data['public_key'] ?? '');
|
||||
if (!empty($public_key) && strlen($public_key) < 32) {
|
||||
api_err("Invalid public key");
|
||||
}
|
||||
@@ -180,7 +185,7 @@ if ($q == "getAddress") {
|
||||
*
|
||||
* @apiParam {string} [public_key] Public key
|
||||
* @apiParam {string} [account] Account id / address
|
||||
* @apiParam {numeric} [limit] Number of confirmed transactions, max 1000, min 1
|
||||
* @apiParam {numeric} [limit] Number of confirmed transactions, max 100, min 1
|
||||
*
|
||||
* @apiSuccess {string} block Block ID
|
||||
* @apiSuccess {numeric} confirmation Number of confirmations
|
||||
@@ -199,6 +204,7 @@ if ($q == "getAddress") {
|
||||
*/
|
||||
|
||||
$account = san($data['account']);
|
||||
$public_key = san($data['public_key'] ?? '');
|
||||
if (!empty($public_key) && strlen($public_key) < 32) {
|
||||
api_err("Invalid public key");
|
||||
}
|
||||
@@ -337,6 +343,7 @@ if ($q == "getAddress") {
|
||||
*
|
||||
* @apiParam {numeric} [height] Block Height
|
||||
* @apiParam {string} [block] Block id
|
||||
* @apiParam {boolean} [includeMiningRewards] Include mining rewards
|
||||
*
|
||||
* @apiSuccess {string} block Block ID
|
||||
* @apiSuccess {numeric} confirmations Number of confirmations
|
||||
@@ -355,7 +362,13 @@ if ($q == "getAddress") {
|
||||
*/
|
||||
$height = san($data['height']);
|
||||
$block = san($data['block']);
|
||||
$ret = $trx->get_transactions($height, $block);
|
||||
$includeMiningRewards = (
|
||||
isset($data['includeMiningRewards']) &&
|
||||
!($data['includeMiningRewards'] === '0' || $data['includeMiningRewards'] === 'false')
|
||||
);
|
||||
|
||||
$ret = $trx->get_transactions($height, $block, $includeMiningRewards);
|
||||
|
||||
if ($ret === false) {
|
||||
api_err("Invalid block");
|
||||
} else {
|
||||
@@ -406,6 +419,8 @@ if ($q == "getAddress") {
|
||||
$version = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($version==1) {
|
||||
if (!$acc->valid($dst)) {
|
||||
api_err("Invalid destination address");
|
||||
@@ -421,13 +436,22 @@ if ($q == "getAddress") {
|
||||
api_err("Invalid destination alias");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$public_key = san($data['public_key']);
|
||||
if (!$acc->valid_key($public_key)) {
|
||||
api_err("Invalid public key");
|
||||
}
|
||||
if ($_config['use_official_blacklist']!==false) {
|
||||
if (Blacklist::checkPublicKey($public_key)) {
|
||||
api_err("Blacklisted account");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$private_key = san($data['private_key']);
|
||||
if (!$acc->valid_key($private_key)) {
|
||||
api_err("Invalid private key");
|
||||
@@ -447,7 +471,8 @@ if ($q == "getAddress") {
|
||||
if ($date > time() + 86400) {
|
||||
api_err("Invalid Date");
|
||||
}
|
||||
|
||||
|
||||
|
||||
$message=$data['message'];
|
||||
if (strlen($message) > 128) {
|
||||
api_err("The message must be less than 128 chars");
|
||||
@@ -462,10 +487,11 @@ if ($q == "getAddress") {
|
||||
if ($fee > 10 && $current['height'] > 10800) {
|
||||
$fee = 10; //10800
|
||||
}
|
||||
if ($val < 0.00000001) {
|
||||
if ($val < 0) {
|
||||
api_err("Invalid value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// set alias
|
||||
if ($version==3) {
|
||||
$fee=10;
|
||||
@@ -501,6 +527,9 @@ if ($q == "getAddress") {
|
||||
if (empty($private_key) && empty($signature)) {
|
||||
api_err("Either the private_key or the signature must be sent");
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (empty($public_key)) {
|
||||
$pk = coin2pem($private_key, true);
|
||||
$pkey = openssl_pkey_get_private($pk);
|
||||
@@ -528,11 +557,12 @@ if ($q == "getAddress") {
|
||||
$transaction['id'] = $hash;
|
||||
|
||||
|
||||
|
||||
|
||||
if (!$trx->check($transaction)) {
|
||||
api_err("Transaction signature failed");
|
||||
}
|
||||
|
||||
|
||||
$res = $db->single("SELECT COUNT(1) FROM mempool WHERE id=:id", [":id" => $hash]);
|
||||
if ($res != 0) {
|
||||
api_err("The transaction is already in mempool");
|
||||
@@ -559,6 +589,7 @@ if ($q == "getAddress") {
|
||||
|
||||
|
||||
$trx->add_mempool($transaction, "local");
|
||||
$hash=escapeshellarg(san($hash));
|
||||
system("php propagate.php transaction $hash > /dev/null 2>&1 &");
|
||||
api_echo($hash);
|
||||
} elseif ($q == "mempoolSize") {
|
||||
@@ -624,7 +655,7 @@ if ($q == "getAddress") {
|
||||
$public_key=san($data['public_key']);
|
||||
$signature=san($data['signature']);
|
||||
$data=$data['data'];
|
||||
|
||||
|
||||
api_echo(ec_verify($data, $signature, $public_key));
|
||||
} elseif ($q == "masternodes") {
|
||||
/**
|
||||
@@ -633,16 +664,23 @@ if ($q == "getAddress") {
|
||||
* @apiGroup API
|
||||
* @apiDescription Returns all the masternode data
|
||||
*
|
||||
* @apiParam {string} [public_key] Optional public key
|
||||
*
|
||||
*
|
||||
* @apiSuccess {boolean} data masternode date
|
||||
* @apiSuccess {json} data masternode date
|
||||
*/
|
||||
$bind=[];
|
||||
$whr='';
|
||||
$public_key=san($data['public_key']);
|
||||
if(!empty($public_key)){
|
||||
$whr="WHERE public_key=:public_key";
|
||||
$bind[':public_key']=$public_key;
|
||||
}
|
||||
$res=$db->run("SELECT * FROM masternode $whr ORDER by public_key ASC",$bind);
|
||||
|
||||
$res=$db->run("SELECT * FROM masternode");
|
||||
api_echo($res);
|
||||
api_echo(["masternodes"=>$res, "hash"=>md5(json_encode($res))]);
|
||||
} elseif ($q == "getAlias") {
|
||||
/**
|
||||
* @api {get} /api.php?q=getAlias 189. getAlias
|
||||
* @api {get} /api.php?q=getAlias 19. getAlias
|
||||
* @apiName getAlias
|
||||
* @apiGroup API
|
||||
* @apiDescription Returns the alias of an account
|
||||
@@ -653,7 +691,7 @@ if ($q == "getAddress") {
|
||||
*
|
||||
* @apiSuccess {string} data alias
|
||||
*/
|
||||
|
||||
|
||||
$public_key = $data['public_key'];
|
||||
$account = $data['account'];
|
||||
if (!empty($public_key) && strlen($public_key) < 32) {
|
||||
@@ -662,13 +700,163 @@ if ($q == "getAddress") {
|
||||
if (!empty($public_key)) {
|
||||
$account = $acc->get_address($public_key);
|
||||
}
|
||||
|
||||
|
||||
if (empty($account)) {
|
||||
api_err("Invalid account id");
|
||||
}
|
||||
$account = san($account);
|
||||
|
||||
|
||||
api_echo($acc->account2alias($account));
|
||||
} elseif ($q === 'sanity') {
|
||||
/**
|
||||
* @api {get} /api.php?q=sanity 20. sanity
|
||||
* @apiName sanity
|
||||
* @apiGroup API
|
||||
* @apiDescription Returns details about the node's sanity process.
|
||||
*
|
||||
* @apiSuccess {object} data A collection of data about the sanity process.
|
||||
* @apiSuccess {boolean} data.sanity_running Whether the sanity process is currently running.
|
||||
* @apiSuccess {number} data.last_sanity The timestamp for the last time the sanity process was run.
|
||||
* @apiSuccess {boolean} data.sanity_sync Whether the sanity process is currently synchronising.
|
||||
*/
|
||||
$sanity = file_exists(__DIR__.'/tmp/sanity-lock');
|
||||
|
||||
$lastSanity = (int)$db->single("SELECT val FROM config WHERE cfg='sanity_last'");
|
||||
$sanitySync = (bool)$db->single("SELECT val FROM config WHERE cfg='sanity_sync'");
|
||||
api_echo(['sanity_running' => $sanity, 'last_sanity' => $lastSanity, 'sanity_sync' => $sanitySync]);
|
||||
} elseif ($q === 'node-info') {
|
||||
/**
|
||||
* @api {get} /api.php?q=node-info 21. node-info
|
||||
* @apiName node-info
|
||||
* @apiGroup API
|
||||
* @apiDescription Returns details about the node.
|
||||
*
|
||||
* @apiSuccess {object} data A collection of data about the node.
|
||||
* @apiSuccess {string} data.hostname The hostname of the node.
|
||||
* @apiSuccess {string} data.version The current version of the node.
|
||||
* @apiSuccess {string} data.dbversion The database schema version for the node.
|
||||
* @apiSuccess {number} data.accounts The number of accounts known by the node.
|
||||
* @apiSuccess {number} data.transactions The number of transactions known by the node.
|
||||
* @apiSuccess {number} data.mempool The number of transactions in the mempool.
|
||||
* @apiSuccess {number} data.masternodes The number of masternodes known by the node.
|
||||
* @apiSuccess {number} data.peers The number of valid peers.
|
||||
*/
|
||||
$dbVersion = $db->single("SELECT val FROM config WHERE cfg='dbversion'");
|
||||
$hostname = $db->single("SELECT val FROM config WHERE cfg='hostname'");
|
||||
$acc = $db->single("SELECT COUNT(1) FROM accounts");
|
||||
$tr = $db->single("SELECT COUNT(1) FROM transactions");
|
||||
$masternodes = $db->single("SELECT COUNT(1) FROM masternode");
|
||||
$mempool = $db->single("SELECT COUNT(1) FROM mempool");
|
||||
$peers = $db->single("SELECT COUNT(1) FROM peers WHERE blacklisted<UNIX_TIMESTAMP()");
|
||||
api_echo([
|
||||
'hostname' => $hostname,
|
||||
'version' => VERSION,
|
||||
'dbversion' => $dbVersion,
|
||||
'accounts' => $acc,
|
||||
'transactions' => $tr,
|
||||
'mempool' => $mempool,
|
||||
'masternodes' => $masternodes,
|
||||
'peers' => $peers
|
||||
]);
|
||||
} elseif ($q === 'checkAddress') {
|
||||
/**
|
||||
* @api {get} /api.php?q=checkAddress 22. checkAddress
|
||||
* @apiName checkAddress
|
||||
* @apiGroup API
|
||||
* @apiDescription Checks the validity of an address.
|
||||
*
|
||||
* @apiParam {string} account Account id / address
|
||||
* @apiParam {string} [public_key] Public key
|
||||
*
|
||||
* @apiSuccess {boolean} data True if the address is valid, false otherwise.
|
||||
*/
|
||||
|
||||
$address=$data['account'];
|
||||
$public_key=$data['public_key'];
|
||||
$acc = new Account();
|
||||
if (!$acc->valid($address)) {
|
||||
api_err(false);
|
||||
}
|
||||
|
||||
$dst_b = base58_decode($address);
|
||||
if (strlen($dst_b) != 64) {
|
||||
api_err(false);
|
||||
}
|
||||
if (!empty($public_key)) {
|
||||
if($acc->get_address($public_key)!=$address){
|
||||
api_err(false);
|
||||
}
|
||||
}
|
||||
api_echo(true);
|
||||
} elseif ($q === "assetBalance"){
|
||||
|
||||
$asset = san($data['asset']);
|
||||
$public_key = san($data['public_key']);
|
||||
$account = san($data['account']);
|
||||
if (!empty($public_key) && strlen($public_key) < 32) {
|
||||
api_err("Invalid public key");
|
||||
}
|
||||
if (!empty($public_key)) {
|
||||
$account = $acc->get_address($public_key);
|
||||
}
|
||||
|
||||
if(empty($asset)&&empty($account)){
|
||||
api_err("An asset or an account are necessary");
|
||||
}
|
||||
|
||||
if(!empty($asset)&&!empty($account)){
|
||||
api_err("Choose either account or asset parameter");
|
||||
}
|
||||
|
||||
$whr="WHERE assets_balance.";
|
||||
$bind=[];
|
||||
if(!empty($asset)){
|
||||
$whr.="asset=:asset ";
|
||||
$bind[':asset']=$asset;
|
||||
}
|
||||
elseif(!empty($account)){
|
||||
$whr.="account=:account ";
|
||||
$bind[':account']=$account;
|
||||
}
|
||||
|
||||
$r=$db->run("SELECT asset, alias, account, assets_balance.balance FROM assets_balance LEFT JOIN accounts ON accounts.id=assets_balance.asset $whr LIMIT 1000",$bind);
|
||||
|
||||
if ($r)
|
||||
api_echo($r);
|
||||
else
|
||||
api_err("An asset or an account not found");
|
||||
|
||||
} elseif ($q === "asset-orders"){
|
||||
$asset = san($data['asset']);
|
||||
$account = san($data['account']);
|
||||
if(empty($asset)&&empty($account)){
|
||||
api_err("An asset or an account are necessary");
|
||||
}
|
||||
$whr="status=0";
|
||||
$bind=[];
|
||||
if(!empty($asset)){
|
||||
$whr.=" AND asset=:asset ";
|
||||
$bind[':asset']=$asset;
|
||||
}
|
||||
if(!empty($account)){
|
||||
$whr.=" AND account=:account ";
|
||||
$bind[':account']=$account;
|
||||
}
|
||||
|
||||
$r=$db->run("SELECT * FROM assets_market WHERE $whr", $bind);
|
||||
api_echo($r);
|
||||
|
||||
} elseif ($q === "assets"){
|
||||
$asset = san($data['asset']);
|
||||
$whr="";
|
||||
$bind=[];
|
||||
if(!empty($asset)){
|
||||
$whr.=" WHERE assets.id=:asset ";
|
||||
$bind[':asset']=$asset;
|
||||
}
|
||||
$r=$db->run("SELECT assets.*, accounts.alias, accounts.balance FROM assets LEFT JOIN accounts ON accounts.id=assets.id $whr LIMIT 1000",$bind);
|
||||
api_echo($r);
|
||||
|
||||
} else {
|
||||
api_err("Invalid request");
|
||||
}
|
||||
|
||||
180
doc/api_data.js
180
doc/api_data.js
@@ -101,6 +101,50 @@ define({ "api": [
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=checkAddress",
|
||||
"title": "22. checkAddress",
|
||||
"name": "checkAddress",
|
||||
"group": "API",
|
||||
"description": "<p>Checks the validity of an address.</p>",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "account",
|
||||
"description": "<p>Account id / address</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "public_key",
|
||||
"description": "<p>Public key</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "boolean",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>True if the address is valid, false otherwise.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=checkSignature",
|
||||
@@ -303,7 +347,7 @@ define({ "api": [
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=getAlias",
|
||||
"title": "189. getAlias",
|
||||
"title": "19. getAlias",
|
||||
"name": "getAlias",
|
||||
"group": "API",
|
||||
"description": "<p>Returns the alias of an account</p>",
|
||||
@@ -504,6 +548,13 @@ define({ "api": [
|
||||
"optional": true,
|
||||
"field": "block",
|
||||
"description": "<p>Block id</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "boolean",
|
||||
"optional": true,
|
||||
"field": "includeMiningRewards",
|
||||
"description": "<p>Include mining rewards</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -854,7 +905,7 @@ define({ "api": [
|
||||
"type": "numeric",
|
||||
"optional": true,
|
||||
"field": "limit",
|
||||
"description": "<p>Number of confirmed transactions, max 1000, min 1</p>"
|
||||
"description": "<p>Number of confirmed transactions, max 100, min 1</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1015,6 +1066,86 @@ define({ "api": [
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=node-info",
|
||||
"title": "21. node-info",
|
||||
"name": "node_info",
|
||||
"group": "API",
|
||||
"description": "<p>Returns details about the node.</p>",
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "object",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>A collection of data about the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "data.hostname",
|
||||
"description": "<p>The hostname of the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "data.version",
|
||||
"description": "<p>The current version of the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "data.dbversion",
|
||||
"description": "<p>The database schema version for the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.accounts",
|
||||
"description": "<p>The number of accounts known by the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.transactions",
|
||||
"description": "<p>The number of transactions known by the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.mempool",
|
||||
"description": "<p>The number of transactions in the mempool.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.masternodes",
|
||||
"description": "<p>The number of masternodes known by the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.peers",
|
||||
"description": "<p>The number of valid peers.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=randomNumber",
|
||||
@@ -1073,6 +1204,51 @@ define({ "api": [
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=sanity",
|
||||
"title": "20. sanity",
|
||||
"name": "sanity",
|
||||
"group": "API",
|
||||
"description": "<p>Returns details about the node's sanity process.</p>",
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "object",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>A collection of data about the sanity process.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "boolean",
|
||||
"optional": false,
|
||||
"field": "data.sanity_running",
|
||||
"description": "<p>Whether the sanity process is currently running.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.last_sanity",
|
||||
"description": "<p>The timestamp for the last time the sanity process was run.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "boolean",
|
||||
"optional": false,
|
||||
"field": "data.sanity_sync",
|
||||
"description": "<p>Whether the sanity process is currently synchronising.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=send",
|
||||
|
||||
@@ -101,6 +101,50 @@
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=checkAddress",
|
||||
"title": "22. checkAddress",
|
||||
"name": "checkAddress",
|
||||
"group": "API",
|
||||
"description": "<p>Checks the validity of an address.</p>",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "account",
|
||||
"description": "<p>Account id / address</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "public_key",
|
||||
"description": "<p>Public key</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "boolean",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>True if the address is valid, false otherwise.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=checkSignature",
|
||||
@@ -303,7 +347,7 @@
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=getAlias",
|
||||
"title": "189. getAlias",
|
||||
"title": "19. getAlias",
|
||||
"name": "getAlias",
|
||||
"group": "API",
|
||||
"description": "<p>Returns the alias of an account</p>",
|
||||
@@ -504,6 +548,13 @@
|
||||
"optional": true,
|
||||
"field": "block",
|
||||
"description": "<p>Block id</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "boolean",
|
||||
"optional": true,
|
||||
"field": "includeMiningRewards",
|
||||
"description": "<p>Include mining rewards</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -854,7 +905,7 @@
|
||||
"type": "numeric",
|
||||
"optional": true,
|
||||
"field": "limit",
|
||||
"description": "<p>Number of confirmed transactions, max 1000, min 1</p>"
|
||||
"description": "<p>Number of confirmed transactions, max 100, min 1</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1015,6 +1066,86 @@
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=node-info",
|
||||
"title": "21. node-info",
|
||||
"name": "node_info",
|
||||
"group": "API",
|
||||
"description": "<p>Returns details about the node.</p>",
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "object",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>A collection of data about the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "data.hostname",
|
||||
"description": "<p>The hostname of the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "data.version",
|
||||
"description": "<p>The current version of the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "data.dbversion",
|
||||
"description": "<p>The database schema version for the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.accounts",
|
||||
"description": "<p>The number of accounts known by the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.transactions",
|
||||
"description": "<p>The number of transactions known by the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.mempool",
|
||||
"description": "<p>The number of transactions in the mempool.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.masternodes",
|
||||
"description": "<p>The number of masternodes known by the node.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.peers",
|
||||
"description": "<p>The number of valid peers.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=randomNumber",
|
||||
@@ -1073,6 +1204,51 @@
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=sanity",
|
||||
"title": "20. sanity",
|
||||
"name": "sanity",
|
||||
"group": "API",
|
||||
"description": "<p>Returns details about the node's sanity process.</p>",
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "object",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>A collection of data about the sanity process.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "boolean",
|
||||
"optional": false,
|
||||
"field": "data.sanity_running",
|
||||
"description": "<p>Whether the sanity process is currently running.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "number",
|
||||
"optional": false,
|
||||
"field": "data.last_sanity",
|
||||
"description": "<p>The timestamp for the last time the sanity process was run.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "boolean",
|
||||
"optional": false,
|
||||
"field": "data.sanity_sync",
|
||||
"description": "<p>Whether the sanity process is currently synchronising.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=send",
|
||||
|
||||
@@ -7,7 +7,7 @@ define({
|
||||
"apidoc": "0.3.0",
|
||||
"generator": {
|
||||
"name": "apidoc",
|
||||
"time": "2018-08-05T21:17:14.214Z",
|
||||
"time": "2018-11-05T10:13:13.657Z",
|
||||
"url": "http://apidocjs.com",
|
||||
"version": "0.17.6"
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"apidoc": "0.3.0",
|
||||
"generator": {
|
||||
"name": "apidoc",
|
||||
"time": "2018-08-05T21:17:14.214Z",
|
||||
"time": "2018-11-05T10:13:13.657Z",
|
||||
"url": "http://apidocjs.com",
|
||||
"version": "0.17.6"
|
||||
}
|
||||
|
||||
50
include/Blacklist.php
Normal file
50
include/Blacklist.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Arionum;
|
||||
|
||||
/**
|
||||
* Class Blacklist
|
||||
*/
|
||||
final class Blacklist
|
||||
{
|
||||
/**
|
||||
* The official list of blacklisted public keys
|
||||
*/
|
||||
public const PUBLIC_KEYS = [
|
||||
// phpcs:disable Generic.Files.LineLength
|
||||
'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCvVQcHHCNLfiP9LmzWhhpCHx39Bhc67P5HMQM9cctEFvcsUdgrkGqy18taz9ZMrAGtq7NhBYpQ4ZTHkKYiZDaSUqQ' => 'Faucet Abuser',
|
||||
'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCxYDeQHk7Ke66UB2Un3UMmMoJ7RF5vDZXihdEXi8gk8ZBRAi35aFrER2ZLX1mgND7sLFXKETGTjRYjoHcuRNiJN1g' => 'Octaex Exchange',
|
||||
// phpcs:enable
|
||||
];
|
||||
|
||||
/**
|
||||
* The official list of blacklisted addresses
|
||||
*/
|
||||
public const ADDRESSES = [
|
||||
// phpcs:disable Generic.Files.LineLength
|
||||
'xuzyMbEGA1tmx1o7mcxSXf2nXuuV1GtKbA4sAqjcNq2gh3shuhwBT5nJHez9AynCaxpJwL6dpkavmZBA3JkrMkg' => 'Octaex Exchange',
|
||||
// phpcs:enable
|
||||
];
|
||||
|
||||
/**
|
||||
* Check if a public key is blacklisted
|
||||
*
|
||||
* @param string $publicKey
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkPublicKey(string $publicKey): bool
|
||||
{
|
||||
return key_exists($publicKey, static::PUBLIC_KEYS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an address is blacklisted
|
||||
*
|
||||
* @param string $address
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkAddress(string $address): bool
|
||||
{
|
||||
return key_exists($address, static::ADDRESSES);
|
||||
}
|
||||
}
|
||||
11
include/Exception.php
Normal file
11
include/Exception.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Arionum\Node;
|
||||
|
||||
/**
|
||||
* Class Exception
|
||||
* A custom exception for Arionum error handling.
|
||||
*/
|
||||
class Exception extends \Exception
|
||||
{
|
||||
}
|
||||
81
include/InitialPeers.php
Normal file
81
include/InitialPeers.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Arionum\Node;
|
||||
|
||||
/**
|
||||
* Class InitialPeers
|
||||
*/
|
||||
final class InitialPeers
|
||||
{
|
||||
public const MINIMUM_PEERS_REQUIRED = 2;
|
||||
public const PRELOAD_ERROR = 'Unable to retrieve peers from the preload list.';
|
||||
public const PRELOAD_LIST = 'https://www.arionum.com/peers.txt';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $peerList = [];
|
||||
|
||||
/**
|
||||
* InitialPeers constructor.
|
||||
* @param array|null $peerList
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(?array $peerList = [])
|
||||
{
|
||||
$this->peerList = $peerList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a peer from the initial peer list.
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get(): string
|
||||
{
|
||||
if (!$this->peerList || count($this->peerList) < self::MINIMUM_PEERS_REQUIRED) {
|
||||
$this->retrieveFromPreloadList();
|
||||
}
|
||||
|
||||
return $this->selectPeer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all available initial peers.
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAll(): array
|
||||
{
|
||||
if (!$this->peerList || count($this->peerList) < self::MINIMUM_PEERS_REQUIRED) {
|
||||
$this->retrieveFromPreloadList();
|
||||
}
|
||||
|
||||
return $this->peerList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function selectPeer(): string
|
||||
{
|
||||
return $this->peerList[array_rand($this->peerList)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a peer from
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private function retrieveFromPreloadList(): void
|
||||
{
|
||||
$peerList = file(self::PRELOAD_LIST, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
|
||||
if (!$peerList || count($peerList) < self::MINIMUM_PEERS_REQUIRED) {
|
||||
throw new Exception(self::PRELOAD_ERROR);
|
||||
}
|
||||
|
||||
$this->peerList = $peerList;
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,40 @@ class Account
|
||||
return 'RncXQuc7S7aWkvTUJSHEFvYoV3ntAf7bfxEHjSiZNBvQV37MzZtg44L7GAV7szZ3uV8qWqikBewa3piZMqzBqm';
|
||||
} elseif ($hash == 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCyjKMBY4ihhJ2G25EVezg7KnoCBVbhdvWfqzNA4LC5R7wgu3VNfJgvqkCq9sKKZcCoCpX6Qr9cN882MoXsfGTvZoj') {
|
||||
return 'Rq53oLzpCrb4BdJZ1jqQ2zsixV2ukxVdM4H9uvUhCGJCz1q2wagvuXV4hC6UVwK7HqAt1FenukzhVXgzyG1y32';
|
||||
} elseif ($hash == 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCzZtEj6zAW8WVB6AbDLndbQZrnH2R5Nmpk1sLyHXzqyp4P5cyJAbnUpR5UdG8sBCCuZekWSBHgWNMaGS317vPsVuG'){
|
||||
// mixed keys badly generated address
|
||||
return '3CWXXqpzuda85MaPpgYRee8d7a44wzemqztfFfeZDyEysQ15cN6gZNsPT32MHwjrzbENDvkqKtADoCBgVVqXWP2g';
|
||||
} elseif ($hash == 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCwYhtqidHRVigBiQiun5csb9YnZzcvmSt7aCVS6nH2gYykLr9pQfJHP8bTtYTMkU1WLdmeTkNPGDujYWKjPSGU8XX'){
|
||||
// broken wallet due to webwallet bug
|
||||
return '4JstC5anTNMpY2zmUHt2LDmQXsMQvkh7d9qHBjBhRahAsWVTyyS9RPYMRdmcqdVPSDUQsXJfGyPFMn6y6R9M5QQ7';
|
||||
} elseif ($hash == 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCwoUzVYoaDZGausEDEg5JMtiRQvdmuuv1FKvCxUp6m8iMJhKbohtH75wXPBgi4wYPMSUw4himHeJ3qnDpAQnKSsJU'){
|
||||
// stolen coins hf recovery
|
||||
return '4VLRngC3U24YdusKQ4rGfCX4DDfBUcNemH419wUS5xe2uUf3ku1CXq6RCfGoiZvDK61upmLfrb64YWubyh5eUG4Y';
|
||||
} elseif ($hash == 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCvgAVPik2t9yfM63rDCy13opmvejvMXadRb6qKjEoaiFkGCJHKBUSzggaEtgyDVkRk7ajREQjRrN6J4EcoXTzGM3p'){
|
||||
// stolen coins hf recovery
|
||||
return 'SBWPS7Yu4X4ZQFY9n27bkBL5AnDRveUBbfbZWwhEN1tWZnTCEc8kvx7ddfoaqhjw7tw8rQULk2fEgSB1r2vWqKp';
|
||||
} elseif ($hash == 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCz1Adkpo6MRTogSUKLtEh5NKo1Y8sumnNKqhRW8w2bZtVfMT4sfbStg8ycqtmQNDztvUE39MVHnXmCDtpmv9KKdQN'){
|
||||
// stolen coins hf recovery
|
||||
return 'reMoRxfiUxtoj7RD1aDH5yNfeuXEyTj2XiHaUBdVUhk8Wt5f4VLWrqge6J5yE9BGkVLFPqfS6ZYvj4ocWhbZhru';
|
||||
} elseif ($hash == 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCxXrhv7wkhX4R2YjyRNfssf15wTksz5Ev4FFGfCmhcUL7kt5aXRvh6xknQf5HHzDo4GsG523wBYcFhiAkmBL1kkUo'){
|
||||
// stolen coins hf recovery
|
||||
return '3goaif939N4xy5ThT7iq2GhBgwjrS4buhhTtTQkXrzarKcsYvyg5PU8KVgzrSfgFfhnZGNx9WseaR2JSUpYn1Vch';
|
||||
} elseif ($hash == 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCzhTJ5G37ijQcgdzUsMMVyAPFaxLCyssQjqYF1g1Zsr3XkzYux3Dt75y3DRmXmx6wiNTf7uKxAGFaQA7qao7TXp9j'){
|
||||
// stolen coins hf recovery
|
||||
return 'LtjGjTTurwLNZLbexAbusCRS5SNYhFydMuFdPTaYFRD3WoL2q67tidsrd7qnX8czmTBhrDyrdheP5gCwCbAHBBd';
|
||||
} elseif ($hash == 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCwrgAsdSZtv9e4Ldw2mzg7HwQMHzG1FFVzoRtENwDRZxhRTwSGYU4oUXVLzNWNqpRZ6iEZXenxUANScwr7yDET7xA'){
|
||||
// stolen coins hf recovery
|
||||
return 'aSpfMMbxA8U1rMqBgYoQtXhUyAKyhBJHY17CEW4V3ttgRsvpuZ1Dg3xYc1rcMeKnP2gT2sxnn7vHpmLAVVPQv7w';
|
||||
} elseif ($hash == 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCzPi4ZmDK5E7vNVz14AiJmvcT9UbxXDDWzNVYt973Sqgt6p6BQtuqkJ3X3UM92mbjxVLg3xzmhZricuUSx5J811nW'){
|
||||
// stolen coins hf recovery
|
||||
return '98MsWpiv3fcutf4Mm94wYKZeeS556EAvMWEBLc12y5nf5QzNtD6hDfCuWcJMUr9Q9qmbj8kS326EGuiiTW7YJDo';
|
||||
} elseif ($hash == 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCz9iKvAxdReMiDYmBWJb3GnjeTnNLwE8y7fuyBwFDbRLpECwnscbXSLGXMmvPMbMMRYSnnc7aTyLJBzw7tqxGNw4K'){
|
||||
// stolen coins hf recovery
|
||||
return '2xQGMH8qQuaTeKSYya5wYPWA9dgqiKBBDSeDWu1aUuBhKi8LnsukknqcUDRdzS7VVeC7aezK6Azhkx6L7H24pUjo';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// hashes 9 times in sha512 (binary) and encodes in base58
|
||||
for ($i = 0; $i < 9;
|
||||
$i++) {
|
||||
@@ -103,10 +135,10 @@ class Account
|
||||
if (strlen($id)<4||strlen($id)>25) {
|
||||
return false;
|
||||
}
|
||||
if($orig!=$id){
|
||||
if ($orig!=$id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// making sure the same alias can only be used in one place
|
||||
if ($db->single("SELECT COUNT(1) FROM accounts WHERE alias=:alias", [":alias"=>$id])==0) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -115,12 +147,16 @@ class Account
|
||||
}
|
||||
|
||||
//check if an account already has an alias
|
||||
public function has_alias($public_key){
|
||||
public function has_alias($public_key)
|
||||
{
|
||||
global $db;
|
||||
$public_key=san($public_key);
|
||||
$res=$db->single("SELECT COUNT(1) FROM accounts WHERE public_key=:public_key AND alias IS NOT NULL",[":public_key"=>$public_key]);
|
||||
if($res!=0) return true;
|
||||
else return false;
|
||||
$res=$db->single("SELECT COUNT(1) FROM accounts WHERE public_key=:public_key AND alias IS NOT NULL", [":public_key"=>$public_key]);
|
||||
if ($res!=0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//check alias validity
|
||||
@@ -137,25 +173,27 @@ class Account
|
||||
if (strlen($id)<4||strlen($id)>25) {
|
||||
return false;
|
||||
}
|
||||
if($orig!=$id){
|
||||
if ($orig!=$id) {
|
||||
return false;
|
||||
}
|
||||
return $db->single("SELECT COUNT(1) FROM accounts WHERE alias=:alias", [":alias"=>$id]);
|
||||
}
|
||||
|
||||
//returns the account of an alias
|
||||
public function alias2account($alias){
|
||||
public function alias2account($alias)
|
||||
{
|
||||
global $db;
|
||||
$alias=strtoupper($alias);
|
||||
$res=$db->single("SELECT id FROM accounts WHERE alias=:alias LIMIT 1",[":alias"=>$alias]);
|
||||
$res=$db->single("SELECT id FROM accounts WHERE alias=:alias LIMIT 1", [":alias"=>$alias]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
//returns the alias of an account
|
||||
public function account2alias($id){
|
||||
public function account2alias($id)
|
||||
{
|
||||
global $db;
|
||||
$id=san($id);
|
||||
$res=$db->single("SELECT alias FROM accounts WHERE id=:id LIMIT 1",[":id"=>$id]);
|
||||
$res=$db->single("SELECT alias FROM accounts WHERE id=:id LIMIT 1", [":id"=>$id]);
|
||||
return $res;
|
||||
}
|
||||
// check the validity of an address. At the moment, it checks only the characters to be base58 and the length to be >=70 and <=128.
|
||||
@@ -212,13 +250,14 @@ class Account
|
||||
$block = new Block();
|
||||
$current = $block->current();
|
||||
$public_key = $this->public_key($id);
|
||||
$alias = $this->account2alias($id);
|
||||
$limit = intval($limit);
|
||||
if ($limit > 100 || $limit < 1) {
|
||||
$limit = 100;
|
||||
}
|
||||
$res = $db->run(
|
||||
"SELECT * FROM transactions WHERE dst=:dst or public_key=:src ORDER by height DESC LIMIT :limit",
|
||||
[":src" => $public_key, ":dst" => $id, ":limit" => $limit]
|
||||
"SELECT * FROM transactions WHERE dst=:dst or public_key=:src or dst=:alias ORDER by height DESC LIMIT :limit",
|
||||
[":src" => $public_key, ":dst" => $id, ":limit" => $limit, ":alias"=>$alias]
|
||||
);
|
||||
|
||||
$transactions = [];
|
||||
@@ -299,11 +338,13 @@ class Account
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function get_masternode($public_key){
|
||||
public function get_masternode($public_key)
|
||||
{
|
||||
global $db;
|
||||
$res = $db->row("SELECT * FROM masternode WHERE public_key=:public_key", [":public_key" => $public_key]);
|
||||
if(empty($res['public_key'])) return false;
|
||||
if (empty($res['public_key'])) {
|
||||
return false;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -38,6 +38,10 @@ $_config['allowed_hosts'] = [
|
||||
'127.0.0.1',
|
||||
];
|
||||
|
||||
// Disable transactions and block repropagation
|
||||
$_config['disable_repropagation'] = false;
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Peer Configuration
|
||||
@@ -50,6 +54,41 @@ $_config['transaction_propagation_peers'] = 5;
|
||||
// How many new peers to check from each peer
|
||||
$_config['max_test_peers'] = 5;
|
||||
|
||||
// The initial peers to sync from in sanity
|
||||
$_config['initial_peer_list'] = [
|
||||
'http://peer1.arionum.com',
|
||||
'http://peer2.arionum.com',
|
||||
'http://peer3.arionum.com',
|
||||
'http://peer4.arionum.com',
|
||||
'http://peer5.arionum.com',
|
||||
'http://peer6.arionum.com',
|
||||
'http://peer7.arionum.com',
|
||||
'http://peer8.arionum.com',
|
||||
'http://peer9.arionum.com',
|
||||
'http://peer10.arionum.com',
|
||||
'http://peer11.arionum.com',
|
||||
'http://peer12.arionum.com',
|
||||
'http://peer13.arionum.com',
|
||||
'http://peer14.arionum.com',
|
||||
'http://peer15.arionum.com',
|
||||
'http://peer16.arionum.com',
|
||||
'http://peer17.arionum.com',
|
||||
'http://peer18.arionum.com',
|
||||
'http://peer19.arionum.com',
|
||||
'http://peer20.arionum.com',
|
||||
'http://peer21.arionum.com',
|
||||
'http://peer22.arionum.com',
|
||||
'http://peer23.arionum.com',
|
||||
'http://peer24.arionum.com',
|
||||
'http://peer25.arionum.com',
|
||||
'http://peer26.arionum.com',
|
||||
'http://peer27.arionum.com',
|
||||
];
|
||||
|
||||
// does not peer with any of the peers. Uses the seed peers and syncs only from those peers. Requires a cronjob on sanity.php
|
||||
$_config['passive_peering'] = false;
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Mempool Configuration
|
||||
@@ -65,6 +104,9 @@ $_config['max_mempool_rebroadcast'] = 5000;
|
||||
// The number of blocks between rebroadcasting transactions
|
||||
$_config['sanity_rebroadcast_height'] = 30;
|
||||
|
||||
// Block accepting transfers from addresses blacklisted by the Arionum devs
|
||||
$_config['use_official_blacklist'] = true;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanity Configuration
|
||||
@@ -72,7 +114,7 @@ $_config['sanity_rebroadcast_height'] = 30;
|
||||
*/
|
||||
|
||||
// Recheck the last blocks on sanity
|
||||
$_config['sanity_recheck_blocks'] = 10;
|
||||
$_config['sanity_recheck_blocks'] = 30;
|
||||
|
||||
// The interval to run the sanity in seconds
|
||||
$_config['sanity_interval'] = 900;
|
||||
@@ -84,7 +126,11 @@ $_config['allow_hostname_change'] = false;
|
||||
$_config['sanity_rebroadcast_locals'] = true;
|
||||
|
||||
// Get more peers?
|
||||
$_config['get_more_peers']=true;
|
||||
$_config['get_more_peers'] = true;
|
||||
|
||||
// Allow automated resyncs if the node is stuck. Enabled by default
|
||||
|
||||
$_config['auto_resync'] = true;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -112,3 +158,5 @@ $_config['masternode'] = false;
|
||||
|
||||
// The public key for the masternode
|
||||
$_config['masternode_public_key'] = '';
|
||||
$_config['masternode_voting_public_key'] = '';
|
||||
$_config['masternode_voting_private_key'] = '';
|
||||
@@ -24,6 +24,10 @@ function san_host($a)
|
||||
function api_err($data)
|
||||
{
|
||||
global $_config;
|
||||
|
||||
if (!headers_sent()) {
|
||||
header('Content-Type: application/json');
|
||||
}
|
||||
echo json_encode(["status" => "error", "data" => $data, "coin" => $_config['coin']]);
|
||||
exit;
|
||||
}
|
||||
@@ -32,6 +36,10 @@ function api_err($data)
|
||||
function api_echo($data)
|
||||
{
|
||||
global $_config;
|
||||
|
||||
if (!headers_sent()) {
|
||||
header('Content-Type: application/json');
|
||||
}
|
||||
echo json_encode(["status" => "ok", "data" => $data, "coin" => $_config['coin']]);
|
||||
exit;
|
||||
}
|
||||
@@ -39,6 +47,10 @@ function api_echo($data)
|
||||
// log function, shows only in cli atm
|
||||
function _log($data, $verbosity = 0)
|
||||
{
|
||||
global $_config;
|
||||
if ($_config['log_verbosity'] < $verbosity) {
|
||||
return;
|
||||
}
|
||||
$date = date("[Y-m-d H:i:s]");
|
||||
$trace = debug_backtrace();
|
||||
$loc = count($trace) - 1;
|
||||
@@ -56,7 +68,6 @@ function _log($data, $verbosity = 0)
|
||||
if (php_sapi_name() === 'cli') {
|
||||
echo $res;
|
||||
}
|
||||
global $_config;
|
||||
if ($_config['enable_logging'] == true && $_config['log_verbosity'] >= $verbosity) {
|
||||
@file_put_contents($_config['log_file'], $res, FILE_APPEND);
|
||||
}
|
||||
@@ -239,6 +250,11 @@ function ec_verify($data, $signature, $key)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// verify the validity of an url
|
||||
function isValidURL($url)
|
||||
{
|
||||
return preg_match('|^(ht)?(f)?tp(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
|
||||
}
|
||||
|
||||
// POST data to an URL (usualy peer). The data is an array, json encoded with is sent as $_POST['data']
|
||||
function peer_post($url, $data = [], $timeout = 60, $debug = false)
|
||||
@@ -247,6 +263,9 @@ function peer_post($url, $data = [], $timeout = 60, $debug = false)
|
||||
if ($debug) {
|
||||
echo "\nPeer post: $url\n";
|
||||
}
|
||||
if (!isValidURL($url)) {
|
||||
return false;
|
||||
}
|
||||
$postdata = http_build_query(
|
||||
[
|
||||
'data' => json_encode($data),
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
<?php
|
||||
// ARO version
|
||||
define("VERSION", "0.4.2");
|
||||
// Amsterdam timezone by default, should probably be moved to config
|
||||
define("VERSION", "1.0.0-alpha.7");
|
||||
// UTC timezone by default
|
||||
date_default_timezone_set("UTC");
|
||||
|
||||
//error_reporting(E_ALL & ~E_NOTICE);
|
||||
// error_reporting(E_ALL & ~E_NOTICE);
|
||||
error_reporting(0);
|
||||
ini_set('display_errors', "off");
|
||||
|
||||
ini_set('display_errors', 0);
|
||||
ini_set('display_startup_errors', 0);
|
||||
// not accessible directly
|
||||
if (php_sapi_name() !== 'cli' && substr_count($_SERVER['PHP_SELF'], "/") > 1) {
|
||||
die("This application should only be run in the main directory /");
|
||||
}
|
||||
|
||||
require_once("include/config.inc.php");
|
||||
require_once("include/db.inc.php");
|
||||
require_once("include/functions.inc.php");
|
||||
require_once("include/block.inc.php");
|
||||
require_once("include/account.inc.php");
|
||||
require_once("include/transaction.inc.php");
|
||||
require_once __DIR__.'/Exception.php';
|
||||
require_once __DIR__.'/config.inc.php';
|
||||
require_once __DIR__.'/db.inc.php';
|
||||
require_once __DIR__.'/functions.inc.php';
|
||||
require_once __DIR__.'/Blacklist.php';
|
||||
require_once __DIR__.'/InitialPeers.php';
|
||||
require_once __DIR__.'/block.inc.php';
|
||||
require_once __DIR__.'/account.inc.php';
|
||||
require_once __DIR__.'/transaction.inc.php';
|
||||
|
||||
if ($_config['db_pass'] == "ENTER-DB-PASS") {
|
||||
die("Please update your config file and set your db password");
|
||||
@@ -56,6 +59,20 @@ foreach ($query as $res) {
|
||||
$_config[$res['cfg']] = trim($res['val']);
|
||||
}
|
||||
|
||||
// current hostname
|
||||
$hostname = (!empty($_SERVER['HTTPS']) ? 'https' : 'http')."://".san_host($_SERVER['HTTP_HOST']);
|
||||
// set the hostname to the current one
|
||||
if ($hostname != $_config['hostname'] && $_SERVER['HTTP_HOST'] != "localhost" && $_SERVER['HTTP_HOST'] != "127.0.0.1" && $_SERVER['hostname'] != '::1' && php_sapi_name() !== 'cli' && ($_config['allow_hostname_change'] != false || empty($_config['hostname']))) {
|
||||
$db->run("UPDATE config SET val=:hostname WHERE cfg='hostname' LIMIT 1", [":hostname" => $hostname]);
|
||||
$_config['hostname'] = $hostname;
|
||||
}
|
||||
|
||||
// Getting extra configs from the database
|
||||
$query = $db->run("SELECT cfg, val FROM config");
|
||||
foreach ($query as $res) {
|
||||
$_config[$res['cfg']] = trim($res['val']);
|
||||
}
|
||||
|
||||
// nothing is allowed while in maintenance
|
||||
if ($_config['maintenance'] == 1) {
|
||||
api_err("under-maintenance");
|
||||
@@ -74,7 +91,7 @@ if (file_exists("tmp/db-update")) {
|
||||
$res = unlink("tmp/db-update");
|
||||
if ($res) {
|
||||
echo "Updating db schema! Please refresh!\n";
|
||||
require_once("include/schema.inc.php");
|
||||
require_once __DIR__.'/schema.inc.php';
|
||||
exit;
|
||||
}
|
||||
echo "Could not access the tmp/db-update file. Please give full permissions to this file\n";
|
||||
@@ -90,13 +107,7 @@ if ($_config['testnet'] == true) {
|
||||
$_config['coin'] .= "-testnet";
|
||||
}
|
||||
|
||||
// current hostname
|
||||
$hostname = (!empty($_SERVER['HTTPS']) ? 'https' : 'http')."://".san_host($_SERVER['HTTP_HOST']);
|
||||
// set the hostname to the current one
|
||||
if ($hostname != $_config['hostname'] && $_SERVER['HTTP_HOST'] != "localhost" && $_SERVER['HTTP_HOST'] != "127.0.0.1" && $_SERVER['hostname'] != '::1' && php_sapi_name() !== 'cli' && ($_config['allow_hostname_change'] != false || empty($_config['hostname']))) {
|
||||
$db->run("UPDATE config SET val=:hostname WHERE cfg='hostname' LIMIT 1", [":hostname" => $hostname]);
|
||||
$_config['hostname'] = $hostname;
|
||||
}
|
||||
|
||||
if (empty($_config['hostname']) || $_config['hostname'] == "http://" || $_config['hostname'] == "https://") {
|
||||
api_err("Invalid hostname");
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
// when db schema modifications are done, this function is run.
|
||||
$dbversion = intval($_config['dbversion']);
|
||||
|
||||
$db->beginTransaction();
|
||||
if ($dbversion == 0) {
|
||||
$db->run("
|
||||
@@ -146,7 +147,7 @@ if ($dbversion == 7) {
|
||||
$dbversion++;
|
||||
}
|
||||
if ($dbversion == 8) {
|
||||
$db->run("CREATE TABLE `masternode` (
|
||||
$db->run("CREATE TABLE `masternode` (
|
||||
`public_key` varchar(128) COLLATE utf8mb4_bin NOT NULL,
|
||||
`height` int(11) NOT NULL,
|
||||
`ip` varchar(16) COLLATE utf8mb4_bin NOT NULL,
|
||||
@@ -156,13 +157,108 @@ if ($dbversion == 8) {
|
||||
`status` tinyint(4) NOT NULL DEFAULT '1'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;");
|
||||
|
||||
$db->run("ALTER TABLE `masternode`
|
||||
$db->run("ALTER TABLE `masternode`
|
||||
ADD PRIMARY KEY (`public_key`),
|
||||
ADD KEY `last_won` (`last_won`),
|
||||
ADD KEY `status` (`status`),
|
||||
ADD KEY `blacklist` (`blacklist`),
|
||||
ADD KEY `height` (`height`);");
|
||||
$dbversion++;
|
||||
$dbversion++;
|
||||
}
|
||||
if ($dbversion == 9) {
|
||||
//dev only
|
||||
$dbversion++;
|
||||
}
|
||||
if ($dbversion == 10) {
|
||||
//assets system
|
||||
$db->run("
|
||||
CREATE TABLE `assets` (
|
||||
`id` varbinary(128) NOT NULL,
|
||||
`max_supply` bigint(18) NOT NULL DEFAULT '0',
|
||||
`tradable` tinyint(1) NOT NULL DEFAULT '1',
|
||||
`price` decimal(20,8) NOT NULL DEFAULT '0.00000000',
|
||||
`dividend_only` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`auto_dividend` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`allow_bid` tinyint(1) NOT NULL DEFAULT '1',
|
||||
`height` int(11) NOT NULL DEFAULT '0'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
");
|
||||
$db->run("
|
||||
ALTER TABLE `assets`
|
||||
ADD PRIMARY KEY (`id`)
|
||||
");
|
||||
$db->run("
|
||||
CREATE TABLE `assets_market` (
|
||||
`id` varchar(128) COLLATE utf8mb4_bin NOT NULL,
|
||||
`account` varbinary(128) NOT NULL,
|
||||
`asset` varbinary(128) NOT NULL,
|
||||
`price` decimal(20,8) NOT NULL,
|
||||
`date` int(11) NOT NULL,
|
||||
`status` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`type` enum('bid','ask') COLLATE utf8mb4_bin NOT NULL DEFAULT 'bid',
|
||||
`val` bigint(18) NOT NULL,
|
||||
`val_done` bigint(18) NOT NULL DEFAULT '0',
|
||||
`cancelable` tinyint(1) NOT NULL DEFAULT '1'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
");
|
||||
$db->run("
|
||||
ALTER TABLE `assets_market`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
");
|
||||
$db->run("CREATE TABLE `assets_balance` (
|
||||
`account` varbinary(128) NOT NULL,
|
||||
`asset` varbinary(128) NOT NULL,
|
||||
`balance` bigint(128) NOT NULL DEFAULT '0'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
");
|
||||
|
||||
$db->run("
|
||||
ALTER TABLE `assets_balance`
|
||||
ADD PRIMARY KEY (`account`,`asset`);
|
||||
");
|
||||
|
||||
$dbversion++;
|
||||
}
|
||||
|
||||
if ($dbversion == 11) {
|
||||
$db->run("ALTER TABLE `transactions` ADD INDEX(`version`); ");
|
||||
$db->run("ALTER TABLE `transactions` ADD INDEX(`message`); ");
|
||||
$db->run("
|
||||
CREATE TABLE `logs` (
|
||||
`id` int(11) NOT NULL,
|
||||
`transaction` varbinary(128) NULL DEFAULT NULL,
|
||||
`block` VARBINARY(128) NULL DEFAULT NULL,
|
||||
`json` text DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;");
|
||||
$db->run("ALTER TABLE `logs`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD INDEX(`transaction`),
|
||||
ADD INDEX(`block`);");
|
||||
$db->run("ALTER TABLE `logs` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;");
|
||||
|
||||
$db->run("ALTER TABLE `masternode` ADD `vote_key` VARCHAR(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL AFTER `status`, ADD INDEX(`vote_key`);");
|
||||
$db->run("ALTER TABLE `masternode` ADD `cold_last_won` INT NOT NULL DEFAULT '0' AFTER `vote_key`, ADD INDEX(`cold_last_won`); ");
|
||||
$db->run("ALTER TABLE `masternode` ADD `voted` TINYINT NOT NULL DEFAULT '0' AFTER `cold_last_won`, ADD INDEX (`voted`); ");
|
||||
|
||||
|
||||
|
||||
$db->run("CREATE TABLE `votes` (
|
||||
`id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||
`nfo` varchar(64) NOT NULL,
|
||||
`val` int(11) NOT NULL DEFAULT 0
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;");
|
||||
|
||||
|
||||
|
||||
$db->run("INSERT INTO `votes` (`id`, `nfo`, `val`) VALUES
|
||||
('coldstacking', 'Enable cold stacking for inactive masternodes', 1),
|
||||
('emission30', 'Emission reduction by 30 percent', 1),
|
||||
('endless10reward', 'Minimum reward to be 10 aro forever', 0),
|
||||
('masternodereward50', 'Masternode reward to be 50 percent of the block reward', 1);");
|
||||
|
||||
$db->run("ALTER TABLE `votes` ADD PRIMARY KEY (`id`);");
|
||||
|
||||
$dbversion++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,64 +1,113 @@
|
||||
<?php
|
||||
|
||||
use Arionum\Blacklist;
|
||||
|
||||
class Transaction
|
||||
{
|
||||
public function add_log($x, $log)
|
||||
{
|
||||
global $db;
|
||||
//$json=["table"=>"masternode", "key"=>"public_key","id"=>$x['public_key'], "vals"=>['ip'=>$current_ip] ];
|
||||
$db->run("INSERT into logs SET transaction=:id, json=:json", [':id'=>$x['id'], ":json"=>json_encode($log)]);
|
||||
}
|
||||
public function reverse_log($x)
|
||||
{
|
||||
global $db;
|
||||
$r=$db->run("SELECT json, id FROM logs WHERE transaction=:id ORDER by id DESC", [":id"=>$x['id']]);
|
||||
foreach ($r as $json) {
|
||||
$old=json_decode($json['json'], true);
|
||||
if ($old!==false&&is_array($old)) {
|
||||
//making sure there's no sql injection here, as the table name and keys are sanitized to A-Za-z0-9_
|
||||
$table=san($old['table']);
|
||||
$key=san($old['key'], '_');
|
||||
$id=san($old['id'], '_');
|
||||
foreach ($old['vals'] as $v=>$l) {
|
||||
$v=san($v, '_');
|
||||
$db->run("UPDATE `$table` SET `$v`=:val WHERE `$key`=:keyid", [":keyid"=>$id, ":val"=>$l]);
|
||||
}
|
||||
}
|
||||
$db->run("DELETE FROM logs WHERE id=:id",[":id"=>$json['id']]);
|
||||
}
|
||||
}
|
||||
// reverse and remove all transactions from a block
|
||||
public function reverse($block)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$acc = new Account();
|
||||
$r = $db->run("SELECT * FROM transactions WHERE block=:block ORDER by `version` ASC", [":block" => $block]);
|
||||
$r = $db->run("SELECT * FROM transactions WHERE block=:block ORDER by `version` DESC", [":block" => $block]);
|
||||
foreach ($r as $x) {
|
||||
_log("Reversing transaction $x[id]", 4);
|
||||
if (empty($x['src'])) {
|
||||
$x['src'] = $acc->get_address($x['public_key']);
|
||||
}
|
||||
if ($x['version'] == 2) {
|
||||
// payment sent to alias
|
||||
$db->run(
|
||||
$rez=$db->run(
|
||||
"UPDATE accounts SET balance=balance-:val WHERE alias=:alias",
|
||||
[":alias" => $x['dst'], ":val" => $x['val']]
|
||||
);
|
||||
if ($rez!=1) {
|
||||
_log("Update alias balance minus failed", 3);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// other type of transactions
|
||||
|
||||
if($x['version']!=100) { $db->run(
|
||||
"UPDATE accounts SET balance=balance-:val WHERE id=:id",
|
||||
[":id" => $x['dst'], ":val" => $x['val']]
|
||||
if ($x['version']!=100 && $x['version']<111 && $x['version'] != 54 && $x['version'] != 57 && $x['version'] != 58 && $x['val']>0) {
|
||||
$rez=$db->run(
|
||||
"UPDATE accounts SET balance=balance-:val WHERE id=:id",
|
||||
[":id" => $x['dst'], ":val" => $x['val']]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
if ($rez!=1) {
|
||||
_log("Update accounts balance minus failed - $x[id]", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// on version 0 / reward transaction, don't credit anyone
|
||||
if ($x['version'] > 0) {
|
||||
$db->run(
|
||||
if ($x['version'] > 0 && $x['version']<111 && $x['version'] != 54 && $x['version'] != 57 && $x['version'] != 58 && ($x['val']+$x['fee'])>0) {
|
||||
$rez=$db->run(
|
||||
"UPDATE accounts SET balance=balance+:val WHERE id=:id",
|
||||
[":id" => $x['src'], ":val" => $x['val'] + $x['fee']]
|
||||
);
|
||||
if ($rez!=1) {
|
||||
_log("Update account balance plus failed", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// removing the alias if the alias transaction is reversed
|
||||
if ($x['version']==3) {
|
||||
$db->run(
|
||||
$rez=$db->run(
|
||||
"UPDATE accounts SET alias=NULL WHERE id=:id",
|
||||
[":id" => $x['src']]
|
||||
);
|
||||
if ($rez!=1) {
|
||||
_log("Clear alias failed", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($x['version']>=100&&$x['version']<110&&$x['height']>=80000) {
|
||||
if ($x['version']==100) {
|
||||
$db->run("DELETE FROM masternode WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
$rez=$db->run("DELETE FROM masternode WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
if ($rez!=1) {
|
||||
_log("Delete from masternode failed", 3);
|
||||
return false;
|
||||
}
|
||||
} elseif ($x['version']==101) {
|
||||
$db->run(
|
||||
$rez=$db->run(
|
||||
"UPDATE masternode SET status=1 WHERE public_key=:public_key",
|
||||
[':public_key'=>$x['public_key']]
|
||||
[':public_key'=>$x['public_key']]
|
||||
);
|
||||
} elseif ($x['version']==102) {
|
||||
$db->run("UPDATE masternode SET status=0 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
$rez=$db->run("UPDATE masternode SET status=0 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
} elseif ($x['version']==103) {
|
||||
$mnt=$db->row("SELECT height, `message` FROM transactions WHERE version=100 AND public_key=:public_key ORDER by height DESC LIMIT 1", [":public_key"=>$x['public_key']]);
|
||||
$vers=$db->single(
|
||||
"SELECT `version` FROM transactions WHERE (version=101 or version=102) AND public_key=:public_key AND height>:height ORDER by height DESC LIMIT 1",
|
||||
[":public_key"=>$x['public_key'],":height"=>$mnt['height']]
|
||||
[":public_key"=>$x['public_key'],":height"=>$mnt['height']]
|
||||
);
|
||||
|
||||
$status=1;
|
||||
@@ -67,29 +116,117 @@ class Transaction
|
||||
$status=0;
|
||||
}
|
||||
|
||||
$db->run(
|
||||
$rez=$db->run(
|
||||
"INSERT into masternode SET `public_key`=:public_key, `height`=:height, `ip`=:ip, `status`=:status",
|
||||
[":public_key"=>$x['public_key'], ":height"=>$mnt['height'], ":ip"=>$mnt['message'], ":status"=>$status]
|
||||
[":public_key"=>$x['public_key'], ":height"=>$mnt['height'], ":ip"=>$mnt['message'], ":status"=>$status]
|
||||
);
|
||||
$db->run("UPDATE accounts SET balance=balance-100000 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
if ($rez!=1) {
|
||||
_log("Insert into masternode failed", 3);
|
||||
return false;
|
||||
}
|
||||
$rez=$db->run("UPDATE accounts SET balance=balance-100000 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
if ($rez!=1) {
|
||||
_log("Update masternode balance failed", 3);
|
||||
return false;
|
||||
}
|
||||
} elseif ($x['version']==104) {
|
||||
$this->reverse_log($x);
|
||||
} elseif ($x['version']==105) {
|
||||
$db->run("UPDATE masternode SET vote_key=NULL WHERE public_key=:public_key", [":public_key"=>$x['public_key']]);
|
||||
}
|
||||
}
|
||||
// internal masternode history
|
||||
if ($x['version']==111) {
|
||||
_log("Masternode reverse: $x[message]", 4);
|
||||
$m=explode(",", $x['message']);
|
||||
|
||||
$db->run(
|
||||
$rez=$db->run(
|
||||
"UPDATE masternode SET fails=:fails, blacklist=:blacklist, last_won=:last_won WHERE public_key=:public_key",
|
||||
[":public_key"=>$x['public_key'], ":blacklist"=> $m[0], ":fails"=>$m[2], ":last_won"=>$m[1]]
|
||||
[":public_key"=>$x['public_key'], ":blacklist"=> $m[0], ":fails"=>$m[2], ":last_won"=>$m[1]]
|
||||
);
|
||||
if ($rez!=1) {
|
||||
_log("Update masternode log failed", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// asset transactions
|
||||
if ($x['version']==50) {
|
||||
$db->run("DELETE FROM assets WHERE id=:id", [":id"=>$x['src']]);
|
||||
$db->run("DELETE FROM assets_balance WHERE asset=:id", [":id"=>$x['src']]);
|
||||
} elseif ($x['version']==51) {
|
||||
$t=json_decode($x['message'], true);
|
||||
$db->run(
|
||||
"UPDATE assets_balance SET balance=balance-:balance WHERE account=:account and asset=:asset",
|
||||
[":account"=>$x['dst'], ":asset"=>san($t[0]), ":balance"=>intval($t[1])]
|
||||
);
|
||||
$db->run("UPDATE assets_balance SET balance=balance+:balance WHERE account=:account and asset=:asset", [":account"=>$x['src'], ":asset"=>san($t[0]), ":balance"=>intval($t[1])]);
|
||||
} elseif ($x['version']==52) {
|
||||
$t=json_decode($x['message'], true);
|
||||
if ($t[4]=="ask") {
|
||||
$type="ask";
|
||||
} else {
|
||||
$type="bid";
|
||||
}
|
||||
if ($type=="ask") {
|
||||
$db->run("UPDATE assets_balance SET balance=balance+:val WHERE account=:account AND asset=:asset", [
|
||||
":account"=>$x['src'],
|
||||
":asset"=>san($t[0]),
|
||||
":val"=>intval($t[2])
|
||||
]);
|
||||
} else {
|
||||
$val=number_format($t[2]*$t[1], 8, '.', '');
|
||||
$db->run("UPDATE accounts SET balance=balance+:val WHERE id=:id", [":id"=>$x['src'], ":val"=>$val]);
|
||||
}
|
||||
$db->run("DELETE FROM assets_market WHERE id=:id", [':id'=>$x['id']]);
|
||||
} elseif ($x['version']==53) {
|
||||
$order=$db->row("SELECT * FROM assets_market WHERE id=:id AND account=:account AND status=2", [":id"=>san($x['message']), ":account"=>$x['src']]);
|
||||
if ($order) {
|
||||
$remaining=$order['val']-$order['val_done'];
|
||||
if ($remaining>0) {
|
||||
if ($order['type']=="ask") {
|
||||
$db->run("UPDATE assets_balance SET balance=balance-:val WHERE account=:account AND asset=:asset", [
|
||||
":account"=>$x['src'],
|
||||
":asset"=>san($order['asset']),
|
||||
":val"=>intval($remaining)
|
||||
]);
|
||||
} else {
|
||||
$val=number_format($order['price']*$remaining, 8, '.', '');
|
||||
$db->run("UPDATE accounts SET balance=balance-:val WHERE id=:id", [":id"=>$x['src'], ":val"=>$val]);
|
||||
}
|
||||
$db->run("UPDATE assets_market SET status=0 WHERE id=:id", [":id"=>san($x['message'])]);
|
||||
}
|
||||
}
|
||||
} elseif ($x['version']==54||$x['version']==57) {
|
||||
//nothing to be done
|
||||
} elseif ($x['version']==55) {
|
||||
// the message stores the increment value
|
||||
$plus=intval($x['message']);
|
||||
$db->run("UPDATE assets_balance SET balance=balance-:plus WHERE account=:account AND asset=:asset", [":account"=>$x['src'], ":asset"=>$x['src'], ":plus"=>$plus]);
|
||||
} elseif ($x['version']==58) {
|
||||
// the message stores the number of units
|
||||
$use=intval($x['message']);
|
||||
// we stored the bid order id in the public key field and the ask in the dst field
|
||||
$db->run("UPDATE assets_market SET val_done=val_done-:done WHERE id=:id", [":id"=>$x['public_key'], ":done"=>$use]);
|
||||
$db->run("UPDATE assets_market SET val_done=val_done-:done WHERE id=:id", [":id"=>$x['dst'], ":done"=>$use]);
|
||||
|
||||
$bid=$db->row("SELECT * FROM assets_market WHERE id=:id", [':id'=>$x['public_key']]);
|
||||
$ask=$db->row("SELECT * FROM assets_market WHERE id=:id", [':id'=>$x['dst']]);
|
||||
|
||||
$db->run("UPDATE assets_balance SET balance=balance-:balance WHERE account=:account AND asset=:asset", [":account"=>$bid['account'], ":asset"=>$bid['asset'], ":balance"=>$use]);
|
||||
$aro=$x['val'];
|
||||
$db->run("UPDATE accounts SET balance=balance-:balance WHERE id=:id", [":balance"=>$aro, ":id"=>$ask['account']]);
|
||||
}
|
||||
|
||||
|
||||
// add the transactions to mempool
|
||||
if ($x['version'] > 0 && $x['version']<=110) {
|
||||
if ($x['version'] > 0 && $x['version']<=110 && $x['version'] != 59 && $x['version'] != 58 && $x['version'] != 57) {
|
||||
$this->add_mempool($x);
|
||||
}
|
||||
$res = $db->run("DELETE FROM transactions WHERE id=:id", [":id" => $x['id']]);
|
||||
if ($res != 1) {
|
||||
_log("Delete transaction failed", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -122,6 +259,7 @@ class Transaction
|
||||
if (count($r) > 0) {
|
||||
$i = 0;
|
||||
$balance = [];
|
||||
$assets=0;
|
||||
foreach ($r as $x) {
|
||||
$trans = [
|
||||
"id" => $x['id'],
|
||||
@@ -139,6 +277,24 @@ class Transaction
|
||||
break;
|
||||
}
|
||||
|
||||
//only a single asset creation per block
|
||||
if ($x['version']==50) {
|
||||
$assets++;
|
||||
if ($assets>1) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// single blockchain vote per block
|
||||
|
||||
if ($x['version']==106||$x['version']==107) {
|
||||
$tid=$x['public_key'].$x['message'];
|
||||
if ($exists[$tid]==1) {
|
||||
continue;
|
||||
}
|
||||
$exists[$tid]=1;
|
||||
}
|
||||
|
||||
|
||||
if (empty($x['public_key'])) {
|
||||
_log("$x[id] - Transaction has empty public_key");
|
||||
continue;
|
||||
@@ -182,10 +338,17 @@ class Transaction
|
||||
public function add_mempool($x, $peer = "")
|
||||
{
|
||||
global $db;
|
||||
global $_config;
|
||||
$block = new Block();
|
||||
if ($x['version']>110) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($_config['use_official_blacklist']!==false) {
|
||||
if (Blacklist::checkPublicKey($x['public_key']) || Blacklist::checkAddress($x['src'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$current = $block->current();
|
||||
$height = $current['height'];
|
||||
$x['id'] = san($x['id']);
|
||||
@@ -205,7 +368,7 @@ class Transaction
|
||||
];
|
||||
|
||||
//only a single masternode command of same type, per block
|
||||
if ($x['version']>=100&&$x['version']<110) {
|
||||
if ($x['version']>=100&&$x['version']<110&&$x['version']!=106&&$x['version']!=107) {
|
||||
$check=$db->single("SELECT COUNT(1) FROM mempool WHERE public_key=:public_key", [":public_key"=>$x['public_key']]);
|
||||
if ($check!=0) {
|
||||
_log("Masternode transaction already in mempool", 3);
|
||||
@@ -225,9 +388,14 @@ class Transaction
|
||||
{
|
||||
global $db;
|
||||
$acc = new Account();
|
||||
$acc->add($x['public_key'], $block);
|
||||
if ($x['version']==1) {
|
||||
$acc->add_id($x['dst'], $block);
|
||||
// not a valid or useful public key for internal transactions
|
||||
if ($x['version']!=58 && $x['version']!=59) {
|
||||
// add the public key to the accounts table
|
||||
$acc->add($x['public_key'], $block);
|
||||
if ($x['version']==1 || $x['version'] == 51) {
|
||||
// make sure the destination address in on the accounts table as well
|
||||
$acc->add_id($x['dst'], $block);
|
||||
}
|
||||
}
|
||||
$x['id'] = san($x['id']);
|
||||
$bind = [
|
||||
@@ -250,23 +418,31 @@ class Transaction
|
||||
if ($res != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// market order side chain
|
||||
if ($x['version']==58) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($x['version'] == 2&&$height>=80000) {
|
||||
$db->run("UPDATE accounts SET balance=balance+:val WHERE alias=:alias", [":alias" => $x['dst'], ":val" => $x['val']]);
|
||||
} elseif ($x['version']==50||$x['version']==54||$x['version']==57) {
|
||||
// asset creation and dividend distribution
|
||||
} elseif ($x['version']==100&&$height>=80000) {
|
||||
//master node deposit
|
||||
} elseif ($x['version']==103&&$height>=80000) {
|
||||
$blk=new Block();
|
||||
$blk->masternode_log($x['public_key'],$height,$block);
|
||||
$blk->masternode_log($x['public_key'], $height, $block);
|
||||
|
||||
//master node withdrawal
|
||||
//master node withdrawal
|
||||
} else {
|
||||
$db->run("UPDATE accounts SET balance=balance+:val WHERE id=:id", [":id" => $x['dst'], ":val" => $x['val']]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// no debit when the transaction is reward
|
||||
if ($x['version'] > 0) {
|
||||
// no debit when the transaction is reward or dividend distribution
|
||||
if ($x['version'] > 0 && $x['version'] != 54 && $x['version'] != 57) {
|
||||
$db->run(
|
||||
"UPDATE accounts SET balance=(balance-:val)-:fee WHERE id=:id",
|
||||
[":id" => $x['src'], ":val" => $x['val'], ":fee" => $x['fee']]
|
||||
@@ -277,8 +453,8 @@ class Transaction
|
||||
// set the alias
|
||||
if ($x['version']==3&&$height>=80000) {
|
||||
$db->run(
|
||||
"UPDATE accounts SET alias=:alias WHERE id=:id",
|
||||
[":id" => $x['src'], ":alias"=>$x['message']]
|
||||
"UPDATE accounts SET alias=:alias WHERE id=:id",
|
||||
[":id" => $x['src'], ":alias"=>$x['message']]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -290,16 +466,142 @@ class Transaction
|
||||
$db->run("INSERT into masternode SET `public_key`=:public_key, `height`=:height, `ip`=:ip, `status`=1", [":public_key"=>$x['public_key'], ":height"=>$height, ":ip"=>$message]);
|
||||
} else {
|
||||
if ($x['version']==101) {
|
||||
// pause masternode
|
||||
$db->run("UPDATE masternode SET status=0 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
} elseif ($x['version']==102) {
|
||||
// reactivate pasternode
|
||||
$db->run("UPDATE masternode SET status=1 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
} elseif ($x['version']==103) {
|
||||
// release and cancel the masternode
|
||||
$db->run("DELETE FROM masternode WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
$db->run("UPDATE accounts SET balance=balance+100000 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
} elseif ($x['version']==104) {
|
||||
// update ip
|
||||
$current_ip=$db->single("SELECT ip FROM masternode WHERE public_key=:public_key", [":public_key"=>$x['public_key']]);
|
||||
$json=["table"=>"masternode", "key"=>"public_key","id"=>$x['public_key'], "vals"=>['ip'=>$current_ip] ];
|
||||
$this->add_log($x, $json);
|
||||
$db->run("UPDATE masternode SET ip=:ip WHERE public_key=:public_key", [':ip'=>$message, ":public_key"=>$x['public_key']]);
|
||||
} elseif ($x['version']==105) {
|
||||
// add vote key
|
||||
$db->run("UPDATE masternode SET vote_key=:vote_key WHERE public_key=:public_key AND vote_key is NULL", [':vote_key'=>san($x['message']), ":public_key"=>$x['public_key']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// asset system
|
||||
if ($x['version']==50) {
|
||||
// asset creation
|
||||
$bind=[];
|
||||
$asset=json_decode($x['message'], true);
|
||||
$bind[':max_supply']=intval($asset[0]);
|
||||
$bind[':tradable']=intval($asset[1]);
|
||||
$bind[':price']=number_format($asset[2], 8, '.', '');
|
||||
$bind[':dividend_only']=intval($asset[3]);
|
||||
$bind[':auto_divident']=intval($asset[4]);
|
||||
$bind[':allow_bid']=intval($asset[5]);
|
||||
$bind[':height']=$height;
|
||||
$bind[':id']=$x['src'];
|
||||
$db->run("INSERT into assets SET id=:id, max_supply=:max_supply, tradable=:tradable, price=:price, dividend_only=:dividend_only, auto_dividend=:auto_divident, height=:height, allow_bid=:allow_bid", $bind);
|
||||
if ($bind[':max_supply']>0) {
|
||||
$db->run("INSERT into assets_balance SET account=:account, asset=:asset, balance=:balance", [":account"=>$x['src'], ":asset"=>$x['src'], ":balance"=>$bind[':max_supply']]);
|
||||
}
|
||||
} elseif ($x['version']==51) {
|
||||
// send asset
|
||||
$t=json_decode($x['message'], true);
|
||||
$db->run(
|
||||
"INSERT into assets_balance SET account=:account, asset=:asset, balance=:balance ON DUPLICATE KEY UPDATE balance=balance+:balance2",
|
||||
[":account"=>$x['dst'], ":asset"=>san($t[0]), ":balance"=>intval($t[1]), ":balance2"=>intval($t[1])]
|
||||
);
|
||||
$db->run("UPDATE assets_balance SET balance=balance-:balance WHERE account=:account and asset=:asset", [":account"=>$x['src'], ":asset"=>san($t[0]), ":balance"=>intval($t[1])]);
|
||||
} elseif ($x['version']==52) {
|
||||
// market order
|
||||
$t=json_decode($x['message'], true);
|
||||
|
||||
if ($t[4]=="ask") {
|
||||
$type="ask";
|
||||
} else {
|
||||
$type="bid";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$bind=[":id" => san($x['id']),
|
||||
":account" => $x['src'],
|
||||
":asset" => san($t[0]),
|
||||
":price" => number_format($t[1], 8, '.', ''),
|
||||
":date" => $x['date'],
|
||||
":val"=>intval($t[2]),
|
||||
":type" => $type,
|
||||
":cancel" => intval($t[3])
|
||||
];
|
||||
$db->run("INSERT into assets_market SET id=:id, account=:account, asset=:asset, price=:price, `date`=:date, status=0, `type`=:type, val=:val, val_done=0, cancelable=:cancel", $bind);
|
||||
|
||||
if ($type=="ask") {
|
||||
$db->run("UPDATE assets_balance SET balance=balance-:val WHERE account=:account AND asset=:asset", [
|
||||
":account"=>$x['src'],
|
||||
":asset"=>san($t[0]),
|
||||
":val"=>intval($t[2])
|
||||
]);
|
||||
} else {
|
||||
$val=number_format($t[2]*$t[1], 8, '.', '');
|
||||
$db->run("UPDATE accounts SET balance=balance-:val WHERE id=:id", [":id"=>$x['src'], ":val"=>$val]);
|
||||
}
|
||||
} elseif ($x['version']==53) {
|
||||
// cancel order
|
||||
$order=$db->row("SELECT * FROM assets_market WHERE id=:id AND account=:account AND status=0", [":id"=>san($x['message']), ":account"=>$x['src']]);
|
||||
if ($order) {
|
||||
$remaining=$order['val']-$order['val_done'];
|
||||
if ($remaining>0) {
|
||||
if ($order['type']=="ask") {
|
||||
$db->run("UPDATE assets_balance SET balance=balance+:val WHERE account=:account AND asset=:asset", [
|
||||
":account"=>$x['src'],
|
||||
":asset"=>san($order['asset']),
|
||||
":val"=>intval($remaining)
|
||||
]);
|
||||
} else {
|
||||
$val=number_format($order['price']*$remaining, 8, '.', '');
|
||||
$db->run("UPDATE accounts SET balance=balance+:val WHERE id=:id", [":id"=>$x['src'], ":val"=>$val]);
|
||||
}
|
||||
$db->run("UPDATE assets_market SET status=2 WHERE id=:id", [":id"=>san($x['message'])]);
|
||||
}
|
||||
}
|
||||
} elseif ($x['version']==54||$x['version']==57) {
|
||||
//distribute dividends - only from asset wallet and only to other holders
|
||||
|
||||
$r=$db->run("SELECT * FROM assets_balance WHERE asset=:asset AND balance>0 AND account!=:acc", [":asset"=>$x['src'], ":acc"=>$x['src']]);
|
||||
$total=0;
|
||||
foreach ($r as $g) {
|
||||
$total+=$g['balance'];
|
||||
}
|
||||
_log("Asset dividend distribution: $total units", 3);
|
||||
foreach ($r as $g) {
|
||||
$coins=number_format(($g['balance']/$total)*$x['val'], 8, '.', '');
|
||||
$fee=number_format(($g['balance']/$total)*$x['fee'], 8, '.', '');
|
||||
$hash = hex2coin(hash("sha512", $x['id'].$g['account']));
|
||||
_log("Distributing to $g[account] for $g[balance] units - $coins ARO", 3);
|
||||
|
||||
$new = [
|
||||
"id" => $hash,
|
||||
"public_key" => $x['public_key'],
|
||||
"dst" => $g['account'],
|
||||
"val" => $coins,
|
||||
"fee" => $fee,
|
||||
"signature" => $x['signature'],
|
||||
"version" => 59,
|
||||
"date" => $x['date'],
|
||||
"src" => $x['src'],
|
||||
"message" => '',
|
||||
];
|
||||
$res=$this->add($block, $height, $new);
|
||||
if (!$res) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} elseif ($x['version']==55) {
|
||||
// increase max supply
|
||||
$plus=intval($x['message']);
|
||||
$db->run("INSERT into assets_balance SET balance=:plus, account=:account, asset=:asset ON DUPLICATE KEY UPDATE balance=balance+:plus2", [":account"=>$x['src'], ":asset"=>$x['src'], ":plus"=>$plus, ":plus2"=>$plus]);
|
||||
}
|
||||
|
||||
|
||||
$db->run("DELETE FROM mempool WHERE id=:id", [":id" => $x['id']]);
|
||||
@@ -311,12 +613,20 @@ class Transaction
|
||||
{
|
||||
$info = $x['val']."-".$x['fee']."-".$x['dst']."-".$x['message']."-".$x['version']."-".$x['public_key']."-".$x['date']."-".$x['signature'];
|
||||
$hash = hash("sha512", $info);
|
||||
//_log("Hashing: ".$info,3);
|
||||
//_log("Hash: $hash",3);
|
||||
return hex2coin($hash);
|
||||
}
|
||||
|
||||
// check the transaction for validity
|
||||
public function check($x, $height = 0)
|
||||
{
|
||||
global $db;
|
||||
// blocktime lowered by 1 minute after 216000
|
||||
$blocktime_factor=1;
|
||||
if($height>216000){
|
||||
$blocktime_factor=4;
|
||||
}
|
||||
// if no specific block, use current
|
||||
if ($height === 0) {
|
||||
$block = new Block();
|
||||
@@ -326,15 +636,17 @@ class Transaction
|
||||
$acc = new Account();
|
||||
$info = $x['val']."-".$x['fee']."-".$x['dst']."-".$x['message']."-".$x['version']."-".$x['public_key']."-".$x['date'];
|
||||
|
||||
$src = $acc->get_address($x['public_key']);
|
||||
|
||||
// hard fork at 80000 to implement alias, new mining system, assets
|
||||
// if($x['version']>1 && $height<80000){
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// internal transactions
|
||||
if($x['version']>110){
|
||||
if ($x['version']>110 || $x['version'] == 57 || $x['version'] == 58 || $x['version'] == 59) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// the value must be >=0
|
||||
if ($x['val'] < 0) {
|
||||
@@ -366,8 +678,15 @@ class Transaction
|
||||
_log("The account already has an alias", 3);
|
||||
return false;
|
||||
}
|
||||
if ($x['dst']!=$src) {
|
||||
// just to prevent some bypasses in the future
|
||||
_log("DST must be SRC for this transaction", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//masternode transactions
|
||||
|
||||
if ($x['version']>=100&&$x['version']<110&&$height>=80000) {
|
||||
@@ -378,6 +697,11 @@ class Transaction
|
||||
_log("The Masternode IP is invalid", 3);
|
||||
return false;
|
||||
}
|
||||
global $db;
|
||||
$existing=$db->single("SELECT COUNT(1) FROM masternode WHERE public_key=:id or ip=:ip", ["id"=>$x['public_key'], ":ip"=>$message]);
|
||||
if ($existing!=0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -386,7 +710,12 @@ class Transaction
|
||||
return false;
|
||||
} elseif ($x['version']!=100) {
|
||||
$mn=$acc->get_masternode($x['public_key']);
|
||||
|
||||
|
||||
if ($x['dst']!=$src&&$x['version']!=106) {
|
||||
// just to prevent some bypasses in the future
|
||||
_log("DST must be SRC for this transaction", 3);
|
||||
return false;
|
||||
}
|
||||
if (!$mn) {
|
||||
_log("The masternode does not exist", 3);
|
||||
return false;
|
||||
@@ -401,17 +730,283 @@ class Transaction
|
||||
if ($mn['status']!=0) {
|
||||
_log("The masternode is not paused", 3);
|
||||
return false;
|
||||
} elseif ($height-$mn['last_won']<10800) { //10800
|
||||
} elseif ($height-$mn['last_won']<10800*$blocktime_factor) { //10800
|
||||
_log("The masternode last won block is less than 10800 blocks", 3);
|
||||
return false;
|
||||
} elseif ($height-$mn['height']<32400) { //32400
|
||||
} elseif ($height-$mn['height']<32400*$blocktime_factor) { //32400
|
||||
_log("The masternode start height is less than 32400 blocks! $height - $mn[height]", 3);
|
||||
return false;
|
||||
}
|
||||
} elseif ($x['version']==104) {
|
||||
//only once per month (every 43200 blocks)
|
||||
$res=$db->single("SELECT COUNT(1) FROM transactions WHERE public_key=:public_key AND version=104 AND height>:height", [':public_key'=>$x['public_key'], ":height"=>$height-43200]);
|
||||
if ($res!=0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// already using this ip
|
||||
if ($message==$mn['ip']) {
|
||||
return false;
|
||||
}
|
||||
// valid ips
|
||||
$message=$x['message'];
|
||||
$message=preg_replace("/[^0-9\.]/", "", $message);
|
||||
if (!filter_var($message, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
|
||||
_log("The Masternode IP is invalid", 3);
|
||||
return false;
|
||||
}
|
||||
// making sure the ip is not already in use
|
||||
global $db;
|
||||
$existing=$db->single("SELECT COUNT(1) FROM masternode WHERE ip=:ip", [":ip"=>$message]);
|
||||
if ($existing!=0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} elseif ($x['version']==105) {
|
||||
// masternode voting key can only be set once
|
||||
if(!empty($mn['vote_key'])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// masternode votes
|
||||
elseif ($x['version']==106) {
|
||||
// value always 0
|
||||
if ($x['val']!=0) {
|
||||
return false;
|
||||
}
|
||||
// one vote to each mn per 43200 blocks
|
||||
$res=$db->single("SELECT COUNT(1) FROM transactions WHERE dst=:dst AND version=106 AND public_key=:id AND height>:height", [':dst'=>$x['dst'], ":id"=>$x['public_key'], ":height"=>$height-43200]);
|
||||
if ($res>0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// masternode blockchain votes
|
||||
elseif ($x['version']==107) {
|
||||
// value always 0
|
||||
if ($x['val']!=0) {
|
||||
_log("The value should be 0 for this transaction type - $x[val]",3);
|
||||
return false;
|
||||
}
|
||||
|
||||
// one vote to each mn per 129600 blocks
|
||||
$res=$db->single("SELECT COUNT(1) FROM transactions WHERE message=:message AND version=107 AND public_key=:id AND height>:height", [':message'=>$x['message'], ":id"=>$x['public_key'], ":height"=>$height-129600]);
|
||||
if ($res>0) {
|
||||
_log("There is already a vote in the last 129600 blocks",3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// no asset transactions prior to 216000
|
||||
if($x['version']>=50&&$x['version']<=55&&$height<=216000){
|
||||
return false;
|
||||
}
|
||||
// no masternode voting prior to 216000
|
||||
if(($x['version']==106||$x['version']==107||$x['version']==105||$x['version']==104)&&$height<=216000){
|
||||
return false;
|
||||
}
|
||||
// assets
|
||||
if ($x['version']==50) {
|
||||
// asset creation
|
||||
// fixed asset price 100 +. The 100 are burned and not distributed to miners.
|
||||
if ($x['val']!=100) {
|
||||
_log("The asset creation transaction is not 100", 3);
|
||||
return false;
|
||||
}
|
||||
// stored in message in json format - [max supply, tradable, fixed price, dividend only, autodividend]
|
||||
$asset=json_decode($x['message'], true);
|
||||
if ($asset==false) {
|
||||
_log("Invalid asset creation json", 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
// minimum 0 (for inflatable assets) and maximum 1.000.000.000
|
||||
if ($asset[0]>1000000000||$asset[0]<0||intval($asset[0])!=$asset[0]) {
|
||||
_log("Invalid asset max supply", 3);
|
||||
return false;
|
||||
}
|
||||
// 0 for non-tradable, 1 for tradable on the blockchain market
|
||||
if ($asset[1]!==1&&$asset[1]!==0) {
|
||||
_log("Invalid asset tradable", 3);
|
||||
return false;
|
||||
}
|
||||
// If the price is set, it cannot be sold by the asset wallet at a dfferent price. Max price 1.000.000 aro
|
||||
if (number_format($asset[2], 8, '.', '')!=$asset[2]||$asset[2]<0||$asset[2]>1000000) {
|
||||
_log("Invalid asset price", 3);
|
||||
return false;
|
||||
}
|
||||
// 1 to allow only dividend distribution, 0 to allow all transfers
|
||||
if ($asset[3]!==1&&$asset[3]!==0) {
|
||||
_log("Invalid asset dividend setting", 3);
|
||||
return false;
|
||||
}
|
||||
// automatic dividend distribution every 10000 blocks
|
||||
if ($asset[4]!==1&&$asset[4]!==0) {
|
||||
_log("Invalid asset autodividend setting", 3);
|
||||
return false;
|
||||
}
|
||||
// do not allow this asset to buy other assets via the market
|
||||
if ($asset[5]!==1&&$asset[5]!==0) {
|
||||
_log("Invalid asset bid_only setting", 3);
|
||||
return false;
|
||||
}
|
||||
// make sure there is no similar asset with the same alias
|
||||
$chk=$db->single("SELECT COUNT(1) FROM assets WHERE id=:id", [":id"=>$src]);
|
||||
if ($chk!==0) {
|
||||
_log("The asset already exists", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// asset transfer
|
||||
if ($x['version']==51) {
|
||||
// Transfer details in json format, stored in the message. format: [asset id, units]
|
||||
// The transfer is done to the dst address of the transactions
|
||||
$asset=json_decode($x['message'], true);
|
||||
if ($asset==false) {
|
||||
_log("Invalid asset creation json", 3);
|
||||
return false;
|
||||
}
|
||||
// check if the asset exists
|
||||
$blockasset=$db->row("SELECT id, price FROM assets WHERE id=:id", [":id"=>san($asset[0])]);
|
||||
if (!$blockasset) {
|
||||
_log("Invalid asset", 3);
|
||||
return false;
|
||||
}
|
||||
// minimum 1 unit is transfered
|
||||
if (intval($asset[1])!=$asset[1]||$asset[1]<1) {
|
||||
_log("Invalid amount", 3);
|
||||
return false;
|
||||
}
|
||||
//make sure the wallet has enough asset units
|
||||
$balance=$db->single("SELECT balance FROM assets_balance WHERE account=:account AND asset=:asset", [":account"=>$src, ":asset"=>san($asset[0])]);
|
||||
if ($balance<=$asset[1]) {
|
||||
_log("Not enough balance", 3);
|
||||
return false;
|
||||
}
|
||||
if ($blockasset['price']>0 && $src == $blockasset['id'] && $blockasset['price']!=$asset[1] && $blockasset['tradable'] ==1) {
|
||||
// if the asset has a price defined, check if the asset wallet owns all the asset units and only in this case allow transfers. In such cases, the asset should be sold on market
|
||||
// on a fixed price always
|
||||
$chk=$db->single("SELECT COUNT(1) FROM assets_balance WHERE asset=:asset AND account!=:account", [":account"=>$src, ":asset"=>$src]);
|
||||
if ($chk!=0) {
|
||||
_log("Initial asset distribution already done. Market orders only on fixed price.", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// make sure the dividend only function is not bypassed after height X
|
||||
if (($x['version']==1||$x['version']==2)&&$height>216000) {
|
||||
$check=$db->single("SELECT COUNT(1) FROM assets WHERE id=:id AND dividend_only=1", [":id"=>$src]);
|
||||
if ($check==1) {
|
||||
_log("This asset wallet cannot send funds directly", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// asset market orders
|
||||
|
||||
if ($x['version']==52) {
|
||||
|
||||
// we store the order details in a json array on the format [asset_id, price, amount of asset units, cancelable, order type ]
|
||||
$asset=json_decode($x['message'], true);
|
||||
if ($asset==false) {
|
||||
_log("Invalid asset creation json", 3);
|
||||
return false;
|
||||
}
|
||||
// only ask and bid allowed
|
||||
if ($asset[4]!="ask"&&$asset[4]!="bid") {
|
||||
_log("Invalid asset order type", 3);
|
||||
return false;
|
||||
}
|
||||
$type=san($asset[4]);
|
||||
|
||||
$blockasset=$db->row("SELECT * FROM assets WHERE id=:id", [":id"=>san($asset[0])]);
|
||||
if (!$blockasset||$blockasset['tradable']!=1) {
|
||||
_log("Invalid asset", 3);
|
||||
return false;
|
||||
}
|
||||
// the sale price per unit has to be at least 0.00000001 or max 1000000 aro
|
||||
if (number_format($asset[1], 8, '.', '')!=$asset[1]||$asset[1]<=0||$asset[1]>1000000) {
|
||||
_log("Invalid asset price", 3);
|
||||
return false;
|
||||
}
|
||||
// integer min 1 and max 1000000
|
||||
if (intval($asset[2])!=$asset[2]||$asset[2]<1||$asset[2]>1000000) {
|
||||
_log("Invalid asset value", 3);
|
||||
return false;
|
||||
}
|
||||
// if the order should be cancelable or not
|
||||
if ($asset[3]!=1&&$asset[3]!=0) {
|
||||
_log("Invalid asset cancel setting", 3);
|
||||
return false;
|
||||
}
|
||||
// the type of order, ask or bid
|
||||
if ($type=="ask") {
|
||||
$balance=$db->single("SELECT balance FROM assets_balance WHERE asset=:asset AND account=:account", [":account"=>$src, ":asset"=>$asset[0]]);
|
||||
if ($balance<$asset[2]) {
|
||||
_log("Not enough asset balance", 3);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$balance=$acc->balance($src);
|
||||
if ($balance<$asset[2]*$asset[1]) {
|
||||
_log("Not enough aro balance", 3);
|
||||
return false;
|
||||
}
|
||||
if ($blockasset['id']!=$src) {
|
||||
$asset_bids_allowed=$db->single("SELECT COUNT(1) FROM assets WHERE id=:id AND allow_bid=0", [":id"=>$src]);
|
||||
if ($asset_bids_allowed==1) {
|
||||
_log("This wallet asset is not allowed to buy other assets", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($blockasset['id']==$src && $blockasset['price']>0 && $blockasset['price']!=$asset[1]) {
|
||||
// In case the asset has fixed price, the asset wallet cannot sell on a different price (to prevent abuse by the owner)
|
||||
_log("This asset has fixed market price when sold by it's wallet", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($x['version']==53) {
|
||||
if (san($x['message'])!=$x['message']) {
|
||||
_log("Invalid order id - $x[message]", 3);
|
||||
return false;
|
||||
}
|
||||
$chk=$db->single("SELECT COUNT(1) FROM assets_market WHERE id=:id AND account=:src AND val_done<val AND status=0 AND cancelable=1", [":id"=>san($x['message']), ":src"=>$src]);
|
||||
if ($chk!=1) {
|
||||
_log("Invalid order - $x[message]", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($x['version']==54) {
|
||||
$balance=$acc->balance($src);
|
||||
if ($balance<$x['val']||$x['val']<0.00000001) {
|
||||
_log("Not enough aro balance", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($x['version']==55) {
|
||||
$plus=intval($x['message']);
|
||||
if ($x['message']!=$plus) {
|
||||
_log("Invalid asset value", 3);
|
||||
return false;
|
||||
}
|
||||
$test=$db->single("SELECT COUNT(1) FROM assets WHERE id=:id AND max_supply=0", [":id"=>$src]);
|
||||
if ($test!=1) {
|
||||
_log("Asset not inflatable", 3);
|
||||
return false;
|
||||
}
|
||||
$total=$db->single("SELECT SUM(balance) FROM assets_balance WHERE asset=:id", [":id"=>$src]);
|
||||
$total+=$db->single("SELECT SUM(val-val_done) FROM assets_market WHERE status=0 AND type='ask' AND asset=:id", [":id"=>$src]);
|
||||
if ($total+$plus>1000000000) {
|
||||
_log("Maximum asset unit limits reached", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// max fee after block 10800 is 10
|
||||
if ($height > 10800 && $fee > 10) {
|
||||
@@ -479,10 +1074,26 @@ class Transaction
|
||||
}
|
||||
}
|
||||
|
||||
//verify the ecdsa signature
|
||||
if (!$acc->check_signature($info, $x['signature'], $x['public_key'])) {
|
||||
_log("$x[id] - Invalid signature - $info");
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
|
||||
if ($x['version']==106) {
|
||||
// the masternode votes are using a different signature
|
||||
$vote_key=$db->single("SELECT vote_key FROM masternode WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
if (empty($vote_key)) {
|
||||
return false;
|
||||
}
|
||||
if (!$acc->check_signature($info, $x['signature'], $vote_key)) {
|
||||
_log("$x[id] - Invalid vote key signature - $info");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
//verify the ecdsa signature
|
||||
if (!$acc->check_signature($info, $x['signature'], $x['public_key'])) {
|
||||
_log("$x[id] - Invalid signature - $info");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -551,7 +1162,7 @@ class Transaction
|
||||
}
|
||||
|
||||
// return the transactions for a specific block id or height
|
||||
public function get_transactions($height = "", $id = "")
|
||||
public function get_transactions($height = "", $id = "", $includeMiningRewards = false)
|
||||
{
|
||||
global $db;
|
||||
$block = new Block();
|
||||
@@ -562,10 +1173,11 @@ class Transaction
|
||||
if (empty($id) && empty($height)) {
|
||||
return false;
|
||||
}
|
||||
$versionLimit = $includeMiningRewards ? 0 : 1;
|
||||
if (!empty($id)) {
|
||||
$r = $db->run("SELECT * FROM transactions WHERE block=:id AND version>0", [":id" => $id]);
|
||||
$r = $db->run("SELECT * FROM transactions WHERE block=:id AND version >= :version", [":id" => $id, ":version" => $versionLimit]);
|
||||
} else {
|
||||
$r = $db->run("SELECT * FROM transactions WHERE height=:height AND version>0", [":height" => $height]);
|
||||
$r = $db->run("SELECT * FROM transactions WHERE height=:height AND version >= :version", [":height" => $height, ":version" => $versionLimit]);
|
||||
}
|
||||
$res = [];
|
||||
foreach ($r as $x) {
|
||||
|
||||
327
index.php
327
index.php
@@ -1,323 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2018 AroDev
|
||||
|
||||
www.arionum.com
|
||||
if (file_exists(__DIR__ . '/../app/bootstrap.php')) {
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
$container = require __DIR__ . '/../app/bootstrap.php';
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
$container->getByType(Nette\Application\Application::class)
|
||||
->run();
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/include/init.inc.php';
|
||||
$block = new Block();
|
||||
$current = $block->current();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Arionum Node</title>
|
||||
<style>
|
||||
.title:not(:last-child) {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
body, h1, html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 100%;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
background-color: #fff;
|
||||
font-size: 16px;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
min-width: 300px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
-moz-text-size-adjust: 100%;
|
||||
-ms-text-size-adjust: 100%;
|
||||
text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
*, ::after, ::before {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
section {
|
||||
display: block;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
color: #4a4a4a;
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
span {
|
||||
font-style: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
|
||||
strong {
|
||||
color: #363636;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.container {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.field.is-grouped {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.field.is-grouped > .control {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.field.is-grouped > .control:not(:last-child) {
|
||||
margin-bottom: 0;
|
||||
margin-right: .75rem;
|
||||
}
|
||||
|
||||
.field.is-grouped.is-grouped-multiline {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.field.is-grouped.is-grouped-multiline > .control:last-child, .field.is-grouped.is-grouped-multiline > .control:not(:last-child) {
|
||||
margin-bottom: .75rem;
|
||||
}
|
||||
|
||||
.field.is-grouped.is-grouped-multiline:last-child {
|
||||
margin-bottom: -.75rem;
|
||||
}
|
||||
|
||||
.control {
|
||||
font-size: 1rem;
|
||||
position: relative;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.tags {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.tags .tag {
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
|
||||
.tags .tag:not(:last-child) {
|
||||
margin-right: .5rem;
|
||||
}
|
||||
|
||||
.tags:last-child {
|
||||
margin-bottom: -.5rem;
|
||||
}
|
||||
|
||||
.tags.has-addons .tag {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.tags.has-addons .tag:not(:first-child) {
|
||||
border-bottom-left-radius: 0;
|
||||
border-top-left-radius: 0;
|
||||
}
|
||||
|
||||
.tags.has-addons .tag:not(:last-child) {
|
||||
border-bottom-right-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
}
|
||||
|
||||
.tag:not(body) {
|
||||
align-items: center;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 4px;
|
||||
color: #4a4a4a;
|
||||
display: inline-flex;
|
||||
font-size: .75rem;
|
||||
height: 2em;
|
||||
justify-content: center;
|
||||
line-height: 1.5;
|
||||
padding-left: .75em;
|
||||
padding-right: .75em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tag:not(body).is-light {
|
||||
background-color: #f5f5f5;
|
||||
color: #363636;
|
||||
}
|
||||
|
||||
.tag:not(body).is-info {
|
||||
background-color: #209cee;
|
||||
color: #fff;
|
||||
}
|
||||
.tag:not(body).is-danger {
|
||||
background-color: #f48f42;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.tag:not(body).is-success {
|
||||
background-color: #23d160;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.title {
|
||||
word-break: break-word;
|
||||
color: #363636;
|
||||
font-size: 2rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.125;
|
||||
}
|
||||
|
||||
.hero {
|
||||
align-items: stretch;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.hero.is-dark {
|
||||
background-color: #363636;
|
||||
color: #f5f5f5;
|
||||
}
|
||||
|
||||
.hero.is-dark strong {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.hero.is-dark .title {
|
||||
color: #f5f5f5;
|
||||
}
|
||||
|
||||
.hero.is-fullheight .hero-body {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.hero.is-fullheight .hero-body > .container {
|
||||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
}
|
||||
|
||||
.hero.is-fullheight {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.hero-body {
|
||||
flex-grow: 1;
|
||||
flex-shrink: 0;
|
||||
padding: 3rem 1.5rem;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #3273dc;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #363636;
|
||||
}
|
||||
|
||||
a.is-dark {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1088px) {
|
||||
|
||||
.container {
|
||||
max-width: 960px;
|
||||
width: 960px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1280px) {
|
||||
|
||||
.container {
|
||||
max-width: 1152px;
|
||||
width: 1152px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1472px) {
|
||||
|
||||
.container {
|
||||
max-width: 1344px;
|
||||
width: 1344px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<section class="hero is-dark is-fullheight">
|
||||
<div class="hero-body">
|
||||
<div class="container">
|
||||
<h1 class="title">Arionum Node</h1>
|
||||
|
||||
<div class="field is-grouped is-grouped-multiline">
|
||||
<div class="control">
|
||||
<div class="tags has-addons">
|
||||
<strong class="tag is-success">Current Block</strong>
|
||||
<span class="tag is-light"><?= $current['height']; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control">
|
||||
<div class="tags has-addons">
|
||||
<strong class="tag is-danger">Version</strong>
|
||||
<span class="tag is-light"><?= VERSION; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control">
|
||||
<div class="tags has-addons">
|
||||
<strong class="tag is-info">Public API</strong>
|
||||
<span class="tag is-light"><?= ($_config['public_api']) ? 'yes' : 'no'; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control">
|
||||
<a class="tags is-dark" href="./doc/" target="_blank">
|
||||
<strong class="tag is-info">Documentation</strong>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
} else {
|
||||
|
||||
require_once __DIR__.'/node-index.php';
|
||||
|
||||
}
|
||||
17
mine.php
17
mine.php
@@ -23,7 +23,7 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
require_once("include/init.inc.php");
|
||||
require_once __DIR__.'/include/init.inc.php';
|
||||
$block = new Block();
|
||||
$acc = new Account();
|
||||
set_time_limit(360);
|
||||
@@ -56,10 +56,17 @@ if ($q == "info") {
|
||||
$argon_threads=1;
|
||||
$argon_time=1;
|
||||
}
|
||||
} elseif($current_height>=80460&&$current_height%2==0){
|
||||
$argon_mem=524288;
|
||||
} elseif($current_height>=80458){
|
||||
if($current_height%2==0){
|
||||
$argon_mem=524288;
|
||||
$argon_threads=1;
|
||||
$argon_time=1;
|
||||
} else {
|
||||
$argon_mem=16384;
|
||||
$argon_threads=4;
|
||||
$argon_time=4;
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
@@ -73,7 +80,7 @@ if ($q == "info") {
|
||||
"SELECT public_key FROM masternode WHERE status=1 AND blacklist<:current AND height<:start ORDER by last_won ASC, public_key ASC LIMIT 1",
|
||||
[":current"=>$current_height, ":start"=>$current_height-360]
|
||||
);
|
||||
$recommendation="pause";
|
||||
//$recommendation="pause";
|
||||
if ($winner===false) {
|
||||
$recommendation="mine";
|
||||
}
|
||||
@@ -111,6 +118,7 @@ if ($q == "info") {
|
||||
if ($res) {
|
||||
//if the new block is generated, propagate it to all peers in background
|
||||
$current = $block->current();
|
||||
$current['id']=escapeshellarg(san($current['id']));
|
||||
system("php propagate.php block $current[id] > /dev/null 2>&1 &");
|
||||
api_echo("accepted");
|
||||
}
|
||||
@@ -186,6 +194,7 @@ if ($q == "info") {
|
||||
if ($res) {
|
||||
//if the new block is generated, propagate it to all peers in background
|
||||
$current = $block->current();
|
||||
$current['id']=escapeshellarg(san($current['id']));
|
||||
system("php propagate.php block $current[id] > /dev/null 2>&1 &");
|
||||
api_echo("accepted");
|
||||
} else {
|
||||
|
||||
274
node-index.php
Executable file
274
node-index.php
Executable file
@@ -0,0 +1,274 @@
|
||||
<?php
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2018 AroDev
|
||||
www.arionum.com
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
require_once __DIR__.'/include/init.inc.php';
|
||||
$block = new Block();
|
||||
$current = $block->current();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Arionum Node</title>
|
||||
<style>
|
||||
.title:not(:last-child) {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
body, h1, html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 100%;
|
||||
font-weight: 400;
|
||||
}
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
background-color: #fff;
|
||||
font-size: 16px;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
min-width: 300px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
-moz-text-size-adjust: 100%;
|
||||
-ms-text-size-adjust: 100%;
|
||||
text-size-adjust: 100%;
|
||||
}
|
||||
*, ::after, ::before {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
section {
|
||||
display: block;
|
||||
}
|
||||
body {
|
||||
font-family: "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
color: #4a4a4a;
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
}
|
||||
span {
|
||||
font-style: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
strong {
|
||||
color: #363636;
|
||||
font-weight: 700;
|
||||
}
|
||||
.container {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.field.is-grouped {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.field.is-grouped > .control {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.field.is-grouped > .control:not(:last-child) {
|
||||
margin-bottom: 0;
|
||||
margin-right: .75rem;
|
||||
}
|
||||
.field.is-grouped.is-grouped-multiline {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.field.is-grouped.is-grouped-multiline > .control:last-child, .field.is-grouped.is-grouped-multiline > .control:not(:last-child) {
|
||||
margin-bottom: .75rem;
|
||||
}
|
||||
.field.is-grouped.is-grouped-multiline:last-child {
|
||||
margin-bottom: -.75rem;
|
||||
}
|
||||
.control {
|
||||
font-size: 1rem;
|
||||
position: relative;
|
||||
text-align: left;
|
||||
}
|
||||
.tags {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.tags .tag {
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
.tags .tag:not(:last-child) {
|
||||
margin-right: .5rem;
|
||||
}
|
||||
.tags:last-child {
|
||||
margin-bottom: -.5rem;
|
||||
}
|
||||
.tags.has-addons .tag {
|
||||
margin-right: 0;
|
||||
}
|
||||
.tags.has-addons .tag:not(:first-child) {
|
||||
border-bottom-left-radius: 0;
|
||||
border-top-left-radius: 0;
|
||||
}
|
||||
.tags.has-addons .tag:not(:last-child) {
|
||||
border-bottom-right-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
}
|
||||
.tag:not(body) {
|
||||
align-items: center;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 4px;
|
||||
color: #4a4a4a;
|
||||
display: inline-flex;
|
||||
font-size: .75rem;
|
||||
height: 2em;
|
||||
justify-content: center;
|
||||
line-height: 1.5;
|
||||
padding-left: .75em;
|
||||
padding-right: .75em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.tag:not(body).is-light {
|
||||
background-color: #f5f5f5;
|
||||
color: #363636;
|
||||
}
|
||||
.tag:not(body).is-info {
|
||||
background-color: #209cee;
|
||||
color: #fff;
|
||||
}
|
||||
.tag:not(body).is-danger {
|
||||
background-color: #f48f42;
|
||||
color: #fff;
|
||||
}
|
||||
.tag:not(body).is-success {
|
||||
background-color: #23d160;
|
||||
color: #fff;
|
||||
}
|
||||
.title {
|
||||
word-break: break-word;
|
||||
color: #363636;
|
||||
font-size: 2rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.125;
|
||||
}
|
||||
.hero {
|
||||
align-items: stretch;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.hero.is-dark {
|
||||
background-color: #363636;
|
||||
color: #f5f5f5;
|
||||
}
|
||||
.hero.is-dark strong {
|
||||
color: inherit;
|
||||
}
|
||||
.hero.is-dark .title {
|
||||
color: #f5f5f5;
|
||||
}
|
||||
.hero.is-fullheight .hero-body {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
}
|
||||
.hero.is-fullheight .hero-body > .container {
|
||||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
}
|
||||
.hero.is-fullheight {
|
||||
min-height: 100vh;
|
||||
}
|
||||
.hero-body {
|
||||
flex-grow: 1;
|
||||
flex-shrink: 0;
|
||||
padding: 3rem 1.5rem;
|
||||
}
|
||||
a {
|
||||
color: #3273dc;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
color: #363636;
|
||||
}
|
||||
a.is-dark {
|
||||
color: #fff;
|
||||
}
|
||||
@media screen and (min-width: 1088px) {
|
||||
.container {
|
||||
max-width: 960px;
|
||||
width: 960px;
|
||||
}
|
||||
}
|
||||
@media screen and (min-width: 1280px) {
|
||||
.container {
|
||||
max-width: 1152px;
|
||||
width: 1152px;
|
||||
}
|
||||
}
|
||||
@media screen and (min-width: 1472px) {
|
||||
.container {
|
||||
max-width: 1344px;
|
||||
width: 1344px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<section class="hero is-dark is-fullheight">
|
||||
<div class="hero-body">
|
||||
<div class="container">
|
||||
<h1 class="title">Arionum Node</h1>
|
||||
|
||||
<div class="field is-grouped is-grouped-multiline">
|
||||
<div class="control">
|
||||
<div class="tags has-addons">
|
||||
<strong class="tag is-success">Current Block</strong>
|
||||
<span class="tag is-light"><?= $current['height']; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control">
|
||||
<div class="tags has-addons">
|
||||
<strong class="tag is-danger">Version</strong>
|
||||
<span class="tag is-light"><?= VERSION; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control">
|
||||
<div class="tags has-addons">
|
||||
<strong class="tag is-info">Public API</strong>
|
||||
<span class="tag is-light"><?= ($_config['public_api']) ? 'yes' : 'no'; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control">
|
||||
<a class="tags is-dark" href="./doc/" target="_blank">
|
||||
<strong class="tag is-info">Documentation</strong>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
26
peer.php
26
peer.php
@@ -23,7 +23,10 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
require_once("include/init.inc.php");
|
||||
const SANITY_LOCK_PATH = __DIR__.'/tmp/sanity-lock';
|
||||
require_once __DIR__.'/include/init.inc.php';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$trx = new Transaction();
|
||||
$block = new Block();
|
||||
$q = $_GET['q'];
|
||||
@@ -39,6 +42,12 @@ if ($_POST['coin'] != $_config['coin']) {
|
||||
$ip = san_ip($_SERVER['REMOTE_ADDR']);
|
||||
$ip = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
|
||||
|
||||
// there should not be any local peering attempts
|
||||
if($_SERVER['REMOTE_ADDR']==$_SERVER['SERVER_ADDR']){
|
||||
api_err("invalid-ip");
|
||||
}
|
||||
|
||||
|
||||
// peer with the current node
|
||||
if ($q == "peer") {
|
||||
// sanitize the hostname
|
||||
@@ -143,13 +152,14 @@ if ($q == "peer") {
|
||||
if ($balance - $memspent < $val + $fee) {
|
||||
api_err("Not enough funds (mempool)");
|
||||
}
|
||||
|
||||
|
||||
// add to mempool
|
||||
$trx->add_mempool($data, $ip);
|
||||
|
||||
// rebroadcast the transaction to some peers unless the transaction is smaller than the average size of transactions in mempool - protect against garbage data flooding
|
||||
$res = $db->row("SELECT COUNT(1) as c, sum(val) as v FROM mempool ", [":src" => $data['src']]);
|
||||
if ($res['c'] < $_config['max_mempool_rebroadcast'] && $res['v'] / $res['c'] < $data['val']) {
|
||||
$data['id']=escapeshellarg(san($data['id']));
|
||||
system("php propagate.php transaction '$data[id]' > /dev/null 2>&1 &");
|
||||
}
|
||||
api_echo("transaction-ok");
|
||||
@@ -158,9 +168,17 @@ if ($q == "peer") {
|
||||
|
||||
// if sanity sync, refuse all
|
||||
if ($_config['sanity_sync'] == 1) {
|
||||
_log('['.$ip."] Block rejected due to sanity sync");
|
||||
//api_err("sanity-sync");
|
||||
}
|
||||
$sanity_lock=fopen(SANITY_LOCK_PATH,'w+');
|
||||
if(!flock($sanity_lock, LOCK_EX | LOCK_NB)){
|
||||
_log('['.$ip."] Block rejected due to sanity sync");
|
||||
api_err("sanity-sync");
|
||||
}
|
||||
// make sure sanity doesn't start while we add a new block and no other blocks are added at the same time
|
||||
flock($sanity_lock, LOCK_EX);
|
||||
|
||||
$data['id'] = san($data['id']);
|
||||
$current = $block->current();
|
||||
// block already in the blockchain
|
||||
@@ -185,6 +203,7 @@ if ($q == "peer") {
|
||||
if ($accept_new) {
|
||||
// if the new block is accepted, run a microsanity to sync it
|
||||
_log('['.$ip."] Starting microsanity - $data[height]");
|
||||
$ip=escapeshellarg($ip);
|
||||
system("php sanity.php microsanity '$ip' > /dev/null 2>&1 &");
|
||||
api_echo("microsanity");
|
||||
} else {
|
||||
@@ -200,7 +219,7 @@ if ($q == "peer") {
|
||||
if (!$pr) {
|
||||
api_err("block-too-old");
|
||||
}
|
||||
$peer_host = base58_encode($pr['hostname']);
|
||||
$peer_host = escapeshellcmd(base58_encode($pr['hostname']));
|
||||
$pr['ip'] = escapeshellcmd(san_ip($pr['ip']));
|
||||
system("php propagate.php block current '$peer_host' '$pr[ip]' > /dev/null 2>&1 &");
|
||||
_log('['.$ip."] block too old, sending our current block - $data[height]");
|
||||
@@ -243,6 +262,7 @@ if ($q == "peer") {
|
||||
_log('['.$ip."] block ok, repropagating - $data[height]");
|
||||
|
||||
// send it to all our peers
|
||||
$data['id']=escapeshellcmd(san($data['id']));
|
||||
system("php propagate.php block '$data[id]' all all linear > /dev/null 2>&1 &");
|
||||
api_echo("block-ok");
|
||||
} // return the current block, used in syncing
|
||||
|
||||
@@ -24,7 +24,7 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
set_time_limit(360);
|
||||
require_once("include/init.inc.php");
|
||||
require_once __DIR__.'/include/init.inc.php';
|
||||
$block = new Block();
|
||||
|
||||
$type = san($argv[1]);
|
||||
@@ -69,9 +69,13 @@ if ((empty($peer) || $peer == 'all') && $type == "block") {
|
||||
foreach ($r as $x) {
|
||||
if($x['hostname']==$_config['hostname']) continue;
|
||||
// encode the hostname in base58 and sanitize the IP to avoid any second order shell injections
|
||||
$host = base58_encode($x['hostname']);
|
||||
$ip = filter_var($x['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
|
||||
$host = escapeshellcmd(base58_encode($x['hostname']));
|
||||
$ip = escapeshellcmd(filter_var($x['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE));
|
||||
// fork a new process to send the blocks async
|
||||
$type=escapeshellcmd(san($type));
|
||||
$id=escapeshellcmd(san($id));
|
||||
|
||||
|
||||
if ($debug) {
|
||||
system("php propagate.php '$type' '$id' '$host' '$ip' debug");
|
||||
} elseif ($linear) {
|
||||
@@ -166,7 +170,8 @@ if ($type == "transaction") {
|
||||
if ($data['peer'] == "local") {
|
||||
$r = $db->run("SELECT hostname FROM peers WHERE blacklisted < UNIX_TIMESTAMP()");
|
||||
} else {
|
||||
$r = $db->run("SELECT hostname FROM peers WHERE blacklisted < UNIX_TIMESTAMP() AND reserve=0 ORDER by RAND() LIMIT ".intval($_config['transaction_propagation_peers']));
|
||||
|
||||
$r = $db->run("SELECT hostname FROM peers WHERE blacklisted < UNIX_TIMESTAMP() AND reserve=0 ORDER by RAND() LIMIT :limit",["limit"=>intval($_config['transaction_propagation_peers'])]);
|
||||
}
|
||||
foreach ($r as $x) {
|
||||
$res = peer_post($x['hostname']."/peer.php?q=submitTransaction", $data);
|
||||
|
||||
577
sanity.php
577
sanity.php
@@ -23,6 +23,9 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
const SANITY_LOCK_PATH = __DIR__.'/tmp/sanity-lock';
|
||||
|
||||
set_time_limit(0);
|
||||
error_reporting(0);
|
||||
|
||||
@@ -31,27 +34,16 @@ if (php_sapi_name() !== 'cli') {
|
||||
die("This should only be run as cli");
|
||||
}
|
||||
|
||||
require_once __DIR__.'/include/init.inc.php';
|
||||
|
||||
// make sure there's only a single sanity process running at the same time
|
||||
if (file_exists("tmp/sanity-lock")) {
|
||||
$ignore_lock = false;
|
||||
if ($argv[1] == "force") {
|
||||
$res = intval(shell_exec("ps aux|grep sanity.php|grep -v grep|wc -l"));
|
||||
if ($res == 1) {
|
||||
$ignore_lock = true;
|
||||
}
|
||||
}
|
||||
$pid_time = filemtime("tmp/sanity-lock");
|
||||
// if the process died, restart after 1day
|
||||
if (time() - $pid_time > 86400) {
|
||||
@unlink("tmp/sanity-lock");
|
||||
}
|
||||
if (!$ignore_lock) {
|
||||
die("Sanity lock in place");
|
||||
}
|
||||
$sanity_lock=fopen(SANITY_LOCK_PATH,'w+');
|
||||
if(!flock($sanity_lock, LOCK_EX | LOCK_NB)){
|
||||
die("Sanity lock in place".PHP_EOL);
|
||||
}
|
||||
// set the new sanity lock
|
||||
$lock = fopen("tmp/sanity-lock", "w");
|
||||
fclose($lock);
|
||||
flock($sanity_lock, LOCK_EX);
|
||||
|
||||
$arg = trim($argv[1]);
|
||||
$arg2 = trim($argv[2]);
|
||||
echo "Sleeping for 3 seconds\n";
|
||||
@@ -60,13 +52,15 @@ if ($arg != "microsanity") {
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
|
||||
require_once("include/init.inc.php");
|
||||
if ($argv[1]=="dev") {
|
||||
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
||||
ini_set("display_errors", "on");
|
||||
}
|
||||
|
||||
// the sanity can't run without the schema being installed
|
||||
if ($_config['dbversion'] < 2) {
|
||||
die("DB schema not created");
|
||||
@unlink("tmp/sanity-lock");
|
||||
@unlink(SANITY_LOCK_PATH);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -74,66 +68,50 @@ ini_set('memory_limit', '2G');
|
||||
|
||||
$block = new Block();
|
||||
$acc = new Account();
|
||||
$trx= new Transaction();
|
||||
|
||||
$current = $block->current();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// bootstrapping the initial sync
|
||||
if ($current['height']==1) {
|
||||
echo "Bootstrapping!\n";
|
||||
$last=file_get_contents("http://dumps.arionum.com/last");
|
||||
$last=intval($last);
|
||||
$failed_sync=false;
|
||||
for ($i=1000;$i<=$last;$i=$i+1000) {
|
||||
echo "Download file $i\n";
|
||||
$res=trim(file_get_contents("http://dumps.arionum.com/aro.db.$i"));
|
||||
if ($res===false) {
|
||||
echo "Could not download the bootstrap file $i. Syncing the old fashioned way.\n";
|
||||
break;
|
||||
}
|
||||
$data=json_decode($res, true);
|
||||
|
||||
if ($data===false||is_null($data)) {
|
||||
echo "Could not parse the bootstrap file $i. Syncing the old fashioned way.\n";
|
||||
echo json_last_error_msg();
|
||||
break;
|
||||
}
|
||||
foreach ($data as $x) {
|
||||
if (count($x['data'])>0) {
|
||||
$transactions=[];
|
||||
|
||||
foreach ($x['data'] as $d) {
|
||||
$trans = [
|
||||
"id" => $d[0],
|
||||
"dst" => $d[1],
|
||||
"val" => $d[2],
|
||||
"fee" => $d[3],
|
||||
"signature" => $d[4],
|
||||
"message" => $d[5],
|
||||
"version" => $d[6],
|
||||
"date" => $d[7],
|
||||
"public_key" => $d[8],
|
||||
];
|
||||
ksort($trans);
|
||||
$transactions[$d[0]] = $trans;
|
||||
}
|
||||
ksort($transactions);
|
||||
$x['data']=$transactions;
|
||||
}
|
||||
|
||||
|
||||
echo "-> Adding block $x[height]\n";
|
||||
$db_name=substr($_config['db_connect'], strrpos($_config['db_connect'], "dbname=")+7);
|
||||
$db_host=substr($_config['db_connect'], strpos($_config['db_connect'], ":host=")+6);
|
||||
$db_host=substr($db_host, 0, strpos($db_host, ";"));
|
||||
|
||||
$res=$block->add($x['height'], $x['public_key'], $x['nonce'], $x['data'], $x['date'], $x['signature'], $x['difficulty'], $x['reward_signature'], $x['argon'], true);
|
||||
if (!$res) {
|
||||
echo "Error: Adding the block failed. Syncing the old way.\n";
|
||||
$failed_sync=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($failed_sync) {
|
||||
break;
|
||||
}
|
||||
echo "DB name: $db_name\n";
|
||||
echo "DB host: $db_host\n";
|
||||
echo "Downloading the blockchain dump from arionum.info\n";
|
||||
$arofile=__DIR__ . '/tmp/aro.sql';
|
||||
if (file_exists("/usr/bin/curl")) {
|
||||
// system("/usr/bin/curl -o $arofile 'https://arionum.info/dump/aro.sql'", $ret);
|
||||
} elseif (file_exists("/usr/bin/wget")) {
|
||||
// system("/usr/bin/wget -O $arofile 'https://arionum.info/dump/aro.sql'", $ret);
|
||||
} else {
|
||||
die("/usr/bin/curl and /usr/bin/wget not installed or inaccessible. Please install either of them.");
|
||||
}
|
||||
|
||||
|
||||
echo "Importing the blockchain dump\n";
|
||||
// system("mysql -h ".escapeshellarg($db_host)." -u ".escapeshellarg($_config['db_user'])." -p".escapeshellarg($_config['db_pass'])." ".escapeshellarg($db_name). " < ".$arofile);
|
||||
echo "Bootstrapping completed. Waiting 2mins for the tables to be unlocked.\n";
|
||||
|
||||
while (1) {
|
||||
sleep(120);
|
||||
|
||||
$res=$db->run("SHOW OPEN TABLES WHERE In_use > 0");
|
||||
if (count($res==0)) {
|
||||
break;
|
||||
}
|
||||
echo "Tables still locked. Sleeping for another 2 min. \n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
$current = $block->current();
|
||||
}
|
||||
// the microsanity process is an anti-fork measure that will determine the best blockchain to choose for the last block
|
||||
@@ -224,7 +202,7 @@ if ($arg == "microsanity" && !empty($arg2)) {
|
||||
_log("Synced block from $host - $b[height] $b[difficulty]");
|
||||
} while (0);
|
||||
|
||||
@unlink("tmp/sanity-lock");
|
||||
@unlink(SANITY_LOCK_PATH);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -243,13 +221,18 @@ $blocks = [];
|
||||
$blocks_count = [];
|
||||
$most_common = "";
|
||||
$most_common_size = 0;
|
||||
$most_common_height = 0;
|
||||
$total_active_peers = 0;
|
||||
$largest_most_common = "";
|
||||
$largest_most_common_size = 0;
|
||||
$largest_most_common_height = 0;
|
||||
|
||||
|
||||
// checking peers
|
||||
|
||||
// delete the dead peers
|
||||
$db->run("DELETE from peers WHERE fails>100 OR stuckfail>200");
|
||||
$r = $db->run("SELECT id,hostname,stuckfail,fails FROM peers WHERE reserve=0 AND blacklisted<UNIX_TIMESTAMP()");
|
||||
$db->run("DELETE from peers WHERE fails>100 OR stuckfail>100");
|
||||
$r = $db->run("SELECT id,hostname,stuckfail,fails FROM peers WHERE reserve=0 AND blacklisted<UNIX_TIMESTAMP() LIMIT 50");
|
||||
|
||||
$total_peers = count($r);
|
||||
|
||||
@@ -257,16 +240,20 @@ $peered = [];
|
||||
// if we have no peers, get the seed list from the official site
|
||||
if ($total_peers == 0 && $_config['testnet'] == false) {
|
||||
$i = 0;
|
||||
echo "No peers found. Attempting to get peers from arionum.com\n";
|
||||
$f = file("https://www.arionum.com/peers.txt");
|
||||
shuffle($f);
|
||||
// we can't connect to arionum.com
|
||||
if (count($f) < 2) {
|
||||
@unlink("tmp/sanity-lock");
|
||||
die("Could not connect to arionum.com! Will try later!\n");
|
||||
echo 'No peers found. Attempting to get peers from the initial list.'.PHP_EOL;
|
||||
|
||||
$initialPeers = new \Arionum\Node\InitialPeers($_config['initial_peer_list'] ?? []);
|
||||
|
||||
try {
|
||||
$peers = $initialPeers->getAll();
|
||||
} catch (\Arionum\Node\Exception $e) {
|
||||
@unlink(SANITY_LOCK_PATH);
|
||||
die($e->getMessage().PHP_EOL);
|
||||
}
|
||||
foreach ($f as $peer) {
|
||||
//peer with all until max_peers, this will ask them to send a peering request to our peer.php where we add their peer to the db.
|
||||
|
||||
foreach ($peers as $peer) {
|
||||
// Peer with all until max_peers
|
||||
// This will ask them to send a peering request to our peer.php where we add their peer to the db.
|
||||
$peer = trim(san_host($peer));
|
||||
$bad_peers = ["127.", "localhost", "10.", "192.168.","172.16.","172.17.","172.18.","172.19.","172.20.","172.21.","172.22.","172.23.","172.24.","172.25.","172.26.","172.27.","172.28.","172.29.","172.30.","172.31."];
|
||||
|
||||
@@ -288,7 +275,15 @@ if ($total_peers == 0 && $_config['testnet'] == false) {
|
||||
continue;
|
||||
}
|
||||
$peered[$pid] = 1;
|
||||
$res = peer_post($peer."/peer.php?q=peer", ["hostname" => $_config['hostname'], "repeer" => 1]);
|
||||
|
||||
if ($_config['passive_peering'] == true) {
|
||||
// does not peer, just add it to DB in passive mode
|
||||
$db->run("INSERT into peers set hostname=:hostname, ping=0, reserve=0,ip=:ip", [":hostname"=>$peer, ":ip"=>md5($peer)]);
|
||||
$res=true;
|
||||
} else {
|
||||
// forces the other node to peer with us.
|
||||
$res = peer_post($peer."/peer.php?q=peer", ["hostname" => $_config['hostname'], "repeer" => 1]);
|
||||
}
|
||||
if ($res !== false) {
|
||||
$i++;
|
||||
echo "Peering OK - $peer\n";
|
||||
@@ -304,18 +299,79 @@ if ($total_peers == 0 && $_config['testnet'] == false) {
|
||||
$total_peers = count($r);
|
||||
if ($total_peers == 0) {
|
||||
// something went wrong, could not add any peers -> exit
|
||||
@unlink("tmp/sanity-lock");
|
||||
@unlink(SANITY_LOCK_PATH);
|
||||
die("Could not peer to any peers! Please check internet connectivity!\n");
|
||||
}
|
||||
}
|
||||
|
||||
// contact all the active peers
|
||||
$i = 0;
|
||||
foreach ($r as $x) {
|
||||
_log("Contacting peer $x[hostname]");
|
||||
$url = $x['hostname']."/peer.php?q=";
|
||||
// get their peers list
|
||||
if($_config['get_more_peers']==true){
|
||||
$data = peer_post($url."getPeers", [], 5);
|
||||
if ($_config['get_more_peers']==true && $_config['passive_peering']!=true) {
|
||||
$data = peer_post($url."getPeers", [], 5);
|
||||
if ($data === false) {
|
||||
_log("Peer $x[hostname] unresponsive");
|
||||
// if the peer is unresponsive, mark it as failed and blacklist it for a while
|
||||
$db->run(
|
||||
"UPDATE peers SET fails=fails+1, blacklisted=UNIX_TIMESTAMP()+((fails+1)*3600) WHERE id=:id",
|
||||
[":id" => $x['id']]
|
||||
);
|
||||
continue;
|
||||
}
|
||||
foreach ($data as $peer) {
|
||||
// store the hostname as md5 hash, for easier checking
|
||||
$peer['hostname'] = san_host($peer['hostname']);
|
||||
$peer['ip'] = san_ip($peer['ip']);
|
||||
$pid = md5($peer['hostname']);
|
||||
// do not peer if we are already peered
|
||||
if ($peered[$pid] == 1) {
|
||||
continue;
|
||||
}
|
||||
$peered[$pid] = 1;
|
||||
$bad_peers = ["127.", "localhost", "10.", "192.168.","172.16.","172.17.","172.18.","172.19.","172.20.","172.21.","172.22.","172.23.","172.24.","172.25.","172.26.","172.27.","172.28.","172.29.","172.30.","172.31."];
|
||||
$tpeer=str_replace(["https://","http://","//"], "", $peer['hostname']);
|
||||
foreach ($bad_peers as $bp) {
|
||||
if (strpos($tpeer, $bp)===0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// if it's our hostname, ignore
|
||||
if ($peer['hostname'] == $_config['hostname']) {
|
||||
continue;
|
||||
}
|
||||
// if invalid hostname, ignore
|
||||
if (!filter_var($peer['hostname'], FILTER_VALIDATE_URL)) {
|
||||
continue;
|
||||
}
|
||||
// make sure there's no peer in db with this ip or hostname
|
||||
if (!$db->single(
|
||||
"SELECT COUNT(1) FROM peers WHERE ip=:ip or hostname=:hostname",
|
||||
[":ip" => $peer['ip'], ":hostname" => $peer['hostname']]
|
||||
)) {
|
||||
$i++;
|
||||
// check a max_test_peers number of peers from each peer
|
||||
if ($i > $_config['max_test_peers']) {
|
||||
break;
|
||||
}
|
||||
$peer['hostname'] = filter_var($peer['hostname'], FILTER_SANITIZE_URL);
|
||||
// peer with each one
|
||||
_log("Trying to peer with recommended peer: $peer[hostname]");
|
||||
$test = peer_post($peer['hostname']."/peer.php?q=peer", ["hostname" => $_config['hostname']], 5);
|
||||
if ($test !== false) {
|
||||
$total_peers++;
|
||||
echo "Peered with: $peer[hostname]\n";
|
||||
// a single new peer per sanity
|
||||
$_config['get_more_peers']=false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get the current block and check it's blockchain
|
||||
$data = peer_post($url."currentBlock", [], 5);
|
||||
if ($data === false) {
|
||||
_log("Peer $x[hostname] unresponsive");
|
||||
// if the peer is unresponsive, mark it as failed and blacklist it for a while
|
||||
@@ -323,59 +379,7 @@ if($_config['get_more_peers']==true){
|
||||
"UPDATE peers SET fails=fails+1, blacklisted=UNIX_TIMESTAMP()+((fails+1)*3600) WHERE id=:id",
|
||||
[":id" => $x['id']]
|
||||
);
|
||||
continue;
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($data as $peer) {
|
||||
// store the hostname as md5 hash, for easier checking
|
||||
$peer['hostname'] = san_host($peer['hostname']);
|
||||
$peer['ip'] = san_ip($peer['ip']);
|
||||
$pid = md5($peer['hostname']);
|
||||
// do not peer if we are already peered
|
||||
if ($peered[$pid] == 1) {
|
||||
continue;
|
||||
}
|
||||
$peered[$pid] = 1;
|
||||
$bad_peers = ["127.", "localhost", "10.", "192.168.","172.16.","172.17.","172.18.","172.19.","172.20.","172.21.","172.22.","172.23.","172.24.","172.25.","172.26.","172.27.","172.28.","172.29.","172.30.","172.31."];
|
||||
$tpeer=str_replace(["https://","http://","//"], "", $peer['hostname']);
|
||||
foreach ($bad_peers as $bp) {
|
||||
if (strpos($tpeer, $bp)===0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// if it's our hostname, ignore
|
||||
if ($peer['hostname'] == $_config['hostname']) {
|
||||
continue;
|
||||
}
|
||||
// if invalid hostname, ignore
|
||||
if (!filter_var($peer['hostname'], FILTER_VALIDATE_URL)) {
|
||||
continue;
|
||||
}
|
||||
// make sure there's no peer in db with this ip or hostname
|
||||
if (!$db->single(
|
||||
"SELECT COUNT(1) FROM peers WHERE ip=:ip or hostname=:hostname",
|
||||
[":ip" => $peer['ip'], ":hostname" => $peer['hostname']]
|
||||
)) {
|
||||
$i++;
|
||||
// check a max_test_peers number of peers from each peer
|
||||
if ($i > $_config['max_test_peers']) {
|
||||
break;
|
||||
}
|
||||
$peer['hostname'] = filter_var($peer['hostname'], FILTER_SANITIZE_URL);
|
||||
// peer with each one
|
||||
_log("Trying to peer with recommended peer: $peer[hostname]");
|
||||
$test = peer_post($peer['hostname']."/peer.php?q=peer", ["hostname" => $_config['hostname']], 5);
|
||||
if ($test !== false) {
|
||||
$total_peers++;
|
||||
echo "Peered with: $peer[hostname]\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get the current block and check it's blockchain
|
||||
$data = peer_post($url."currentBlock", [], 5);
|
||||
if ($data === false) {
|
||||
|
||||
continue;
|
||||
}
|
||||
// peer was responsive, mark it as good
|
||||
@@ -407,6 +411,12 @@ if($_config['get_more_peers']==true){
|
||||
if ($blocks_count[$data['id']] > $most_common_size) {
|
||||
$most_common = $data['id'];
|
||||
$most_common_size = $blocks_count[$data['id']];
|
||||
$most_common_height = $data['height'];
|
||||
}
|
||||
if ($blocks_count[$data['id']] > $largest_most_common_size && $data['height'] > $current['height']) {
|
||||
$largest_most_common = $data['id'];
|
||||
$largest_most_common_size = $blocks_count[$data['id']];
|
||||
$largest_most_common_height = $data['height'];
|
||||
}
|
||||
// set the largest height block
|
||||
if ($data['height'] > $largest_height) {
|
||||
@@ -437,11 +447,54 @@ if($_config['get_more_peers']==true){
|
||||
}
|
||||
}
|
||||
}
|
||||
$largest_size=$blocks_count[$largest_height_block];
|
||||
echo "Most common: $most_common\n";
|
||||
echo "Most common block: $most_common_size\n";
|
||||
echo "Max height: $largest_height\n";
|
||||
echo "Most common block size: $most_common_size\n";
|
||||
echo "Most common height: $most_common_height\n\n";
|
||||
echo "Longest chain height: $largest_height\n";
|
||||
echo "Longest chain size: $largest_size\n\n";
|
||||
echo "Larger Most common: $largest_most_common\n";
|
||||
echo "Larger Most common block size: $largest_most_common_size\n";
|
||||
echo "Larger Most common height: $largest_most_common_height\n\n";
|
||||
echo "Total size: $total_active_peers\n\n";
|
||||
|
||||
echo "Current block: $current[height]\n";
|
||||
|
||||
// if this is the node that's ahead, and other nodes are not catching up, pop 200
|
||||
|
||||
if($largest_height-$most_common_height>100&&$largest_size==1&&$current['id']==$largest_height_block){
|
||||
_log("Current node is alone on the chain and over 100 blocks ahead. Poping 200 blocks.");
|
||||
$db->run("UPDATE config SET val=1 WHERE cfg='sanity_sync'");
|
||||
$block->pop(200);
|
||||
$db->run("UPDATE config SET val=0 WHERE cfg='sanity_sync'");
|
||||
_log("Exiting sanity, next sanity will sync from 200 blocks ago.");
|
||||
|
||||
@unlink(SANITY_LOCK_PATH);
|
||||
exit;
|
||||
}
|
||||
|
||||
// if there's a single node with over 100 blocks ahead on a single peer, use the most common block
|
||||
if($largest_height-$most_common_height>100 && $largest_size==1){
|
||||
if($current['id']==$most_common && $largest_most_common_size>3){
|
||||
_log("Longest chain is way ahead, using largest most common block");
|
||||
$largest_height=$largest_most_common_height;
|
||||
$largest_size=$largest_most_common_size;
|
||||
$largest_height_block=$largest_most_common;
|
||||
} else {
|
||||
_log("Longest chain is way ahead, using most common block");
|
||||
$largest_height=$most_common_height;
|
||||
$largest_size=$most_common_size;
|
||||
$largest_height_block=$most_common;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$block_parse_failed=false;
|
||||
|
||||
$failed_syncs=0;
|
||||
// if we're not on the largest height
|
||||
if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
// start sanity sync / block all other transactions/blocks
|
||||
@@ -475,17 +528,19 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
break;
|
||||
}
|
||||
} elseif ($data['id'] != $current['id'] && $data['id'] != $most_common) {
|
||||
//if we're not on the same blockchain and also it's not the most common, verify all the blocks on on this blockchain starting at current-10 until current
|
||||
//if we're not on the same blockchain and also it's not the most common, verify all the blocks on on this blockchain starting at current-30 until current
|
||||
$invalid = false;
|
||||
$last_good = $current['height'];
|
||||
for ($i = $current['height'] - 10; $i < $current['height']; $i++) {
|
||||
for ($i = $current['height'] - 100; $i < $current['height']; $i++) {
|
||||
$data = peer_post($url."getBlock", ["height" => $i]);
|
||||
if ($data === false) {
|
||||
$invalid = true;
|
||||
_log("Could not get block from $host - $i");
|
||||
break;
|
||||
}
|
||||
$ext = $block->get($i);
|
||||
if ($i == $current['height'] - 10 && $ext['id'] != $data['id']) {
|
||||
if ($i == $current['height'] - 100 && $ext['id'] != $data['id']) {
|
||||
_log("100 blocks ago was still on a different chain. Ignoring.");
|
||||
$invalid = true;
|
||||
break;
|
||||
}
|
||||
@@ -494,8 +549,12 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
$last_good = $i;
|
||||
}
|
||||
}
|
||||
if ($last_good==$current['height']-1&&$last_good%3==2) {
|
||||
$block->pop(1);
|
||||
if ($last_good==$current['height']-1) {
|
||||
$try_pop=$block->pop(1);
|
||||
if($try_pop==false){
|
||||
// we can't pop the last block, we should resync
|
||||
$block_parse_failed=true;
|
||||
}
|
||||
}
|
||||
// if last 10 blocks are good, verify all the blocks
|
||||
if ($invalid == false) {
|
||||
@@ -503,6 +562,7 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
for ($i = $last_good; $i <= $largest_height; $i++) {
|
||||
$data = peer_post($url."getBlock", ["height" => $i]);
|
||||
if ($data === false) {
|
||||
_log("Could not get block from $host - $i");
|
||||
$invalid = true;
|
||||
break;
|
||||
}
|
||||
@@ -510,7 +570,7 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
}
|
||||
// check if the block mining data is correct
|
||||
for ($i = $last_good + 1; $i <= $largest_height; $i++) {
|
||||
if (($i-1)%3==2) {
|
||||
if (($i-1)%3==2&&$cblock[$i - 1]['height']<80458) {
|
||||
continue;
|
||||
}
|
||||
if (!$block->mine(
|
||||
@@ -530,13 +590,21 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
// if the blockchain proves ok, delete until the last block
|
||||
if ($invalid == false) {
|
||||
_log("Changing fork, deleting $last_good", 1);
|
||||
$block->delete($last_good);
|
||||
$res=$block->delete($last_good);
|
||||
if($res==false){
|
||||
$block_parse_failed=true;
|
||||
break;
|
||||
}
|
||||
$current = $block->current();
|
||||
$data = $current;
|
||||
}
|
||||
}
|
||||
// if current still doesn't match the data, something went wrong
|
||||
if ($data['id'] != $current['id']) {
|
||||
if($largest_size==1){
|
||||
//blacklisting the peer if it's the largest height on a broken blockchain
|
||||
$db->run("UPDATE peers SET blacklisted=UNIX_TIMESTAMP()+1800 WHERE hostname=:host LIMIT 1",[':host'=>$host]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// start syncing all blocks
|
||||
@@ -553,8 +621,10 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
$b['height'] = san($b['height']);
|
||||
|
||||
if (!$block->check($b)) {
|
||||
$block_parse_failed=true;
|
||||
_log("Block check: could not add block - $b[id] - $b[height]");
|
||||
$good_peer = false;
|
||||
$failed_syncs++;
|
||||
break;
|
||||
}
|
||||
$res = $block->add(
|
||||
@@ -569,8 +639,10 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
$b['argon']
|
||||
);
|
||||
if (!$res) {
|
||||
$block_parse_failed=true;
|
||||
_log("Block add: could not add block - $b[id] - $b[height]");
|
||||
$good_peer = false;
|
||||
$failed_syncs++;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -584,24 +656,76 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
if ($good_peer) {
|
||||
break;
|
||||
}
|
||||
if ($failed_syncs>5) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($block_parse_failed==true||$argv[1]=="resync") {
|
||||
$last_resync=$db->single("SELECT val FROM config WHERE cfg='last_resync'");
|
||||
if ($last_resync<time()-(3600*24)||$argv[1]=="resync") {
|
||||
if ((($current['date']<time()-(3600*72)) && $_config['auto_resync']!==false) || $argv[1]=="resync") {
|
||||
$db->run("SET foreign_key_checks=0;");
|
||||
$tables = ["accounts", "transactions", "mempool", "masternode","blocks"];
|
||||
foreach ($tables as $table) {
|
||||
$db->run("TRUNCATE TABLE {$table}");
|
||||
}
|
||||
|
||||
_log("Removing $to_remove blocks, the blockchain is stale.");
|
||||
//$block->pop($to_remove);
|
||||
$db->run("SET foreign_key_checks=1;");
|
||||
|
||||
$resyncing=true;
|
||||
$db->run("UPDATE config SET val=0 WHERE cfg='sanity_sync'", [":time" => $t]);
|
||||
|
||||
_log("Exiting sanity, next sanity will resync from scratch.");
|
||||
|
||||
@unlink(SANITY_LOCK_PATH);
|
||||
exit;
|
||||
} elseif ($current['date']<time()-(3600*24)) {
|
||||
_log("Removing 200 blocks, the blockchain is stale.");
|
||||
//$block->pop(200);
|
||||
|
||||
$resyncing=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$db->run("UPDATE config SET val=0 WHERE cfg='sanity_sync'", [":time" => $t]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$resyncing=false;
|
||||
if ($block_parse_failed==true&&$current['date']<time()-(3600*24)) {
|
||||
_log("Rechecking reward transactions");
|
||||
$current = $block->current();
|
||||
$rwpb=$db->single("SELECT COUNT(1) FROM transactions WHERE version=0 AND message=''");
|
||||
if ($rwpb!=$current['height']) {
|
||||
$failed=$db->single("SELECT blocks.height FROM blocks LEFT JOIN transactions ON transactions.block=blocks.id and transactions.version=0 and transactions.message='' WHERE transactions.height is NULL ORDER by blocks.height ASC LIMIT 1");
|
||||
if ($failed>1) {
|
||||
_log("Found failed block - $faield");
|
||||
$block->delete($failed);
|
||||
$block_parse_failed==false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// deleting mempool transactions older than 14 days
|
||||
$db->run("DELETE FROM `mempool` WHERE `date` < UNIX_TIMESTAMP()-(3600*24*14)");
|
||||
|
||||
|
||||
//rebroadcasting local transactions
|
||||
if ($_config['sanity_rebroadcast_locals'] == true) {
|
||||
if ($_config['sanity_rebroadcast_locals'] == true && $_config['disable_repropagation'] == false) {
|
||||
$r = $db->run(
|
||||
"SELECT id FROM mempool WHERE height>=:current and peer='local' order by `height` asc LIMIT 20",
|
||||
"SELECT id FROM mempool WHERE height<:current and peer='local' order by `height` asc LIMIT 20",
|
||||
[":current" => $current['height']]
|
||||
);
|
||||
_log("Rebroadcasting local transactions - ".count($r));
|
||||
foreach ($r as $x) {
|
||||
$x['id'] = san($x['id']);
|
||||
$x['id'] = escapeshellarg(san($x['id'])); // i know it's redundant due to san(), but some people are too scared of any exec
|
||||
system("php propagate.php transaction $x[id] > /dev/null 2>&1 &");
|
||||
$db->run(
|
||||
"UPDATE mempool SET height=:current WHERE id=:id",
|
||||
@@ -611,21 +735,29 @@ if ($_config['sanity_rebroadcast_locals'] == true) {
|
||||
}
|
||||
|
||||
//rebroadcasting transactions
|
||||
$forgotten = $current['height'] - $_config['sanity_rebroadcast_height'];
|
||||
$r = $db->run(
|
||||
"SELECT id FROM mempool WHERE height<:forgotten ORDER by val DESC LIMIT 10",
|
||||
[":forgotten" => $forgotten]
|
||||
);
|
||||
if ($_config['disable_repropagation'] == false) {
|
||||
$forgotten = $current['height'] - $_config['sanity_rebroadcast_height'];
|
||||
$r1 = $db->run(
|
||||
"SELECT id FROM mempool WHERE height<:forgotten ORDER by val DESC LIMIT 10",
|
||||
[":forgotten" => $forgotten]
|
||||
);
|
||||
// getting some random transactions as well
|
||||
$r2 = $db->run(
|
||||
"SELECT id FROM mempool WHERE height<:forgotten ORDER by RAND() LIMIT 10",
|
||||
[":forgotten" => $forgotten]
|
||||
);
|
||||
$r=array_merge($r1, $r2);
|
||||
|
||||
_log("Rebroadcasting external transactions - ".count($r));
|
||||
|
||||
foreach ($r as $x) {
|
||||
$x['id'] = san($x['id']);
|
||||
system("php propagate.php transaction $x[id] > /dev/null 2>&1 &");
|
||||
$db->run("UPDATE mempool SET height=:current WHERE id=:id", [":id" => $x['id'], ":current" => $current['height']]);
|
||||
_log("Rebroadcasting external transactions - ".count($r));
|
||||
|
||||
foreach ($r as $x) {
|
||||
$x['id'] = escapeshellarg(san($x['id'])); // i know it's redundant due to san(), but some people are too scared of any exec
|
||||
system("php propagate.php transaction $x[id] > /dev/null 2>&1 &");
|
||||
$db->run("UPDATE mempool SET height=:current WHERE id=:id", [":id" => $x['id'], ":current" => $current['height']]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//add new peers if there aren't enough active
|
||||
if ($total_peers < $_config['max_peers'] * 0.7) {
|
||||
$res = $_config['max_peers'] - $total_peers;
|
||||
@@ -633,7 +765,7 @@ if ($total_peers < $_config['max_peers'] * 0.7) {
|
||||
}
|
||||
|
||||
//random peer check
|
||||
$r = $db->run("SELECT * FROM peers WHERE blacklisted<UNIX_TIMESTAMP() and reserve=1 LIMIT ".$_config['max_test_peers']);
|
||||
$r = $db->run("SELECT * FROM peers WHERE blacklisted<UNIX_TIMESTAMP() and reserve=1 LIMIT :limit", [":limit"=>intval($_config['max_test_peers'])]);
|
||||
foreach ($r as $x) {
|
||||
$url = $x['hostname']."/peer.php?q=";
|
||||
$data = peer_post($url."ping", [], 5);
|
||||
@@ -649,23 +781,10 @@ foreach ($r as $x) {
|
||||
}
|
||||
}
|
||||
|
||||
//clean tmp files
|
||||
_log("Cleaning tmp files");
|
||||
$f = scandir("tmp/");
|
||||
$time = time();
|
||||
foreach ($f as $x) {
|
||||
if (strlen($x) < 5 && substr($x, 0, 1) == ".") {
|
||||
continue;
|
||||
}
|
||||
$pid_time = filemtime("tmp/$x");
|
||||
if ($time - $pid_time > 7200) {
|
||||
@unlink("tmp/$x");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//recheck the last blocks
|
||||
if ($_config['sanity_recheck_blocks'] > 0 && $_config['testnet'] == false&&1==2) {
|
||||
if ($_config['sanity_recheck_blocks'] > 0 && $_config['testnet'] == false) {
|
||||
_log("Rechecking blocks");
|
||||
$blocks = [];
|
||||
$all_blocks_ok = true;
|
||||
@@ -708,6 +827,102 @@ if ($_config['sanity_recheck_blocks'] > 0 && $_config['testnet'] == false&&1==2)
|
||||
}
|
||||
}
|
||||
|
||||
// not too often to not cause load
|
||||
if (rand(0, 10)==1) {
|
||||
// after 10000 blocks, clear asset internal transactions
|
||||
$db->run("DELETE FROM transactions WHERE (version=57 or version=58 or version=59) AND height<:height", [":height"=>$current['height']-10000]);
|
||||
|
||||
// remove market orders that have been filled, after 10000 blocks
|
||||
$r=$db->run("SELECT id FROM assets_market WHERE val_done=val or status=2");
|
||||
foreach ($r as $x) {
|
||||
$last=$db->single("SELECT height FROM transactions WHERE (public_key=:id or dst=:id2) ORDER by height DESC LIMIT 1", [":id"=>$x['id'], ":id2"=>$x['id']]);
|
||||
if ($current['height']-$last>10000) {
|
||||
$db->run("DELETE FROM assets_market WHERE id=:id", [":id"=>$x['id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($_config['masternode']==true&&!empty($_config['masternode_public_key'])&&!empty($_config['masternode_voting_public_key'])&&!empty($_config['masternode_voting_private_key'])) {
|
||||
echo "Masternode votes\n";
|
||||
$r=$db->run("SELECT * FROM masternode WHERE status=1 ORDER by RAND() LIMIT 3");
|
||||
foreach ($r as $x) {
|
||||
$blacklist=0;
|
||||
$x['ip']=san_ip($x['ip']);
|
||||
echo "Testing masternode: $x[ip]\n";
|
||||
$f=file_get_contents("http://$x[ip]/api.php?q=currentBlock");
|
||||
if ($f) {
|
||||
$res=json_decode($f, true);
|
||||
$res=$res['data'];
|
||||
if ($res['height']<$current['height']-10080) {
|
||||
$blacklist=1;
|
||||
}
|
||||
echo "Masternode Height: ".$res['height']."\n";
|
||||
} else {
|
||||
echo "---> Unresponsive\n";
|
||||
$blacklist=1;
|
||||
}
|
||||
|
||||
if ($blacklist) {
|
||||
echo "Blacklisting masternode $x[public_key]\n";
|
||||
$val='0.00000000';
|
||||
$fee='0.00000001';
|
||||
$date=time();
|
||||
$version=106;
|
||||
$msg=san($x['public_key']);
|
||||
$address=$acc->get_address($x['public_key']);
|
||||
$public_key=$_config['masternode_public_key'];
|
||||
$private_key=$_config['masternode_voting_private_key'];
|
||||
$info=$val."-".$fee."-".$address."-".$msg."-$version-".$public_key."-".$date;
|
||||
$signature=ec_sign($info, $private_key);
|
||||
|
||||
|
||||
$transaction = [
|
||||
"src" => $acc->get_address($_config['masternode_public_key']),
|
||||
"val" => $val,
|
||||
"fee" => $fee,
|
||||
"dst" => $address,
|
||||
"public_key" => $public_key,
|
||||
"date" => $date,
|
||||
"version" => $version,
|
||||
"message" => $msg,
|
||||
"signature" => $signature,
|
||||
];
|
||||
|
||||
$hash = $trx->hash($transaction);
|
||||
$transaction['id'] = $hash;
|
||||
if (!$trx->check($transaction)) {
|
||||
print("Blacklist transaction signature failed\n");
|
||||
}
|
||||
$res = $db->single("SELECT COUNT(1) FROM mempool WHERE id=:id", [":id" => $hash]);
|
||||
if ($res != 0) {
|
||||
print("Blacklist transaction already in mempool\n");
|
||||
}
|
||||
$trx->add_mempool($transaction, "local");
|
||||
$hash=escapeshellarg(san($hash));
|
||||
system("php propagate.php transaction $hash > /dev/null 2>&1 &");
|
||||
echo "Blacklist Hash: $hash\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//clean tmp files
|
||||
_log("Cleaning tmp files");
|
||||
$f = scandir("tmp/");
|
||||
$time = time();
|
||||
foreach ($f as $x) {
|
||||
if (strlen($x) < 5 && substr($x, 0, 1) == ".") {
|
||||
continue;
|
||||
}
|
||||
$pid_time = filemtime("tmp/$x");
|
||||
if ($time - $pid_time > 7200) {
|
||||
@unlink("tmp/$x");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
_log("Finishing sanity");
|
||||
|
||||
@unlink("tmp/sanity-lock");
|
||||
@unlink(SANITY_LOCK_PATH);
|
||||
|
||||
3
tmp/.gitignore
vendored
Executable file
3
tmp/.gitignore
vendored
Executable file
@@ -0,0 +1,3 @@
|
||||
*
|
||||
!.gitignore
|
||||
!db-update
|
||||
@@ -1 +0,0 @@
|
||||
4.0.1
|
||||
174
util.php
174
util.php
@@ -29,7 +29,7 @@ if (php_sapi_name() !== 'cli') {
|
||||
die("This should only be run as cli");
|
||||
}
|
||||
|
||||
require_once("include/init.inc.php");
|
||||
require_once __DIR__.'/include/init.inc.php';
|
||||
$cmd = trim($argv[1]);
|
||||
|
||||
/**
|
||||
@@ -43,6 +43,10 @@ $cmd = trim($argv[1]);
|
||||
*/
|
||||
|
||||
if ($cmd == 'clean') {
|
||||
if (file_exists("tmp/sanity-lock")) {
|
||||
die("Sanity running. Wait for it to finish");
|
||||
}
|
||||
touch("tmp/sanity-lock");
|
||||
$db->run("SET foreign_key_checks=0;");
|
||||
$tables = ["accounts", "transactions", "mempool", "masternode","blocks"];
|
||||
foreach ($tables as $table) {
|
||||
@@ -51,6 +55,7 @@ if ($cmd == 'clean') {
|
||||
$db->run("SET foreign_key_checks=1;");
|
||||
|
||||
echo "\n The database has been cleared\n";
|
||||
unlink("tmp/sanity-lock");
|
||||
} /**
|
||||
* @api {php util.php} pop Pop
|
||||
* @apiName pop
|
||||
@@ -64,9 +69,14 @@ if ($cmd == 'clean') {
|
||||
*/
|
||||
|
||||
elseif ($cmd == 'pop') {
|
||||
if (file_exists("tmp/sanity-lock")) {
|
||||
die("Sanity running. Wait for it to finish");
|
||||
}
|
||||
touch("tmp/sanity-lock");
|
||||
$no = intval($argv[2]);
|
||||
$block = new Block();
|
||||
$block->pop($no);
|
||||
unlink("tmp/sanity-lock");
|
||||
} /**
|
||||
* @api {php util.php} block-time Block-time
|
||||
* @apiName block-time
|
||||
@@ -93,7 +103,7 @@ elseif ($cmd == 'block-time') {
|
||||
}
|
||||
$time = $t - $x['date'];
|
||||
$t = $x['date'];
|
||||
echo "$x[height] -> $time\n";
|
||||
echo "$x[height]\t\t$time\t\t$x[difficulty]\n";
|
||||
$end = $x['date'];
|
||||
}
|
||||
echo "Average block time: ".ceil(($start - $end) / 100)." seconds\n";
|
||||
@@ -183,7 +193,7 @@ elseif ($cmd == "blocks") {
|
||||
if ($limit < 1) {
|
||||
$limit = 100;
|
||||
}
|
||||
$r = $db->run("SELECT * FROM blocks WHERE height>:height ORDER by height ASC LIMIT $limit", [":height" => $height]);
|
||||
$r = $db->run("SELECT * FROM blocks WHERE height>:height ORDER by height ASC LIMIT :limit", [":height" => $height, ":limit"=>$limit]);
|
||||
foreach ($r as $x) {
|
||||
echo "$x[height]\t$x[id]\n";
|
||||
}
|
||||
@@ -411,7 +421,7 @@ elseif ($cmd == "check-address") {
|
||||
}
|
||||
|
||||
echo "The address is valid\n";
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @api {php util.php} get-address Get-Address
|
||||
* @apiName get-address
|
||||
@@ -443,33 +453,149 @@ elseif ($cmd == 'get-address') {
|
||||
* php util.php clean-blacklist
|
||||
*
|
||||
*/
|
||||
|
||||
} elseif ($cmd == 'clean-blacklist') {
|
||||
$db->run("UPDATE peers SET blacklisted=0, fails=0, stuckfail=0");
|
||||
echo "All the peers have been removed from the blacklist\n";
|
||||
}elseif($cmd == 'resync-accounts'){
|
||||
// resyncs the balance on all accounts
|
||||
$db->run("UPDATE peers SET blacklisted=0, fails=0, stuckfail=0");
|
||||
echo "All the peers have been removed from the blacklist\n";
|
||||
} elseif ($cmd == 'resync-accounts') {
|
||||
die("Currently disabled due to asset implementation.");
|
||||
// resyncs the balance on all accounts
|
||||
if (file_exists("tmp/sanity-lock")) {
|
||||
die("Sanity running. Wait for it to finish");
|
||||
}
|
||||
touch("tmp/sanity-lock");
|
||||
// lock table to avoid race conditions on blocks
|
||||
$db->exec("LOCK TABLES blocks WRITE, accounts WRITE, transactions WRITE, mempool WRITE, masternode WRITE, peers write, config WRITE, assets WRITE, assets_balance WRITE, assets_market WRITE");
|
||||
|
||||
// lock table to avoid race conditions on blocks
|
||||
$db->exec("LOCK TABLES blocks WRITE, accounts WRITE, transactions WRITE, mempool WRITE");
|
||||
|
||||
$r=$db->run("SELECT * FROM accounts");
|
||||
foreach($r as $x){
|
||||
$r=$db->run("SELECT * FROM accounts");
|
||||
foreach ($r as $x) {
|
||||
$alias=$x['alias'];
|
||||
if(empty($alias)) $alias="A";
|
||||
$rec=$db->single("SELECT SUM(val) FROM transactions WHERE (dst=:id or dst=:alias) AND (height<80000 OR (version!=100 AND version!=103)) and version<111",[":id"=>$x['id'], ":alias"=>$alias]);
|
||||
$spent=$db->single("SELECT SUM(val+fee) FROM transactions WHERE public_key=:pub AND version>0",[":pub"=>$x['public_key']]);
|
||||
if($spent==false) $spent=0;
|
||||
$balance=round(($rec-$spent),8);
|
||||
if($x['balance']!=$balance){
|
||||
echo "rec: $rec, spent: $spent, bal: $x[balance], should be: $balance - $x[id] $x[public_key]\n";
|
||||
$db->run("UPDATE accounts SET balance=:bal WHERE id=:id",[":id"=>$x['id'], ":bal"=>$balance]);
|
||||
if (empty($alias)) {
|
||||
$alias="A";
|
||||
}
|
||||
}
|
||||
$db->exec("UNLOCK TABLES");
|
||||
echo "All done";
|
||||
$rec=$db->single("SELECT SUM(val) FROM transactions WHERE (dst=:id or dst=:alias) AND (height<80000 OR version!=100) and version<111", [":id"=>$x['id'], ":alias"=>$alias]);
|
||||
$releases=$db->single("SELECT COUNT(1) FROM transactions WHERE dst=:id AND version=103", [":id"=>$x['id']]);
|
||||
|
||||
if ($releases>0) { //masternode releases
|
||||
$rec+=$releases*100000;
|
||||
|
||||
}
|
||||
$spent=$db->single("SELECT SUM(val+fee) FROM transactions WHERE public_key=:pub AND version>0", [":pub"=>$x['public_key']]);
|
||||
if ($spent==false) {
|
||||
$spent=0;
|
||||
}
|
||||
$balance=round(($rec-$spent), 8);
|
||||
if ($x['balance']!=$balance) {
|
||||
echo "rec: $rec, spent: $spent, bal: $x[balance], should be: $balance - $x[id] $x[public_key]\n";
|
||||
if (trim($argv[2])!="check") {
|
||||
$db->run("UPDATE accounts SET balance=:bal WHERE id=:id", [":id"=>$x['id'], ":bal"=>$balance]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$db->exec("UNLOCK TABLES");
|
||||
echo "All done";
|
||||
unlink("tmp/sanity-lock");
|
||||
} elseif ($cmd=="compare-blocks") {
|
||||
$block=new Block();
|
||||
|
||||
$current=$block->current();
|
||||
$peer=trim($argv[2]);
|
||||
$limit=intval($argv[3]);
|
||||
if ($limit==0) {
|
||||
$limit=5000;
|
||||
}
|
||||
for ($i=$current['height']-$limit;$i<=$current['height'];$i++) {
|
||||
$data=peer_post($peer."/peer.php?q=getBlock", ["height" => $i]);
|
||||
if ($data==false) {
|
||||
continue;
|
||||
}
|
||||
$our=$block->export(false, $i);
|
||||
if ($data!=$our) {
|
||||
echo "Failed block -> $i\n";
|
||||
if ($argv[4]=="dump") {
|
||||
echo "\n\n ---- Internal ----\n\n";
|
||||
var_dump($our);
|
||||
echo "\n\n ---- External ----\n\n";
|
||||
var_dump($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($cmd=='compare-accounts') {
|
||||
$peer=trim($argv[2]);
|
||||
$r=$db->run("SELECT id,balance FROM accounts");
|
||||
foreach ($r as $x) {
|
||||
$data=peer_post($peer."/api.php?q=getBalance", ["account" => $x['id']]);
|
||||
if ($data==false) {
|
||||
continue;
|
||||
}
|
||||
if ($data!=$x['balance']) {
|
||||
echo "$x[id]\t\t$x[balance]\t$data\n";
|
||||
}
|
||||
}
|
||||
} elseif ($cmd=='masternode-hash') {
|
||||
$res=$db->run("SELECT * FROM masternode ORDER by public_key ASC");
|
||||
$block=new Block();
|
||||
$current=$block->current();
|
||||
echo "Height:\t\t$current[height]\n";
|
||||
echo "Hash:\t\t".md5(json_encode($res))."\n\n";
|
||||
} elseif ($cmd=='accounts-hash') {
|
||||
$res=$db->run("SELECT * FROM accounts ORDER by id ASC");
|
||||
$block=new Block();
|
||||
$current=$block->current();
|
||||
echo "Height:\t\t$current[height]\n";
|
||||
echo "Hash:\t\t".md5(json_encode($res))."\n\n";
|
||||
} elseif ($cmd == "version") {
|
||||
echo "\n\n".VERSION."\n\n";
|
||||
} elseif ($cmd == "sendblock") {
|
||||
$peer=trim($argv[3]);
|
||||
if (!filter_var($peer, FILTER_VALIDATE_URL)) {
|
||||
die("Invalid peer hostname");
|
||||
}
|
||||
$peer = filter_var($peer, FILTER_SANITIZE_URL);
|
||||
$height=intval($argv[2]);
|
||||
$block=new Block();
|
||||
$data = $block->export("", $height);
|
||||
|
||||
|
||||
if ($data===false) {
|
||||
die("Could not find this block");
|
||||
}
|
||||
$response = peer_post($peer."/peer.php?q=submitBlock", $data, 60, true);
|
||||
var_dump($response);
|
||||
} elseif ($cmd == "recheck-external-blocks") {
|
||||
$peer=trim($argv[2]);
|
||||
if (!filter_var($peer, FILTER_VALIDATE_URL)) {
|
||||
die("Invalid peer hostname");
|
||||
}
|
||||
$peer = filter_var($peer, FILTER_SANITIZE_URL);
|
||||
|
||||
|
||||
$blocks = [];
|
||||
$block = new Block();
|
||||
$height=intval($argv[3]);
|
||||
|
||||
$last=peer_post($peer."/peer.php?q=currentBlock");
|
||||
|
||||
$b=peer_post($peer."/peer.php?q=getBlock", ["height"=>$height]);
|
||||
|
||||
for ($i = $height+1; $i <= $last['height']; $i++) {
|
||||
$c=peer_post($peer."/peer.php?q=getBlock", ["height"=>$i]);
|
||||
|
||||
if (!$block->mine(
|
||||
$c['public_key'],
|
||||
$c['nonce'],
|
||||
$c['argon'],
|
||||
$c['difficulty'],
|
||||
$b['id'],
|
||||
$b['height'],
|
||||
$c['date']
|
||||
)) {
|
||||
print("Invalid block detected. $c[height] - $c[id]\n");
|
||||
break;
|
||||
}
|
||||
echo "Block $i -> ok\n";
|
||||
$b=$c;
|
||||
}
|
||||
} else {
|
||||
echo "Invalid command\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user