-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BCF-2685: move LOOPP command from core
- Loading branch information
Showing
8 changed files
with
121 additions
and
40 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
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,75 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/go-plugin" | ||
"github.com/pelletier/go-toml/v2" | ||
|
||
"github.com/smartcontractkit/chainlink-relay/pkg/loop" | ||
"github.com/smartcontractkit/chainlink-solana/pkg/solana" | ||
) | ||
|
||
const ( | ||
loggerName = "PluginSolana" | ||
) | ||
|
||
func main() { | ||
s := loop.MustNewStartedServer(loggerName) | ||
defer s.Stop() | ||
|
||
p := &pluginRelayer{Plugin: loop.Plugin{Logger: s.Logger}} | ||
defer s.Logger.ErrorIfFn(p.Close, "Failed to close") | ||
|
||
s.MustRegister(p) | ||
|
||
stopCh := make(chan struct{}) | ||
defer close(stopCh) | ||
|
||
plugin.Serve(&plugin.ServeConfig{ | ||
HandshakeConfig: loop.PluginRelayerHandshakeConfig(), | ||
Plugins: map[string]plugin.Plugin{ | ||
loop.PluginRelayerName: &loop.GRPCPluginRelayer{ | ||
PluginServer: p, | ||
BrokerConfig: loop.BrokerConfig{ | ||
StopCh: stopCh, | ||
Logger: s.Logger, | ||
GRPCOpts: s.GRPCOpts, | ||
}, | ||
}, | ||
}, | ||
GRPCServer: s.GRPCOpts.NewServer, | ||
}) | ||
} | ||
|
||
type pluginRelayer struct { | ||
loop.Plugin | ||
} | ||
|
||
func (c *pluginRelayer) NewRelayer(ctx context.Context, config string, keystore loop.Keystore) (loop.Relayer, error) { | ||
d := toml.NewDecoder(strings.NewReader(config)) | ||
d.DisallowUnknownFields() | ||
var cfg struct { | ||
Solana solana.TOMLConfig | ||
} | ||
|
||
if err := d.Decode(&cfg); err != nil { | ||
return nil, fmt.Errorf("failed to decode config toml: %w:\n\t%s", err, config) | ||
} | ||
|
||
opts := solana.ChainOpts{ | ||
Logger: c.Logger, | ||
KeyStore: keystore, | ||
} | ||
chain, err := solana.NewChain(&cfg.Solana, opts) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create chain: %w", err) | ||
} | ||
ra := loop.NewRelayerAdapter(solana.NewRelayer(c.Logger, chain), chain) | ||
|
||
c.SubService(ra) | ||
|
||
return ra, 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