Skip to content

Commit

Permalink
Tidy-ups.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Nov 18, 2024
1 parent 7cd0510 commit ccecb7a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 3 additions & 4 deletions jsonrpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

// Service is an Starknet client service.
type Service struct {
log zerolog.Logger
base *url.URL
address string
webSocketAddress string
Expand All @@ -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...)
Expand All @@ -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)
}
Expand Down Expand Up @@ -109,6 +107,7 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) {
})

s := &Service{
log: log,
base: base,
client: rpcClient,
address: address.String(),
Expand Down
3 changes: 3 additions & 0 deletions jsonrpc/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ func TestService(t *testing.T) {
{
name: "AddressNil",
parameters: []jsonrpc.Parameter{
jsonrpc.WithLogLevel(zerolog.Disabled),
jsonrpc.WithTimeout(5 * time.Second),
},
err: "no address specified",
},
{
name: "TimeoutZero",
parameters: []jsonrpc.Parameter{
jsonrpc.WithLogLevel(zerolog.Disabled),
jsonrpc.WithAddress(os.Getenv("JSONRPC_ADDRESS")),
jsonrpc.WithTimeout(0),
},
Expand All @@ -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),
},
Expand Down
6 changes: 3 additions & 3 deletions types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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':
Expand Down

0 comments on commit ccecb7a

Please sign in to comment.