-
Notifications
You must be signed in to change notification settings - Fork 3
/
wait.go
60 lines (50 loc) · 1.39 KB
/
wait.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
package tx
import (
"errors"
"fmt"
"net/url"
_ "time/tzdata"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/gorilla/mux"
"github.com/nodeset-org/hyperdrive/daemon-utils/server"
"github.com/nodeset-org/hyperdrive/hyperdrive-daemon/server/utils"
"github.com/nodeset-org/hyperdrive/shared/types/api"
"github.com/nodeset-org/hyperdrive/shared/utils/input"
)
// ===============
// === Factory ===
// ===============
type txWaitContextFactory struct {
handler *TxHandler
}
func (f *txWaitContextFactory) Create(args url.Values) (*txWaitContext, error) {
c := &txWaitContext{
handler: f.handler,
}
inputErrs := []error{
server.ValidateArg("hash", args, input.ValidateHash, &c.hash),
}
return c, errors.Join(inputErrs...)
}
func (f *txWaitContextFactory) RegisterRoute(router *mux.Router) {
utils.RegisterQuerylessGet[*txWaitContext, api.SuccessData](
router, "wait", f, f.handler.serviceProvider,
)
}
// ===============
// === Context ===
// ===============
type txWaitContext struct {
handler *TxHandler
hash common.Hash
}
func (c *txWaitContext) PrepareData(data *api.SuccessData, opts *bind.TransactOpts) error {
sp := c.handler.serviceProvider
txMgr := sp.GetTransactionManager()
err := txMgr.WaitForTransactionByHash(c.hash)
if err != nil {
return fmt.Errorf("error waiting for tx %s: %w", c.hash.Hex(), err)
}
return nil
}