Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Add TBTCSystem event log #740

Merged
merged 4 commits into from
Nov 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions pkg/chain/ethereum/gen/eventlog/TBTCSystemEventLog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package eventlog

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 `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 NewTBTCSystemEventLog(
contractAddress common.Address,
backend bind.ContractBackend,
) (*TBTCSystemEventLog, error) {
contract, err := abi.NewTBTCSystem(contractAddress, backend)
if err != nil {
return nil, err
}

return &TBTCSystemEventLog{contract}, nil
}

type TBTCSystemRedemptionRequested struct {
DepositContractAddress common.Address
Requester common.Address
Digest [32]byte
UtxoValue *big.Int
RedeemerOutputScript []byte
RequestedFee *big.Int
Outpoint []byte
BlockNumber uint64
}

func (tsel *TBTCSystemEventLog) PastRedemptionRequestedEvents(
depositsAddresses []common.Address,
startBlock uint64,
endBlock *uint64,
) ([]*TBTCSystemRedemptionRequested, error) {
iterator, err := tsel.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,
BlockNumber: event.Raw.BlockNumber,
})
}

return events, nil
}