From 0c46d6f2249b3715b0e81c99a256a6ece9ee4d8c Mon Sep 17 00:00:00 2001 From: Benjamin Bollen <ben@erisindustries.com> Date: Wed, 20 Jul 2016 17:25:24 +0200 Subject: [PATCH] rpc/v0: move RpcRequest Response type definition --- rpc/v0/methods.go | 165 ++++++++++++++++++++++---------------------- rpc/v0/wsService.go | 35 +++++----- 2 files changed, 99 insertions(+), 101 deletions(-) diff --git a/rpc/v0/methods.go b/rpc/v0/methods.go index be89ebbe..f5f55409 100644 --- a/rpc/v0/methods.go +++ b/rpc/v0/methods.go @@ -4,7 +4,6 @@ import ( core_types "github.com/eris-ltd/eris-db/core/types" definitions "github.com/eris-ltd/eris-db/definitions" rpc "github.com/eris-ltd/eris-db/rpc" - rpc_tendermint "github.com/eris-ltd/eris-db/rpc/tendermint" "github.com/eris-ltd/eris-db/txs" ) @@ -56,7 +55,7 @@ type ErisDbMethods struct { } // Used to handle requests. interface{} param is a wildcard used for example with socket events. -type RequestHandlerFunc func(*rpc_tendermint.RPCRequest, interface{}) (interface{}, int, error) +type RequestHandlerFunc func(*rpc.RPCRequest, interface{}) (interface{}, int, error) // Private. Create a method name -> method handler map. func (this *ErisDbMethods) getMethods() map[string]RequestHandlerFunc { @@ -108,374 +107,374 @@ func (this *ErisDbMethods) getMethods() map[string]RequestHandlerFunc { // *************************************** Accounts *************************************** -func (this *ErisDbMethods) GenPrivAccount(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) GenPrivAccount(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { pac, errC := this.pipe.Accounts().GenPrivAccount() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return pac, 0, nil } -func (this *ErisDbMethods) GenPrivAccountFromKey(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) GenPrivAccountFromKey(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &PrivKeyParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } privKey := param.PrivKey pac, errC := this.pipe.Accounts().GenPrivAccountFromKey(privKey) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return pac, 0, nil } -func (this *ErisDbMethods) Account(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Account(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &AddressParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } address := param.Address // TODO is address check? account, errC := this.pipe.Accounts().Account(address) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return account, 0, nil } -func (this *ErisDbMethods) Accounts(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Accounts(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &AccountsParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } list, errC := this.pipe.Accounts().Accounts(param.Filters) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return list, 0, nil } -func (this *ErisDbMethods) AccountStorage(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) AccountStorage(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &AddressParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } address := param.Address storage, errC := this.pipe.Accounts().Storage(address) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return storage, 0, nil } -func (this *ErisDbMethods) AccountStorageAt(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) AccountStorageAt(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &StorageAtParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } address := param.Address key := param.Key storageItem, errC := this.pipe.Accounts().StorageAt(address, key) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return storageItem, 0, nil } // *************************************** Blockchain ************************************ -func (this *ErisDbMethods) BlockchainInfo(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) BlockchainInfo(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { status, errC := this.pipe.Blockchain().Info() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return status, 0, nil } -func (this *ErisDbMethods) ChainId(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) ChainId(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { chainId, errC := this.pipe.Blockchain().ChainId() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &core_types.ChainId{chainId}, 0, nil } -func (this *ErisDbMethods) GenesisHash(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) GenesisHash(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { hash, errC := this.pipe.Blockchain().GenesisHash() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &core_types.GenesisHash{hash}, 0, nil } -func (this *ErisDbMethods) LatestBlockHeight(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) LatestBlockHeight(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { height, errC := this.pipe.Blockchain().LatestBlockHeight() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &core_types.LatestBlockHeight{height}, 0, nil } -func (this *ErisDbMethods) LatestBlock(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) LatestBlock(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { block, errC := this.pipe.Blockchain().LatestBlock() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return block, 0, nil } -func (this *ErisDbMethods) Blocks(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Blocks(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &BlocksParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } blocks, errC := this.pipe.Blockchain().Blocks(param.Filters) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return blocks, 0, nil } -func (this *ErisDbMethods) Block(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Block(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &HeightParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } height := param.Height block, errC := this.pipe.Blockchain().Block(height) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return block, 0, nil } // *************************************** Consensus ************************************ -func (this *ErisDbMethods) ConsensusState(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) ConsensusState(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { state, errC := this.pipe.Consensus().State() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return state, 0, nil } -func (this *ErisDbMethods) Validators(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Validators(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { validators, errC := this.pipe.Consensus().Validators() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return validators, 0, nil } // *************************************** Net ************************************ -func (this *ErisDbMethods) NetworkInfo(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) NetworkInfo(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { info, errC := this.pipe.Net().Info() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return info, 0, nil } -func (this *ErisDbMethods) ClientVersion(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) ClientVersion(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { version, errC := this.pipe.Net().ClientVersion() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &core_types.ClientVersion{version}, 0, nil } -func (this *ErisDbMethods) Moniker(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Moniker(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { moniker, errC := this.pipe.Net().Moniker() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &core_types.Moniker{moniker}, 0, nil } -func (this *ErisDbMethods) Listening(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Listening(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { listening, errC := this.pipe.Net().Listening() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &core_types.Listening{listening}, 0, nil } -func (this *ErisDbMethods) Listeners(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Listeners(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { listeners, errC := this.pipe.Net().Listeners() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &core_types.Listeners{listeners}, 0, nil } -func (this *ErisDbMethods) Peers(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Peers(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { peers, errC := this.pipe.Net().Peers() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return peers, 0, nil } -func (this *ErisDbMethods) Peer(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Peer(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &PeerParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } address := param.Address peer, errC := this.pipe.Net().Peer(address) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return peer, 0, nil } // *************************************** Txs ************************************ -func (this *ErisDbMethods) Call(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Call(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &CallParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } from := param.From to := param.Address data := param.Data call, errC := this.pipe.Transactor().Call(from, to, data) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return call, 0, nil } -func (this *ErisDbMethods) CallCode(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) CallCode(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &CallCodeParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } from := param.From code := param.Code data := param.Data call, errC := this.pipe.Transactor().CallCode(from, code, data) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return call, 0, nil } -func (this *ErisDbMethods) BroadcastTx(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) BroadcastTx(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &txs.CallTx{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } receipt, errC := this.pipe.Transactor().BroadcastTx(param) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return receipt, 0, nil } -func (this *ErisDbMethods) Transact(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) Transact(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &TransactParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } receipt, errC := this.pipe.Transactor().Transact(param.PrivKey, param.Address, param.Data, param.GasLimit, param.Fee) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return receipt, 0, nil } -func (this *ErisDbMethods) TransactAndHold(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) TransactAndHold(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &TransactParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } ce, errC := this.pipe.Transactor().TransactAndHold(param.PrivKey, param.Address, param.Data, param.GasLimit, param.Fee) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return ce, 0, nil } -func (this *ErisDbMethods) TransactNameReg(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) TransactNameReg(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &TransactNameRegParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } receipt, errC := this.pipe.Transactor().TransactNameReg(param.PrivKey, param.Name, param.Data, param.Amount, param.Fee) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return receipt, 0, nil } -func (this *ErisDbMethods) UnconfirmedTxs(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) UnconfirmedTxs(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { txs, errC := this.pipe.Transactor().UnconfirmedTxs() if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return txs, 0, nil } -func (this *ErisDbMethods) SignTx(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) SignTx(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &SignTxParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } tx := param.Tx pAccs := param.PrivAccounts txRet, errC := this.pipe.Transactor().SignTx(tx, pAccs) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return txRet, 0, nil } // *************************************** Name Registry *************************************** -func (this *ErisDbMethods) NameRegEntry(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) NameRegEntry(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &NameRegEntryParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } name := param.Name // TODO is address check? entry, errC := this.pipe.NameReg().Entry(name) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return entry, 0, nil } -func (this *ErisDbMethods) NameRegEntries(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbMethods) NameRegEntries(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &FilterListParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } list, errC := this.pipe.NameReg().Entries(param.Filters) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return list, 0, nil } diff --git a/rpc/v0/wsService.go b/rpc/v0/wsService.go index 73f396e8..a95262bd 100644 --- a/rpc/v0/wsService.go +++ b/rpc/v0/wsService.go @@ -11,7 +11,6 @@ import ( definitions "github.com/eris-ltd/eris-db/definitions" event "github.com/eris-ltd/eris-db/event" rpc "github.com/eris-ltd/eris-db/rpc" - rpc_tendermint "github.com/eris-ltd/eris-db/rpc/tendermint" server "github.com/eris-ltd/eris-db/server" ) @@ -40,18 +39,18 @@ func NewErisDbWsService(codec rpc.Codec, func (this *ErisDbWsService) Process(msg []byte, session *server.WSSession) { log.Debug("REQUEST: %s\n", string(msg)) // Create new request object and unmarshal. - req := &rpc_tendermint.RPCRequest{} + req := &rpc.RPCRequest{} errU := json.Unmarshal(msg, req) // Error when unmarshaling. if errU != nil { - this.writeError("Failed to parse request: "+errU.Error()+" . Raw: "+string(msg), "", rpc_tendermint.PARSE_ERROR, session) + this.writeError("Failed to parse request: "+errU.Error()+" . Raw: "+string(msg), "", rpc.PARSE_ERROR, session) return } // Wrong protocol version. if req.JSONRPC != "2.0" { - this.writeError("Wrong protocol version: "+req.JSONRPC, req.Id, rpc_tendermint.INVALID_REQUEST, session) + this.writeError("Wrong protocol version: "+req.JSONRPC, req.Id, rpc.INVALID_REQUEST, session) return } @@ -65,13 +64,13 @@ func (this *ErisDbWsService) Process(msg []byte, session *server.WSSession) { this.writeResponse(req.Id, resp, session) } } else { - this.writeError("Method not found: "+mName, req.Id, rpc_tendermint.METHOD_NOT_FOUND, session) + this.writeError("Method not found: "+mName, req.Id, rpc.METHOD_NOT_FOUND, session) } } // Convenience method for writing error responses. func (this *ErisDbWsService) writeError(msg, id string, code int, session *server.WSSession) { - response := rpc_tendermint.NewRPCErrorResponse(id, code, msg) + response := rpc.NewRPCErrorResponse(id, code, msg) bts, err := this.codec.EncodeBytes(response) // If there's an error here all bets are off. if err != nil { @@ -82,11 +81,11 @@ func (this *ErisDbWsService) writeError(msg, id string, code int, session *serve // Convenience method for writing responses. func (this *ErisDbWsService) writeResponse(id string, result interface{}, session *server.WSSession) error { - response := rpc_tendermint.NewRPCResponse(id, result) + response := rpc.NewRPCResponse(id, result) bts, err := this.codec.EncodeBytes(response) log.Debug("RESPONSE: %v\n", response) if err != nil { - this.writeError("Internal error: "+err.Error(), id, rpc_tendermint.INTERNAL_ERROR, session) + this.writeError("Internal error: "+err.Error(), id, rpc.INTERNAL_ERROR, session) return err } return session.Write(bts) @@ -94,20 +93,20 @@ func (this *ErisDbWsService) writeResponse(id string, result interface{}, sessio // *************************************** Events ************************************ -func (this *ErisDbWsService) EventSubscribe(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbWsService) EventSubscribe(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { session, ok := requester.(*server.WSSession) if !ok { - return 0, rpc_tendermint.INTERNAL_ERROR, fmt.Errorf("Passing wrong object to websocket events") + return 0, rpc.INTERNAL_ERROR, fmt.Errorf("Passing wrong object to websocket events") } param := &EventIdParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } eventId := param.EventId subId, errSID := event.GenerateSubId() if errSID != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errSID + return nil, rpc.INTERNAL_ERROR, errSID } callback := func(ret events.EventData) { @@ -115,26 +114,26 @@ func (this *ErisDbWsService) EventSubscribe(request *rpc_tendermint.RPCRequest, } _, errC := this.pipe.Events().Subscribe(subId, eventId, callback) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &event.EventSub{subId}, 0, nil } -func (this *ErisDbWsService) EventUnsubscribe(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbWsService) EventUnsubscribe(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &EventIdParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } eventId := param.EventId result, errC := this.pipe.Events().Unsubscribe(eventId) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &event.EventUnsub{result}, 0, nil } -func (this *ErisDbWsService) EventPoll(request *rpc_tendermint.RPCRequest, requester interface{}) (interface{}, int, error) { - return nil, rpc_tendermint.INTERNAL_ERROR, fmt.Errorf("Cannot poll with websockets") +func (this *ErisDbWsService) EventPoll(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { + return nil, rpc.INTERNAL_ERROR, fmt.Errorf("Cannot poll with websockets") } -- GitLab