Skip to content

Commit

Permalink
Add chain_reader.go with ChainReader type defs, add ChainReader() to …
Browse files Browse the repository at this point in the history
…PluginProvider
  • Loading branch information
reductionista committed Oct 12, 2023
1 parent 215fd09 commit 3391610
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
66 changes: 66 additions & 0 deletions pkg/types/chain_reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package types

import (
"math/big"
"time"
)

type BigInt big.Int
type String string

// Union of BigInt & String
type BlockID interface {
bi() *BigInt
s() String
}

func (b *BigInt) bi() *BigInt {
return b
}

func (b String) s() String {
return b
}

type ChainReader interface {
RegisterEventFilter(filterName string, filter EventFilter, startingBlock BlockID) (string, error)
UnregisterEventFilter(filterName string) error
QueryEvents(query EventQuery) ([]Event, error)
// The params argument of GetLatestValue() can be any object which maps a set of generic parameters into chain specific parameters defined in RelayConfig. It must be something which can be passed into
// json.Marshal(). Typically would be either an anonymous map such as `map[string]any{"baz": 42, "test": true}}` or something which implements the `MarshalJSON()` method (satisfying `Marshaller` interface).
//
// returnVal should satisfy Marshaller interface.
GetLatestValue(bc BoundContract, method string, params, returnVal any) error
}

type BoundContract struct {
Address string
Name string
Pending bool
}

type Event struct {
ChainId string
EventIndexInBlock string
Address string
TxHash string
BlockHash string
BlockNumber int64
BlockTimestamp time.Time
CreatedAt time.Time
Keys []string
Data []byte
}

type EventFilter struct {
AddressList []string // contract address
KeysList [][]string // 2D list of indexed search keys, outer dim = AND, inner dim = OR. Params[0] is the name of the event (or "event type"), rest are any narrowing parameters that may help further specify the event
Retention time.Duration
}

type EventQuery struct {
FromBlock BlockID
ToBlock BlockID
Filter EventFilter
Pending bool
}
1 change: 1 addition & 0 deletions pkg/types/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ type Plugin = PluginProvider
type PluginProvider interface {
ConfigProvider
ContractTransmitter() ocrtypes.ContractTransmitter
ChainReader() ChainReader
}

0 comments on commit 3391610

Please sign in to comment.