Skip to content

Commit

Permalink
Add DataSource to ChainOpts and pass down to tx mgr from NewChain
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Nov 5, 2024
1 parent b49b2be commit a454b32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 8 additions & 4 deletions pkg/solana/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/chains"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink-common/pkg/utils"
Expand Down Expand Up @@ -49,6 +49,7 @@ const DefaultRequestTimeout = 30 * time.Second
type ChainOpts struct {
Logger logger.Logger
KeyStore core.Keystore
DS sqlutil.DataSource
}

func (o *ChainOpts) Validate() (err error) {
Expand All @@ -61,6 +62,9 @@ func (o *ChainOpts) Validate() (err error) {
if o.KeyStore == nil {
err = errors.Join(err, required("KeyStore"))
}
if o.DS == nil {
err = errors.Join(err, required("DataSource"))
}
return
}

Expand All @@ -72,7 +76,7 @@ func NewChain(cfg *config.TOMLConfig, opts ChainOpts) (Chain, error) {
if !cfg.IsEnabled() {
return nil, fmt.Errorf("cannot create new chain with ID %s: chain is disabled", *cfg.ChainID)
}
c, err := newChain(*cfg.ChainID, cfg, opts.KeyStore, opts.Logger)
c, err := newChain(*cfg.ChainID, cfg, opts.KeyStore, opts.Logger, opts.DS)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -222,7 +226,7 @@ func (v *verifiedCachedClient) GetAccountInfoWithOpts(ctx context.Context, addr
return v.ReaderWriter.GetAccountInfoWithOpts(ctx, addr, opts)
}

func newChain(id string, cfg *config.TOMLConfig, ks loop.Keystore, lggr logger.Logger) (*chain, error) {
func newChain(id string, cfg *config.TOMLConfig, ks core.Keystore, lggr logger.Logger, ds sqlutil.DataSource) (*chain, error) {
lggr = logger.With(lggr, "chainID", id, "chain", "solana")
var ch = chain{
id: id,
Expand Down Expand Up @@ -306,7 +310,7 @@ func newChain(id string, cfg *config.TOMLConfig, ks loop.Keystore, lggr logger.L
bc = internal.NewLoader[monitor.BalanceClient](func() (monitor.BalanceClient, error) { return ch.multiNode.SelectRPC() })
}

ch.txm = txm.NewTxm(ch.id, tc, sendTx, cfg, ks, lggr)
ch.txm = txm.NewTxm(ch.id, tc, sendTx, cfg, ks, lggr, ds)
ch.balanceMonitor = monitor.NewBalanceMonitor(ch.id, cfg, lggr, ks, bc)
return &ch, nil
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/solana/txm/txm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
solanaGo "github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
"github.com/google/uuid"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/loop"
Expand Down Expand Up @@ -55,6 +56,7 @@ type Txm struct {
cfg config.Config
txs PendingTxContext
ks SimpleKeystore
ds sqlutil.DataSource
client internal.Loader[client.ReaderWriter]
fee fees.Estimator
// sendTx is an override for sending transactions rather than using a single client
Expand Down Expand Up @@ -85,7 +87,7 @@ type pendingTx struct {
// NewTxm creates a txm. Uses simulation so should only be used to send txes to trusted contracts i.e. OCR.
func NewTxm(chainID string, client internal.Loader[client.ReaderWriter],
sendTx func(ctx context.Context, tx *solanaGo.Transaction) (solanaGo.Signature, error),
cfg config.Config, ks SimpleKeystore, lggr logger.Logger) *Txm {
cfg config.Config, ks SimpleKeystore, lggr logger.Logger, ds sqlutil.DataSource) *Txm {
if sendTx == nil {
// default sendTx using a single RPC
sendTx = func(ctx context.Context, tx *solanaGo.Transaction) (solanaGo.Signature, error) {
Expand All @@ -105,6 +107,7 @@ func NewTxm(chainID string, client internal.Loader[client.ReaderWriter],
cfg: cfg,
txs: newPendingTxContextWithProm(chainID),
ks: ks,
ds: ds,
client: client,
sendTx: sendTx,
}
Expand Down

0 comments on commit a454b32

Please sign in to comment.