<?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功能类的更多相关文章

  1. 【socket】Socket的三个功能类TCPClient、TCPListener 和 UDPClient

    Socket的三个功能类TCPClient.TCPListener 和 UDPClient (转) 应用程序可以通过 TCPClient.TCPListener 和 UDPClient 类使用传输控制 ...

  2. php之框架增加日志记录功能类

    <?php /* 思路:给定文件,写入读取(fopen ,fwrite……) 如果大于1M 则重写备份 传给一个内容, 判断大小,如果大于1M,备份 小于则写入 */ class Log{ // ...

  3. 为什么我在css里使用功能类优先

    前言 我想在我们开始的学CSS语法的时候,都是从以下的流程开始的: 1.写一个CSS类选择器: .my-class { } 2.往选择器里填充CSS语法: .my-class { display fl ...

  4. php加密解密功能类

    这两天突发奇想想要用php写一个对日常项目加密以及解密的功能,经过努力简单的封装了一个对php代码进行加密解密的类,一些思想也是来自于网络,初步测试用着还行,可以实现对指定项目的加密以及解密(只针对本 ...

  5. ThinkPHP---TP功能类之邮件

    [一]概论 (1)简介: 这里说的邮件不是平时说的email邮件(邮件地址带有@符号的),而是指的一般论坛网站的站内信息,也叫私信或者pm(private message私信) [二]站内信案例 (1 ...

  6. ThinkPHP---TP功能类之公文管理功能2----------继续完善

    [前言] 之前已经完成了公文的添加和列表展示功能,今天继续完善.做下公文的编辑和删除功能. [主体] (1)分析 控制器:DocController.class.php 方法:edit(将模板展示和数 ...

  7. ThinkPHP---TP功能类之分页

    (1)核心 数据分页通过limit语法实现 (2)分页类 ThinkPHP里系统封装好了分页类:Page.class.php (3)代码分析 位置:Think/Page.class.php, ①查看相 ...

  8. php实现图片缩放功能类

    http://www.poluoluo.com/jzxy/201312/255447.html <?php /** * Images类是一个图片处理类 * @package applicatio ...

  9. Socket的三个功能类TCPClient、TCPListener 和 UDPClient (转)

    应用程序可以通过 TCPClient.TCPListener 和 UDPClient 类使用传输控制协议 (TCP) 和用户数据文报协议 (UDP) 服务.这些协议类建立在 System.Net.So ...

随机推荐

  1. 一文教会你用Python实现最有效的剪切板实时监控

    前言 上网浏览网页的时候,看见好的内容免不了要使用复制粘贴,但是我们看到的内容.心里想要的内容和实际粘贴后的内容往往不一致.数据的获取始于复制,终于粘贴,那么问题来了,在这中间系统做了哪些操作,我们怎 ...

  2. USACO 2008 November Gold Cheering up the Cows /// MST oj24381

    题目大意: 输入n,p:n个点,p条路 接下来n行输入c[]:在各个点需要花费的时间 接下来p行输入u,v,w:u点到v点的路需要花费时间w 求经过所有点且最后回到起点的最少花费时间 https:// ...

  3. 面试系列13 redis都有哪些数据类型

    (1)string 这是最基本的类型了,没啥可说的,就是普通的set和get,做简单的kv缓存 (2)hash 这个是类似map的一种结构,这个一般就是可以将结构化的数据,比如一个对象(前提是这个对象 ...

  4. JS控制语句 编程练习 学生数据,分别是姓名、性别、年龄和年级,接下来呢,我们要利用JavaScript的知识挑出其中所有是大一的女生的的名字哦。

    编程练习 在一个大学的编程选修课班里,我们得到了一组参加该班级的学生数据,分别是姓名.性别.年龄和年级,接下来呢,我们要利用JavaScript的知识挑出其中所有是大一的女生的的名字哦. 学生信息如下 ...

  5. SPOJ694 New Distinct Substrings

    New Distinct Substrings 题目大意 给定一个字符串,求本质不同的子串个数 题解 SA常见思想:每一个子串都是某个后缀的前缀 考虑每一个后缀的贡献,首先他拥有n - sa[i]个( ...

  6. Luogu P4246 [SHOI2008]堵塞的交通(线段树+模拟)

    P4246 [SHOI2008]堵塞的交通 题意 题目描述 有一天,由于某种穿越现象作用,你来到了传说中的小人国.小人国的布局非常奇特,整个国家的交通系统可以被看成是一个\(2\)行\(C\)列的矩形 ...

  7. OpenGL 鼠标交互响应事件

    OpenGL 鼠标.键盘交互响应事件 先来一个样例: uses gl,glu,glut; procedure InitEnvironment;cdecl; begin glClearColor();/ ...

  8. html--图片背景兼容,兼容IE6

    在IE6中对图片格式png24支持度不高, 如果使用的图片格式是png24,则会导致透明效果无法正常显示 解决方法: 1.可以使用png8来代替png24,即可解决问题, 但是使用png8代替png2 ...

  9. loj2509 hnoi2018排列

    题意:对于a数组,求它的一个合法排列的最大权值.合法排列:对于任意j,k,如果a[p[j]]=p[k],那么k<j. 权值:sigma(a[p[i]]*i).n<=50W. 标程: #in ...

  10. Codeforces Parking Lot

    http://codeforces.com/problemset/problem/630/I 简单的排列组合,推式子技巧:举一个小样例,看着推,别抽象着推,容易错 #include <iostr ...