gitlab.com/aquachain/aquachain@v1.17.16-rc3.0.20221018032414-e3ddf1e1c055/rpc/rpcclient/jsontypes_test.go (about) 1 // Copyright 2018 The aquachain Authors 2 // This file is part of the aquachain library. 3 // 4 // The aquachain library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The aquachain library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the aquachain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package rpc 18 19 import ( 20 "encoding/json" 21 "io" 22 "sync" 23 24 "gitlab.com/aquachain/aquachain/rpc" 25 ) 26 27 const ( 28 JsonrpcVersion = "2.0" 29 ServiceMethodSeparator = "_" 30 ) 31 32 type testError interface{} 33 34 type jsonRequest struct { 35 Method string `json:"method"` 36 Version string `json:"jsonrpc"` 37 Id json.RawMessage `json:"id,omitempty"` 38 Payload json.RawMessage `json:"params,omitempty"` 39 } 40 41 type jsonSuccessResponse struct { 42 Version string `json:"jsonrpc"` 43 Id interface{} `json:"id,omitempty"` 44 Result interface{} `json:"result"` 45 } 46 47 type jsonErrResponse struct { 48 Version string `json:"jsonrpc"` 49 Id interface{} `json:"id,omitempty"` 50 Error rpc.JsonError `json:"error"` 51 } 52 53 type jsonSubscription struct { 54 Subscription string `json:"subscription"` 55 Result interface{} `json:"result,omitempty"` 56 } 57 58 type jsonNotification struct { 59 Version string `json:"jsonrpc"` 60 Method string `json:"method"` 61 Params jsonSubscription `json:"params"` 62 } 63 64 // jsonCodec reads and writes JSON-RPC messages to the underlying connection. It 65 // also has support for parsing arguments and serializing (result) objects. 66 type jsonCodec struct { 67 closer sync.Once // close closed channel once 68 closed chan interface{} // closed on Close 69 decMu sync.Mutex // guards d 70 decode func(v interface{}) error // decodes incoming requests 71 encMu sync.Mutex // guards e 72 encode func(v interface{}) error // encodes responses 73 rw io.ReadWriteCloser // connection 74 }