1515package bindings
1616
1717import (
18+ "fmt"
1819 "strings"
1920
2021 "github.com/ethereum/go-ethereum/accounts/abi"
@@ -27,37 +28,69 @@ import (
2728 "perun.network/go-perun/backend/ethereum/bindings/trivialapp"
2829)
2930
30- // This file contains all the parsed ABI definitions of our contracts.
31+ // ABI contains all the parsed ABI definitions of our contracts.
3132// Use it together with `bind.NewBoundContract` to create a bound contract.
33+ var ABI = struct {
34+ // ERC20Token is the parsed ABI definition of contract ERC20Token.
35+ ERC20Token abi.ABI
36+ // Adjudicator is the parsed ABI definition of contract Adjudicator.
37+ Adjudicator abi.ABI
38+ // AssetHolder is the parsed ABI definition of contract AssetHolder.
39+ AssetHolder abi.ABI
40+ // ETHAssetHolder is the parsed ABI definition of contract ETHAssetHolder.
41+ ETHAssetHolder abi.ABI
42+ // ERC20AssetHolder is the parsed ABI definition of contract ERC20AssetHolder.
43+ ERC20AssetHolder abi.ABI
44+ // TrivialApp is the parsed ABI definition of contract TrivialApp.
45+ TrivialApp abi.ABI
46+ }{}
3247
33- var (
34- // ERC20TokenABI is the parsed ABI definition of contract ERC20Token.
35- ERC20TokenABI abi.ABI
36- // AdjudicatorABI is the parsed ABI definition of contract Adjudicator.
37- AdjudicatorABI abi.ABI
38- // AssetHolderABI is the parsed ABI definition of contract AssetHolder.
39- AssetHolderABI abi.ABI
40- // ETHAssetHolderABI is the parsed ABI definition of contract ETHAssetHolder.
41- ETHAssetHolderABI abi.ABI
42- // ERC20AssetHolderABI is the parsed ABI definition of contract ERC20AssetHolder.
43- ERC20AssetHolderABI abi.ABI
44- // TrivialAppABI is the parsed ABI definition of contract TrivialApp.
45- TrivialAppABI abi.ABI
46- )
48+ // Events contains the event names for specific events.
49+ var Events = struct {
50+ // AdjChannelUpdate is the ChannelUpdate event of the Adjudicator contract.
51+ AdjChannelUpdate string
52+ // AhDeposited is the Deposited event of the Assetholder contract.
53+ AhDeposited string
54+ // AhWithdrawn is the Withdrawn event of the Assetholder contract.
55+ AhWithdrawn string
56+ // ERC20Approval is the Approval event of the ERC20Token contract.
57+ ERC20Approval string
58+ }{}
4759
4860func init () {
49- parseABI := func (raw string ) abi.ABI {
61+ parseABIs ()
62+ extractEvents ()
63+ }
64+
65+ func parseABIs () {
66+ parse := func (raw string ) abi.ABI {
5067 abi , err := abi .JSON (strings .NewReader (raw ))
5168 if err != nil {
5269 panic (err )
5370 }
5471 return abi
5572 }
5673
57- ERC20TokenABI = parseABI (peruntoken .ERC20ABI )
58- AdjudicatorABI = parseABI (adjudicator .AdjudicatorABI )
59- AssetHolderABI = parseABI (assetholder .AssetHolderABI )
60- ETHAssetHolderABI = parseABI (assetholdereth .AssetHolderETHABI )
61- ERC20AssetHolderABI = parseABI (assetholdererc20 .AssetHolderERC20ABI )
62- TrivialAppABI = parseABI (trivialapp .TrivialAppABI )
74+ ABI .ERC20Token = parse (peruntoken .ERC20ABI )
75+ ABI .Adjudicator = parse (adjudicator .AdjudicatorABI )
76+ ABI .AssetHolder = parse (assetholder .AssetHolderABI )
77+ ABI .ETHAssetHolder = parse (assetholdereth .AssetHolderETHABI )
78+ ABI .ERC20AssetHolder = parse (assetholdererc20 .AssetHolderERC20ABI )
79+ ABI .TrivialApp = parse (trivialapp .TrivialAppABI )
80+ }
81+
82+ // extractEvents sets the event names and panics if any event does not exist.
83+ func extractEvents () {
84+ extract := func (abi abi.ABI , eName string ) string {
85+ e , ok := abi .Events [eName ]
86+ if ! ok {
87+ panic (fmt .Sprintf ("Event '%s' not found." , eName ))
88+ }
89+ return e .Name
90+ }
91+
92+ Events .AdjChannelUpdate = extract (ABI .Adjudicator , "ChannelUpdate" )
93+ Events .AhDeposited = extract (ABI .AssetHolder , "Deposited" )
94+ Events .AhWithdrawn = extract (ABI .AssetHolder , "Withdrawn" )
95+ Events .ERC20Approval = extract (ABI .ERC20Token , "Approval" )
6396}
0 commit comments