Skip to content

Commit

Permalink
resolver: drop useless duplicating code
Browse files Browse the repository at this point in the history
Reuse neofs-contract.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Jun 13, 2024
1 parent 892e514 commit 332139b
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions api/resolver/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ import (

"github.com/nspcc-dev/neo-go/pkg/rpcclient"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
"github.com/nspcc-dev/neo-go/pkg/util"
rpcNNS "github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
)

const (
nnsContract = int32(1)
)

// Container is a wrapper for the [NNSResolver]. It allows to update resolvers in runtime, without service restarting.
//
// The Container should be used like regular [NNSResolver].
Expand Down Expand Up @@ -73,23 +68,13 @@ func NewResolver(ctx context.Context, endpoint string) (*NNSResolver, error) {
return nil, fmt.Errorf("rpcclient: %w", err)
}

nnsHash, err := systemContractHash(cl, nnsContract)
if err != nil {
return nil, fmt.Errorf("nns contract: %w", err)
}

inv := invoker.New(cl, nil)
nnsReader := rpcNNS.NewReader(inv, nnsHash)
return NewNNSResolver(nnsReader), nil
}

func systemContractHash(cl *rpcclient.Client, id int32) (util.Uint160, error) {
c, err := cl.GetContractStateByID(id)
nnsReader, err := nns.NewInferredReader(cl, inv)
if err != nil {
return util.Uint160{}, fmt.Errorf("GetContractStateByID [%d]: %w", id, err)
return nil, fmt.Errorf("nns reader instantiation: %w", err)
}

return c.Hash, nil
return NewNNSResolver(nnsReader), nil
}

func rpcClient(ctx context.Context, endpoint string) (*rpcclient.Client, error) {
Expand Down

0 comments on commit 332139b

Please sign in to comment.