forked from fioprotocol/fiostore
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.go
49 lines (41 loc) · 1 KB
/
init.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
package fiostore
import (
"github.com/fioprotocol/fio-go"
"log"
"os"
"strings"
)
var (
// the following are set via environment variables.
privkey string // PRIV_KEY
nodeos string // NODEOS
sender string // FIO_ADDRESS
tokens []string // TOKENS (comma separated list)
xff bool // TRUST_XFF
account *fio.Account
api *fio.API
opts *fio.TxOptions
)
func init() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
var err error
privkey = os.Getenv("PRIV_KEY")
nodeos = os.Getenv("NODEOS")
sender = os.Getenv("FIO_ADDRESS")
t := strings.ReplaceAll(os.Getenv("TOKENS"), " ", "")
switch "" {
case privkey, nodeos, sender, t:
log.Fatal("Please set the PRIV_KEY, NODEOS, TOKENS, and FIO_ADDRESS environment variables.")
}
if os.Getenv("TRUST_XFF") != "" {
xff = true
}
tokens = strings.Split(t, ",")
if len(tokens) == 0 || tokens[0] == "" {
log.Fatal("No tokens specified")
}
account, api, opts, err = fio.NewWifConnect(privkey, nodeos)
if err != nil {
log.Fatal(err)
}
}