From 0a7603539810a0a07107f1da1168ce0c24d0b639 Mon Sep 17 00:00:00 2001 From: David Kajpust Date: Fri, 29 Jun 2018 09:37:14 -0400 Subject: [PATCH 1/2] fee collection now works in gaia --- client/context/helpers.go | 6 +++++- client/context/types.go | 7 +++++++ client/context/viper.go | 1 + cmd/gaia/app/app.go | 33 ++++++++++++++++++--------------- types/context.go | 8 ++++++++ 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/client/context/helpers.go b/client/context/helpers.go index c782503b09..b5d539fbd7 100644 --- a/client/context/helpers.go +++ b/client/context/helpers.go @@ -124,6 +124,10 @@ func (ctx CoreContext) SignAndBuild(name, passphrase string, msgs []sdk.Msg, cdc accnum := ctx.AccountNumber sequence := ctx.Sequence memo := ctx.Memo + fee , err := sdk.ParseCoin(ctx.Fee) + if err != nil { + return nil, err + } signMsg := auth.StdSignMsg{ ChainID: chainID, @@ -131,7 +135,7 @@ func (ctx CoreContext) SignAndBuild(name, passphrase string, msgs []sdk.Msg, cdc Sequence: int64(sequence), Msgs: msgs, Memo: memo, - Fee: auth.NewStdFee(ctx.Gas, sdk.Coin{}), // TODO run simulate to estimate gas? + Fee: auth.NewStdFee(ctx.Gas, fee), // TODO run simulate to estimate gas? } keybase, err := keys.GetKeyBase() diff --git a/client/context/types.go b/client/context/types.go index 6b0c074f2c..489a39333b 100644 --- a/client/context/types.go +++ b/client/context/types.go @@ -11,6 +11,7 @@ type CoreContext struct { ChainID string Height int64 Gas int64 + Fee string TrustNode bool NodeURI string FromAddressName string @@ -40,6 +41,12 @@ func (c CoreContext) WithGas(gas int64) CoreContext { return c } +// WithFee - return a copy of the context with an updated fee +func (c CoreContext) WithFee(fee string) CoreContext { + c.Fee = fee + return c +} + // WithTrustNode - return a copy of the context with an updated TrustNode flag func (c CoreContext) WithTrustNode(trustNode bool) CoreContext { c.TrustNode = trustNode diff --git a/client/context/viper.go b/client/context/viper.go index d3896fe580..0b9864d857 100644 --- a/client/context/viper.go +++ b/client/context/viper.go @@ -31,6 +31,7 @@ func NewCoreContextFromViper() CoreContext { ChainID: chainID, Height: viper.GetInt64(client.FlagHeight), Gas: viper.GetInt64(client.FlagGas), + Fee: viper.GetString(client.FlagFee), TrustNode: viper.GetBool(client.FlagTrustNode), FromAddressName: viper.GetString(client.FlagName), NodeURI: nodeURI, diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index 67aea321f6..c56fddede9 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -37,12 +37,13 @@ type GaiaApp struct { cdc *wire.Codec // keys to access the substores - keyMain *sdk.KVStoreKey - keyAccount *sdk.KVStoreKey - keyIBC *sdk.KVStoreKey - keyStake *sdk.KVStoreKey - keySlashing *sdk.KVStoreKey - keyGov *sdk.KVStoreKey + keyMain *sdk.KVStoreKey + keyAccount *sdk.KVStoreKey + keyIBC *sdk.KVStoreKey + keyStake *sdk.KVStoreKey + keySlashing *sdk.KVStoreKey + keyGov *sdk.KVStoreKey + keyFeeCollection *sdk.KVStoreKey // Manage getting and setting accounts accountMapper auth.AccountMapper @@ -59,14 +60,15 @@ func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp { // create your application object var app = &GaiaApp{ - 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"), - keyGov: sdk.NewKVStoreKey("gov"), + 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"), + keyGov: sdk.NewKVStoreKey("gov"), + keyFeeCollection: sdk.NewKVStoreKey("feeCollection"), } // define the accountMapper @@ -82,6 +84,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp { 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)) app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace)) + app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.cdc, app.keyFeeCollection) // register message routes app.Router(). @@ -96,7 +99,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp { 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, app.keyGov) + app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyIBC, app.keyStake, app.keySlashing, app.keyGov, app.keyFeeCollection) err := app.LoadLatestVersion(app.keyMain) if err != nil { cmn.Exit(err.Error()) diff --git a/types/context.go b/types/context.go index 4184911526..ed92002db8 100644 --- a/types/context.go +++ b/types/context.go @@ -46,6 +46,7 @@ func NewContext(ms MultiStore, header abci.Header, isCheckTx bool, logger log.Lo c = c.WithLogger(logger) c = c.WithSigningValidators(nil) c = c.WithGasMeter(NewInfiniteGasMeter()) + c = c.WithFeeCollection(0) return c } @@ -132,6 +133,7 @@ const ( contextKeyLogger contextKeySigningValidators contextKeyGasMeter + contextKeyFeeCollector ) // NOTE: Do not expose MultiStore. @@ -166,6 +168,9 @@ func (c Context) SigningValidators() []abci.SigningValidator { func (c Context) GasMeter() GasMeter { return c.Value(contextKeyGasMeter).(GasMeter) } +func (c Context) FeeCollection() int64 { + return c.Value(contextKeyFeeCollector).(int64) +} func (c Context) WithMultiStore(ms MultiStore) Context { return c.withValue(contextKeyMultiStore, ms) } @@ -194,6 +199,9 @@ func (c Context) WithSigningValidators(SigningValidators []abci.SigningValidator func (c Context) WithGasMeter(meter GasMeter) Context { return c.withValue(contextKeyGasMeter, meter) } +func (c Context) WithFeeCollection(fee int64) Context { + return c.withValue(contextKeyFeeCollector, fee) +} // Cache the multistore and return a new cached context. The cached context is // written to the context when writeCache is called. From 64ea408b388d754b4d1284ccfb06872f91be4d35 Mon Sep 17 00:00:00 2001 From: David Kajpust Date: Fri, 29 Jun 2018 11:50:32 -0400 Subject: [PATCH 2/2] fixed error for blank fee string --- client/context/helpers.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/context/helpers.go b/client/context/helpers.go index b5d539fbd7..8cc85dfa4a 100644 --- a/client/context/helpers.go +++ b/client/context/helpers.go @@ -124,9 +124,14 @@ func (ctx CoreContext) SignAndBuild(name, passphrase string, msgs []sdk.Msg, cdc accnum := ctx.AccountNumber sequence := ctx.Sequence memo := ctx.Memo - fee , err := sdk.ParseCoin(ctx.Fee) - if err != nil { - return nil, err + + fee := sdk.Coin{} + if ctx.Fee != "" { + parsedFee, err := sdk.ParseCoin(ctx.Fee) + if err != nil { + return nil, err + } + fee = parsedFee } signMsg := auth.StdSignMsg{