<?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));
}
}

最新文章

  1. ClassNotFoundException: org.apache.catalina.loader.DevLoader 自己摸索,丰衣足食
  2. springmvc使用RSA算法加密表单
  3. ZK 长时操作带进度条
  4. 让MyEclipse2013兼容Retina屏幕
  5. Repository模式中,Update总是失败及其解析
  6. Linux(centOS6.5)下SVN的安装、配置及开机启动
  7. 【leetcode】363. Max Sum of Rectangle No Larger Than K
  8. 浏览我的php网页时,出现的都是网页的代码
  9. 浅谈mapreduce程序部署
  10. html5+css3学习笔记音频和视频
  11. caffe卷积输入通道如何到输出通道
  12. Tensorflow源码解析1 -- 内核架构和源码结构
  13. C# DateTimePicker控件获取他的年,月,日,时,分,秒
  14. 3D游戏的角色移动
  15. hdu2121 最小树形图的虚根
  16. 腾讯Alloy团队代码规范
  17. python opencv画图可视化
  18. Binary Analysis Tool安装使用教程
  19. SQL获取连续数字中断数字
  20. python生成器异步使用

热门文章

  1. POJ 1743-POJ - 3261~后缀数组关于最长字串问题
  2. 宽域POST提交数据
  3. LoadRunner穿过防火墙运行Vuser和进行监控
  4. HTML+css 小组件
  5. csp-s模拟64trade,sum,building题解
  6. codevs1222 信与信封的问题
  7. js获取base64格式图片预览上传并用php保存到本地服务器指定文件夹
  8. php多维数组
  9. 你知道的和不知道的sass
  10. Windbg 问题集锦记录