Skip to content

Commit

Permalink
updated avail.go
Browse files Browse the repository at this point in the history
  • Loading branch information
chandiniv1 committed Aug 23, 2023
1 parent f0ab456 commit 0712600
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
25 changes: 13 additions & 12 deletions da/avail/avail.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand All @@ -20,13 +20,13 @@ type Config struct {
Seed string `json:"seed"`
ApiURL string `json:"api_url"`
AppID int `json:"app_id"`
confidence float64 `json:"confidence"`
Confidence float64 `json:"confidence"`
}

type DataAvailabilityLayerClient struct {
namespace types.NamespaceID
config Config
logger log.Logger
_ types.NamespaceID
config Config
logger log.Logger
}

type Confidence struct {
Expand All @@ -44,7 +44,7 @@ var _ da.DataAvailabilityLayerClient = &DataAvailabilityLayerClient{}
var _ da.BlockRetriever = &DataAvailabilityLayerClient{}

// Init initializes DataAvailabilityLayerClient instance.
func (c *DataAvailabilityLayerClient) Init(namespaceID types.NamespaceID, config []byte, kvStore ds.Datastore, logger log.Logger) error {
func (c *DataAvailabilityLayerClient) Init(_ types.NamespaceID, config []byte, kvStore ds.Datastore, logger log.Logger) error {
c.logger = logger

if len(config) > 0 {
Expand Down Expand Up @@ -98,7 +98,7 @@ func (c *DataAvailabilityLayerClient) SubmitBlocks(ctx context.Context, blocks [
return da.ResultSubmitBlocks{
BaseResult: da.BaseResult{
Code: da.StatusSuccess,
Message: "data submitted succesfully",
Message: "data submitted successfully",
DAHeight: 1,
},
}
Expand All @@ -112,7 +112,6 @@ func (c *DataAvailabilityLayerClient) CheckBlockAvailability(ctx context.Context
confidenceURL := fmt.Sprintf(c.config.BaseURL+"/confidence/%d", blockNumber)

response, err := http.Get(confidenceURL)

Check failure on line 114 in da/avail/avail.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

G107: Potential HTTP request made with variable url (gosec)

if err != nil {
return da.ResultCheckBlock{
BaseResult: da.BaseResult{
Expand All @@ -121,8 +120,9 @@ func (c *DataAvailabilityLayerClient) CheckBlockAvailability(ctx context.Context
},
}
}
defer response.Body.Close()

Check failure on line 123 in da/avail/avail.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

Error return value of `response.Body.Close` is not checked (errcheck)

responseData, err := ioutil.ReadAll(response.Body)
responseData, err := io.ReadAll(response.Body)
if err != nil {
return da.ResultCheckBlock{
BaseResult: da.BaseResult{
Expand All @@ -148,11 +148,11 @@ func (c *DataAvailabilityLayerClient) CheckBlockAvailability(ctx context.Context
Code: da.StatusSuccess,
DAHeight: uint64(confidenceObject.Block),
},
DataAvailable: confidenceObject.Confidence > float64(c.config.confidence),
DataAvailable: confidenceObject.Confidence > float64(c.config.Confidence),
}
}

//RetrieveBlocks gets the block from DA layer.
// RetrieveBlocks gets the block from DA layer.

func (c *DataAvailabilityLayerClient) RetrieveBlocks(ctx context.Context, dataLayerHeight uint64) da.ResultRetrieveBlocks {

Expand All @@ -171,8 +171,9 @@ func (c *DataAvailabilityLayerClient) RetrieveBlocks(ctx context.Context, dataLa
},
}
}
defer response.Body.Close()

Check failure on line 174 in da/avail/avail.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

Error return value of `response.Body.Close` is not checked (errcheck)

responseData, err := ioutil.ReadAll(response.Body)
responseData, err := io.ReadAll(response.Body)
if err != nil {
return da.ResultRetrieveBlocks{
BaseResult: da.BaseResult{
Expand Down
20 changes: 10 additions & 10 deletions da/avail/datasubmit/submitdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (

// submit data submits the extrinsic through substrate api
func SubmitData(apiURL string, seed string, appID int, data []byte) error {

// if app id is greater than 0 then it must be created before submitting data
if appID == 0 {
return errors.New("AppID cant be 0")
}

api, err := gsrpc.NewSubstrateAPI(apiURL)
if err != nil {
return err
Expand All @@ -20,18 +26,12 @@ func SubmitData(apiURL string, seed string, appID int, data []byte) error {
return err
}

//if app id is greater than 0 then it must be created before submitting data
err = errors.New("AppID cant be 0")
if appID == 0 {
return err
}

c, err := types.NewCall(meta, "DataAvailability.submit_data", data)
if err != nil {
return err
}

//Create the extrinsic
// Create the extrinsic
ext := types.NewExtrinsic(c)

genesisHash, err := api.RPC.Chain.GetBlockHash(0)
Expand All @@ -57,11 +57,11 @@ func SubmitData(apiURL string, seed string, appID int, data []byte) error {
var accountInfo types.AccountInfo
ok, err := api.RPC.State.GetStorageLatest(key, &accountInfo)
if err != nil || !ok {
return err
return errors.New("failed to get the latest storage")
}

nonce := uint32(accountInfo.Nonce)
o := types.SignatureOptions{
signOptions := types.SignatureOptions{
BlockHash: genesisHash,
Era: types.ExtrinsicEra{IsMortalEra: false},
GenesisHash: genesisHash,
Expand All @@ -73,7 +73,7 @@ func SubmitData(apiURL string, seed string, appID int, data []byte) error {
}

// Sign the transaction using Alice's default account
err = ext.Sign(keyringPair, o)
err = ext.Sign(keyringPair, signOptions)
if err != nil {
return err
}
Expand Down

0 comments on commit 0712600

Please sign in to comment.