From 51ba2fcc97179edf50e337fa2cb990fd55f6277a Mon Sep 17 00:00:00 2001 From: ilija Date: Tue, 12 Nov 2024 13:40:46 +0100 Subject: [PATCH] Rearrange Relayer ChainService --- pkg/loop/internal/types/types.go | 8 -------- pkg/types/chain_writer.go | 3 +++ pkg/types/relayer.go | 31 ++++++++++++++++++------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/loop/internal/types/types.go b/pkg/loop/internal/types/types.go index 9e3f50e39..c307c74d1 100644 --- a/pkg/loop/internal/types/types.go +++ b/pkg/loop/internal/types/types.go @@ -44,14 +44,6 @@ type OCR3CapabilityProvider interface { // Relayer is like types.Relayer, but with a dynamic NewPluginProvider method. type Relayer interface { types.ChainService - - // NewChainWriter returns a new ChainWriter. - // The format of config depends on the implementation. - NewChainWriter(ctx context.Context, chainWriterConfig []byte) (types.ChainWriter, error) - - // NewContractReader returns a new ContractReader. - // The format of contractReaderConfig depends on the implementation. - NewContractReader(ctx context.Context, contractReaderConfig []byte) (types.ContractReader, error) NewConfigProvider(context.Context, types.RelayArgs) (types.ConfigProvider, error) NewPluginProvider(context.Context, types.RelayArgs, types.PluginArgs) (types.PluginProvider, error) NewLLOProvider(context.Context, types.RelayArgs, types.PluginArgs) (types.LLOProvider, error) diff --git a/pkg/types/chain_writer.go b/pkg/types/chain_writer.go index 28b243546..438f76481 100644 --- a/pkg/types/chain_writer.go +++ b/pkg/types/chain_writer.go @@ -11,6 +11,9 @@ const ( ErrSettingTransactionGasLimitNotSupported = InvalidArgumentError("setting transaction gas limit is not supported") ) +type ContractWriter = ChainWriter + +// Deprecated: Use ContractWriter instead. type ChainWriter interface { services.Service diff --git a/pkg/types/relayer.go b/pkg/types/relayer.go index ea87f1d17..de8c849eb 100644 --- a/pkg/types/relayer.go +++ b/pkg/types/relayer.go @@ -78,33 +78,38 @@ type NodeStatus struct { State string } -// ChainService is a sub-interface that encapsulates the explicit interactions with a chain, rather than through a provider. -type ChainService interface { - Service - +type ChainReader interface { + // NewContractReader returns a new ContractReader. + // The format of contractReaderConfig depends on the implementation. + NewContractReader(ctx context.Context, contractReaderConfig []byte) (ContractReader, error) // LatestHead returns the latest head for the underlying chain. LatestHead(ctx context.Context) (Head, error) // GetChainStatus returns the ChainStatus for this Relayer. GetChainStatus(ctx context.Context) (ChainStatus, error) // ListNodeStatuses returns the status of RPC nodes. ListNodeStatuses(ctx context.Context, pageSize int32, pageToken string) (stats []NodeStatus, nextPageToken string, total int, err error) +} + +type IChainWriter interface { + // NewChainWriter returns a new ChainWriter. + // The format of config depends on the implementation. + NewChainWriter(ctx context.Context, config []byte) (ChainWriter, error) // Transact submits a transaction to transfer tokens. // If balanceCheck is true, the balance will be checked before submitting. Transact(ctx context.Context, from, to string, amount *big.Int, balanceCheck bool) error } +// ChainService encapsulates ChainReader and IChainWriter sub-interfaces that encapsulate explicit read/write interactions with a chain and smart contract read/write components ContractReader and ContractWriter. +type ChainService interface { + Service + + ChainReader + IChainWriter +} + // Relayer extends ChainService with providers for each product. type Relayer interface { ChainService - - // NewChainWriter returns a new ChainWriter. - // The format of config depends on the implementation. - NewChainWriter(ctx context.Context, config []byte) (ChainWriter, error) - - // NewContractReader returns a new ContractReader. - // The format of contractReaderConfig depends on the implementation. - NewContractReader(ctx context.Context, contractReaderConfig []byte) (ContractReader, error) - NewConfigProvider(ctx context.Context, rargs RelayArgs) (ConfigProvider, error) NewMedianProvider(ctx context.Context, rargs RelayArgs, pargs PluginArgs) (MedianProvider, error)