ETH功能类
<?php /**
* Ethereum JSON-RPC interface
*
* See Ethereum API documentation for more information:
* http://ethereum.gitbooks.io/frontier-guide/content/rpc.html
*/
namespace org; use org\JsonRpc; class Ethereum extends JsonRpc
{
private function ether_request($method, $params=array())
{
try {
$ret = $this->request($method, $params);
return $ret;
} catch (RPCException $e) {
throw $e;
}
} private function decode_hex($input)
{
if (substr($input, 0, 2) == '0x') {
$input = substr($input, 2);
} if (preg_match('/[a-f0-9]+/', $input)) {
return hexdec($input);
} return $input;
} public function web3_clientVersion()
{
return $this->ether_request(__FUNCTION__);
} public function web3_sha3($input)
{
return $this->ether_request(__FUNCTION__, array($input));
} public function net_version()
{
return $this->ether_request(__FUNCTION__);
} public function net_listening()
{
return $this->ether_request(__FUNCTION__);
} public function net_peerCount()
{
return $this->ether_request(__FUNCTION__);
} public function eth_protocolVersion()
{
return $this->ether_request(__FUNCTION__);
} public function eth_coinbase()
{
return $this->ether_request(__FUNCTION__);
} public function eth_mining()
{
return $this->ether_request(__FUNCTION__);
} public function eth_hashrate()
{
return $this->ether_request(__FUNCTION__);
} public function eth_gasPrice()
{
return $this->ether_request(__FUNCTION__);
} public function eth_accounts()
{
return $this->ether_request(__FUNCTION__);
} public function personal_newAccount($passwd)
{
return $this->ether_request(__FUNCTION__, array($passwd));
} public function personal_unlockAccount($account, $passwd)
{
return $this->ether_request(__FUNCTION__, array($account,$passwd));
} public function eth_blockNumber($decode_hex=false)
{
$block = $this->ether_request(__FUNCTION__); if ($decode_hex) {
$block = $this->decode_hex($block);
} return $block;
} public function eth_getBalance($address, $block='latest', $decode_hex=false)
{
$balance = $this->ether_request(__FUNCTION__, array($address, $block)); if ($decode_hex) {
$balance = $this->decode_hex($balance);
} return $balance;
} public function eth_getStorageAt($address, $at, $block='latest')
{
return $this->ether_request(__FUNCTION__, array($address, $at, $block));
} public function eth_getTransactionCount($address, $block='latest', $decode_hex=false)
{
$count = $this->ether_request(__FUNCTION__, array($address, $block)); if ($decode_hex) {
$count = $this->decode_hex($count);
} return $count;
} public function eth_getBlockTransactionCountByHash($tx_hash)
{
return $this->ether_request(__FUNCTION__, array($tx_hash));
} public function eth_getBlockTransactionCountByNumber($tx='latest')
{
return $this->ether_request(__FUNCTION__, array($tx));
} public function eth_getUncleCountByBlockHash($block_hash)
{
return $this->ether_request(__FUNCTION__, array($block_hash));
} public function eth_getUncleCountByBlockNumber($block='latest')
{
return $this->ether_request(__FUNCTION__, array($block));
} public function eth_getCode($address, $block='latest')
{
return $this->ether_request(__FUNCTION__, array($address, $block));
} public function eth_sign($address, $input)
{
return $this->ether_request(__FUNCTION__, array($address, $input));
} // function eth_sendTransaction($transaction)
// {
// if(!is_a($transaction, 'Ethereum_Transaction'))
// {
// throw new ErrorException('Transaction object expected');
// }
// else
// {
// return $this->ether_request(__FUNCTION__, $transaction->toArray());
// }
// }
public function eth_sendTransaction($account_from, $account_to, $amount)
{
return $this->ether_request(__FUNCTION__, array(array("from"=>$account_from,"to"=>$account_to,"value"=>'0x'.$amount, "gas" => '0x5208', "gasPrice" => '0x55ae82600'))); // "gas" => '0xc350', "gasPrice" => '0x1a13b8600'
} public function eth_call($message, $block)
{
if (!is_a($message, 'Ethereum_Message')) {
throw new ErrorException('Message object expected');
} else {
return $this->ether_request(__FUNCTION__, $message->toArray());
}
} public function eth_estimateGas($message, $block)
{
if (!is_a($message, 'Ethereum_Message')) {
throw new ErrorException('Message object expected');
} else {
return $this->ether_request(__FUNCTION__, $message->toArray());
}
} public function eth_getBlockByHash($hash, $full_tx=true)
{
return $this->ether_request(__FUNCTION__, array($hash, $full_tx));
} public function eth_getBlockByNumber($block='latest', $full_tx=true)
{
return $this->ether_request(__FUNCTION__, array($block, $full_tx));
} public function eth_getTransactionByHash($hash)
{
return $this->ether_request(__FUNCTION__, array($hash));
} public function eth_getTransactionByBlockHashAndIndex($hash, $index)
{
return $this->ether_request(__FUNCTION__, array($hash, $index));
} public function eth_getTransactionByBlockNumberAndIndex($block, $index)
{
return $this->ether_request(__FUNCTION__, array($block, $index));
} public function eth_getTransactionReceipt($tx_hash)
{
return $this->ether_request(__FUNCTION__, array($tx_hash));
} public function eth_getUncleByBlockHashAndIndex($hash, $index)
{
return $this->ether_request(__FUNCTION__, array($hash, $index));
} public function eth_getUncleByBlockNumberAndIndex($block, $index)
{
return $this->ether_request(__FUNCTION__, array($block, $index));
} public function eth_getCompilers()
{
return $this->ether_request(__FUNCTION__);
} public function eth_compileSolidity($code)
{
return $this->ether_request(__FUNCTION__, array($code));
} public function eth_compileLLL($code)
{
return $this->ether_request(__FUNCTION__, array($code));
} public function eth_compileSerpent($code)
{
return $this->ether_request(__FUNCTION__, array($code));
} public function eth_newFilter($filter, $decode_hex=false)
{
if (!is_a($filter, 'Ethereum_Filter')) {
throw new ErrorException('Expected a Filter object');
} else {
$id = $this->ether_request(__FUNCTION__, $filter->toArray()); if ($decode_hex) {
$id = $this->decode_hex($id);
} return $id;
}
} public function eth_newBlockFilter($decode_hex=false)
{
$id = $this->ether_request(__FUNCTION__); if ($decode_hex) {
$id = $this->decode_hex($id);
} return $id;
} public function eth_newPendingTransactionFilter($decode_hex=false)
{
$id = $this->ether_request(__FUNCTION__); if ($decode_hex) {
$id = $this->decode_hex($id);
} return $id;
} public function eth_uninstallFilter($id)
{
return $this->ether_request(__FUNCTION__, array($id));
} public function eth_getFilterChanges($id)
{
return $this->ether_request(__FUNCTION__, array($id));
} public function eth_getFilterLogs($id)
{
return $this->ether_request(__FUNCTION__, array($id));
} public function eth_getLogs($filter)
{
if (!is_a($filter, 'Ethereum_Filter')) {
throw new ErrorException('Expected a Filter object');
} else {
return $this->ether_request(__FUNCTION__, $filter->toArray());
}
} public function eth_getWork()
{
return $this->ether_request(__FUNCTION__);
} public function eth_submitWork($nonce, $pow_hash, $mix_digest)
{
return $this->ether_request(__FUNCTION__, array($nonce, $pow_hash, $mix_digest));
} public function db_putString($db, $key, $value)
{
return $this->ether_request(__FUNCTION__, array($db, $key, $value));
} public function db_getString($db, $key)
{
return $this->ether_request(__FUNCTION__, array($db, $key));
} public function db_putHex($db, $key, $value)
{
return $this->ether_request(__FUNCTION__, array($db, $key, $value));
} public function db_getHex($db, $key)
{
return $this->ether_request(__FUNCTION__, array($db, $key));
} public function shh_version()
{
return $this->ether_request(__FUNCTION__);
} public function shh_post($post)
{
if (!is_a($post, 'Whisper_Post')) {
throw new ErrorException('Expected a Whisper post');
} else {
return $this->ether_request(__FUNCTION__, $post->toArray());
}
} public function shh_newIdentinty()
{
return $this->ether_request(__FUNCTION__);
} public function shh_hasIdentity($id)
{
return $this->ether_request(__FUNCTION__);
} public function shh_newFilter($to=null, $topics=array())
{
return $this->ether_request(__FUNCTION__, array(array('to'=>$to, 'topics'=>$topics)));
} public function shh_uninstallFilter($id)
{
return $this->ether_request(__FUNCTION__, array($id));
} public function shh_getFilterChanges($id)
{
return $this->ether_request(__FUNCTION__, array($id));
} public function shh_getMessages($id)
{
return $this->ether_request(__FUNCTION__, array($id));
}
}
ETH功能类的更多相关文章
- 【socket】Socket的三个功能类TCPClient、TCPListener 和 UDPClient
Socket的三个功能类TCPClient.TCPListener 和 UDPClient (转) 应用程序可以通过 TCPClient.TCPListener 和 UDPClient 类使用传输控制 ...
- php之框架增加日志记录功能类
<?php /* 思路:给定文件,写入读取(fopen ,fwrite……) 如果大于1M 则重写备份 传给一个内容, 判断大小,如果大于1M,备份 小于则写入 */ class Log{ // ...
- 为什么我在css里使用功能类优先
前言 我想在我们开始的学CSS语法的时候,都是从以下的流程开始的: 1.写一个CSS类选择器: .my-class { } 2.往选择器里填充CSS语法: .my-class { display fl ...
- php加密解密功能类
这两天突发奇想想要用php写一个对日常项目加密以及解密的功能,经过努力简单的封装了一个对php代码进行加密解密的类,一些思想也是来自于网络,初步测试用着还行,可以实现对指定项目的加密以及解密(只针对本 ...
- ThinkPHP---TP功能类之邮件
[一]概论 (1)简介: 这里说的邮件不是平时说的email邮件(邮件地址带有@符号的),而是指的一般论坛网站的站内信息,也叫私信或者pm(private message私信) [二]站内信案例 (1 ...
- ThinkPHP---TP功能类之公文管理功能2----------继续完善
[前言] 之前已经完成了公文的添加和列表展示功能,今天继续完善.做下公文的编辑和删除功能. [主体] (1)分析 控制器:DocController.class.php 方法:edit(将模板展示和数 ...
- ThinkPHP---TP功能类之分页
(1)核心 数据分页通过limit语法实现 (2)分页类 ThinkPHP里系统封装好了分页类:Page.class.php (3)代码分析 位置:Think/Page.class.php, ①查看相 ...
- php实现图片缩放功能类
http://www.poluoluo.com/jzxy/201312/255447.html <?php /** * Images类是一个图片处理类 * @package applicatio ...
- Socket的三个功能类TCPClient、TCPListener 和 UDPClient (转)
应用程序可以通过 TCPClient.TCPListener 和 UDPClient 类使用传输控制协议 (TCP) 和用户数据文报协议 (UDP) 服务.这些协议类建立在 System.Net.So ...
随机推荐
- 13-8-return的高级使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Nand flash 芯片工作原理
Nand flash 芯片型号为 Samsung K9F1208U0B,数据存储容量为 64MB,采用块页式存储管理.8 个 I/O 引脚充当数据.地址.命令的复用端口. 芯片内部存储布局及存储操作特 ...
- h5对接jssdk支付分并调用开启支付分页面
1.ws.config签名 调用ticket等获取ws.config的签名,下面会调用方法再调用方法时需要再次按照调用方法的签名 wx.config({ debug: true, // 开启调试模 ...
- gdb调试工具的使用
GDB是一个由GNU开源组织发布的.UNIX/LINUX操作系统下的.基于命令行的.功能强大的程序调试工具. GDB中的命令固然很多,但我们只需掌握其中十个左右的命令,就大致可以完成日常的基本的程序调 ...
- windows下VisualSVN Server搭建
转自:https://www.cnblogs.com/shuilangyizu/p/10365604.html 使用 VisualSVN Server来实现主要的 SVN功能则要比使用原始的 SVN和 ...
- PKUSC2019 D2T2
PKUSC2019 D2T2 把n(n<=100)的树(无边权)放在m维空间上(坐标都是整点),使得任意两个点的曼哈顿距离都是原树上的距离 求最小的m,并给出构造方案 性质好题,巧妙构造题. 原 ...
- 深入浅出Mybatis系列(一)---Mybatis入门[转]
最近两年 springmvc + mybatis 的在这种搭配还是蛮火的,楼主我呢,也从来没真正去接触过mybatis, 趁近日得闲, 就去学习一下mybatis吧. 本次拟根据自己的学习进度,做一次 ...
- Jeecg-Boot 2.0.1 版本发布,前后端分离快速开发平台
Jeecg-Boot项目简介 Jeecg-boot 是一款基于代码生成器的快速开发平台! 采用前后端分离技术:SpringBoot,Mybatis,Shiro,JWT,Vue & Ant De ...
- 使用dubbo中间件出现NoSuchBeanDefinitionException异常
dubbo中间件中有一个import com.alibaba.dubbo.config.annotation.Service类,在service层添加注解时要注意,我们添加的是import org.s ...
- 《DSP using MATLAB》Problem 8.30
10月1日,新中国70周岁生日,上午观看了盛大的庆祝仪式,整齐的方阵,先进的武器,尊敬的先辈英雄,欢乐的人们,愿我们的 国家越来越好,人民生活越来越好. 接着做题. 代码: %% ---------- ...