From 70eb0b175ac015f5635aa640b407e91a96478e2d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 13 Mar 2020 10:00:18 +0300 Subject: [PATCH] rpc: move getassetstate RPC to a separate func --- pkg/rpc/server/server.go | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index e14c8fb42..7f4bebb12 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -277,24 +277,7 @@ Methods: results = validateAddress(param.Value) case "getassetstate": - param, ok := reqParams.ValueWithType(0, request.StringT) - if !ok { - resultsErr = response.ErrInvalidParams - break Methods - } - - paramAssetID, err := param.GetUint256() - if err != nil { - resultsErr = response.ErrInvalidParams - break - } - - as := s.chain.GetAssetState(paramAssetID) - if as != nil { - results = result.NewAssetState(as) - } else { - resultsErr = response.NewRPCError("Unknown asset", "", nil) - } + results, resultsErr = s.getAssetState(reqParams) case "getaccountstate": results, resultsErr = s.getAccountState(reqParams, false) @@ -344,6 +327,24 @@ Methods: s.WriteResponse(req, w, results) } +func (s *Server) getAssetState(reqParams request.Params) (interface{}, error) { + param, ok := reqParams.ValueWithType(0, request.StringT) + if !ok { + return nil, response.ErrInvalidParams + } + + paramAssetID, err := param.GetUint256() + if err != nil { + return nil, response.ErrInvalidParams + } + + as := s.chain.GetAssetState(paramAssetID) + if as != nil { + return result.NewAssetState(as), nil + } + return nil, response.NewRPCError("Unknown asset", "", nil) +} + // getApplicationLog returns the contract log based on the specified txid. func (s *Server) getApplicationLog(reqParams request.Params) (interface{}, error) { param, ok := reqParams.Value(0)