Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parachain Relayer V2 #1321

Open
wants to merge 23 commits into
base: vincent/v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions relayer/relays/parachain/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ func (s *Scanner) findTasks(
var pendingOrders []PendingOrder
for _, key := range keys {
var pendingOrder PendingOrder
ok, err := s.paraConn.API().RPC.State.GetStorage(key, &pendingOrder, paraHash)
value, err := s.paraConn.API().RPC.State.GetStorageRaw(key, paraHash)
if err != nil {
return nil, fmt.Errorf("fetch value of pendingOrder with key '%v' and hash '%v': %w", key, paraHash, err)
}
if ok {
pendingOrders = append(pendingOrders, pendingOrder)
decoder := scale.NewDecoder(bytes.NewReader(*value))
err = decoder.Decode(&pendingOrder)
if err != nil {
return nil, fmt.Errorf("decode order error: %w", err)
}
pendingOrders = append(pendingOrders, pendingOrder)
}

tasks, err := s.findTasksImpl(
Expand Down
28 changes: 25 additions & 3 deletions relayer/relays/parachain/types_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package parachain
import (
"math/big"

"github.com/snowfork/go-substrate-rpc-client/v4/scale"
"github.com/snowfork/go-substrate-rpc-client/v4/types"
"github.com/snowfork/snowbridge/relayer/contracts"
)
Expand Down Expand Up @@ -58,7 +59,28 @@ type MessageProofV2 struct {
}

type PendingOrder struct {
Nonce types.U64
BlockNumber types.U32
Fee types.U128
Nonce uint64
BlockNumber uint32
Fee big.Int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use types.UCompact then you won't need to write a custom decoder.

}

func (p *PendingOrder) Decode(decoder scale.Decoder) error {
var nonce types.U64
err := decoder.Decode(&nonce)
if err != nil {
return err
}
p.Nonce = uint64(nonce)
var blockNumber types.U32
err = decoder.Decode(&blockNumber)
if err != nil {
return err
}
p.BlockNumber = uint32(blockNumber)
decoded, err := decoder.DecodeUintCompact()
if err != nil {
return err
}
p.Fee = *types.U128{Int: decoded}.Int
return nil
}
Loading