-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
80 lines (65 loc) · 1.77 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/joho/godotenv"
wallet2 "optijack/jackal/wallet"
"optijack/server"
"github.com/desmos-labs/cosmos-go-wallet/types"
"github.com/desmos-labs/cosmos-go-wallet/wallet"
_ "modernc.org/sqlite"
storageTypes "github.com/jackalLabs/canine-chain/v3/x/storage/types"
)
func buyStorage(w *wallet.Wallet) {
buyStorageMsg := storageTypes.NewMsgBuyStorage(w.AccAddress(), w.AccAddress(), 60, 3_000_000_000, "ujkl")
data := types.NewTransactionData(
buyStorageMsg,
).WithGasAuto().WithFeeAuto()
res, err := w.BroadcastTxCommit(data)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(res.RawLog)
}
func checkAndBuyStorage(w *wallet.Wallet) {
cl := storageTypes.NewQueryClient(w.Client.GRPCConn)
res, err := cl.StoragePaymentInfo(context.Background(), &storageTypes.QueryStoragePaymentInfo{Address: w.AccAddress()})
if err != nil {
buyStorage(w)
return
}
if res.StoragePaymentInfo.End.Before(time.Now().AddDate(0, 0, 5)) {
buyStorage(w)
return
}
}
func main() {
if err := godotenv.Load(); err != nil {
fmt.Printf("Failed to load the env vars: %v\n", err)
}
seed := os.Getenv("JACKAL_SEED")
w, err := wallet2.CreateWallet(seed, "m/44'/118'/0'/0/0", types.ChainConfig{
Bech32Prefix: "jkl",
RPCAddr: os.Getenv("JACKAL_RPC"),
GRPCAddr: os.Getenv("JACKAL_GRPC"),
GasPrice: "0.02ujkl",
GasAdjustment: 1.5,
})
if err != nil {
fmt.Println("failed to create wallet")
panic(err)
}
fmt.Printf("Starting rollup server for %s...\n", w.AccAddress())
checkAndBuyStorage(w)
js := server.NewJackalStore(w)
da := server.NewDAServer("0.0.0.0", 3100, js, true)
err = da.Start()
if err != nil {
fmt.Println("failed to start server")
panic(err)
}
fmt.Println("closing server...")
}