Skip to content

Commit

Permalink
refactor genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-lashin committed Sep 8, 2018
1 parent 0495e9e commit 30f69b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions cmd/minter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ func startTendermintNode(app *minter.Blockchain) *tmNode.Node {
)

if err != nil {
println(fmt.Errorf("Failed to create a node: %v", err))
log.Error(fmt.Sprintf("Failed to create a node: %v", err))
os.Exit(1)
}

if err = node.Start(); err != nil {
println(fmt.Errorf("Failed to start node: %v", err))
log.Error(fmt.Sprintf("Failed to start node: %v", err))
os.Exit(1)
}

Expand Down
6 changes: 3 additions & 3 deletions core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (app *Blockchain) InitChain(req abciTypes.RequestInitChain) abciTypes.Respo
}

for _, validator := range req.Validators {
app.stateDeliver.CreateCandidate(genesisState.FirstValidatorAddress, validator.PubKey.Data, 10, 1, types.GetBaseCoin(), helpers.BipToPip(big.NewInt(1000000)))
app.stateDeliver.CreateValidator(genesisState.FirstValidatorAddress, validator.PubKey.Data, 10, 1, types.GetBaseCoin(), helpers.BipToPip(big.NewInt(1000000)))
app.stateDeliver.CreateCandidate(genesisState.FirstValidatorAddress, validator.PubKey.Data, 100, 1, types.GetBaseCoin(), helpers.BipToPip(big.NewInt(1000000)))
app.stateDeliver.CreateValidator(genesisState.FirstValidatorAddress, validator.PubKey.Data, 100, 1, types.GetBaseCoin(), helpers.BipToPip(big.NewInt(1000000)))
app.stateDeliver.SetCandidateOnline(validator.PubKey.Data)
app.activeValidators = append(app.activeValidators, validator)
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func (app *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.Respons

// calculate total power
totalPower := big.NewInt(0)
for _, candidate := range newCandidates[:valsCount] {
for _, candidate := range newCandidates {
totalPower.Add(totalPower, candidate.TotalBipStake)
}

Expand Down
30 changes: 15 additions & 15 deletions genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ var (

func GetTestnetGenesis() (*tmtypes.GenesisDoc, error) {

validatorPubKeyBytes, err := base64.StdEncoding.DecodeString("SuHuc+YTbIWwypM6mhNHdYozSIXxCzI4OYpnrC6xU7g=")

if err != nil {
return nil, err
validatorsPubKeys := []string{"7tc5AFPB+1XJ2Rs63OeDQZgF9k9MY+nZ+sp99dZP2dA="}
validators := make([]tmtypes.GenesisValidator, len(validatorsPubKeys))

for i, val := range validatorsPubKeys {
validatorPubKeyBytes, _ := base64.StdEncoding.DecodeString(val)
var validatorPubKey ed25519.PubKeyEd25519
copy(validatorPubKey[:], validatorPubKeyBytes)

validators[i] = tmtypes.GenesisValidator{
PubKey: validatorPubKey,
Power: 10,
}
}

var validatorPubKey ed25519.PubKeyEd25519
copy(validatorPubKey[:], validatorPubKeyBytes)

appHash, err := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000000")

if err != nil {
Expand Down Expand Up @@ -62,14 +67,9 @@ func GetTestnetGenesis() (*tmtypes.GenesisDoc, error) {
ChainID: Network,
GenesisTime: time.Date(2018, 8, 22, 0, 0, 0, 0, time.UTC),
ConsensusParams: nil,
Validators: []tmtypes.GenesisValidator{
{
PubKey: validatorPubKey,
Power: 100000000,
},
},
AppHash: common.HexBytes(appHash),
AppState: json.RawMessage([]byte(appStateJSON)),
Validators: validators,
AppHash: common.HexBytes(appHash),
AppState: json.RawMessage([]byte(appStateJSON)),
}

err = genesis.ValidateAndComplete()
Expand Down

0 comments on commit 30f69b7

Please sign in to comment.