Beispiel #1
0
// create a new miner api instance
func NewMinerApi(expanse *exp.Expanse, coder codec.Codec) *minerApi {
	return &minerApi{
		expanse: expanse,
		methods: MinerMapping,
		codec:   coder.New(nil),
	}
}
Beispiel #2
0
// create a new web3 api instance
func NewWeb3Api(xeth *xeth.XEth, coder codec.Codec) *web3Api {
	return &web3Api{
		xeth:    xeth,
		methods: Web3Mapping,
		codec:   coder.New(nil),
	}
}
Beispiel #3
0
// Create a new in process client
func NewHttpClient(cfg HttpConfig, c codec.Codec) *httpClient {
	return &httpClient{
		address: cfg.ListenAddress,
		port:    cfg.ListenPort,
		codec:   c.New(nil),
	}
}
Beispiel #4
0
// create a new txpool api instance
func NewTxPoolApi(xeth *xeth.XEth, exp *exp.Expanse, coder codec.Codec) *txPoolApi {
	return &txPoolApi{
		xeth:    xeth,
		expanse: exp,
		methods: txpoolMapping,
		codec:   coder.New(nil),
	}
}
Beispiel #5
0
// create a new net api instance
func NewPersonalApi(xeth *xeth.XEth, exp *exp.Expanse, coder codec.Codec) *personalApi {
	return &personalApi{
		xeth:    xeth,
		expanse: exp,
		methods: personalMapping,
		codec:   coder.New(nil),
	}
}
Beispiel #6
0
// create a new db api instance
func NewDbApi(xeth *xeth.XEth, expanse *exp.Expanse, coder codec.Codec) *dbApi {
	return &dbApi{
		xeth:    xeth,
		expanse: expanse,
		methods: DbMapping,
		codec:   coder.New(nil),
	}
}
Beispiel #7
0
// create a new whisper api instance
func NewShhApi(xeth *xeth.XEth, exp *exp.Expanse, coder codec.Codec) *shhApi {
	return &shhApi{
		xeth:    xeth,
		expanse: exp,
		methods: shhMapping,
		codec:   coder.New(nil),
	}
}
Beispiel #8
0
// create a new net api instance
func NewNetApi(xeth *xeth.XEth, exp *exp.Expanse, coder codec.Codec) *netApi {
	return &netApi{
		xeth:    xeth,
		expanse: exp,
		methods: netMapping,
		codec:   coder.New(nil),
	}
}
Beispiel #9
0
func handle(id int, conn net.Conn, api shared.ExpanseApi, c codec.Codec) {
	codec := c.New(conn)

	defer func() {
		if r := recover(); r != nil {
			glog.Errorf("panic: %v\n", r)
		}
		codec.Close()
	}()

	for {
		requests, isBatch, err := codec.ReadRequest()
		if err == io.EOF {
			return
		} else if err != nil {
			glog.V(logger.Debug).Infof("Closed IPC Conn %06d recv err - %v\n", id, err)
			return
		}

		if isBatch {
			responses := make([]*interface{}, len(requests))
			responseCount := 0
			for _, req := range requests {
				res, err := api.Execute(req)
				if req.Id != nil {
					rpcResponse := shared.NewRpcResponse(req.Id, req.Jsonrpc, res, err)
					responses[responseCount] = rpcResponse
					responseCount += 1
				}
			}

			err = codec.WriteResponse(responses[:responseCount])
			if err != nil {
				glog.V(logger.Debug).Infof("Closed IPC Conn %06d send err - %v\n", id, err)
				return
			}
		} else {
			var rpcResponse interface{}
			res, err := api.Execute(requests[0])

			rpcResponse = shared.NewRpcResponse(requests[0].Id, requests[0].Jsonrpc, res, err)
			err = codec.WriteResponse(rpcResponse)
			if err != nil {
				glog.V(logger.Debug).Infof("Closed IPC Conn %06d send err - %v\n", id, err)
				return
			}
		}
	}
}
Beispiel #10
0
// create a new admin api instance
func NewAdminApi(xeth *xeth.XEth, expanse *exp.Expanse, codec codec.Codec) *adminApi {
	return &adminApi{
		xeth:    xeth,
		expanse: expanse,
		codec:   codec,
		coder:   codec.New(nil),
	}
}
Beispiel #11
0
func newIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) {
	c, err := net.DialUnix("unix", nil, &net.UnixAddr{cfg.Endpoint, "unix"})
	if err != nil {
		return nil, err
	}

	coder := codec.New(c)
	msg := shared.Request{
		Id:      0,
		Method:  useragent.EnableUserAgentMethod,
		Jsonrpc: shared.JsonRpcVersion,
		Params:  []byte("[]"),
	}

	coder.WriteResponse(msg)
	coder.Recv()

	return &ipcClient{cfg.Endpoint, c, codec, coder}, nil
}
Beispiel #12
0
// create new ethApi instance
func NewEthApi(xeth *xeth.XEth, exp *exp.Expanse, codec codec.Codec) *ethApi {
	return &ethApi{xeth, exp, ethMapping, codec.New(nil)}
}