-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangzhiqiang
committed
Jun 20, 2018
1 parent
09670e4
commit ddb015c
Showing
19 changed files
with
1,275 additions
and
1,152 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
# | ||
# [prune] | ||
# non-go = false | ||
# go-tests = true | ||
# unused-packages = true | ||
|
||
[[constraint]] | ||
name = "github.com/spf13/cobra" | ||
version = "~0.0.1" | ||
|
||
[[constraint]] | ||
name = "github.com/spf13/viper" | ||
version = "~1.0.0" | ||
|
||
[[constraint]] | ||
name = "github.com/cosmos/cosmos-sdk" | ||
version = "v0.19.0" | ||
|
||
[[constraint]] | ||
name = "github.com/tendermint/abci" | ||
version = "=0.11.0" | ||
|
||
[[constraint]] | ||
name = "github.com/tendermint/go-crypto" | ||
version = "~0.6.2" | ||
|
||
[[constraint]] | ||
name = "github.com/tendermint/tendermint" | ||
version = "=0.20.0" | ||
|
||
[[override]] | ||
name = "github.com/tendermint/tmlibs" | ||
revision = "0c98d10b4ffbd87978d79c160e835b3d3df241ec" | ||
|
||
# this got updated and broke, so locked to an old working commit ... | ||
[[override]] | ||
name = "google.golang.org/genproto" | ||
revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200" | ||
|
||
[prune] | ||
go-tests = true | ||
unused-packages = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
all: get_vendor_deps install test | ||
all: get_vendor_deps install | ||
|
||
get_vendor_deps: | ||
go get github.com/Masterminds/glide | ||
glide install | ||
|
||
@rm -rf vendor/ | ||
@echo "--> Running dep ensure" | ||
@dep ensure -v | ||
|
||
install: | ||
go install ./cmd/iris | ||
go build ./cmd/iriscli | ||
|
||
build_linux: | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/iris ./cmd/iris | ||
|
||
test: | ||
@go test `glide novendor` | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/iris ./cmd/iris && \ | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/iriscli ./cmd/iriscli | ||
|
||
test_cli: | ||
bash ./cmd/iris/sh_tests/stake.sh | ||
build_cur: | ||
go build -o build/iris ./cmd/iris && \ | ||
go build -o build/iriscli ./cmd/iriscli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
package app | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
abci "github.com/tendermint/abci/types" | ||
tmtypes "github.com/tendermint/tendermint/types" | ||
cmn "github.com/tendermint/tmlibs/common" | ||
dbm "github.com/tendermint/tmlibs/db" | ||
"github.com/tendermint/tmlibs/log" | ||
|
||
bam "github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/wire" | ||
"github.com/cosmos/cosmos-sdk/x/auth" | ||
"github.com/cosmos/cosmos-sdk/x/bank" | ||
"github.com/cosmos/cosmos-sdk/x/ibc" | ||
"github.com/cosmos/cosmos-sdk/x/slashing" | ||
"github.com/cosmos/cosmos-sdk/x/stake" | ||
) | ||
|
||
const ( | ||
appName = "IrisApp" | ||
) | ||
|
||
// default home directories for expected binaries | ||
var ( | ||
DefaultCLIHome = os.ExpandEnv("$HOME/.iriscli") | ||
DefaultNodeHome = os.ExpandEnv("$HOME/.iris") | ||
) | ||
|
||
// Extended ABCI application | ||
type IrisApp struct { | ||
*bam.BaseApp | ||
cdc *wire.Codec | ||
|
||
// keys to access the substores | ||
keyMain *sdk.KVStoreKey | ||
keyAccount *sdk.KVStoreKey | ||
keyIBC *sdk.KVStoreKey | ||
keyStake *sdk.KVStoreKey | ||
keySlashing *sdk.KVStoreKey | ||
|
||
// Manage getting and setting accounts | ||
accountMapper auth.AccountMapper | ||
feeCollectionKeeper auth.FeeCollectionKeeper | ||
coinKeeper bank.Keeper | ||
ibcMapper ibc.Mapper | ||
stakeKeeper stake.Keeper | ||
slashingKeeper slashing.Keeper | ||
} | ||
|
||
func NewIrisApp(logger log.Logger, db dbm.DB) *IrisApp { | ||
cdc := MakeCodec() | ||
|
||
// create your application object | ||
var app = &IrisApp{ | ||
BaseApp: bam.NewBaseApp(appName, cdc, logger, db), | ||
cdc: cdc, | ||
keyMain: sdk.NewKVStoreKey("main"), | ||
keyAccount: sdk.NewKVStoreKey("acc"), | ||
keyIBC: sdk.NewKVStoreKey("ibc"), | ||
keyStake: sdk.NewKVStoreKey("stake"), | ||
keySlashing: sdk.NewKVStoreKey("slashing"), | ||
} | ||
|
||
// define the accountMapper | ||
app.accountMapper = auth.NewAccountMapper( | ||
app.cdc, | ||
app.keyAccount, // target store | ||
&auth.BaseAccount{}, // prototype | ||
) | ||
|
||
// add handlers | ||
app.coinKeeper = bank.NewKeeper(app.accountMapper) | ||
app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace)) | ||
app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace)) | ||
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.RegisterCodespace(slashing.DefaultCodespace)) | ||
|
||
// register message routes | ||
app.Router(). | ||
AddRoute("bank", bank.NewHandler(app.coinKeeper)). | ||
AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)). | ||
AddRoute("stake", stake.NewHandler(app.stakeKeeper)). | ||
AddRoute("slashing", slashing.NewHandler(app.slashingKeeper)) | ||
|
||
// initialize BaseApp | ||
app.SetInitChainer(app.initChainer) | ||
app.SetBeginBlocker(app.BeginBlocker) | ||
app.SetEndBlocker(app.EndBlocker) | ||
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, app.feeCollectionKeeper)) | ||
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyIBC, app.keyStake, app.keySlashing) | ||
err := app.LoadLatestVersion(app.keyMain) | ||
if err != nil { | ||
cmn.Exit(err.Error()) | ||
} | ||
|
||
return app | ||
} | ||
|
||
// custom tx codec | ||
func MakeCodec() *wire.Codec { | ||
var cdc = wire.NewCodec() | ||
ibc.RegisterWire(cdc) | ||
bank.RegisterWire(cdc) | ||
stake.RegisterWire(cdc) | ||
slashing.RegisterWire(cdc) | ||
auth.RegisterWire(cdc) | ||
sdk.RegisterWire(cdc) | ||
wire.RegisterCrypto(cdc) | ||
return cdc | ||
} | ||
|
||
// application updates every end block | ||
func (app *IrisApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { | ||
tags := slashing.BeginBlocker(ctx, req, app.slashingKeeper) | ||
|
||
return abci.ResponseBeginBlock{ | ||
Tags: tags.ToKVPairs(), | ||
} | ||
} | ||
|
||
// application updates every end block | ||
func (app *IrisApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { | ||
validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper) | ||
|
||
return abci.ResponseEndBlock{ | ||
ValidatorUpdates: validatorUpdates, | ||
} | ||
} | ||
|
||
// custom logic for gaia initialization | ||
func (app *IrisApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { | ||
stateJSON := req.AppStateBytes | ||
// TODO is this now the whole genesis file? | ||
|
||
var genesisState GenesisState | ||
err := app.cdc.UnmarshalJSON(stateJSON, &genesisState) | ||
if err != nil { | ||
panic(err) // TODO https://github.com/cosmos/cosmos-sdk/issues/468 | ||
// return sdk.ErrGenesisParse("").TraceCause(err, "") | ||
} | ||
|
||
// load the accounts | ||
for _, gacc := range genesisState.Accounts { | ||
acc := gacc.ToAccount() | ||
acc.AccountNumber = app.accountMapper.GetNextAccountNumber(ctx) | ||
app.accountMapper.SetAccount(ctx, acc) | ||
} | ||
|
||
// load the initial stake information | ||
stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData) | ||
|
||
return abci.ResponseInitChain{} | ||
} | ||
|
||
// export the state of gaia for a genesis file | ||
func (app *IrisApp) ExportAppStateAndValidators() (appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) { | ||
ctx := app.NewContext(true, abci.Header{}) | ||
|
||
// iterate to get the accounts | ||
accounts := []GenesisAccount{} | ||
appendAccount := func(acc auth.Account) (stop bool) { | ||
account := NewGenesisAccountI(acc) | ||
accounts = append(accounts, account) | ||
return false | ||
} | ||
app.accountMapper.IterateAccounts(ctx, appendAccount) | ||
|
||
genState := GenesisState{ | ||
Accounts: accounts, | ||
StakeData: stake.WriteGenesis(ctx, app.stakeKeeper), | ||
} | ||
appState, err = wire.MarshalJSONIndent(app.cdc, genState) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
validators = stake.WriteValidators(ctx, app.stakeKeeper) | ||
return appState, validators, nil | ||
} |
Oops, something went wrong.