-
Notifications
You must be signed in to change notification settings - Fork 108
/
create-lot.go
66 lines (54 loc) · 1.49 KB
/
create-lot.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
61
62
63
64
65
66
package auction
import (
"fmt"
"github.com/urfave/cli"
"github.com/rocket-pool/smartnode/shared/services/gas"
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
cliutils "github.com/rocket-pool/smartnode/shared/utils/cli"
)
func createLot(c *cli.Context) error {
// Get RP client
rp, err := rocketpool.NewClientFromCtx(c).WithReady()
if err != nil {
return err
}
defer rp.Close()
// Check lot can be created
canCreate, err := rp.CanCreateLot()
if err != nil {
return fmt.Errorf("Error checking if creating lot is possible: %w", err)
}
if !canCreate.CanCreate {
fmt.Println("Cannot create lot:")
if canCreate.InsufficientBalance {
fmt.Println("The auction contract does not have a sufficient RPL balance to create a lot.")
}
if canCreate.CreateLotDisabled {
fmt.Println("Lot creation is currently disabled.")
}
return nil
}
// Assign max fees
err = gas.AssignMaxFeeAndLimit(canCreate.GasInfo, rp, c.Bool("yes"))
if err != nil {
return err
}
// Prompt for confirmation
if !(c.Bool("yes") || cliutils.Confirm("Are you sure you want to create this lot?")) {
fmt.Println("Cancelled.")
return nil
}
// Create lot
response, err := rp.CreateLot()
if err != nil {
return err
}
fmt.Printf("Creating lot...\n")
cliutils.PrintTransactionHash(rp, response.TxHash)
if _, err = rp.WaitForTransaction(response.TxHash); err != nil {
return err
}
// Log & return
fmt.Printf("Successfully created a new lot with ID %d.\n", response.LotId)
return nil
}