Skip to content

Commit

Permalink
Merge branch 'stake' into start
Browse files Browse the repository at this point in the history
  • Loading branch information
maggie-5miles committed Feb 27, 2018
2 parents 157cc19 + 29c9d24 commit f6e8313
Show file tree
Hide file tree
Showing 30 changed files with 1,973 additions and 55 deletions.
29 changes: 29 additions & 0 deletions app/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/tendermint/go-wire/data"
//"github.com/tendermint/go-wire"
"github.com/CyberMiles/travis/modules/stake"
//crypto "github.com/tendermint/go-crypto"
//auth "github.com/cosmos/cosmos-sdk/modules/auth"
)

// BaseApp - The ABCI application
Expand Down Expand Up @@ -72,6 +74,15 @@ func (app *BaseApp) DeliverTx(txBytes []byte) abci.ResponseDeliverTx {
app.WorkingHeight(),
app.Logger().With("call", "delivertx"),
)

//// fixme check if it's sendTx
//switch tx.Unwrap().(type) {
//case coin.SendTx:
// //return h.sendTx(ctx, store, t, cb)
// fmt.Println("transfer tx")
//}


res, err := app.handler.DeliverTx(ctx, app.Append(), tx)

if err != nil {
Expand Down Expand Up @@ -112,6 +123,17 @@ func (app *BaseApp) CheckTx(txBytes []byte) abci.ResponseCheckTx {
app.WorkingHeight(),
app.Logger().With("call", "checktx"),
)

//ctx2, err := verifySignature(ctx, tx)
//
//// fixme check if it's sendTx
//switch tx.Unwrap().(type) {
//case coin.SendTx:
// //return h.sendTx(ctx, store, t, cb)
// fmt.Println("checkTx: transfer")
// return sdk.NewCheck(21000, "").ToABCI()
//}

res, err := app.handler.CheckTx(ctx, app.Check(), tx)

if err != nil {
Expand Down Expand Up @@ -168,6 +190,13 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) {
fmt.Printf("ethermint Commit response: %v\n", resp)
*/
return app.StoreApp.Commit()
/*=======
var hash = resp.Data
fmt.Printf("ethermint Commit response, %v, hash: %v\n", resp, hash.String())
return abci.ResponseCommit{Data: resp.Data}
>>>>>>> stake
*/
}

func (app *BaseApp) InitState(module, key, value string) error {
Expand Down
6 changes: 1 addition & 5 deletions cmd/travis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
"github.com/cosmos/cosmos-sdk/client/commands/query"
txcmd "github.com/CyberMiles/travis/modules/txs"
stakecmd "github.com/CyberMiles/travis/modules/stake/commands"
authcmd "github.com/cosmos/cosmos-sdk/modules/auth/commands"
authcmd "github.com/CyberMiles/travis/modules/auth/commands"
basecmd "github.com/cosmos/cosmos-sdk/modules/base/commands"
//feecmd "github.com/cosmos/cosmos-sdk/modules/fee/commands"
//noncecmd "github.com/cosmos/cosmos-sdk/modules/nonce/commands"
rolecmd "github.com/cosmos/cosmos-sdk/modules/roles/commands"
)

Expand Down Expand Up @@ -38,9 +36,7 @@ func prepareClientCommands() {

// set up the middleware
txcmd.Middleware = txcmd.Wrappers{
//feecmd.FeeWrapper{},
rolecmd.RoleWrapper{},
//noncecmd.NonceWrapper{},
basecmd.ChainWrapper{},
authcmd.SigWrapper{},
}
Expand Down
15 changes: 3 additions & 12 deletions cmd/travis/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@ package main

import (
"github.com/spf13/cobra"

abci "github.com/tendermint/abci/types"

sdk "github.com/cosmos/cosmos-sdk"
basecmd "github.com/CyberMiles/travis/server/commands"
"github.com/cosmos/cosmos-sdk/state"
"github.com/cosmos/cosmos-sdk/stack"
"github.com/CyberMiles/travis/modules/stake"
"github.com/CyberMiles/travis/modules/coin"
"github.com/CyberMiles/travis/modules/fee"
"github.com/cosmos/cosmos-sdk/modules/base"
//"github.com/cosmos/cosmos-sdk/modules/nonce"
"github.com/cosmos/cosmos-sdk/modules/ibc"
"github.com/cosmos/cosmos-sdk/modules/roles"
"github.com/cosmos/cosmos-sdk/modules/fee"
"github.com/cosmos/cosmos-sdk/modules/coin"
"github.com/cosmos/cosmos-sdk/modules/auth"
"github.com/CyberMiles/travis/modules/auth"
)

// nodeCmd is the entry point for this binary
Expand All @@ -33,18 +29,13 @@ func prepareNodeCommands() {
auth.Signatures{},
base.Chain{},
stack.Checkpoint{OnCheck: true},
//nonce.ReplayCheck{},
).
IBC(ibc.NewMiddleware()).
Apps(
roles.NewMiddleware(),
fee.NewSimpleFeeMiddleware(coin.Coin{"cmt", 0}, fee.Bank),
stack.Checkpoint{OnDeliver: true},
).
Dispatch(
coin.NewHandler(),
stack.WrapHandler(roles.NewHandler()),
stack.WrapHandler(ibc.NewHandler()),
stake.NewHandler(),
)

Expand Down
113 changes: 113 additions & 0 deletions genesis/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package genesis

import (
"encoding/json"

sdk "github.com/cosmos/cosmos-sdk"
"github.com/pkg/errors"

cmn "github.com/tendermint/tmlibs/common"
)

// KeyDelimiter is used to separate module and key in
// the options
const KeyDelimiter = "/"

// Option just holds module/key/value triples from
// parsing the genesis file
type Option struct {
Module string
Key string
Value string
}

// InitStater is anything that can handle app options
// from genesis file. Setting the merkle store, config options,
// or anything else
type InitStater interface {
InitState(module, key, value string) error
}

// Load parses the genesis file and sets the initial
// state based on that
func Load(app InitStater, filePath string) error {
opts, err := GetOptions(filePath)
if err != nil {
return err
}

// execute all the genesis init options
// abort on any error
for _, opt := range opts {
err = app.InitState(opt.Module, opt.Key, opt.Value)
if err != nil {
return err
}
}
return nil
}

// GetOptions parses the genesis file in a format
// that can easily be handed into InitStaters
func GetOptions(path string) ([]Option, error) {
genDoc, err := load(path)
if err != nil {
return nil, err
}

opts := genDoc.AppOptions
validators := genDoc.Validators
cnt := 1 + len(opts.Accounts) + len(validators)
res := make([]Option, 0, cnt)
res = append(res, Option{sdk.ModuleNameBase, sdk.ChainKey, genDoc.ChainID})

// set accounts
//for _, validator := range validators {
// res = append(res, Option{"coin", "validator", string(validator)})
//}
res = append(res, Option{"stake", "validators", string(validators)})

// set accounts
for _, acct := range opts.Accounts {
res = append(res, Option{"coin", "account", string(acct)})
}

return res, nil
}

type keyValue struct {
Key string `json:"key"`
Value string `json:"value"`
}

// FullDoc - includes tendermint (in the json, we ignore here)
type FullDoc struct {
ChainID string `json:"chain_id"`
AppOptions *Doc `json:"app_options"`
Validators json.RawMessage `json:"validators"`
}

// Doc - All genesis values
type Doc struct {
Accounts []json.RawMessage `json:"accounts"`
}

func load(filePath string) (*FullDoc, error) {
bytes, err := cmn.ReadFile(filePath)
if err != nil {
return nil, errors.Wrap(err, "loading genesis file")
}

// the basecoin genesis go-wire/data :)
genDoc := new(FullDoc)
err = json.Unmarshal(bytes, genDoc)
if err != nil {
return nil, errors.Wrap(err, "unmarshaling genesis file")
}

if genDoc.AppOptions == nil {
genDoc.AppOptions = new(Doc)
}

return genDoc, nil
}
Loading

0 comments on commit f6e8313

Please sign in to comment.