-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (50 loc) · 1.52 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
package main
import (
"fmt"
"sync"
"time"
"github.com/ComputerKeeda/junctionAPI/admin"
"github.com/ComputerKeeda/junctionAPI/api"
"github.com/ComputerKeeda/junctionAPI/chain"
"github.com/ComputerKeeda/junctionAPI/config"
)
func main() {
// connect to junction && create admin wallet if do not exists
client, account, addr, ctx, sAPI := config.JunctionConnection()
// connect to levelDB
dbIPaddress := config.LevelDB()
// check admin balance
isBalance, amount, err := chain.CheckBalance(ctx, addr, client)
if err != nil {
fmt.Println("Error in checking balance", err)
return
}
// call faucet (if balance is 0)
if amount < 3 || !isBalance {
fmt.Println("admin currently don't have faucet, requesting faucet from this address:", addr)
// calling faucet api
err = admin.RequestFaucet(addr)
if err != nil {
fmt.Println("Error in calling faucet api", err)
return
}
fmt.Println("Faucet request successful!")
// check admin balance
_, amount, err := chain.CheckBalance(ctx, addr, client)
if err != nil {
fmt.Println("Error in checking balance", err)
return
}
fmt.Println("Admin have", amount, "tokens \nstarting api...")
// await 2 seconds
time.Sleep(2 * time.Second)
}
var wg sync.WaitGroup
wg.Add(2)
go api.StartAPI(&wg, client, ctx, account, addr, dbIPaddress, sAPI)
go admin.AdminBalanceCheckerTimer(&wg, ctx, client, account, addr, dbIPaddress)
// Wait for both functions to finish
wg.Wait()
// wg Crashed. send report to admin
fmt.Println("wg Crashed: faucet api stopped")
}