diff --git a/jsonrpc/service.go b/jsonrpc/service.go index 11b2804..7fc925b 100644 --- a/jsonrpc/service.go +++ b/jsonrpc/service.go @@ -35,6 +35,7 @@ import ( // Service is an Starknet client service. type Service struct { + log zerolog.Logger base *url.URL address string webSocketAddress string @@ -47,9 +48,6 @@ type Service struct { connectionSynced bool } -// log is a service-wide logger. -var log zerolog.Logger - // New creates a new execution client service, connecting with a standard HTTP. func New(ctx context.Context, params ...Parameter) (*Service, error) { parameters, err := parseAndCheckParameters(params...) @@ -58,7 +56,7 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { } // Set logging. - log = zerologger.With().Str("service", "client").Str("impl", "jsonrpc").Logger() + log := zerologger.With().Str("service", "client").Str("impl", "jsonrpc").Logger() if parameters.logLevel != log.GetLevel() { log = log.Level(parameters.logLevel) } @@ -109,6 +107,7 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { }) s := &Service{ + log: log, base: base, client: rpcClient, address: address.String(), diff --git a/jsonrpc/service_test.go b/jsonrpc/service_test.go index 9e6c7ff..50e1d8e 100644 --- a/jsonrpc/service_test.go +++ b/jsonrpc/service_test.go @@ -42,6 +42,7 @@ func TestService(t *testing.T) { { name: "AddressNil", parameters: []jsonrpc.Parameter{ + jsonrpc.WithLogLevel(zerolog.Disabled), jsonrpc.WithTimeout(5 * time.Second), }, err: "no address specified", @@ -49,6 +50,7 @@ func TestService(t *testing.T) { { name: "TimeoutZero", parameters: []jsonrpc.Parameter{ + jsonrpc.WithLogLevel(zerolog.Disabled), jsonrpc.WithAddress(os.Getenv("JSONRPC_ADDRESS")), jsonrpc.WithTimeout(0), }, @@ -57,6 +59,7 @@ func TestService(t *testing.T) { { name: "AddressInvalid", parameters: []jsonrpc.Parameter{ + jsonrpc.WithLogLevel(zerolog.Disabled), jsonrpc.WithAddress(string([]byte{0x01})), jsonrpc.WithTimeout(5 * time.Second), }, diff --git a/types/address.go b/types/address.go index 6a0332e..b7c9f5a 100644 --- a/types/address.go +++ b/types/address.go @@ -32,12 +32,12 @@ type Address [AddressLength]byte var zeroAddress = Address{} // IsZero returns true if the address is zero. -func (a *Address) IsZero() bool { +func (a Address) IsZero() bool { return bytes.Equal(a[:], zeroAddress[:]) } // String returns the string representation of the address. -func (a *Address) String() string { +func (a Address) String() string { res := hex.EncodeToString(a[:]) // Leading 0s not allowed... res = strings.TrimLeft(res, "0") @@ -50,7 +50,7 @@ func (a *Address) String() string { } // Format formats the address. -func (a *Address) Format(state fmt.State, v rune) { +func (a Address) Format(state fmt.State, v rune) { format := string(v) switch v { case 's':