Skip to content

Commit

Permalink
relayer client: update options to easier pass projectAccessKey / jwt …
Browse files Browse the repository at this point in the history
…token
  • Loading branch information
pkieltyka committed Jan 23, 2024
1 parent 4dd663b commit 2a2d713
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
9 changes: 5 additions & 4 deletions relayer/proto/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ import (
)

type Options struct {
HTTPClient HTTPClient
JWTAuthToken string
HTTPClient HTTPClient
ProjectAccessKey string
JWTAuthToken string
}

func NewRelayer(relayerServiceURL string, projectAccessKey string, options ...Options) Relayer {
func NewRelayer(relayerServiceURL string, options ...Options) Relayer {
opts := Options{}
if len(options) > 0 {
opts = options[0]
}

client := &httpclient{
client: opts.HTTPClient,
projectAccessKey: projectAccessKey,
projectAccessKey: opts.ProjectAccessKey,
}
if opts.HTTPClient == nil {
client.client = http.DefaultClient
Expand Down
10 changes: 8 additions & 2 deletions relayer/rpc_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ type RpcRelayer struct {

var _ sequence.Relayer = &RpcRelayer{}

func NewRpcRelayer(provider *ethrpc.Provider, receiptListener *ethreceipts.ReceiptsListener, rpcRelayerURL string, httpClient proto.HTTPClient) (*RpcRelayer, error) {
type Options = proto.Options

func NewRpcRelayer(provider *ethrpc.Provider, receiptListener *ethreceipts.ReceiptsListener, rpcRelayerURL string, options ...Options) (*RpcRelayer, error) {
// TODO: move receiptListener to Options, and if unspecified, use the Sequence Indexer
// for the receipts listener instead. Or, we can also have the receipts filter method
// on the relayer service too.

_, err := url.Parse(rpcRelayerURL)
if err != nil {
return nil, fmt.Errorf("rpcRelayerURL is invalid: %w", err)
}

service := proto.NewRelayerClient(rpcRelayerURL, httpClient)
service := proto.NewRelayer(rpcRelayerURL, options...)

return &RpcRelayer{
provider: provider,
Expand Down
3 changes: 1 addition & 2 deletions testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log"
"math/big"
"net/http"
"testing"
"time"

Expand Down Expand Up @@ -163,7 +162,7 @@ func (c *TestChain) V2SequenceContext() sequence.WalletContext {
}

func (c *TestChain) SetRpcRelayer(relayerURL string) error {
rpcRelayer, err := relayer.NewRpcRelayer(c.Provider, c.ReceiptsListener, relayerURL, http.DefaultClient)
rpcRelayer, err := relayer.NewRpcRelayer(c.Provider, c.ReceiptsListener, relayerURL)
if err != nil {
return err
}
Expand Down

0 comments on commit 2a2d713

Please sign in to comment.