-
Notifications
You must be signed in to change notification settings - Fork 7
/
genesis.go
52 lines (43 loc) · 1.11 KB
/
genesis.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
package app
import (
sdk "bitbucket.org/shareringvn/cosmos-sdk/types"
"github.com/sharering/shareledger/types"
"github.com/sharering/shareledger/x/auth"
"github.com/sharering/shareledger/x/pos"
)
// State to Unmarshal
type GenesisState struct {
Accounts []GenesisAccount `json:"accounts"`
StakeData pos.GenesisState `json:"stake"`
}
func (gs *GenesisState) ToJSON() []byte {
cdc := MakeCodec()
jsonBytes, err := cdc.MarshalJSONIndent(gs, "", " ")
if err != nil {
panic(err)
}
return jsonBytes
}
// GenesisAccount doesn't need pubkey or sequence
type GenesisAccount struct {
Address sdk.Address `json:"address"`
Coins types.Coins `json:"coins"`
}
func NewGenesisAccount(acc *auth.SHRAccount) GenesisAccount {
return GenesisAccount{
Address: acc.Address,
Coins: acc.Coins,
}
}
// convert GenesisAccount to auth.BaseAccount
func (ga *GenesisAccount) ToSHRAccount() (acc *auth.SHRAccount) {
return &auth.SHRAccount{
Address: ga.Address,
Coins: ga.Coins,
}
}
func GenerateGenesisState(pubKey types.PubKeySecp256k1) GenesisState {
return GenesisState{
StakeData: pos.GenerateGenesis(pubKey),
}
}