-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BCF-3168: changes required to integrate with the RelayerSet from chai… (
#13000) * BCF-3168: changes required to integrate with the RelayerSet from chainlink common * lint * lint * goimports
- Loading branch information
Showing
24 changed files
with
318 additions
and
356 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": minor | ||
--- | ||
|
||
#internal changes to core required by change BCF3168 in common to add relayer set |
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
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
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
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,87 @@ | ||
package generic | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/google/uuid" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/loop" | ||
"github.com/smartcontractkit/chainlink-common/pkg/types" | ||
"github.com/smartcontractkit/chainlink-common/pkg/types/core" | ||
) | ||
|
||
type RelayGetter interface { | ||
GetIDToRelayerMap() (map[types.RelayID]loop.Relayer, error) | ||
} | ||
|
||
type RelayerSet struct { | ||
wrappedRelayers map[types.RelayID]core.Relayer | ||
} | ||
|
||
func NewRelayerSet(relayGetter RelayGetter, externalJobID uuid.UUID, jobID int32, isNew bool) (*RelayerSet, error) { | ||
|
||
wrappedRelayers := map[types.RelayID]core.Relayer{} | ||
|
||
relayers, err := relayGetter.GetIDToRelayerMap() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get relayers: %w", err) | ||
} | ||
|
||
for id, relayer := range relayers { | ||
wrappedRelayers[id] = relayerWrapper{Relayer: relayer, ExternalJobID: externalJobID, JobID: jobID, New: isNew} | ||
} | ||
|
||
return &RelayerSet{wrappedRelayers: wrappedRelayers}, nil | ||
} | ||
|
||
func (r *RelayerSet) Get(_ context.Context, id types.RelayID) (core.Relayer, error) { | ||
if relayer, ok := r.wrappedRelayers[id]; ok { | ||
return relayer, nil | ||
} | ||
|
||
return nil, fmt.Errorf("relayer with id %s not found", id) | ||
} | ||
|
||
func (r *RelayerSet) List(_ context.Context, relayIDs ...types.RelayID) (map[types.RelayID]core.Relayer, error) { | ||
|
||
if len(relayIDs) == 0 { | ||
return r.wrappedRelayers, nil | ||
} | ||
|
||
filterer := map[types.RelayID]bool{} | ||
for _, id := range relayIDs { | ||
filterer[id] = true | ||
} | ||
|
||
result := map[types.RelayID]core.Relayer{} | ||
for id, relayer := range r.wrappedRelayers { | ||
if _, ok := filterer[id]; ok { | ||
result[id] = relayer | ||
} | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
type relayerWrapper struct { | ||
loop.Relayer | ||
ExternalJobID uuid.UUID | ||
JobID int32 | ||
New bool // Whether this is a first time job add. | ||
} | ||
|
||
func (r relayerWrapper) NewPluginProvider(ctx context.Context, rargs core.RelayArgs, pargs core.PluginArgs) (types.PluginProvider, error) { | ||
|
||
relayArgs := types.RelayArgs{ | ||
ExternalJobID: r.ExternalJobID, | ||
JobID: r.JobID, | ||
ContractID: rargs.ContractID, | ||
New: r.New, | ||
RelayConfig: rargs.RelayConfig, | ||
ProviderType: rargs.ProviderType, | ||
MercuryCredentials: rargs.MercuryCredentials, | ||
} | ||
|
||
return r.Relayer.NewPluginProvider(ctx, relayArgs, types.PluginArgs(pargs)) | ||
} |
Oops, something went wrong.