untested hf
This commit is contained in:
@@ -43,6 +43,31 @@ class Block
|
|||||||
|
|
||||||
$msg = '';
|
$msg = '';
|
||||||
|
|
||||||
|
$mn_reward_rate=0.33;
|
||||||
|
|
||||||
|
// hf
|
||||||
|
if($height>212000){
|
||||||
|
$votes=[];
|
||||||
|
$r=$db->run("SELECT id,val FROM votes");
|
||||||
|
foreach($r as $vote){
|
||||||
|
$votes[$vote['id']]=$vote['val'];
|
||||||
|
}
|
||||||
|
// emission cut by 30%
|
||||||
|
if($votes['emission30']==1){
|
||||||
|
$reward=round($reward*0.7);
|
||||||
|
}
|
||||||
|
// 50% to masternodes
|
||||||
|
if($votes['masternodereward50']==1){
|
||||||
|
$mn_reward_rate=0.5;
|
||||||
|
}
|
||||||
|
// minimum reward to always be 50 aro
|
||||||
|
if($votes['endless50reward']==1&&$reward<50){
|
||||||
|
$reward=50;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($height>=80458) {
|
if ($height>=80458) {
|
||||||
//reward the masternode
|
//reward the masternode
|
||||||
|
|
||||||
@@ -52,7 +77,7 @@ class Block
|
|||||||
);
|
);
|
||||||
_log("MN Winner: $mn_winner", 2);
|
_log("MN Winner: $mn_winner", 2);
|
||||||
if ($mn_winner!==false) {
|
if ($mn_winner!==false) {
|
||||||
$mn_reward=round(0.33*$reward, 8);
|
$mn_reward=round($mn_reward_rate*$reward, 8);
|
||||||
$reward=round($reward-$mn_reward, 8);
|
$reward=round($reward-$mn_reward, 8);
|
||||||
$reward=number_format($reward, 8, ".", "");
|
$reward=number_format($reward, 8, ".", "");
|
||||||
$mn_reward=number_format($mn_reward, 8, ".", "");
|
$mn_reward=number_format($mn_reward, 8, ".", "");
|
||||||
@@ -674,17 +699,41 @@ class Block
|
|||||||
|
|
||||||
// reward transaction and signature
|
// reward transaction and signature
|
||||||
$reward = $this->reward($height, $data);
|
$reward = $this->reward($height, $data);
|
||||||
|
$mn_reward_rate=0.33;
|
||||||
|
global $db;
|
||||||
|
// hf
|
||||||
|
if($height>212000){
|
||||||
|
$votes=[];
|
||||||
|
$r=$db->run("SELECT id,val FROM votes");
|
||||||
|
foreach($r as $vote){
|
||||||
|
$votes[$vote['id']]=$vote['val'];
|
||||||
|
}
|
||||||
|
// emission cut by 30%
|
||||||
|
if($votes['emission30']==1){
|
||||||
|
$reward=round($reward*0.7);
|
||||||
|
}
|
||||||
|
// 50% to masternodes
|
||||||
|
if($votes['masternodereward50']==1){
|
||||||
|
$mn_reward_rate=0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// minimum reward to always be 50 aro
|
||||||
|
if($votes['endless50reward']==1&&$reward<50){
|
||||||
|
$reward=50;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if ($height>=80458) {
|
if ($height>=80458) {
|
||||||
//reward the masternode
|
//reward the masternode
|
||||||
global $db;
|
|
||||||
$mn_winner=$db->single(
|
$mn_winner=$db->single(
|
||||||
"SELECT public_key FROM masternode WHERE status=1 AND blacklist<:current AND height<:start ORDER by last_won ASC, public_key ASC LIMIT 1",
|
"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"=>$height, ":start"=>$height-360]
|
[":current"=>$height, ":start"=>$height-360]
|
||||||
);
|
);
|
||||||
_log("MN Winner: $mn_winner", 2);
|
_log("MN Winner: $mn_winner", 2);
|
||||||
if ($mn_winner!==false) {
|
if ($mn_winner!==false) {
|
||||||
$mn_reward=round(0.33*$reward, 8);
|
$mn_reward=round($mn_reward_rate*$reward, 8);
|
||||||
$reward=round($reward-$mn_reward, 8);
|
$reward=round($reward-$mn_reward, 8);
|
||||||
$reward=number_format($reward, 8, ".", "");
|
$reward=number_format($reward, 8, ".", "");
|
||||||
$mn_reward=number_format($mn_reward, 8, ".", "");
|
$mn_reward=number_format($mn_reward, 8, ".", "");
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ if ($dbversion == 7) {
|
|||||||
$dbversion++;
|
$dbversion++;
|
||||||
}
|
}
|
||||||
if ($dbversion == 8) {
|
if ($dbversion == 8) {
|
||||||
$db->run("CREATE TABLE `masternode` (
|
$db->run("CREATE TABLE `masternode` (
|
||||||
`public_key` varchar(128) COLLATE utf8mb4_bin NOT NULL,
|
`public_key` varchar(128) COLLATE utf8mb4_bin NOT NULL,
|
||||||
`height` int(11) NOT NULL,
|
`height` int(11) NOT NULL,
|
||||||
`ip` varchar(16) COLLATE utf8mb4_bin NOT NULL,
|
`ip` varchar(16) COLLATE utf8mb4_bin NOT NULL,
|
||||||
@@ -157,21 +157,21 @@ if ($dbversion == 8) {
|
|||||||
`status` tinyint(4) NOT NULL DEFAULT '1'
|
`status` tinyint(4) NOT NULL DEFAULT '1'
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;");
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;");
|
||||||
|
|
||||||
$db->run("ALTER TABLE `masternode`
|
$db->run("ALTER TABLE `masternode`
|
||||||
ADD PRIMARY KEY (`public_key`),
|
ADD PRIMARY KEY (`public_key`),
|
||||||
ADD KEY `last_won` (`last_won`),
|
ADD KEY `last_won` (`last_won`),
|
||||||
ADD KEY `status` (`status`),
|
ADD KEY `status` (`status`),
|
||||||
ADD KEY `blacklist` (`blacklist`),
|
ADD KEY `blacklist` (`blacklist`),
|
||||||
ADD KEY `height` (`height`);");
|
ADD KEY `height` (`height`);");
|
||||||
$dbversion++;
|
$dbversion++;
|
||||||
}
|
}
|
||||||
if ($dbversion = 9) {
|
if ($dbversion = 9) {
|
||||||
//dev only
|
//dev only
|
||||||
$dbversion++;
|
$dbversion++;
|
||||||
}
|
}
|
||||||
if ($dbversion = 10) {
|
if ($dbversion = 10) {
|
||||||
//assets system
|
//assets system
|
||||||
$db->run("
|
$db->run("
|
||||||
CREATE TABLE `assets` (
|
CREATE TABLE `assets` (
|
||||||
`id` varbinary(128) NOT NULL,
|
`id` varbinary(128) NOT NULL,
|
||||||
`max_supply` bigint(18) NOT NULL DEFAULT '0',
|
`max_supply` bigint(18) NOT NULL DEFAULT '0',
|
||||||
@@ -183,11 +183,11 @@ if ($dbversion = 10) {
|
|||||||
`height` int(11) NOT NULL DEFAULT '0'
|
`height` int(11) NOT NULL DEFAULT '0'
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||||
");
|
");
|
||||||
$db->run("
|
$db->run("
|
||||||
ALTER TABLE `assets`
|
ALTER TABLE `assets`
|
||||||
ADD PRIMARY KEY (`id`)
|
ADD PRIMARY KEY (`id`)
|
||||||
");
|
");
|
||||||
$db->run("
|
$db->run("
|
||||||
CREATE TABLE `assets_market` (
|
CREATE TABLE `assets_market` (
|
||||||
`id` varchar(128) COLLATE utf8mb4_bin NOT NULL,
|
`id` varchar(128) COLLATE utf8mb4_bin NOT NULL,
|
||||||
`account` varbinary(128) NOT NULL,
|
`account` varbinary(128) NOT NULL,
|
||||||
@@ -201,25 +201,45 @@ if ($dbversion = 10) {
|
|||||||
`cancelable` tinyint(1) NOT NULL DEFAULT '1'
|
`cancelable` tinyint(1) NOT NULL DEFAULT '1'
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||||
");
|
");
|
||||||
$db->run("
|
$db->run("
|
||||||
ALTER TABLE `assets_market`
|
ALTER TABLE `assets_market`
|
||||||
ADD PRIMARY KEY (`id`);
|
ADD PRIMARY KEY (`id`);
|
||||||
");
|
");
|
||||||
$db->run("CREATE TABLE `assets_balance` (
|
$db->run("CREATE TABLE `assets_balance` (
|
||||||
`account` varbinary(128) NOT NULL,
|
`account` varbinary(128) NOT NULL,
|
||||||
`asset` varbinary(128) NOT NULL,
|
`asset` varbinary(128) NOT NULL,
|
||||||
`balance` bigint(128) NOT NULL DEFAULT '0'
|
`balance` bigint(128) NOT NULL DEFAULT '0'
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||||
");
|
");
|
||||||
|
|
||||||
$db->run("
|
$db->run("
|
||||||
ALTER TABLE `assets_balance`
|
ALTER TABLE `assets_balance`
|
||||||
ADD PRIMARY KEY (`account`,`asset`);
|
ADD PRIMARY KEY (`account`,`asset`);
|
||||||
");
|
");
|
||||||
|
|
||||||
$dbversion++;
|
$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) NOT NULL,
|
||||||
|
`json` text DEFAULT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;");
|
||||||
|
$db->run("ALTER TABLE `logs`
|
||||||
|
ADD PRIMARY KEY (`id`),
|
||||||
|
ADD KEY `transaction` (`transaction`);");
|
||||||
|
$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`; ");
|
||||||
|
|
||||||
|
$dbversion++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// update the db version to the latest one
|
// update the db version to the latest one
|
||||||
if ($dbversion != $_config['dbversion']) {
|
if ($dbversion != $_config['dbversion']) {
|
||||||
|
|||||||
@@ -4,6 +4,30 @@ use Arionum\Blacklist;
|
|||||||
|
|
||||||
class Transaction
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// reverse and remove all transactions from a block
|
// reverse and remove all transactions from a block
|
||||||
public function reverse($block)
|
public function reverse($block)
|
||||||
{
|
{
|
||||||
@@ -29,10 +53,10 @@ class Transaction
|
|||||||
} else {
|
} else {
|
||||||
// other type of transactions
|
// other type of transactions
|
||||||
|
|
||||||
if ($x['version']!=100 && $x['version']<111 && $x['version'] != 54 && $x['version'] != 57 && $x['version'] != 58 ) {
|
if ($x['version']!=100 && $x['version']<111 && $x['version'] != 54 && $x['version'] != 57 && $x['version'] != 58) {
|
||||||
$rez=$db->run(
|
$rez=$db->run(
|
||||||
"UPDATE accounts SET balance=balance-:val WHERE id=:id",
|
"UPDATE accounts SET balance=balance-:val WHERE id=:id",
|
||||||
[":id" => $x['dst'], ":val" => $x['val']]
|
[":id" => $x['dst'], ":val" => $x['val']]
|
||||||
);
|
);
|
||||||
if ($rez!=1) {
|
if ($rez!=1) {
|
||||||
_log("Update accounts balance minus failed ", 3);
|
_log("Update accounts balance minus failed ", 3);
|
||||||
@@ -74,7 +98,7 @@ class Transaction
|
|||||||
} elseif ($x['version']==101) {
|
} elseif ($x['version']==101) {
|
||||||
$rez=$db->run(
|
$rez=$db->run(
|
||||||
"UPDATE masternode SET status=1 WHERE public_key=:public_key",
|
"UPDATE masternode SET status=1 WHERE public_key=:public_key",
|
||||||
[':public_key'=>$x['public_key']]
|
[':public_key'=>$x['public_key']]
|
||||||
);
|
);
|
||||||
} elseif ($x['version']==102) {
|
} elseif ($x['version']==102) {
|
||||||
$rez=$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']]);
|
||||||
@@ -82,7 +106,7 @@ class Transaction
|
|||||||
$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']]);
|
$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(
|
$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",
|
"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;
|
$status=1;
|
||||||
@@ -93,7 +117,7 @@ class Transaction
|
|||||||
|
|
||||||
$rez=$db->run(
|
$rez=$db->run(
|
||||||
"INSERT into masternode SET `public_key`=:public_key, `height`=:height, `ip`=:ip, `status`=:status",
|
"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]
|
||||||
);
|
);
|
||||||
if ($rez!=1) {
|
if ($rez!=1) {
|
||||||
_log("Insert into masternode failed", 3);
|
_log("Insert into masternode failed", 3);
|
||||||
@@ -104,6 +128,10 @@ class Transaction
|
|||||||
_log("Update masternode balance failed", 3);
|
_log("Update masternode balance failed", 3);
|
||||||
return false;
|
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
|
// internal masternode history
|
||||||
@@ -113,7 +141,7 @@ class Transaction
|
|||||||
|
|
||||||
$rez=$db->run(
|
$rez=$db->run(
|
||||||
"UPDATE masternode SET fails=:fails, blacklist=:blacklist, last_won=:last_won WHERE public_key=:public_key",
|
"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) {
|
if ($rez!=1) {
|
||||||
_log("Update masternode log failed", 3);
|
_log("Update masternode log failed", 3);
|
||||||
@@ -123,73 +151,71 @@ class Transaction
|
|||||||
|
|
||||||
|
|
||||||
// asset transactions
|
// asset transactions
|
||||||
if($x['version']==50){
|
if ($x['version']==50) {
|
||||||
$db->run("DELETE FROM assets WHERE id=:id",[":id"=>$x['src']]);
|
$db->run("DELETE FROM assets WHERE id=:id", [":id"=>$x['src']]);
|
||||||
$db->run("DELETE FROM assets_balance WHERE asset=:id",[":id"=>$x['src']]);
|
$db->run("DELETE FROM assets_balance WHERE asset=:id", [":id"=>$x['src']]);
|
||||||
} elseif ($x['version']==51){
|
} elseif ($x['version']==51) {
|
||||||
$t=json_decode($x['message'],true);
|
$t=json_decode($x['message'], true);
|
||||||
$db->run("UPDATE assets_balance SET balance=balance-:balance WHERE account=:account and asset=:asset",
|
$db->run(
|
||||||
[":account"=>$x['dst'], ":asset"=>san($t[0]), ":balance"=>intval($t[1])]);
|
"UPDATE assets_balance SET balance=balance-:balance WHERE account=:account and asset=:asset",
|
||||||
$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])]);
|
[":account"=>$x['dst'], ":asset"=>san($t[0]), ":balance"=>intval($t[1])]
|
||||||
} elseif ($x['version']==52){
|
);
|
||||||
$t=json_decode($x['message'],true);
|
$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])]);
|
||||||
if($t[4]=="ask"){
|
} elseif ($x['version']==52) {
|
||||||
|
$t=json_decode($x['message'], true);
|
||||||
|
if ($t[4]=="ask") {
|
||||||
$type="ask";
|
$type="ask";
|
||||||
} else {
|
} else {
|
||||||
$type="bid";
|
$type="bid";
|
||||||
}
|
}
|
||||||
if($type=="ask"){
|
if ($type=="ask") {
|
||||||
$db->run("UPDATE assets_balance SET balance=balance+:val WHERE account=:account AND asset=:asset", [
|
$db->run("UPDATE assets_balance SET balance=balance+:val WHERE account=:account AND asset=:asset", [
|
||||||
":account"=>$x['src'],
|
":account"=>$x['src'],
|
||||||
":asset"=>san($t[0]),
|
":asset"=>san($t[0]),
|
||||||
":val"=>intval($t[2])
|
":val"=>intval($t[2])
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$val=number_format($t[2]*$t[1], 8, '.', '');
|
$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("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']]);
|
$db->run("DELETE FROM assets_market WHERE id=:id", [':id'=>$x['id']]);
|
||||||
|
} elseif ($x['version']==53) {
|
||||||
} 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']]);
|
||||||
$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) {
|
||||||
if($order)
|
|
||||||
{
|
|
||||||
$remaining=$order['val']-$order['val_done'];
|
$remaining=$order['val']-$order['val_done'];
|
||||||
if ($remaining>0) {
|
if ($remaining>0) {
|
||||||
if ($order['type']=="ask") {
|
if ($order['type']=="ask") {
|
||||||
$db->run("UPDATE assets_balance SET balance=balance-:val WHERE account=:account AND asset=:asset", [
|
$db->run("UPDATE assets_balance SET balance=balance-:val WHERE account=:account AND asset=:asset", [
|
||||||
":account"=>$x['src'],
|
":account"=>$x['src'],
|
||||||
":asset"=>san($order['asset']),
|
":asset"=>san($order['asset']),
|
||||||
":val"=>intval($remaining)
|
":val"=>intval($remaining)
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$val=number_format($order['price']*$remaining, 8, '.', '');
|
$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 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'])]);
|
$db->run("UPDATE assets_market SET status=0 WHERE id=:id", [":id"=>san($x['message'])]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} elseif ($x['version']==54||$x['version']==57) {
|
||||||
} elseif ($x['version']==54||$x['version']==57){
|
|
||||||
//nothing to be done
|
//nothing to be done
|
||||||
} elseif ($x['version']==55){
|
} elseif ($x['version']==55) {
|
||||||
// the message stores the increment value
|
// the message stores the increment value
|
||||||
$plus=intval($x['message']);
|
$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]);
|
$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){
|
} elseif ($x['version']==58) {
|
||||||
// the message stores the number of units
|
// the message stores the number of units
|
||||||
$use=intval($x['message']);
|
$use=intval($x['message']);
|
||||||
// we stored the bid order id in the public key field and the ask in the dst field
|
// 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['public_key'], ":done"=>$use]);
|
||||||
$db->run("UPDATE assets_market SET val_done=val_done-:done WHERE id=:id",[":id"=>$x['dst'], ":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']]);
|
$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']]);
|
$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]);
|
$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'];
|
$aro=$x['val'];
|
||||||
$db->run("UPDATE accounts SET balance=balance-:balance WHERE id=:id",[":balance"=>$aro, ":id"=>$ask['account']]);
|
$db->run("UPDATE accounts SET balance=balance-:balance WHERE id=:id", [":balance"=>$aro, ":id"=>$ask['account']]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -251,9 +277,9 @@ class Transaction
|
|||||||
}
|
}
|
||||||
|
|
||||||
//only a single asset creation per block
|
//only a single asset creation per block
|
||||||
if($x['version']==50){
|
if ($x['version']==50) {
|
||||||
$assets++;
|
$assets++;
|
||||||
if($assets>1){
|
if ($assets>1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,13 +410,13 @@ class Transaction
|
|||||||
}
|
}
|
||||||
|
|
||||||
// market order side chain
|
// market order side chain
|
||||||
if($x['version']==58){
|
if ($x['version']==58) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($x['version'] == 2&&$height>=80000) {
|
if ($x['version'] == 2&&$height>=80000) {
|
||||||
$db->run("UPDATE accounts SET balance=balance+:val WHERE alias=:alias", [":alias" => $x['dst'], ":val" => $x['val']]);
|
$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){
|
} elseif ($x['version']==50||$x['version']==54||$x['version']==57) {
|
||||||
// asset creation and dividend distribution
|
// asset creation and dividend distribution
|
||||||
} elseif ($x['version']==100&&$height>=80000) {
|
} elseif ($x['version']==100&&$height>=80000) {
|
||||||
//master node deposit
|
//master node deposit
|
||||||
@@ -417,8 +443,8 @@ class Transaction
|
|||||||
// set the alias
|
// set the alias
|
||||||
if ($x['version']==3&&$height>=80000) {
|
if ($x['version']==3&&$height>=80000) {
|
||||||
$db->run(
|
$db->run(
|
||||||
"UPDATE accounts SET alias=:alias WHERE id=:id",
|
"UPDATE accounts SET alias=:alias WHERE id=:id",
|
||||||
[":id" => $x['src'], ":alias"=>$x['message']]
|
[":id" => $x['src'], ":alias"=>$x['message']]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,20 +456,32 @@ 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]);
|
$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 {
|
} else {
|
||||||
if ($x['version']==101) {
|
if ($x['version']==101) {
|
||||||
|
// pause masternode
|
||||||
$db->run("UPDATE masternode SET status=0 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
$db->run("UPDATE masternode SET status=0 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||||
} elseif ($x['version']==102) {
|
} elseif ($x['version']==102) {
|
||||||
|
// reactivate pasternode
|
||||||
$db->run("UPDATE masternode SET status=1 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
$db->run("UPDATE masternode SET status=1 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||||
} elseif ($x['version']==103) {
|
} 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("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']]);
|
$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
|
// asset system
|
||||||
if($x['version']==50){
|
if ($x['version']==50) {
|
||||||
// asset creation
|
// asset creation
|
||||||
$bind=[];
|
$bind=[];
|
||||||
$asset=json_decode($x['message'],true);
|
$asset=json_decode($x['message'], true);
|
||||||
$bind[':max_supply']=intval($asset[0]);
|
$bind[':max_supply']=intval($asset[0]);
|
||||||
$bind[':tradable']=intval($asset[1]);
|
$bind[':tradable']=intval($asset[1]);
|
||||||
$bind[':price']=number_format($asset[2], 8, '.', '');
|
$bind[':price']=number_format($asset[2], 8, '.', '');
|
||||||
@@ -452,21 +490,23 @@ class Transaction
|
|||||||
$bind[':allow_bid']=intval($asset[5]);
|
$bind[':allow_bid']=intval($asset[5]);
|
||||||
$bind[':height']=$height;
|
$bind[':height']=$height;
|
||||||
$bind[':id']=$x['src'];
|
$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);
|
$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){
|
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']]);
|
$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){
|
} elseif ($x['version']==51) {
|
||||||
// send asset
|
// send asset
|
||||||
$t=json_decode($x['message'],true);
|
$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",
|
$db->run(
|
||||||
[":account"=>$x['dst'], ":asset"=>san($t[0]), ":balance"=>intval($t[1]), ":balance2"=>intval($t[1])]);
|
"INSERT into assets_balance SET account=:account, asset=:asset, balance=:balance ON DUPLICATE KEY UPDATE balance=balance+:balance2",
|
||||||
$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])]);
|
[":account"=>$x['dst'], ":asset"=>san($t[0]), ":balance"=>intval($t[1]), ":balance2"=>intval($t[1])]
|
||||||
} elseif($x['version']==52){
|
);
|
||||||
|
$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
|
// market order
|
||||||
$t=json_decode($x['message'],true);
|
$t=json_decode($x['message'], true);
|
||||||
|
|
||||||
if($t[4]=="ask"){
|
if ($t[4]=="ask") {
|
||||||
$type="ask";
|
$type="ask";
|
||||||
} else {
|
} else {
|
||||||
$type="bid";
|
$type="bid";
|
||||||
@@ -476,7 +516,7 @@ class Transaction
|
|||||||
|
|
||||||
|
|
||||||
$bind=[":id" => san($x['id']),
|
$bind=[":id" => san($x['id']),
|
||||||
":account" => $x['src'],
|
":account" => $x['src'],
|
||||||
":asset" => san($t[0]),
|
":asset" => san($t[0]),
|
||||||
":price" => number_format($t[1], 8, '.', ''),
|
":price" => number_format($t[1], 8, '.', ''),
|
||||||
":date" => $x['date'],
|
":date" => $x['date'],
|
||||||
@@ -484,54 +524,51 @@ class Transaction
|
|||||||
":type" => $type,
|
":type" => $type,
|
||||||
":cancel" => intval($t[3])
|
":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);
|
$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"){
|
if ($type=="ask") {
|
||||||
$db->run("UPDATE assets_balance SET balance=balance-:val WHERE account=:account AND asset=:asset", [
|
$db->run("UPDATE assets_balance SET balance=balance-:val WHERE account=:account AND asset=:asset", [
|
||||||
":account"=>$x['src'],
|
":account"=>$x['src'],
|
||||||
":asset"=>san($t[0]),
|
":asset"=>san($t[0]),
|
||||||
":val"=>intval($t[2])
|
":val"=>intval($t[2])
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$val=number_format($t[2]*$t[1], 8, '.', '');
|
$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("UPDATE accounts SET balance=balance-:val WHERE id=:id", [":id"=>$x['src'], ":val"=>$val]);
|
||||||
}
|
}
|
||||||
} elseif($x['version']==53){
|
} elseif ($x['version']==53) {
|
||||||
// cancel order
|
// 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']]);
|
$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)
|
if ($order) {
|
||||||
{
|
|
||||||
$remaining=$order['val']-$order['val_done'];
|
$remaining=$order['val']-$order['val_done'];
|
||||||
if ($remaining>0) {
|
if ($remaining>0) {
|
||||||
if ($order['type']=="ask") {
|
if ($order['type']=="ask") {
|
||||||
$db->run("UPDATE assets_balance SET balance=balance+:val WHERE account=:account AND asset=:asset", [
|
$db->run("UPDATE assets_balance SET balance=balance+:val WHERE account=:account AND asset=:asset", [
|
||||||
":account"=>$x['src'],
|
":account"=>$x['src'],
|
||||||
":asset"=>san($order['asset']),
|
":asset"=>san($order['asset']),
|
||||||
":val"=>intval($remaining)
|
":val"=>intval($remaining)
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$val=number_format($order['price']*$remaining, 8, '.', '');
|
$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 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'])]);
|
$db->run("UPDATE assets_market SET status=2 WHERE id=:id", [":id"=>san($x['message'])]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} elseif ($x['version']==54||$x['version']==57) {
|
||||||
|
|
||||||
} elseif($x['version']==54||$x['version']==57){
|
|
||||||
//distribute dividends - only from asset wallet and only to other holders
|
//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']]);
|
$r=$db->run("SELECT * FROM assets_balance WHERE asset=:asset AND balance>0 AND account!=:acc", [":asset"=>$x['src'], ":acc"=>$x['src']]);
|
||||||
$total=0;
|
$total=0;
|
||||||
foreach($r as $g){
|
foreach ($r as $g) {
|
||||||
$total+=$g['balance'];
|
$total+=$g['balance'];
|
||||||
}
|
}
|
||||||
_log("Asset dividend distribution: $total units",3);
|
_log("Asset dividend distribution: $total units", 3);
|
||||||
foreach ($r as $g){
|
foreach ($r as $g) {
|
||||||
$coins=number_format(($g['balance']/$total)*$x['val'], 8, '.', '');
|
$coins=number_format(($g['balance']/$total)*$x['val'], 8, '.', '');
|
||||||
$fee=number_format(($g['balance']/$total)*$x['fee'], 8, '.', '');
|
$fee=number_format(($g['balance']/$total)*$x['fee'], 8, '.', '');
|
||||||
$hash = hex2coin(hash("sha512", $x['id'].$g['account']));
|
$hash = hex2coin(hash("sha512", $x['id'].$g['account']));
|
||||||
_log("Distributing to $g[account] for $g[balance] units - $coins ARO",3);
|
_log("Distributing to $g[account] for $g[balance] units - $coins ARO", 3);
|
||||||
|
|
||||||
$new = [
|
$new = [
|
||||||
"id" => $hash,
|
"id" => $hash,
|
||||||
@@ -545,11 +582,12 @@ class Transaction
|
|||||||
"src" => $x['src'],
|
"src" => $x['src'],
|
||||||
"message" => '',
|
"message" => '',
|
||||||
];
|
];
|
||||||
$res=$this->add($block,$height,$new);
|
$res=$this->add($block, $height, $new);
|
||||||
if(!$res) return false;
|
if (!$res) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} elseif ($x['version']==55) {
|
||||||
} elseif($x['version']==55){
|
|
||||||
// increase max supply
|
// increase max supply
|
||||||
$plus=intval($x['message']);
|
$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("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]);
|
||||||
@@ -623,13 +661,15 @@ class Transaction
|
|||||||
_log("The account already has an alias", 3);
|
_log("The account already has an alias", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($x['dst']!=$src){
|
if ($x['dst']!=$src) {
|
||||||
// just to prevent some bypasses in the future
|
// just to prevent some bypasses in the future
|
||||||
_log("DST must be SRC for this transaction", 3);
|
_log("DST must be SRC for this transaction", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//masternode transactions
|
//masternode transactions
|
||||||
|
|
||||||
if ($x['version']>=100&&$x['version']<110&&$height>=80000) {
|
if ($x['version']>=100&&$x['version']<110&&$height>=80000) {
|
||||||
@@ -654,7 +694,7 @@ class Transaction
|
|||||||
} elseif ($x['version']!=100) {
|
} elseif ($x['version']!=100) {
|
||||||
$mn=$acc->get_masternode($x['public_key']);
|
$mn=$acc->get_masternode($x['public_key']);
|
||||||
|
|
||||||
if($x['dst']!=$src){
|
if ($x['dst']!=$src) {
|
||||||
// just to prevent some bypasses in the future
|
// just to prevent some bypasses in the future
|
||||||
_log("DST must be SRC for this transaction", 3);
|
_log("DST must be SRC for this transaction", 3);
|
||||||
return false;
|
return false;
|
||||||
@@ -680,108 +720,154 @@ class Transaction
|
|||||||
_log("The masternode start height is less than 32400 blocks! $height - $mn[height]", 3);
|
_log("The masternode start height is less than 32400 blocks! $height - $mn[height]", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} elseif ($x['version']==104) {
|
||||||
|
//only once per month (every 10800 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-10800]);
|
||||||
|
if ($res!=0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} elseif ($x['version']==105) {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// masternode votes
|
||||||
|
elseif ($x['version']==106) {
|
||||||
|
// value always 0
|
||||||
|
if ($x['val']!=0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// one vote to each mn per 10800 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-10800]);
|
||||||
|
if ($res>0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// masternode blockchain votes
|
||||||
|
elseif ($x['version']==107) {
|
||||||
|
// value always 0
|
||||||
|
if ($x['val']!=0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// one vote to each mn per 32400 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-32400]);
|
||||||
|
if ($res>0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// assets
|
// assets
|
||||||
if ($x['version']==50) {
|
if ($x['version']==50) {
|
||||||
// asset creation
|
// asset creation
|
||||||
// fixed asset price 100 +. The 100 are burned and not distributed to miners.
|
// fixed asset price 100 +. The 100 are burned and not distributed to miners.
|
||||||
if ($x['val']!=100) {
|
if ($x['val']!=100) {
|
||||||
_log("The asset creation transaction is not 100", 3);
|
_log("The asset creation transaction is not 100", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// stored in message in json format - [max supply, tradable, fixed price, dividend only, autodividend]
|
// stored in message in json format - [max supply, tradable, fixed price, dividend only, autodividend]
|
||||||
$asset=json_decode($x['message'],true);
|
$asset=json_decode($x['message'], true);
|
||||||
if($asset==false){
|
if ($asset==false) {
|
||||||
_log("Invalid asset creation json", 3);
|
_log("Invalid asset creation json", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// minimum 0 (for inflatable assets) and maximum 1.000.000.000
|
// minimum 0 (for inflatable assets) and maximum 1.000.000.000
|
||||||
if($asset[0]>1000000000||$asset[0]<0||intval($asset[0])!=$asset[0]){
|
if ($asset[0]>1000000000||$asset[0]<0||intval($asset[0])!=$asset[0]) {
|
||||||
_log("Invalid asset max supply", 3);
|
_log("Invalid asset max supply", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 0 for non-tradable, 1 for tradable on the blockchain market
|
// 0 for non-tradable, 1 for tradable on the blockchain market
|
||||||
if($asset[1]!==1&&$asset[1]!==0){
|
if ($asset[1]!==1&&$asset[1]!==0) {
|
||||||
_log("Invalid asset tradable", 3);
|
_log("Invalid asset tradable", 3);
|
||||||
return false;
|
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 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){
|
if (number_format($asset[2], 8, '.', '')!=$asset[2]||$asset[2]<0||$asset[2]>1000000) {
|
||||||
_log("Invalid asset price", 3);
|
_log("Invalid asset price", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 1 to allow only dividend distribution, 0 to allow all transfers
|
// 1 to allow only dividend distribution, 0 to allow all transfers
|
||||||
if($asset[3]!==1&&$asset[3]!==0){
|
if ($asset[3]!==1&&$asset[3]!==0) {
|
||||||
_log("Invalid asset dividend setting", 3);
|
_log("Invalid asset dividend setting", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// automatic dividend distribution every 10000 blocks
|
// automatic dividend distribution every 10000 blocks
|
||||||
if($asset[4]!==1&&$asset[4]!==0){
|
if ($asset[4]!==1&&$asset[4]!==0) {
|
||||||
_log("Invalid asset autodividend setting", 3);
|
_log("Invalid asset autodividend setting", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// do not allow this asset to buy other assets via the market
|
// do not allow this asset to buy other assets via the market
|
||||||
if($asset[5]!==1&&$asset[5]!==0){
|
if ($asset[5]!==1&&$asset[5]!==0) {
|
||||||
_log("Invalid asset bid_only setting", 3);
|
_log("Invalid asset bid_only setting", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// make sure there is no similar asset with the same alias
|
// make sure there is no similar asset with the same alias
|
||||||
$chk=$db->single("SELECT COUNT(1) FROM assets WHERE id=:id",[":id"=>$src]);
|
$chk=$db->single("SELECT COUNT(1) FROM assets WHERE id=:id", [":id"=>$src]);
|
||||||
if($chk!==0){
|
if ($chk!==0) {
|
||||||
_log("The asset already exists", 3);
|
_log("The asset already exists", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// asset transfer
|
// asset transfer
|
||||||
if($x['version']==51){
|
if ($x['version']==51) {
|
||||||
// Transfer details in json format, stored in the message. format: [asset id, units]
|
// Transfer details in json format, stored in the message. format: [asset id, units]
|
||||||
// The transfer is done to the dst address of the transactions
|
// The transfer is done to the dst address of the transactions
|
||||||
$asset=json_decode($x['message'],true);
|
$asset=json_decode($x['message'], true);
|
||||||
if($asset==false){
|
if ($asset==false) {
|
||||||
_log("Invalid asset creation json", 3);
|
_log("Invalid asset creation json", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check if the asset exists
|
// check if the asset exists
|
||||||
$blockasset=$db->row("SELECT id, price FROM assets WHERE id=:id",[":id"=>san($asset[0])]);
|
$blockasset=$db->row("SELECT id, price FROM assets WHERE id=:id", [":id"=>san($asset[0])]);
|
||||||
if(!$blockasset){
|
if (!$blockasset) {
|
||||||
_log("Invalid asset", 3);
|
_log("Invalid asset", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// minimum 1 unit is transfered
|
// minimum 1 unit is transfered
|
||||||
if(intval($asset[1])!=$asset[1]||$asset[1]<1){
|
if (intval($asset[1])!=$asset[1]||$asset[1]<1) {
|
||||||
_log("Invalid amount", 3);
|
_log("Invalid amount", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//make sure the wallet has enough asset units
|
//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])]);
|
$balance=$db->single("SELECT balance FROM assets_balance WHERE account=:account AND asset=:asset", [":account"=>$src, ":asset"=>san($asset[0])]);
|
||||||
if($balance<=$asset[1]){
|
if ($balance<=$asset[1]) {
|
||||||
_log("Not enough balance", 3);
|
_log("Not enough balance", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($blockasset['price']>0 && $src == $blockasset['id'] && $blockasset['price']!=$asset[1] && $blockasset['tradable'] ==1 ){
|
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
|
// 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
|
// on a fixed price always
|
||||||
$chk=$db->single("SELECT COUNT(1) FROM assets_balance WHERE asset=:asset AND account!=:account",[":account"=>$src, ":asset"=>$src]);
|
$chk=$db->single("SELECT COUNT(1) FROM assets_balance WHERE asset=:asset AND account!=:account", [":account"=>$src, ":asset"=>$src]);
|
||||||
if($chk!=0){
|
if ($chk!=0) {
|
||||||
_log("Initial asset distribution already done. Market orders only on fixed price.", 3);
|
_log("Initial asset distribution already done. Market orders only on fixed price.", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// make sure the dividend only function is not bypassed after height X
|
// make sure the dividend only function is not bypassed after height X
|
||||||
if(($x['version']==1||$x['version']==2)&&$height>11111){
|
if (($x['version']==1||$x['version']==2)&&$height>11111) {
|
||||||
$check=$db->single("SELECT COUNT(1) FROM assets WHERE id=:id AND dividend_only=1",[":id"=>$src]);
|
$check=$db->single("SELECT COUNT(1) FROM assets WHERE id=:id AND dividend_only=1", [":id"=>$src]);
|
||||||
if($check==1){
|
if ($check==1) {
|
||||||
_log("This asset wallet cannot send funds directly", 3);
|
_log("This asset wallet cannot send funds directly", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -796,96 +882,94 @@ class Transaction
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// only ask and bid allowed
|
// only ask and bid allowed
|
||||||
if($asset[4]!="ask"&&$asset[4]!="bid"){
|
if ($asset[4]!="ask"&&$asset[4]!="bid") {
|
||||||
_log("Invalid asset order type", 3);
|
_log("Invalid asset order type", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$type=san($asset[4]);
|
$type=san($asset[4]);
|
||||||
|
|
||||||
$blockasset=$db->row("SELECT * FROM assets WHERE id=:id",[":id"=>san($asset[0])]);
|
$blockasset=$db->row("SELECT * FROM assets WHERE id=:id", [":id"=>san($asset[0])]);
|
||||||
if(!$blockasset||$blockasset['tradable']!=1){
|
if (!$blockasset||$blockasset['tradable']!=1) {
|
||||||
_log("Invalid asset", 3);
|
_log("Invalid asset", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// the sale price per unit has to be at least 0.00000001 or max 1000000 aro
|
// 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){
|
if (number_format($asset[1], 8, '.', '')!=$asset[1]||$asset[1]<=0||$asset[1]>1000000) {
|
||||||
_log("Invalid asset price", 3);
|
_log("Invalid asset price", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// integer min 1 and max 1000000
|
// integer min 1 and max 1000000
|
||||||
if(intval($asset[2])!=$asset[2]||$asset[2]<1||$asset[2]>1000000){
|
if (intval($asset[2])!=$asset[2]||$asset[2]<1||$asset[2]>1000000) {
|
||||||
_log("Invalid asset value", 3);
|
_log("Invalid asset value", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// if the order should be cancelable or not
|
// if the order should be cancelable or not
|
||||||
if($asset[3]!=1&&$asset[3]!=0){
|
if ($asset[3]!=1&&$asset[3]!=0) {
|
||||||
_log("Invalid asset cancel setting", 3);
|
_log("Invalid asset cancel setting", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// the type of order, ask or bid
|
// the type of order, ask or bid
|
||||||
if($type=="ask"){
|
if ($type=="ask") {
|
||||||
$balance=$db->single("SELECT balance FROM assets_balance WHERE asset=:asset AND account=:account",[":account"=>$src, ":asset"=>$asset[0]]);
|
$balance=$db->single("SELECT balance FROM assets_balance WHERE asset=:asset AND account=:account", [":account"=>$src, ":asset"=>$asset[0]]);
|
||||||
if($balance<$asset[2]){
|
if ($balance<$asset[2]) {
|
||||||
_log("Not enough asset balance", 3);
|
_log("Not enough asset balance", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$balance=$acc->balance($src);
|
$balance=$acc->balance($src);
|
||||||
if ($balance<$asset[2]*$asset[1]) {
|
if ($balance<$asset[2]*$asset[1]) {
|
||||||
_log("Not enough aro balance", 3);
|
_log("Not enough aro balance", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($blockasset['id']!=$src){
|
if ($blockasset['id']!=$src) {
|
||||||
$asset_bids_allowed=$db->single("SELECT COUNT(1) FROM assets WHERE id=:id AND allow_bid=0",[":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){
|
if ($asset_bids_allowed==1) {
|
||||||
_log("This wallet asset is not allowed to buy other assets", 3);
|
_log("This wallet asset is not allowed to buy other assets", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if($blockasset['id']==$src && $blockasset['price']>0 && $blockasset['price']!=$asset[1]){
|
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)
|
// 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);
|
_log("This asset has fixed market price when sold by it's wallet", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($x['version']==53){
|
if ($x['version']==53) {
|
||||||
if(san($x['message'])!=$x['message']){
|
if (san($x['message'])!=$x['message']) {
|
||||||
_log("Invalid order id - $x[message]", 3);
|
_log("Invalid order id - $x[message]", 3);
|
||||||
return false;
|
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]);
|
$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){
|
if ($chk!=1) {
|
||||||
_log("Invalid order - $x[message]", 3);
|
_log("Invalid order - $x[message]", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($x['version']==54){
|
if ($x['version']==54) {
|
||||||
$balance=$acc->balance($src);
|
$balance=$acc->balance($src);
|
||||||
if ($balance<$x['val']||$x['val']<0.00000001) {
|
if ($balance<$x['val']||$x['val']<0.00000001) {
|
||||||
_log("Not enough aro balance", 3);
|
_log("Not enough aro balance", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($x['version']==55){
|
if ($x['version']==55) {
|
||||||
$plus=intval($x['message']);
|
$plus=intval($x['message']);
|
||||||
if($x['message']!=$plus){
|
if ($x['message']!=$plus) {
|
||||||
_log("Invalid asset value", 3);
|
_log("Invalid asset value", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$test=$db->single("SELECT COUNT(1) FROM assets WHERE id=:id AND max_supply=0",[":id"=>$src]);
|
$test=$db->single("SELECT COUNT(1) FROM assets WHERE id=:id AND max_supply=0", [":id"=>$src]);
|
||||||
if($test!=1){
|
if ($test!=1) {
|
||||||
_log("Asset not inflatable", 3);
|
_log("Asset not inflatable", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$total=$db->single("SELECT SUM(balance) FROM assets_balance WHERE asset=:id",[":id"=>$src]);
|
$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]);
|
$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){
|
if ($total+$plus>1000000000) {
|
||||||
_log("Maximum asset unit limits reached", 3);
|
_log("Maximum asset unit limits reached", 3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -955,10 +1039,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;
|
return true;
|
||||||
|
|||||||
@@ -658,7 +658,12 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
|||||||
if (empty($alias)) {
|
if (empty($alias)) {
|
||||||
$alias="A";
|
$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]);
|
$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']]);
|
$spent=$db->single("SELECT SUM(val+fee) FROM transactions WHERE public_key=:pub AND version>0", [":pub"=>$x['public_key']]);
|
||||||
if ($spent==false) {
|
if ($spent==false) {
|
||||||
$spent=0;
|
$spent=0;
|
||||||
|
|||||||
21
util.php
21
util.php
@@ -472,7 +472,11 @@ elseif ($cmd == 'get-address') {
|
|||||||
if (empty($alias)) {
|
if (empty($alias)) {
|
||||||
$alias="A";
|
$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]);
|
$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']]);
|
$spent=$db->single("SELECT SUM(val+fee) FROM transactions WHERE public_key=:pub AND version>0", [":pub"=>$x['public_key']]);
|
||||||
if ($spent==false) {
|
if ($spent==false) {
|
||||||
$spent=0;
|
$spent=0;
|
||||||
@@ -539,7 +543,7 @@ elseif ($cmd == 'get-address') {
|
|||||||
echo "Hash:\t\t".md5(json_encode($res))."\n\n";
|
echo "Hash:\t\t".md5(json_encode($res))."\n\n";
|
||||||
} elseif ($cmd == "version") {
|
} elseif ($cmd == "version") {
|
||||||
echo "\n\n".VERSION."\n\n";
|
echo "\n\n".VERSION."\n\n";
|
||||||
} elseif ($cmd == "sendblock"){
|
} elseif ($cmd == "sendblock") {
|
||||||
$peer=trim($argv[3]);
|
$peer=trim($argv[3]);
|
||||||
if (!filter_var($peer, FILTER_VALIDATE_URL)) {
|
if (!filter_var($peer, FILTER_VALIDATE_URL)) {
|
||||||
die("Invalid peer hostname");
|
die("Invalid peer hostname");
|
||||||
@@ -550,13 +554,12 @@ elseif ($cmd == 'get-address') {
|
|||||||
$data = $block->export("", $height);
|
$data = $block->export("", $height);
|
||||||
|
|
||||||
|
|
||||||
if($data===false){
|
if ($data===false) {
|
||||||
die("Could not find this block");
|
die("Could not find this block");
|
||||||
}
|
}
|
||||||
$response = peer_post($peer."/peer.php?q=submitBlock", $data, 60, true);
|
$response = peer_post($peer."/peer.php?q=submitBlock", $data, 60, true);
|
||||||
var_dump($response);
|
var_dump($response);
|
||||||
|
} elseif ($cmd == "recheck-external-blocks") {
|
||||||
}elseif ($cmd == "recheck-external-blocks") {
|
|
||||||
$peer=trim($argv[2]);
|
$peer=trim($argv[2]);
|
||||||
if (!filter_var($peer, FILTER_VALIDATE_URL)) {
|
if (!filter_var($peer, FILTER_VALIDATE_URL)) {
|
||||||
die("Invalid peer hostname");
|
die("Invalid peer hostname");
|
||||||
@@ -570,10 +573,10 @@ elseif ($cmd == 'get-address') {
|
|||||||
|
|
||||||
$last=peer_post($peer."/peer.php?q=currentBlock");
|
$last=peer_post($peer."/peer.php?q=currentBlock");
|
||||||
|
|
||||||
$b=peer_post($peer."/peer.php?q=getBlock",["height"=>$height]);
|
$b=peer_post($peer."/peer.php?q=getBlock", ["height"=>$height]);
|
||||||
|
|
||||||
for ($i = $height+1; $i <= $last['height']; $i++) {
|
for ($i = $height+1; $i <= $last['height']; $i++) {
|
||||||
$c=peer_post($peer."/peer.php?q=getBlock",["height"=>$i]);
|
$c=peer_post($peer."/peer.php?q=getBlock", ["height"=>$i]);
|
||||||
|
|
||||||
if (!$block->mine(
|
if (!$block->mine(
|
||||||
$c['public_key'],
|
$c['public_key'],
|
||||||
@@ -586,12 +589,10 @@ elseif ($cmd == 'get-address') {
|
|||||||
)) {
|
)) {
|
||||||
print("Invalid block detected. $c[height] - $c[id]\n");
|
print("Invalid block detected. $c[height] - $c[id]\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
echo "Block $i -> ok\n";
|
echo "Block $i -> ok\n";
|
||||||
$b=$c;
|
$b=$c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo "Invalid command\n";
|
echo "Invalid command\n";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user