ethereum_proxy

package module
v0.0.0-...-9de16bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2021 License: GPL-3.0 Imports: 25 Imported by: 0

README

ethereum_proxy

ethereum_proxy

go build -o ./bin/ethereum_proxy ./cmd
export PROXY_HOST=127.0.0.1:37101
export PROXY_PORT=5000

./bin/ethereum_proxy
curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_estimateGas","params":[],"id":1}' 127.0.0.1:5000

curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' 127.0.0.1:5000

curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x3e8", true],"id":1}' 127.0.0.1:5000

// dpzuVdosQrF2kmzumhVeFQZa1aYcdgFpN => 0x93F86A462A3174C7AD1281BCF400A9F18D244E06
curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x93F86A462A3174C7AD1281BCF400A9F18D244E06", "latest"],"id":1}' 127.0.0.1:5000

curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0x27f55958c8c1656699563b2f7bf3e3ad4e4476f5526d41065a9efa6e50b082b5"],"id":1}' 127.0.0.1:5000

// If true it returns the full transaction objects, if false only the hashes of the transactions.
curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_getBlockByHash","params":["0x494181a8688c1550e8deea48e1eca750790169cf1b654089f88b126e4624c33e",false],"id":1}' 127.0.0.1:5000


// contractName => 0x
curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_getCode","params":["0x313131312D2D2D2D2D476574436F646554657372"],"id":1}' 127.0.0.1:5000

curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0xa46a766ce422e1e1a9827efe6989eeacc82a2352765287fe557497465751d9ab"],"id":1}' 127.0.0.1:5000

curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"fromBlock":"0","toBlock":"13672"}],"id":1}' 127.0.0.1:5000

curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_newFilter","params":[{"fromBlock":"0","toBlock":"13672"}],"id":1}' 127.0.0.1:5000

curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_uninstallFilter","params":["0x282b21d7db0eaedb137e25b56337666d"],"id":1}' 127.0.0.1:5000

curl -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"eth_getFilterLogs","params":["0xdcccf7c1c88df9e5e8249f8caf0861a"],"id":1}' 127.0.0.1:5000


Documentation

Index

Constants

View Source
const (
	AddressLength = 42

	LogsBloomZore = "" /* 514-byte string literal not displayed */
)
View Source
const NetworkID = "xuperchain"

Variables

View Source
var FilterMap = make(map[string]*types.Filter)
View Source
var ZeroAddress = make([]byte, 20)

Functions

func NewRPCCodec

func NewRPCCodec() rpc.Codec

Types

type EthService

type EthService interface {
	GetCode(r *http.Request, arg *string, reply *string) error
	//Call(r *http.Request, args *types.EthArgs, reply *string) error
	//SendTransaction(r *http.Request, args *types.EthArgs, reply *string) error
	//GetTransactionReceipt(r *http.Request, arg *string, reply *types.TxReceipt) error
	//Accounts(r *http.Request, arg *string, reply *[]string) error
	EstimateGas(r *http.Request, args *types.EthArgs, reply *string) error
	GetBalance(r *http.Request, p *[]string, reply *string) error
	GetBlockByNumber(r *http.Request, p *[]interface{}, reply *types.Block) error
	GetBlockByHash(r *http.Request, p *[]interface{}, reply *types.Block) error
	BlockNumber(r *http.Request, _ *interface{}, reply *string) error
	GetTransactionByHash(r *http.Request, txID *string, reply *types.Transaction) error
	//GetTransactionCount(r *http.Request, _ *interface{}, reply *string) error
	GetLogs(*http.Request, *types.GetLogsArgs, *[]types.Log) error
	NewFilter(*http.Request, *types.GetLogsArgs, *string) error
	GetFilterLogs(*http.Request, *string, *[]types.Log) error
	UninstallFilter(*http.Request, *string, *bool) error
	GetFilter(*http.Request, *string, *types.Filter) error
}

EthService is the rpc server implementation. Each function is an implementation of one ethereum json-rpc https://github.com/ethereum/wiki/wiki/JSON-RPC

Arguments and return values are formatted as HEX value encoding https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding

gorilla RPC is the receiver of these functions, they must all take three pointers, and return a single error

see godoc for RegisterService(receiver interface{}, name string) error

func NewEthService

func NewEthService(xchainClient pb.XchainClient, eventClient pb.EventServiceClient, logger *zap.SugaredLogger) EthService

type EthereumProxy

type EthereumProxy struct {
	RPCServer  *rpc.Server
	HTTPServer *http.Server
}

func NewEthereumProxy

func NewEthereumProxy(service EthService, port int) *EthereumProxy

func (*EthereumProxy) Shutdown

func (p *EthereumProxy) Shutdown() error

func (*EthereumProxy) Start

func (p *EthereumProxy) Start() error

type NetService

type NetService struct {
}

NetService returns data about the network the client is connected to.

func (*NetService) Version

func (s *NetService) Version(r *http.Request, _ *interface{}, reply *string) error

Version takes no parameters and returns the network identifier.

https://github.com/ethereum/wiki/wiki/JSON-RPC#net_version

Directories

Path Synopsis
Package types contains the types used to interact with the json-rpc interface.
Package types contains the types used to interact with the json-rpc interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL