<?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. springcloud(十五):服务网关zuul

    前面的文章我们介绍了,Eureka用于服务的注册于发现,Feign支持服务的调用以及均衡负载,Hystrix处理服务的熔断防止故障扩散,Spring Cloud Config服务集群配置中心,似乎一个 ...

  2. JS流程控制语句 来来回回(Do...while循环) 先执行后判断 do while结构的基本原理和while结构是基本相同的,但是它保证循环体至少被执行一次。

    来来回回(Do...while循环) do while结构的基本原理和while结构是基本相同的,但是它保证循环体至少被执行一次.因为它是先执行代码,后判断条件,如果条件为真,继续循环. do...w ...

  3. sed 批量替换文件

    1.想把某个目录下包含only-upstage的文件都替换成onlyu-base sed  -i -e 's/onlyu-upstage/onlyu-base/g'  ` grep -rl onlyu ...

  4. go string和[ ]byte

    https://www.cnblogs.com/zhangboyu/p/7623712.html

  5. uoj51 元旦三侠的游戏

    题意:询问a,b,n.每次可以a+1或b+1,保证a^b<=n,不能操作者输.问先手是否赢? n<=1e9. 标程: #include<cstdio> #include< ...

  6. 「BZOJ2300」[HAOI2011] 防线修建

    传送门 操作离线之后倒着做,只有加点操作. 用set动态维护凸包即可. //Achen #include<algorithm> #include<iostream> #incl ...

  7. golang的表格驱动测试

    一.leetcode的算法题 package main import ( "fmt" "strings" ) func lengthOfNonRepeating ...

  8. 使用phpStudy自带的mysql-front学习建库建表以及基本的mysql语句

    1.鼠标左键phpStudy图标,点击mysql管理器,如下图 2.选择Mysql-Front,选择localhost进入,可以看到本地建立的数据库.然后新建一个数据库,如下图: 3.在新建的数据库上 ...

  9. 深入浅出 Java Concurrency (24): 并发容器 part 9 双向队列集合 Deque[转]

    有一段时间没有更新了.接着上节继续吧. Queue除了前面介绍的实现外,还有一种双向的Queue实现Deque.这种队列允许在队列头和尾部进行入队出队操作,因此在功能上比Queue显然要更复杂.下图描 ...

  10. VS2010-MFC(对话框:非模态对话框的创建及显示)

    转自:http://www.jizhuomi.com/software/162.html 前面已经说过,非模态对话框显示后,程序其他窗口仍能正常运行,可以响应用户输入,还可以相互切换.本节会将上一讲中 ...