2022-02-01 14:49:36 +00:00
|
|
|
import std/macros
|
|
|
|
import pkg/contractabi
|
|
|
|
import ./basics
|
2022-02-02 15:56:37 +00:00
|
|
|
import ./provider
|
2022-02-01 14:49:36 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
Event* = object of RootObj
|
|
|
|
ValueType = uint8 | uint16 | uint32 | uint64 | UInt256 | UInt128 |
|
|
|
|
int8 | int16 | int32 | int64 | Int256 | Int128 |
|
|
|
|
bool | Address
|
2022-03-29 08:26:31 +00:00
|
|
|
SmallByteArray = array[ 1, byte] | array[ 2, byte] | array[ 3, byte] |
|
|
|
|
array[ 4, byte] | array[ 5, byte] | array[ 6, byte] |
|
|
|
|
array[ 7, byte] | array[ 8, byte] | array[ 9, byte] |
|
|
|
|
array[10, byte] | array[11, byte] | array[12, byte] |
|
|
|
|
array[13, byte] | array[14, byte] | array[15, byte] |
|
|
|
|
array[16, byte] | array[17, byte] | array[18, byte] |
|
|
|
|
array[19, byte] | array[20, byte] | array[21, byte] |
|
|
|
|
array[22, byte] | array[23, byte] | array[24, byte] |
|
|
|
|
array[25, byte] | array[26, byte] | array[27, byte] |
|
|
|
|
array[28, byte] | array[29, byte] | array[30, byte] |
|
|
|
|
array[31, byte] | array[32, byte]
|
2022-02-01 14:49:36 +00:00
|
|
|
|
|
|
|
push: {.upraises: [].}
|
|
|
|
|
|
|
|
template indexed* {.pragma.}
|
|
|
|
|
2022-02-02 16:18:09 +00:00
|
|
|
func decode*[E: Event](decoder: var AbiDecoder, _: type E): ?!E =
|
2022-02-01 14:49:36 +00:00
|
|
|
var event: E
|
2022-04-13 08:05:41 +00:00
|
|
|
decoder.startTuple()
|
2022-02-01 14:49:36 +00:00
|
|
|
for field in event.fields:
|
|
|
|
if not field.hasCustomPragma(indexed):
|
|
|
|
field = ?decoder.read(typeof(field))
|
2022-04-13 08:05:41 +00:00
|
|
|
decoder.finishTuple()
|
2022-02-01 14:49:36 +00:00
|
|
|
success event
|
|
|
|
|
|
|
|
func decode*[E: Event](_: type E, data: seq[byte], topics: seq[Topic]): ?!E =
|
|
|
|
var event = ?Abidecoder.decode(data, E)
|
|
|
|
var i = 1
|
|
|
|
for field in event.fields:
|
|
|
|
if field.hasCustomPragma(indexed):
|
|
|
|
if i >= topics.len:
|
|
|
|
return failure "indexed event parameter not found"
|
2022-03-29 08:26:31 +00:00
|
|
|
if typeof(field) is ValueType or typeof(field) is SmallByteArray:
|
2022-02-01 14:49:36 +00:00
|
|
|
field = ?AbiDecoder.decode(@(topics[i]), typeof(field))
|
|
|
|
inc i
|
|
|
|
success event
|