blob: 5ffb86fd74542defa6f18e72735f36a80ec992a8 (
plain)
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
|
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.
package main
import (
"encoding/json"
"io"
"net/url"
"os"
"strings"
)
type config struct {
// AccountMnemonic is the mnemonic of the account from which we would like to spend Algos.
AccountMnemonic string
// AccountMnemonicList, if provided, is a series of mnemonics for accounts from which to spend Algos.
AccountMnemonicList []string
// ClientURL is the url ( such as http://127.0.0.1:8080 ) that would be used to communicate with a node REST endpoint
ClientURL *url.URL `json:"-"`
// APIToken is the API token used to communicate with the node.
APIToken string
// RoundModulator is the modulator used to determine of the current round is the round at which transactions need to be sent.
RoundModulator uint64
// RoundOffset is the offset used to determine of the current round is the round at which transactions need to be sent.
RoundOffset uint64
// Fee is the amount of algos that would be specified in the transaction fee field.
Fee uint64
// TxnsToSend is the number of transactions to send in the round where (((round + RoundOffset) % RoundModulator) == 0)
TxnsToSend int
}
type fileConfig struct {
config
ClientURL string `json:"ClientURL"`
}
func loadConfig(configFileName string) (cfg config, err error) {
var fin io.Reader
if len(configFileName) > 0 && configFileName[0] == '{' {
// read -config "{json literal}"
fin = strings.NewReader(configFileName)
} else {
var fd *os.File
fd, err = os.Open(configFileName)
if err != nil {
return config{}, err
}
defer fd.Close()
fin = fd
}
jsonDecoder := json.NewDecoder(fin)
var fileCfg fileConfig
err = jsonDecoder.Decode(&fileCfg)
if err == nil {
cfg = fileCfg.config
cfg.ClientURL, err = url.Parse(fileCfg.ClientURL)
}
return
}
|