@@ -36,6 +36,7 @@ func WithTBTCExtension(
3636 ethereumChain .client ,
3737 ethereumChain .nonceManager ,
3838 ethereumChain .miningWaiter ,
39+ ethereumChain .blockCounter ,
3940 ethereumChain .transactionMutex ,
4041 )
4142 if err != nil {
@@ -52,129 +53,109 @@ func WithTBTCExtension(
5253// on-chain notification of a new deposit creation is seen.
5354func (tec * TBTCEthereumChain ) OnDepositCreated (
5455 handler func (depositAddress string ),
55- ) (subscription.EventSubscription , error ) {
56- return tec .tbtcSystemContract .WatchCreated (
57- func (
58- DepositContractAddress common.Address ,
59- KeepAddress common.Address ,
60- Timestamp * big.Int ,
61- blockNumber uint64 ,
62- ) {
63- handler (DepositContractAddress .Hex ())
64- },
65- func (err error ) error {
66- return fmt .Errorf ("watch deposit created failed: [%v]" , err )
67- },
56+ ) subscription.EventSubscription {
57+ onEvent := func (
58+ DepositContractAddress common.Address ,
59+ KeepAddress common.Address ,
60+ Timestamp * big.Int ,
61+ blockNumber uint64 ,
62+ ) {
63+ handler (DepositContractAddress .Hex ())
64+ }
65+
66+ return tec .tbtcSystemContract .Created (
6867 nil ,
6968 nil ,
70- )
69+ nil ,
70+ ).OnEvent (onEvent )
7171}
7272
7373// OnDepositRegisteredPubkey installs a callback that is invoked when an
7474// on-chain notification of a deposit's pubkey registration is seen.
7575func (tec * TBTCEthereumChain ) OnDepositRegisteredPubkey (
7676 handler func (depositAddress string ),
77- ) (subscription.EventSubscription , error ) {
78- return tec .tbtcSystemContract .WatchRegisteredPubkey (
79- func (
80- DepositContractAddress common.Address ,
81- SigningGroupPubkeyX [32 ]uint8 ,
82- SigningGroupPubkeyY [32 ]uint8 ,
83- Timestamp * big.Int ,
84- blockNumber uint64 ,
85- ) {
86- handler (DepositContractAddress .Hex ())
87- },
88- func (err error ) error {
89- return fmt .Errorf (
90- "watch deposit registered pubkey failed: [%v]" ,
91- err ,
92- )
93- },
94- nil ,
95- )
77+ ) subscription.EventSubscription {
78+ onEvent := func (
79+ DepositContractAddress common.Address ,
80+ SigningGroupPubkeyX [32 ]uint8 ,
81+ SigningGroupPubkeyY [32 ]uint8 ,
82+ Timestamp * big.Int ,
83+ blockNumber uint64 ,
84+ ) {
85+ handler (DepositContractAddress .Hex ())
86+ }
87+
88+ return tec .tbtcSystemContract .RegisteredPubkey (nil , nil ).OnEvent (onEvent )
9689}
9790
9891// OnDepositRedemptionRequested installs a callback that is invoked when an
9992// on-chain notification of a deposit redemption request is seen.
10093func (tec * TBTCEthereumChain ) OnDepositRedemptionRequested (
10194 handler func (depositAddress string ),
102- ) (subscription.EventSubscription , error ) {
103- return tec .tbtcSystemContract .WatchRedemptionRequested (
104- func (
105- DepositContractAddress common.Address ,
106- Requester common.Address ,
107- Digest [32 ]uint8 ,
108- UtxoValue * big.Int ,
109- RedeemerOutputScript []uint8 ,
110- RequestedFee * big.Int ,
111- Outpoint []uint8 ,
112- blockNumber uint64 ,
113- ) {
114- handler (DepositContractAddress .Hex ())
115- },
116- func (err error ) error {
117- return fmt .Errorf (
118- "watch deposit redemption requested failed: [%v]" ,
119- err ,
120- )
121- },
95+ ) subscription.EventSubscription {
96+ onEvent := func (
97+ DepositContractAddress common.Address ,
98+ Requester common.Address ,
99+ Digest [32 ]uint8 ,
100+ UtxoValue * big.Int ,
101+ RedeemerOutputScript []uint8 ,
102+ RequestedFee * big.Int ,
103+ Outpoint []uint8 ,
104+ blockNumber uint64 ,
105+ ) {
106+ handler (DepositContractAddress .Hex ())
107+ }
108+
109+ return tec .tbtcSystemContract .RedemptionRequested (
122110 nil ,
123111 nil ,
124112 nil ,
125- )
113+ nil ,
114+ ).OnEvent (onEvent )
126115}
127116
128117// OnDepositGotRedemptionSignature installs a callback that is invoked when an
129118// on-chain notification of a deposit receiving a redemption signature is seen.
130119func (tec * TBTCEthereumChain ) OnDepositGotRedemptionSignature (
131120 handler func (depositAddress string ),
132- ) (subscription.EventSubscription , error ) {
133- return tec .tbtcSystemContract .WatchGotRedemptionSignature (
134- func (
135- DepositContractAddress common.Address ,
136- Digest [32 ]uint8 ,
137- R [32 ]uint8 ,
138- S [32 ]uint8 ,
139- Timestamp * big.Int ,
140- blockNumber uint64 ,
141- ) {
142- handler (DepositContractAddress .Hex ())
143- },
144- func (err error ) error {
145- return fmt .Errorf (
146- "watch deposit got redemption signature failed: [%v]" ,
147- err ,
148- )
149- },
121+ ) subscription.EventSubscription {
122+ onEvent := func (
123+ DepositContractAddress common.Address ,
124+ Digest [32 ]uint8 ,
125+ R [32 ]uint8 ,
126+ S [32 ]uint8 ,
127+ Timestamp * big.Int ,
128+ blockNumber uint64 ,
129+ ) {
130+ handler (DepositContractAddress .Hex ())
131+ }
132+
133+ return tec .tbtcSystemContract .GotRedemptionSignature (
150134 nil ,
151135 nil ,
152- )
136+ nil ,
137+ ).OnEvent (onEvent )
153138}
154139
155140// OnDepositRedeemed installs a callback that is invoked when an
156141// on-chain notification of a deposit redemption is seen.
157142func (tec * TBTCEthereumChain ) OnDepositRedeemed (
158143 handler func (depositAddress string ),
159- ) (subscription.EventSubscription , error ) {
160- return tec .tbtcSystemContract .WatchRedeemed (
161- func (
162- DepositContractAddress common.Address ,
163- Txid [32 ]uint8 ,
164- Timestamp * big.Int ,
165- blockNumber uint64 ,
166- ) {
167- handler (DepositContractAddress .Hex ())
168- },
169- func (err error ) error {
170- return fmt .Errorf (
171- "watch deposit redeemed failed: [%v]" ,
172- err ,
173- )
174- },
144+ ) subscription.EventSubscription {
145+ onEvent := func (
146+ DepositContractAddress common.Address ,
147+ Txid [32 ]uint8 ,
148+ Timestamp * big.Int ,
149+ blockNumber uint64 ,
150+ ) {
151+ handler (DepositContractAddress .Hex ())
152+ }
153+
154+ return tec .tbtcSystemContract .Redeemed (
175155 nil ,
176156 nil ,
177- )
157+ nil ,
158+ ).OnEvent (onEvent )
178159}
179160
180161// PastDepositRedemptionRequestedEvents returns all redemption requested
@@ -384,6 +365,7 @@ func (tec *TBTCEthereumChain) getDepositContract(
384365 tec .client ,
385366 tec .nonceManager ,
386367 tec .miningWaiter ,
368+ tec .blockCounter ,
387369 tec .transactionMutex ,
388370 )
389371 if err != nil {
0 commit comments