CollectStdTxs() must check DelegatorAddr against accounts (#3004)

* CollectStdTxs() must check DelegatorAddr against accounts
* Use sdk.AccAdress.String() instead of casting with string()
This commit is contained in:
Alessio Treglia
2018-12-05 13:23:19 -08:00
committed by Jack Zampolin
parent 6395e2a7ab
commit 816248987f
2 changed files with 19 additions and 9 deletions
+18 -9
View File
@@ -213,8 +213,7 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm
addrMap := make(map[string]GenesisAccount, len(appState.Accounts))
for i := 0; i < len(appState.Accounts); i++ {
acc := appState.Accounts[i]
strAddr := string(acc.Address)
addrMap[strAddr] = acc
addrMap[acc.Address.String()] = acc
}
// addresses and IPs (and port) validator server info
@@ -254,20 +253,30 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm
"each genesis transaction must provide a single genesis message")
}
// validate the validator address and funds against the accounts in the state
msg := msgs[0].(stake.MsgCreateValidator)
addr := string(sdk.AccAddress(msg.ValidatorAddr))
acc, ok := addrMap[addr]
// validate delegator and validator addresses and funds against the accounts in the state
delAddr := msg.DelegatorAddr.String()
valAddr := sdk.AccAddress(msg.ValidatorAddr).String()
if !ok {
delAcc, delOk := addrMap[delAddr]
_, valOk := addrMap[valAddr]
accsNotInGenesis := []string{}
if !delOk {
accsNotInGenesis = append(accsNotInGenesis, delAddr)
}
if !valOk {
accsNotInGenesis = append(accsNotInGenesis, valAddr)
}
if len(accsNotInGenesis) != 0 {
return appGenTxs, persistentPeers, fmt.Errorf(
"account %v not in genesis.json: %+v", addr, addrMap)
"account(s) %v not in genesis.json: %+v", strings.Join(accsNotInGenesis, " "), addrMap)
}
if acc.Coins.AmountOf(msg.Delegation.Denom).LT(msg.Delegation.Amount) {
if delAcc.Coins.AmountOf(msg.Delegation.Denom).LT(msg.Delegation.Amount) {
return appGenTxs, persistentPeers, fmt.Errorf(
"insufficient fund for delegation %v: %v < %v",
acc.Address, acc.Coins.AmountOf(msg.Delegation.Denom), msg.Delegation.Amount,
delAcc.Address, delAcc.Coins.AmountOf(msg.Delegation.Denom), msg.Delegation.Amount,
)
}