Skip to content

Commit

Permalink
in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnya97 committed May 24, 2018
1 parent 34f6475 commit cb52712
Show file tree
Hide file tree
Showing 25 changed files with 280 additions and 262 deletions.
3 changes: 2 additions & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
)

// Key to store the header in the DB itself.
Expand Down Expand Up @@ -125,7 +126,7 @@ func (app *BaseApp) SetTxDecoder(txDecoder sdk.TxDecoder) {
// default custom logic for transaction decoding
func defaultTxDecoder(cdc *wire.Codec) sdk.TxDecoder {
return func(txBytes []byte) (sdk.Tx, sdk.Error) {
var tx = sdk.StdTx{}
var tx = auth.StdTx{}

if len(txBytes) == 0 {
return nil, sdk.ErrTxDecode("txBytes are empty")
Expand Down
9 changes: 5 additions & 4 deletions client/context/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"

"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
cmn "github.com/tendermint/tmlibs/common"
Expand Down Expand Up @@ -109,11 +110,11 @@ func (ctx CoreContext) SignAndBuild(name, passphrase string, msg sdk.Msg, cdc *w
return nil, errors.Errorf("Chain ID required but not specified")
}
sequence := ctx.Sequence
signMsg := sdk.StdSignMsg{
signMsg := auth.StdSignMsg{
ChainID: chainID,
Sequences: []int64{sequence},
Msg: msg,
Fee: sdk.NewStdFee(10000, sdk.Coin{}), // TODO run simulate to estimate gas?
Fee: auth.NewStdFee(10000, sdk.Coin{}), // TODO run simulate to estimate gas?
}

keybase, err := keys.GetKeyBase()
Expand All @@ -128,14 +129,14 @@ func (ctx CoreContext) SignAndBuild(name, passphrase string, msg sdk.Msg, cdc *w
if err != nil {
return nil, err
}
sigs := []sdk.StdSignature{{
sigs := []auth.StdSignature{{
PubKey: pubkey,
Signature: sig,
Sequence: sequence,
}}

// marshal bytes
tx := sdk.NewStdTx(signMsg.Msg, signMsg.Fee, sigs)
tx := auth.NewStdTx(signMsg.Msg, signMsg.Fee, sigs)

return cdc.MarshalBinary(tx)
}
Expand Down
6 changes: 3 additions & 3 deletions client/context/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package context
import (
rpcclient "github.com/tendermint/tendermint/rpc/client"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
)

// typical context created in sdk modules for transactions/queries
Expand All @@ -15,7 +15,7 @@ type CoreContext struct {
FromAddressName string
Sequence int64
Client rpcclient.Client
Decoder sdk.AccountDecoder
Decoder auth.AccountDecoder
AccountStore string
}

Expand Down Expand Up @@ -63,7 +63,7 @@ func (c CoreContext) WithClient(client rpcclient.Client) CoreContext {
}

// WithDecoder - return a copy of the context with an updated Decoder
func (c CoreContext) WithDecoder(decoder sdk.AccountDecoder) CoreContext {
func (c CoreContext) WithDecoder(decoder auth.AccountDecoder) CoreContext {
c.Decoder = decoder
return c
}
Expand Down
3 changes: 2 additions & 1 deletion client/tx/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
)

// Get the default command for a tx query
Expand Down Expand Up @@ -95,7 +96,7 @@ type txInfo struct {
}

func parseTx(cdc *wire.Codec, txBytes []byte) (sdk.Tx, error) {
var tx sdk.StdTx
var tx auth.StdTx
err := cdc.UnmarshalBinary(txBytes, &tx)
if err != nil {
return nil, err
Expand Down
18 changes: 13 additions & 5 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import (
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
<<<<<<< HEAD
feed "github.com/cosmos/cosmos-sdk/x/fee_distribution"
=======
"github.com/cosmos/cosmos-sdk/x/baseaccount"
>>>>>>> in progress
"github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/cosmos/cosmos-sdk/x/stake"
)
Expand All @@ -41,7 +45,7 @@ type GaiaApp struct {
keyStake *sdk.KVStoreKey

// Manage getting and setting accounts
accountMapper sdk.AccountMapper
accountMapper auth.AccountMapper
coinKeeper bank.Keeper
ibcMapper ibc.Mapper
stakeKeeper stake.Keeper
Expand All @@ -63,8 +67,8 @@ func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp {
// define the accountMapper
app.accountMapper = auth.NewAccountMapper(
app.cdc,
app.keyAccount, // target store
&auth.BaseAccount{}, // prototype
app.keyAccount, // target store
&baseaccount.BaseAccount{}, // prototype
)

// add handlers
Expand All @@ -82,7 +86,11 @@ func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp {
app.SetInitChainer(app.initChainer)
app.SetEndBlocker(stake.NewEndBlocker(app.stakeKeeper))
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyIBC, app.keyStake)
<<<<<<< HEAD
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, feed.BurnFeeHandler))
=======
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper))
>>>>>>> in progress
err := app.LoadLatestVersion(app.keyMain)
if err != nil {
cmn.Exit(err.Error())
Expand All @@ -97,7 +105,7 @@ func MakeCodec() *wire.Codec {
ibc.RegisterWire(cdc)
bank.RegisterWire(cdc)
stake.RegisterWire(cdc)
auth.RegisterWire(cdc)
baseaccount.RegisterWire(cdc)
sdk.RegisterWire(cdc)
wire.RegisterCrypto(cdc)
return cdc
Expand Down Expand Up @@ -132,7 +140,7 @@ func (app *GaiaApp) ExportAppStateJSON() (appState json.RawMessage, err error) {

// iterate to get the accounts
accounts := []GenesisAccount{}
appendAccount := func(acc sdk.Account) (stop bool) {
appendAccount := func(acc auth.Account) (stop bool) {
account := NewGenesisAccountI(acc)
accounts = append(accounts, account)
return false
Expand Down
11 changes: 6 additions & 5 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
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/baseaccount"
"github.com/cosmos/cosmos-sdk/x/stake"
)

Expand All @@ -28,23 +29,23 @@ type GenesisAccount struct {
Coins sdk.Coins `json:"coins"`
}

func NewGenesisAccount(acc *auth.BaseAccount) GenesisAccount {
func NewGenesisAccount(acc *baseaccount.BaseAccount) GenesisAccount {
return GenesisAccount{
Address: acc.Address,
Coins: acc.Coins,
}
}

func NewGenesisAccountI(acc sdk.Account) GenesisAccount {
func NewGenesisAccountI(acc auth.Account) GenesisAccount {
return GenesisAccount{
Address: acc.GetAddress(),
Coins: acc.GetCoins(),
}
}

// convert GenesisAccount to auth.BaseAccount
func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount) {
return &auth.BaseAccount{
func (ga *GenesisAccount) ToAccount() (acc *baseaccount.BaseAccount) {
return &baseaccount.BaseAccount{
Address: ga.Address,
Coins: ga.Coins.Sort(),
}
Expand Down Expand Up @@ -148,7 +149,7 @@ func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState jso
}

// create the genesis account, give'm few steaks and a buncha token with there name
accAuth := auth.NewBaseAccountWithAddress(genTx.Address)
accAuth := baseaccount.NewBaseAccountWithAddress(genTx.Address)
accAuth.Coins = sdk.Coins{
{genTx.Name + "Token", 1000},
{"steak", freeFermionsAcc},
Expand Down
29 changes: 0 additions & 29 deletions types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/hex"
"errors"

crypto "github.com/tendermint/go-crypto"
cmn "github.com/tendermint/tmlibs/common"
)

Expand All @@ -22,31 +21,3 @@ func GetAddress(address string) (addr Address, err error) {
}
return Address(bz), nil
}

// Account is a standard account using a sequence number for replay protection
// and a pubkey for authentication.
type Account interface {
GetAddress() Address
SetAddress(Address) error // errors if already set.

GetPubKey() crypto.PubKey // can return nil.
SetPubKey(crypto.PubKey) error

GetSequence() int64
SetSequence(int64) error

GetCoins() Coins
SetCoins(Coins) error
}

// AccountMapper stores and retrieves accounts from stores
// retrieved from the context.
type AccountMapper interface {
NewAccountWithAddress(ctx Context, addr Address) Account
GetAccount(ctx Context, addr Address) Account
SetAccount(ctx Context, acc Account)
IterateAccounts(ctx Context, process func(Account) (stop bool))
}

// AccountDecoder unmarshals account bytes
type AccountDecoder func(accountBytes []byte) (Account, error)
3 changes: 0 additions & 3 deletions types/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ package types
// core function variable which application runs for transactions
type Handler func(ctx Context, msg Msg) Result

// core function variable which application runs to handle fees
type FeeHandler func(ctx Context, tx Tx, fee Coins)

// If newCtx.IsZero(), ctx is used instead.
type AnteHandler func(ctx Context, tx Tx) (newCtx Context, result Result, abort bool)
10 changes: 0 additions & 10 deletions types/signature.go

This file was deleted.

117 changes: 0 additions & 117 deletions types/tx_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,123 +31,6 @@ type Tx interface {

// Gets the Msg.
GetMsg() Msg

// Signatures returns the signature of signers who signed the Msg.
// CONTRACT: Length returned is same as length of
// pubkeys returned from MsgKeySigners, and the order
// matches.
// CONTRACT: If the signature is missing (ie the Msg is
// invalid), then the corresponding signature is
// .Empty().
GetSignatures() []StdSignature
}

var _ Tx = (*StdTx)(nil)

// StdTx is a standard way to wrap a Msg with Fee and Signatures.
// NOTE: the first signature is the FeePayer (Signatures must not be nil).
type StdTx struct {
Msg `json:"msg"`
Fee StdFee `json:"fee"`
Signatures []StdSignature `json:"signatures"`
}

func NewStdTx(msg Msg, fee StdFee, sigs []StdSignature) StdTx {
return StdTx{
Msg: msg,
Fee: fee,
Signatures: sigs,
}
}

//nolint
func (tx StdTx) GetMsg() Msg { return tx.Msg }
func (tx StdTx) GetSignatures() []StdSignature { return tx.Signatures }

// FeePayer returns the address responsible for paying the fees
// for the transactions. It's the first address returned by msg.GetSigners().
// If GetSigners() is empty, this panics.
func FeePayer(tx Tx) Address {
return tx.GetMsg().GetSigners()[0]
}

//__________________________________________________________

// StdFee includes the amount of coins paid in fees and the maximum
// gas to be used by the transaction. The ratio yields an effective "gasprice",
// which must be above some miminum to be accepted into the mempool.
type StdFee struct {
Amount Coins `json:"amount"`
Gas int64 `json:"gas"`
}

func NewStdFee(gas int64, amount ...Coin) StdFee {
return StdFee{
Amount: amount,
Gas: gas,
}
}

// fee bytes for signing later
func (fee StdFee) Bytes() []byte {
// normalize. XXX
// this is a sign of something ugly
// (in the lcd_test, client side its null,
// server side its [])
if len(fee.Amount) == 0 {
fee.Amount = Coins{}
}
bz, err := json.Marshal(fee) // TODO
if err != nil {
panic(err)
}
return bz
}

//__________________________________________________________

// StdSignDoc is replay-prevention structure.
// It includes the result of msg.GetSignBytes(),
// as well as the ChainID (prevent cross chain replay)
// and the Sequence numbers for each signature (prevent
// inchain replay and enforce tx ordering per account).
type StdSignDoc struct {
ChainID string `json:"chain_id"`
Sequences []int64 `json:"sequences"`
FeeBytes []byte `json:"fee_bytes"`
MsgBytes []byte `json:"msg_bytes"`
AltBytes []byte `json:"alt_bytes"`
}

// StdSignBytes returns the bytes to sign for a transaction.
// TODO: change the API to just take a chainID and StdTx ?
func StdSignBytes(chainID string, sequences []int64, fee StdFee, msg Msg) []byte {
bz, err := json.Marshal(StdSignDoc{
ChainID: chainID,
Sequences: sequences,
FeeBytes: fee.Bytes(),
MsgBytes: msg.GetSignBytes(),
})
if err != nil {
panic(err)
}
return bz
}

// StdSignMsg is a convenience structure for passing along
// a Msg with the other requirements for a StdSignDoc before
// it is signed. For use in the CLI.
type StdSignMsg struct {
ChainID string
Sequences []int64
Fee StdFee
Msg Msg
// XXX: Alt
}

// get message bytes
func (msg StdSignMsg) Bytes() []byte {
return StdSignBytes(msg.ChainID, msg.Sequences, msg.Fee, msg.Msg)
}

//__________________________________________________________
Expand Down
Loading

0 comments on commit cb52712

Please sign in to comment.