Commit, and working on InitState/SetOpetion
This commit is contained in:
parent
d681049023
commit
1ec9e2e0ae
17
app/base.go
17
app/base.go
|
@ -224,22 +224,11 @@ func (app *BaseApp) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQue
|
||||||
|
|
||||||
// Commit implements abci.Application
|
// Commit implements abci.Application
|
||||||
func (app *BaseApp) Commit() (res abci.Result) {
|
func (app *BaseApp) Commit() (res abci.Result) {
|
||||||
/*
|
commitID := app.store.Commit()
|
||||||
hash, err := app.state.Commit(app.height)
|
|
||||||
if err != nil {
|
|
||||||
// die if we can't commit, not to recover
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
app.logger.Debug("Commit synced",
|
app.logger.Debug("Commit synced",
|
||||||
"height", app.height,
|
"commit", commitID,
|
||||||
"hash", fmt.Sprintf("%X", hash),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if app.state.Size() == 0 {
|
|
||||||
return abci.NewResultOK(nil, "Empty hash for empty tree")
|
|
||||||
}
|
|
||||||
return abci.NewResultOK(hash, "")
|
return abci.NewResultOK(hash, "")
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitChain - ABCI
|
// InitChain - ABCI
|
||||||
|
@ -253,7 +242,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) {
|
||||||
// EndBlock - ABCI
|
// EndBlock - ABCI
|
||||||
// Returns a list of all validator changes made in this block
|
// Returns a list of all validator changes made in this block
|
||||||
func (app *BaseApp) EndBlock(height uint64) (res abci.ResponseEndBlock) {
|
func (app *BaseApp) EndBlock(height uint64) (res abci.ResponseEndBlock) {
|
||||||
// TODO: Compress duplicates
|
// XXX Update to res.Updates.
|
||||||
res.Diffs = app.valSetDiff
|
res.Diffs = app.valSetDiff
|
||||||
app.valSetDiff = nil
|
app.valSetDiff = nil
|
||||||
return
|
return
|
||||||
|
|
10
app/doc.go
10
app/doc.go
|
@ -1,9 +1,11 @@
|
||||||
/*
|
/*
|
||||||
Package app contains data structures that provide basic data storage
|
Package app contains data structures that provide basic data storage
|
||||||
functionality and act as a bridge between the ABCI interface and the internal
|
functionality and act as a bridge between the ABCI interface and the SDK
|
||||||
SDK representations.
|
abstractions.
|
||||||
|
|
||||||
BaseApp has no state except the MultiStore you provide upon init. You must
|
BaseApp has no state except the CommitMultiStore you provide upon init. You must
|
||||||
also provide a Handler and a TxParser.
|
also provide a Handler.
|
||||||
|
|
||||||
|
Transaction parsing is typically handled by the first Decorator.
|
||||||
*/
|
*/
|
||||||
package app
|
package app
|
||||||
|
|
65
app/init.go
65
app/init.go
|
@ -1,65 +0,0 @@
|
||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk"
|
|
||||||
)
|
|
||||||
|
|
||||||
// InitApp - The ABCI application with initialization hooks
|
|
||||||
type InitApp struct {
|
|
||||||
*BaseApp
|
|
||||||
initState sdk.InitStater
|
|
||||||
initVals sdk.InitValidator
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ abci.Application = &InitApp{}
|
|
||||||
|
|
||||||
// NewInitApp extends a BaseApp with initialization callbacks,
|
|
||||||
// which it binds to the proper abci calls
|
|
||||||
func NewInitApp(base *BaseApp, initState sdk.InitStater,
|
|
||||||
initVals sdk.InitValidator) *InitApp {
|
|
||||||
|
|
||||||
return &InitApp{
|
|
||||||
BaseApp: base,
|
|
||||||
initState: initState,
|
|
||||||
initVals: initVals,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// InitState - used to setup state (was SetOption)
|
|
||||||
// to be call from setting up the genesis file
|
|
||||||
func (app *InitApp) InitState(module, key, value string) error {
|
|
||||||
state := app.Append()
|
|
||||||
logger := app.Logger().With("module", module, "key", key)
|
|
||||||
|
|
||||||
if module == sdk.ModuleNameBase {
|
|
||||||
if key == sdk.ChainKey {
|
|
||||||
app.info.SetChainID(state, value)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
logger.Error("Invalid genesis option")
|
|
||||||
return fmt.Errorf("Unknown base option: %s", key)
|
|
||||||
}
|
|
||||||
|
|
||||||
log, err := app.initState.InitState(logger, state, module, key, value)
|
|
||||||
if err != nil {
|
|
||||||
logger.Error("Invalid genesis option", "err", err)
|
|
||||||
} else {
|
|
||||||
logger.Info(log)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// InitChain - ABCI - sets the initial validators
|
|
||||||
func (app *InitApp) InitChain(req abci.RequestInitChain) {
|
|
||||||
// return early if no InitValidator registered
|
|
||||||
if app.initVals == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
logger, store := app.Logger(), app.Append()
|
|
||||||
app.initVals.InitValidators(logger, store, req.Validators)
|
|
||||||
}
|
|
|
@ -153,6 +153,10 @@ func (cid CommitID) IsZero() bool {
|
||||||
return cid.Version == 0 && len(cid.Hash) == 0
|
return cid.Version == 0 && len(cid.Hash) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cid CommitID) String() string {
|
||||||
|
return fmt.Spritnf("CommitID{%v:%X}", cid.Hash, cid.Version)
|
||||||
|
}
|
||||||
|
|
||||||
// bytes.Compare but bounded on both sides by nil.
|
// bytes.Compare but bounded on both sides by nil.
|
||||||
// both (k1, nil) and (nil, k2) return -1
|
// both (k1, nil) and (nil, k2) return -1
|
||||||
func keyCompare(k1, k2 []byte) int {
|
func keyCompare(k1, k2 []byte) int {
|
||||||
|
|
Loading…
Reference in New Issue