common控制器初始化鏈接以太坊節點代碼
<?php
namespace Api\Controller;
use Think\Controller;
class CommonController extends Controller
{
public function _initialize()
{
vendor('jsonRPC.jsonRPCClient');
$url = 'http://127.0.0.1:8545';
$this->eth = new \jsonRPCClient($url);
}
}
區塊數據處理的模型
<?php
namespace Common\Model;
use Think\Model;
class BlockModel extends Model
{
/**
* 自動驗證
* @var array
*/
protected $_validate = array(
array('number', 'require', 'number不能為空'),
array('number','','number已經存在!',0,'unique',1), // 在新增的時候驗證 number 字段是否唯一
);
protected $_auto = array(
array('create_time', NOW_TIME, 1),
array('number','hexdec',1,'function'), // 對number字段在新增和編輯的時候回調hexdec方法
);
/**
* 插入高度記錄
* @DateTime 2018-05-02
* @param [type] $info [description]
* @return [type] [description]
*/
public function update($data)
{
$data = $this->create($data);
return $this->add($data);
}
}
sh腳本
cd /data/wwwroot/www.ethereum.io/
while true
do
php /data/wwwroot/www.ethereum.io/index.php Api/Block/getBlockInfo
done
后臺執行該腳本命令
nohup sh block.sh &