-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite fetcher logic to be more robust
- Loading branch information
1 parent
1055433
commit 977917d
Showing
15 changed files
with
675 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# MacOS Leftovers | ||
.DS_Store | ||
|
||
# Data Leftovers | ||
indexer-db/* | ||
|
||
# Editor Leftovers | ||
.vscode | ||
.idea | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
rpcClient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client" | ||
core_types "github.com/gnolang/gno/tm2/pkg/bft/rpc/core/types" | ||
) | ||
|
||
// Client is the TM2 HTTP client | ||
type Client struct { | ||
client rpcClient.Client | ||
} | ||
|
||
// NewClient creates a new TM2 HTTP client | ||
func NewClient(remote string) *Client { | ||
return &Client{ | ||
client: rpcClient.NewHTTP(remote, ""), | ||
} | ||
} | ||
|
||
func (c *Client) GetLatestBlockNumber() (int64, error) { | ||
status, err := c.client.Status() | ||
if err != nil { | ||
return 0, fmt.Errorf("unable to get chain status, %w", err) | ||
} | ||
|
||
return status.SyncInfo.LatestBlockHeight, nil | ||
} | ||
|
||
func (c *Client) GetBlock(blockNum int64) (*core_types.ResultBlock, error) { | ||
block, err := c.client.Block(&blockNum) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to get block, %w", err) | ||
} | ||
|
||
return block, nil | ||
} | ||
|
||
func (c *Client) GetBlockResults(blockNum int64) (*core_types.ResultBlockResults, error) { | ||
results, err := c.client.BlockResults(&blockNum) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to get block results, %w", err) | ||
} | ||
|
||
return results, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
type waitFunc func(ctx context.Context) error | ||
|
||
// waiter is a concept used for waiting on running services | ||
type waiter struct { | ||
ctx context.Context | ||
cancel context.CancelFunc | ||
|
||
waitFns []waitFunc | ||
} | ||
|
||
// newWaiter creates a new waiter instance | ||
func newWaiter(ctx context.Context) *waiter { | ||
w := &waiter{ | ||
waitFns: []waitFunc{}, | ||
} | ||
|
||
w.ctx, w.cancel = signal.NotifyContext( | ||
ctx, | ||
os.Interrupt, | ||
syscall.SIGINT, | ||
syscall.SIGTERM, | ||
syscall.SIGQUIT, | ||
) | ||
|
||
return w | ||
} | ||
|
||
// add adds a new wait service | ||
func (w *waiter) add(fns ...waitFunc) { | ||
w.waitFns = append(w.waitFns, fns...) | ||
} | ||
|
||
// wait blocks until all added wait services finish | ||
func (w *waiter) wait() error { | ||
g, ctx := errgroup.WithContext(w.ctx) | ||
|
||
g.Go(func() error { | ||
<-ctx.Done() | ||
w.cancel() | ||
|
||
return nil | ||
}) | ||
|
||
for _, fn := range w.waitFns { | ||
fn := fn | ||
|
||
g.Go( | ||
func() error { | ||
return fn(ctx) | ||
}, | ||
) | ||
} | ||
|
||
return g.Wait() | ||
} |
Oops, something went wrong.