Skip to content

Commit

Permalink
fix: implemented new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sherpalden committed Oct 17, 2024
1 parent a08474e commit 0143904
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 23 deletions.
13 changes: 13 additions & 0 deletions relayer/chains/solana/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
solrpc "github.com/gagliardetto/solana-go/rpc"
"github.com/icon-project/centralized-relay/relayer/chains/solana/types"
"github.com/icon-project/centralized-relay/relayer/provider"
relayertypes "github.com/icon-project/centralized-relay/relayer/types"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -92,3 +93,15 @@ func (pc *Config) Validate() error {
func (pc *Config) Enabled() bool {
return !pc.Disabled
}

func (pc *Config) ContractsAddress() relayertypes.ContractConfigMap {
addresses := relayertypes.ContractConfigMap{
relayertypes.ConnectionContract: pc.ConnectionProgram,
relayertypes.XcallContract: pc.XcallProgram,
}
for _, dapp := range pc.Dapps {
addresses[dapp.Name] = dapp.ProgramID
}

return addresses
}
66 changes: 43 additions & 23 deletions relayer/chains/solana/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,38 +81,58 @@ func (p *Provider) FinalityBlock(ctx context.Context) uint64 {
return 0
}

func (p *Provider) GenerateMessages(ctx context.Context, messageKey *relayertypes.MessageKeyWithMessageHeight) ([]*relayertypes.Message, error) {
blockRes, err := p.client.GetBlock(ctx, messageKey.Height)
func (p *Provider) FetchTxMessages(ctx context.Context, txHash string) ([]*relayertypes.Message, error) {
signature := solana.MustSignatureFromBase58(txHash)
txVersion := uint64(0)
txn, err := p.client.GetTransaction(ctx, signature, &solrpc.GetTransactionOpts{MaxSupportedTransactionVersion: &txVersion})
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get txn with sign %s: %w", signature, err)
}

messages := []*relayertypes.Message{}
event := types.SolEvent{
Slot: txn.Slot,
Signature: signature,
Logs: txn.Meta.LogMessages,
}

for _, txn := range blockRes.Transactions {
event := types.SolEvent{
Slot: txn.Slot,
Signature: txn.MustGetTransaction().Signatures[0],
Logs: txn.Meta.LogMessages,
}
return p.parseMessagesFromEvent(event)
}

messages, err := p.parseMessagesFromEvent(event)
func (p *Provider) GenerateMessages(ctx context.Context, fromHeight, toHeight uint64) ([]*relayertypes.Message, error) {
var messages []*relayertypes.Message

for h := fromHeight; h <= toHeight; h++ {
blockRes, err := p.client.GetBlock(ctx, h)
if err != nil {
return nil, fmt.Errorf("failed to parse messages from event [%+v]: %w", event, err)
return nil, err
}
for _, msg := range messages {
p.log.Info("Detected event log: ",
zap.Uint64("height", msg.MessageHeight),
zap.String("event-type", msg.EventType),
zap.Any("sn", msg.Sn),
zap.Any("req-id", msg.ReqID),
zap.String("src", msg.Src),
zap.String("dst", msg.Dst),
zap.Any("data", hex.EncodeToString(msg.Data)),
)
messages = append(messages, msg)

for _, txn := range blockRes.Transactions {
event := types.SolEvent{
Slot: txn.Slot,
Signature: txn.MustGetTransaction().Signatures[0],
Logs: txn.Meta.LogMessages,
}

msgs, err := p.parseMessagesFromEvent(event)
if err != nil {
return nil, fmt.Errorf("failed to parse messages from event [%+v]: %w", event, err)
}
for _, msg := range msgs {
p.log.Info("Detected event log: ",
zap.Uint64("height", msg.MessageHeight),
zap.String("event-type", msg.EventType),
zap.Any("sn", msg.Sn),
zap.Any("req-id", msg.ReqID),
zap.String("src", msg.Src),
zap.String("dst", msg.Dst),
zap.Any("data", hex.EncodeToString(msg.Data)),
)
messages = append(messages, msgs...)
}
}
}

return messages, nil
}

Expand Down

0 comments on commit 0143904

Please sign in to comment.