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 ...
随机推荐
- Spark如何读写hive
原文引自:http://blog.csdn.net/zongzhiyuan/article/details/78076842 hive数据表建立可以在hive上建立,或者使用hiveContext.s ...
- Java开发系列-JDBC
概述 JDBC(Java DataBase Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和 ...
- Ubuntu下使用SSH 命令用于登录远程桌面
https://blog.csdn.net/yucicheung/article/details/79427578 问题描述 做DL的经常需要在一台电脑(本地主机)上写代码,另一台电脑(服务器,计算力 ...
- mysql order by排序查询速度问题
SELECT * FROM `assets_message` LEFT JOIN purchase_message ON assets_message.purchase_id = purchase_m ...
- 7 Serialize and Deserialize Binary Tree 序列化及反序列化二叉树
原题网址:http://www.lintcode.com/zh-cn/problem/serialize-and-deserialize-binary-tree/# 设计一个算法,并编写代码来序列化和 ...
- dns 逐级查找顺序
1.浏览器 dns 缓存 2.Windows Host 文本 3.windows 本地 dns 缓存 方法/步骤 首先我们来查看win系统内保存的dns缓存并进行清空dns缓存操作. ... 点击确定 ...
- elasticDump的安装使用
官方地址:官方地址:https://github.com/taskrabbit/elasticsearch-dump 安装方式如下:安装NodeJS下载源码:wget http://nodejs.or ...
- sip会话流程以及sip介绍(2)
下面我们通过一个简单的场景例子来简单介绍一下 SIP 会话流程. Tom 和 Jerry 是非常好的伙伴,Tom 在他的 PC 上使用一个 SIP 的应用程序呼叫 Internet 上另一个 SIP ...
- org.apache.commons工具类方法解释 转
在Java中,工具类定义了一组公共方法,这篇文章将介绍Java中使用最频繁及最通用的Java工具类.以下工具类.方法按使用流行度排名,参考数据来源于Github上随机选取的5万个开源项目源码. 一. ...
- matlab 实现感知机线性二分类算法(Perceptron)
感知机是简单的线性分类模型 ,是二分类模型.其间用到随机梯度下降方法进行权值更新.参考他人代码,用matlab实现总结下. 权值求解过程通过Perceptron.m函数完成 function W = ...