automated merge

This commit is contained in:
philip-morlier
2023-07-11 16:01:17 -07:00
327 changed files with 15001 additions and 11151 deletions
+3 -3
View File
@@ -43,7 +43,7 @@ var (
const (
// Timeouts
defaultDialTimeout = 10 * time.Second // used if context has no deadline
subscribeTimeout = 5 * time.Second // overall timeout eth_subscribe, rpc_modules calls
subscribeTimeout = 10 * time.Second // overall timeout eth_subscribe, rpc_modules calls
)
const (
@@ -79,7 +79,7 @@ type Client struct {
isHTTP bool // connection type: http, ws or ipc
services *serviceRegistry
idCounter uint32
idCounter atomic.Uint32
// This function, if non-nil, is called when the connection is lost.
reconnectFunc reconnectFunc
@@ -263,7 +263,7 @@ func (c *Client) RegisterName(name string, receiver interface{}) error {
}
func (c *Client) nextID() json.RawMessage {
id := atomic.AddUint32(&c.idCounter, 1)
id := c.idCounter.Add(1)
return strconv.AppendUint(nil, uint64(id), 10)
}
+5 -5
View File
@@ -48,7 +48,7 @@ type Server struct {
mutex sync.Mutex
codecs map[ServerCodec]struct{}
run int32
run atomic.Bool
}
// NewServer creates a new server instance with no registered handlers.
@@ -56,8 +56,8 @@ func NewServer() *Server {
server := &Server{
idgen: randomIDGenerator(),
codecs: make(map[ServerCodec]struct{}),
run: 1,
}
server.run.Store(true)
// Register the default service providing meta information about the RPC service such
// as the services and methods it offers.
rpcService := &RPCService{server}
@@ -95,7 +95,7 @@ func (s *Server) trackCodec(codec ServerCodec) bool {
s.mutex.Lock()
defer s.mutex.Unlock()
if atomic.LoadInt32(&s.run) == 0 {
if !s.run.Load() {
return false // Don't serve if server is stopped.
}
s.codecs[codec] = struct{}{}
@@ -114,7 +114,7 @@ func (s *Server) untrackCodec(codec ServerCodec) {
// this mode.
func (s *Server) serveSingleRequest(ctx context.Context, codec ServerCodec) {
// Don't serve if server is stopped.
if atomic.LoadInt32(&s.run) == 0 {
if !s.run.Load() {
return
}
@@ -144,7 +144,7 @@ func (s *Server) Stop() {
s.mutex.Lock()
defer s.mutex.Unlock()
if atomic.CompareAndSwapInt32(&s.run, 1, 0) {
if s.run.CompareAndSwap(true, false) {
log.Debug("RPC server shutting down")
for codec := range s.codecs {
codec.close()
+1 -12
View File
@@ -217,19 +217,8 @@ func (c *callback) call(ctx context.Context, method string, args []reflect.Value
return results[0].Interface(), nil
}
// Is t context.Context or *context.Context?
func isContextType(t reflect.Type) bool {
for t.Kind() == reflect.Ptr {
t = t.Elem()
}
return t == contextType
}
// Does t satisfy the error interface?
func isErrorType(t reflect.Type) bool {
for t.Kind() == reflect.Ptr {
t = t.Elem()
}
return t.Implements(errorType)
}
@@ -248,7 +237,7 @@ func isPubSub(methodType reflect.Type) bool {
if methodType.NumIn() < 2 || methodType.NumOut() != 2 {
return false
}
return isContextType(methodType.In(1)) &&
return methodType.In(1) == contextType &&
isSubscriptionType(methodType.Out(0)) &&
isErrorType(methodType.Out(1))
}
+26 -18
View File
@@ -65,8 +65,8 @@ type BlockNumber int64
const (
SafeBlockNumber = BlockNumber(-4)
FinalizedBlockNumber = BlockNumber(-3)
PendingBlockNumber = BlockNumber(-2)
LatestBlockNumber = BlockNumber(-1)
LatestBlockNumber = BlockNumber(-2)
PendingBlockNumber = BlockNumber(-1)
EarliestBlockNumber = BlockNumber(0)
)
@@ -111,28 +111,36 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
return nil
}
// Int64 returns the block number as int64.
func (bn BlockNumber) Int64() int64 {
return (int64)(bn)
}
// MarshalText implements encoding.TextMarshaler. It marshals:
// - "safe", "finalized", "latest", "earliest" or "pending" as strings
// - other numbers as hex
func (bn BlockNumber) MarshalText() ([]byte, error) {
switch bn {
case EarliestBlockNumber:
return []byte("earliest"), nil
case LatestBlockNumber:
return []byte("latest"), nil
case PendingBlockNumber:
return []byte("pending"), nil
case FinalizedBlockNumber:
return []byte("finalized"), nil
case SafeBlockNumber:
return []byte("safe"), nil
default:
return hexutil.Uint64(bn).MarshalText()
}
return []byte(bn.String()), nil
}
func (bn BlockNumber) Int64() int64 {
return (int64)(bn)
func (bn BlockNumber) String() string {
switch bn {
case EarliestBlockNumber:
return "earliest"
case LatestBlockNumber:
return "latest"
case PendingBlockNumber:
return "pending"
case FinalizedBlockNumber:
return "finalized"
case SafeBlockNumber:
return "safe"
default:
if bn < 0 {
return fmt.Sprintf("<invalid %d>", bn)
}
return hexutil.Uint64(bn).String()
}
}
type BlockNumberOrHash struct {
+1
View File
@@ -224,6 +224,7 @@ func newClientTransportWS(endpoint string, cfg *clientConfig) (reconnectFunc, er
ReadBufferSize: wsReadBuffer,
WriteBufferSize: wsWriteBuffer,
WriteBufferPool: wsBufferPool,
Proxy: http.ProxyFromEnvironment,
}
}