Skip to content

Commit

Permalink
feat: add error handling when rpc is not connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
rac-sri committed Sep 27, 2024
1 parent 2c3532d commit 7324e4b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions avail_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var ErrNotFound = errors.New("not found")
const AvailByte = 0x0a

func NewAvailDAServer(host string, port int, store AvailStore, log log.Logger, useGenericComm bool) *AvailDAServer {

endpoint := net.JoinHostPort(host, strconv.Itoa(port))
return &AvailDAServer{
log: log,
Expand Down
2 changes: 1 addition & 1 deletion service/avail_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type AvailService struct {
}

func NewAvailService(apiURL string, seed string, appID int, timeout time.Duration) *AvailService {
availSpecs, err := types.NewAvailDASpecs(apiURL, appID, seed, timeout)

availSpecs, err := types.NewAvailDASpecs(apiURL, appID, seed, timeout)
if err != nil {
panic("failed avail initialisation")
}
Expand Down
7 changes: 6 additions & 1 deletion types/avail_block_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ type AvailDASpecs struct {
}

func NewAvailDASpecs(ApiURL string, AppID int, Seed string, Timeout time.Duration) (*AvailDASpecs, error) {

AppID = utils.EnsureValidAppID(AppID)
api, _ := utils.GetSubstrateApi(ApiURL)
api, err := utils.GetSubstrateApi(ApiURL)
if err != nil {
log.Error("⚠️ cannot connect to the rpc: error:%w", err)
return nil, err
}

meta, err := api.RPC.State.GetMetadataLatest()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func GetAccountNonce(accountNonce uint32) uint32 {
}

func GetSubstrateApi(ApiURL string) (*gsrpc.SubstrateAPI, error) {

api, err := gsrpc.NewSubstrateAPI(ApiURL)

if err != nil {
Expand Down

0 comments on commit 7324e4b

Please sign in to comment.