From a67c5258c8e551b38c0b45cecc3bdda897476f5d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 13 Dec 2023 14:18:48 +0600 Subject: [PATCH] Expose blockchain client as interface --- blockchain/client.go | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/blockchain/client.go b/blockchain/client.go index 4d1f463..04c773f 100644 --- a/blockchain/client.go +++ b/blockchain/client.go @@ -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 @@ -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 +}