From aa3467ea58a62b45a199b38c82d0844b409bacc2 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Fri, 23 Oct 2020 13:27:01 +0200 Subject: [PATCH 1/3] Add TBTCSystem events filterer Added a `TBTCSystemFilterer` allowing to access past events emitted by the `TBTCSystem` contract. This is a temporary workaround because contract bindings generated by the `keep-common` generator don't support this feature yet. --- .../gen/filterer/TBTCSystemFilterer.go | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go diff --git a/pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go b/pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go new file mode 100644 index 000000000..110cd569c --- /dev/null +++ b/pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go @@ -0,0 +1,79 @@ +package filterer + +import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + abi "github.com/keep-network/tbtc/pkg/chain/ethereum/gen/abi/system" + "math/big" +) + +// FIXME: This is a temporary structure allowing to access past events +// emitted by the `TBTCSystemFilterer` contract. This structure is +// here because the generated contract wrappers from `gen/contract` +// don't support `Filter*` methods yet. When the contract generator +// will support those methods, the below structure can be removed. +type TBTCSystemFilterer struct { + contract *abi.TBTCSystem +} + +func NewTBTCSystemFilterer( + contractAddress common.Address, + backend bind.ContractBackend, +) (*TBTCSystemFilterer, error) { + contract, err := abi.NewTBTCSystem(contractAddress, backend) + if err != nil { + return nil, err + } + + return &TBTCSystemFilterer{contract}, nil +} + +type TBTCSystemRedemptionRequested struct { + DepositContractAddress common.Address + Requester common.Address + Digest [32]byte + UtxoValue *big.Int + RedeemerOutputScript []byte + RequestedFee *big.Int + Outpoint []byte +} + +func (tsf *TBTCSystemFilterer) FilterRedemptionRequested( + depositsAddresses []common.Address, + startBlock uint64, + endBlock *uint64, +) ([]*TBTCSystemRedemptionRequested, error) { + iterator, err := tsf.contract.FilterRedemptionRequested( + &bind.FilterOpts{ + Start: startBlock, + End: endBlock, + }, + depositsAddresses, + nil, + nil, + ) + if err != nil { + return nil, err + } + + events := make([]*TBTCSystemRedemptionRequested, 0) + + for { + if !iterator.Next() { + break + } + + event := iterator.Event + events = append(events, &TBTCSystemRedemptionRequested{ + DepositContractAddress: event.DepositContractAddress, + Requester: event.Requester, + Digest: event.Digest, + UtxoValue: event.UtxoValue, + RedeemerOutputScript: event.RedeemerOutputScript, + RequestedFee: event.RequestedFee, + Outpoint: event.Outpoint, + }) + } + + return events, nil +} From c4c21e8404c5d2bd8cbce1271fcc00e131034150 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Fri, 23 Oct 2020 14:11:53 +0200 Subject: [PATCH 2/3] Add block number to redemption requested event binding --- pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go b/pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go index 110cd569c..b33b224fe 100644 --- a/pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go +++ b/pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go @@ -36,6 +36,7 @@ type TBTCSystemRedemptionRequested struct { RedeemerOutputScript []byte RequestedFee *big.Int Outpoint []byte + BlockNumber uint64 } func (tsf *TBTCSystemFilterer) FilterRedemptionRequested( @@ -72,6 +73,7 @@ func (tsf *TBTCSystemFilterer) FilterRedemptionRequested( RedeemerOutputScript: event.RedeemerOutputScript, RequestedFee: event.RequestedFee, Outpoint: event.Outpoint, + BlockNumber: event.Raw.BlockNumber, }) } From cb9246987718ca9385ef673a3e70f1e0e4ec35f3 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Mon, 26 Oct 2020 10:35:13 +0100 Subject: [PATCH 3/3] Switch naming from `filterer` to `event log` --- .../TBTCSystemEventLog.go} | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) rename pkg/chain/ethereum/gen/{filterer/TBTCSystemFilterer.go => eventlog/TBTCSystemEventLog.go} (75%) diff --git a/pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go b/pkg/chain/ethereum/gen/eventlog/TBTCSystemEventLog.go similarity index 75% rename from pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go rename to pkg/chain/ethereum/gen/eventlog/TBTCSystemEventLog.go index b33b224fe..684856b10 100644 --- a/pkg/chain/ethereum/gen/filterer/TBTCSystemFilterer.go +++ b/pkg/chain/ethereum/gen/eventlog/TBTCSystemEventLog.go @@ -1,4 +1,4 @@ -package filterer +package eventlog import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -8,24 +8,24 @@ import ( ) // FIXME: This is a temporary structure allowing to access past events -// emitted by the `TBTCSystemFilterer` contract. This structure is -// here because the generated contract wrappers from `gen/contract` -// don't support `Filter*` methods yet. When the contract generator -// will support those methods, the below structure can be removed. -type TBTCSystemFilterer struct { +// emitted by the `TBTCSystem` contract. This structure is here because +// the generated contract wrappers from `gen/contract` don't support +// `Filter*` methods yet. When the contract generator will support +// those methods, the below structure can be removed. +type TBTCSystemEventLog struct { contract *abi.TBTCSystem } -func NewTBTCSystemFilterer( +func NewTBTCSystemEventLog( contractAddress common.Address, backend bind.ContractBackend, -) (*TBTCSystemFilterer, error) { +) (*TBTCSystemEventLog, error) { contract, err := abi.NewTBTCSystem(contractAddress, backend) if err != nil { return nil, err } - return &TBTCSystemFilterer{contract}, nil + return &TBTCSystemEventLog{contract}, nil } type TBTCSystemRedemptionRequested struct { @@ -39,12 +39,12 @@ type TBTCSystemRedemptionRequested struct { BlockNumber uint64 } -func (tsf *TBTCSystemFilterer) FilterRedemptionRequested( +func (tsel *TBTCSystemEventLog) PastRedemptionRequestedEvents( depositsAddresses []common.Address, startBlock uint64, endBlock *uint64, ) ([]*TBTCSystemRedemptionRequested, error) { - iterator, err := tsf.contract.FilterRedemptionRequested( + iterator, err := tsel.contract.FilterRedemptionRequested( &bind.FilterOpts{ Start: startBlock, End: endBlock,