-
Notifications
You must be signed in to change notification settings - Fork 0
/
EthereumTxEvent.go
65 lines (57 loc) · 1.31 KB
/
EthereumTxEvent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package watcher
import (
"errors"
"github.com/itsabgr/go-handy"
"gopkg.in/yaml.v3"
"math/big"
"time"
)
type EthereumTxEvent interface {
Event
WithTx
}
type ethereumTxEvent struct {
tx EthereumTx
time time.Time
block *big.Int
}
func (n *ethereumTxEvent) MarshalYAML() []byte {
b, err := yaml.Marshal(struct {
To, From, Tx []byte
Event, Net string
Timestamp, Amount, Gas, GasPrice, GasFeeCap, GasTipCap, Block uint64
}{
Event: n.Kind(),
Tx: n.tx.ID(),
Net: n.Net(),
Block: n.block.Uint64(),
Timestamp: uint64(n.time.Unix()),
To: n.tx.Receiver(),
From: n.tx.Receiver(),
Amount: n.tx.Amount().Uint64(),
Gas: n.tx.Gas().Uint64(),
GasPrice: n.tx.GasPrice().Uint64(),
GasFeeCap: n.tx.GasFeeCap().Uint64(),
GasTipCap: n.tx.GasTipCap().Uint64(),
})
handy.Throw(err)
return b
}
func (n *ethereumTxEvent) Tx() Tx {
return n.tx
}
func (n *ethereumTxEvent) Net() string {
return "ethereum"
}
func (n *ethereumTxEvent) Kind() string {
return "transaction"
}
func NewEthereumTxEvent(tx EthereumTx) (EthereumTxEvent, error) {
if tx == nil {
panic(errors.New("nil tx ptr"))
}
o := ðereumTxEvent{}
o.tx = tx
o.time = time.Now()
return o, nil
}