Skip to content

Commit

Permalink
Expose blockchain client as interface
Browse files Browse the repository at this point in the history
  • Loading branch information
khssnv committed Dec 13, 2023
1 parent 27a9c4d commit a67c525
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions blockchain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ import (
"github.com/cerebellum-network/cere-ddc-sdk-go/blockchain/pallets"
)

type Client struct {
type Client interface {
DdcClusters() *pallets.DdcClustersApi
DdcCustomers() *pallets.DdcCustomersApi
DdcNodes() *pallets.DdcNodesApi
}

type client struct {
*gsrpc.SubstrateAPI

DdcClusters *pallets.DdcClustersApi
DdcCustomers *pallets.DdcCustomersApi
DdcNodes *pallets.DdcNodesApi
ddcClusters *pallets.DdcClustersApi
ddcCustomers *pallets.DdcCustomersApi
ddcNodes *pallets.DdcNodesApi
}

func NewClient(url string) (*Client, error) {
func NewClient(url string) (Client, error) {
substrateApi, err := gsrpc.NewSubstrateAPI(url)
if err != nil {
return nil, err
Expand All @@ -24,10 +30,22 @@ func NewClient(url string) (*Client, error) {
return nil, err
}

return &Client{
return &client{
SubstrateAPI: substrateApi,
DdcClusters: pallets.NewDdcClustersApi(substrateApi),
DdcCustomers: pallets.NewDdcCustomersApi(substrateApi, meta),
DdcNodes: pallets.NewDdcNodesApi(substrateApi, meta),
ddcClusters: pallets.NewDdcClustersApi(substrateApi),
ddcCustomers: pallets.NewDdcCustomersApi(substrateApi, meta),
ddcNodes: pallets.NewDdcNodesApi(substrateApi, meta),
}, nil
}

func (c *client) DdcClusters() *pallets.DdcClustersApi {
return c.ddcClusters
}

func (c *client) DdcCustomers() *pallets.DdcCustomersApi {
return c.ddcCustomers
}

func (c *client) DdcNodes() *pallets.DdcNodesApi {
return c.ddcNodes
}

0 comments on commit a67c525

Please sign in to comment.