Skip to content

Commit

Permalink
set solana-specific transmission and state addresses in the feed
Browse files Browse the repository at this point in the history
config as optional fields
  • Loading branch information
topliceanu committed Jan 26, 2022
1 parent 326666e commit b2c9376
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 50 deletions.
2 changes: 1 addition & 1 deletion cmd/monitoring/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func main() {
ctx := context.Background()

coreLog := logger.NewLogger(loggerConfig{})
coreLog := logger.NewLogger(loggerConfig{}).With("project", "solana")
log := logWrapper{coreLog}

solanaConfig, err := monitoring.ParseSolanaConfig()
Expand Down
103 changes: 54 additions & 49 deletions pkg/monitoring/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,6 @@ import (
relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring"
)

func SolanaFeedParser(buf io.ReadCloser) ([]relayMonitoring.FeedConfig, error) {
rawFeeds := []SolanaFeedConfig{}
decoder := json.NewDecoder(buf)
if err := decoder.Decode(&rawFeeds); err != nil {
return nil, fmt.Errorf("unable to unmarshal feeds config data: %w", err)
}
feeds := make([]relayMonitoring.FeedConfig, len(rawFeeds))
for i, rawFeed := range rawFeeds {
contractAddress, err := solana.PublicKeyFromBase58(rawFeed.ContractAddressBase58)
if err != nil {
return nil, fmt.Errorf("failed to parse program id '%s' from JSON at index i=%d: %w", rawFeed.ContractAddressBase58, i, err)
}
transmissionsAccount, err := solana.PublicKeyFromBase58(rawFeed.TransmissionsAccountBase58)
if err != nil {
return nil, fmt.Errorf("failed to parse transmission account '%s' from JSON at index i=%d: %w", rawFeed.TransmissionsAccountBase58, i, err)
}
stateAccount, err := solana.PublicKeyFromBase58(rawFeed.StateAccountBase58)
if err != nil {
return nil, fmt.Errorf("failed to parse state account '%s' from JSON at index i=%d: %w", rawFeed.StateAccountBase58, i, err)
}
feeds[i] = relayMonitoring.FeedConfig(SolanaFeedConfig{
rawFeed.Name,
rawFeed.Path,
rawFeed.Symbol,
rawFeed.HeartbeatSec,
rawFeed.ContractType,
rawFeed.ContractStatus,

rawFeed.ContractAddressBase58,
rawFeed.TransmissionsAccountBase58,
rawFeed.StateAccountBase58,

contractAddress,
transmissionsAccount,
stateAccount,
})
}
return feeds, nil
}

type SolanaFeedConfig struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
Expand Down Expand Up @@ -106,14 +66,59 @@ func (s SolanaFeedConfig) GetContractAddressBytes() []byte {

func (s SolanaFeedConfig) ToMapping() map[string]interface{} {
return map[string]interface{}{
"feed_name": s.Name,
"feed_path": s.Path,
"symbol": s.Symbol,
"heartbeat_sec": int64(s.HeartbeatSec),
"contract_type": s.ContractType,
"contract_status": s.ContractStatus,
"contract_address": s.ContractAddress.Bytes(),
"transmissions_account": s.TransmissionsAccount.Bytes(),
"state_account": s.StateAccount.Bytes(),
"feed_name": s.Name,
"feed_path": s.Path,
"symbol": s.Symbol,
"heartbeat_sec": int64(s.HeartbeatSec),
"contract_type": s.ContractType,
"contract_status": s.ContractStatus,
"contract_address": s.ContractAddress.Bytes(),

"transmissions_account": map[string]interface{}{
"bytes": s.TransmissionsAccount.Bytes(),
},
"state_account": map[string]interface{}{
"bytes": s.StateAccount.Bytes(),
},
}
}

func SolanaFeedParser(buf io.ReadCloser) ([]relayMonitoring.FeedConfig, error) {
rawFeeds := []SolanaFeedConfig{}
decoder := json.NewDecoder(buf)
if err := decoder.Decode(&rawFeeds); err != nil {
return nil, fmt.Errorf("unable to unmarshal feeds config data: %w", err)
}
feeds := make([]relayMonitoring.FeedConfig, len(rawFeeds))
for i, rawFeed := range rawFeeds {
contractAddress, err := solana.PublicKeyFromBase58(rawFeed.ContractAddressBase58)
if err != nil {
return nil, fmt.Errorf("failed to parse program id '%s' from JSON at index i=%d: %w", rawFeed.ContractAddressBase58, i, err)
}
transmissionsAccount, err := solana.PublicKeyFromBase58(rawFeed.TransmissionsAccountBase58)
if err != nil {
return nil, fmt.Errorf("failed to parse transmission account '%s' from JSON at index i=%d: %w", rawFeed.TransmissionsAccountBase58, i, err)
}
stateAccount, err := solana.PublicKeyFromBase58(rawFeed.StateAccountBase58)
if err != nil {
return nil, fmt.Errorf("failed to parse state account '%s' from JSON at index i=%d: %w", rawFeed.StateAccountBase58, i, err)
}
feeds[i] = relayMonitoring.FeedConfig(SolanaFeedConfig{
rawFeed.Name,
rawFeed.Path,
rawFeed.Symbol,
rawFeed.HeartbeatSec,
rawFeed.ContractType,
rawFeed.ContractStatus,

rawFeed.ContractAddressBase58,
rawFeed.TransmissionsAccountBase58,
rawFeed.StateAccountBase58,

contractAddress,
transmissionsAccount,
stateAccount,
})
}
return feeds, nil
}

0 comments on commit b2c9376

Please sign in to comment.