/
init.go
97 lines (88 loc) · 2.32 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package app
import (
"encoding/json"
"fmt"
"path/filepath"
"github.com/iov-one/weave"
"github.com/iov-one/weave/app"
"github.com/iov-one/weave/coin"
"github.com/iov-one/weave/commands/server"
"github.com/iov-one/weave/crypto"
"github.com/iov-one/weave/gconf"
"github.com/iov-one/weave/x/cash"
abci "github.com/tendermint/tendermint/abci/types"
)
// GenInitOptions will produce some basic options for one rich
// account, to use for dev mode
//
// You can set
func GenInitOptions(args []string) (json.RawMessage, error) {
code := "MYC"
if len(args) > 0 {
code = args[0]
}
var addr string
if len(args) > 1 {
addr = args[1]
} else {
// if no address provided, auto-generate one
// and print out a recovery phrase
bz, phrase, err := GenerateCoinKey()
if err != nil {
return nil, err
}
addr = bz.String()
fmt.Println(phrase)
}
type (
dict map[string]interface{}
array []interface{}
)
return json.Marshal(dict{
"cash": array{
dict{
"address": addr,
"coins": array{
dict{
"whole": 123456789,
"ticker": code,
},
},
},
},
"gconf": dict{
cash.GconfCollectorAddress: "66616b652d636f6c6c6563746f722d61646472657373",
cash.GconfMinimalFee: coin.Coin{Whole: 0}, // no fee
},
})
}
// GenerateApp is used to create a stub for server/start.go command
func GenerateApp(options *server.Options) (abci.Application, error) {
// db goes in a subdir, but "" -> "" for memdb
var dbPath string
if options.Home != "" {
dbPath = filepath.Join(options.Home, "abci.db")
}
stack := Stack(options.MinFee)
application, err := Application("mycoin", stack, TxDecoder, dbPath, options.Debug)
if err != nil {
return nil, err
}
application.WithInit(app.ChainInitializers(
&gconf.Initializer{},
&cash.Initializer{},
))
// set the logger and return
application.WithLogger(options.Logger)
return application, nil
}
// GenerateCoinKey returns the address of a public key,
// along with the secret phrase to recover the private key.
// You can give coins to this address and return the recovery
// phrase to the user to access them.
func GenerateCoinKey() (weave.Address, string, error) {
// XXX: we need to generate BIP39 recovery phrases in crypto
privKey := crypto.GenPrivKeyEd25519()
addr := privKey.PublicKey().Address()
return addr, "TODO: add a recovery phrase", nil
}