-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add chain_reader.go with ChainReader type defs, add ChainReader() to …
…PluginProvider
- Loading branch information
1 parent
215fd09
commit 3391610
Showing
2 changed files
with
67 additions
and
0 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
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 | ||
} |
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