diff --git a/handlers/base.go b/modules/fee/handler.go similarity index 93% rename from handlers/base.go rename to modules/fee/handler.go index 0728bc341..18b82812b 100644 --- a/handlers/base.go +++ b/modules/fee/handler.go @@ -1,10 +1,9 @@ -package handlers +package fee import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" "github.com/tendermint/basecoin/stack" - "github.com/tendermint/basecoin/txs" "github.com/tendermint/basecoin/types" ) @@ -35,7 +34,7 @@ var _ stack.Middleware = SimpleFeeHandler{} // Yes, I know refactor a bit... really too late already func (h SimpleFeeHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { - feeTx, ok := tx.Unwrap().(*txs.Fee) + feeTx, ok := tx.Unwrap().(*Fee) if !ok { return res, errors.InvalidFormat() } @@ -58,7 +57,7 @@ func (h SimpleFeeHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx } func (h SimpleFeeHandler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { - feeTx, ok := tx.Unwrap().(*txs.Fee) + feeTx, ok := tx.Unwrap().(*Fee) if !ok { return res, errors.InvalidFormat() } diff --git a/modules/fee/tx.go b/modules/fee/tx.go new file mode 100644 index 000000000..10f5d7cfd --- /dev/null +++ b/modules/fee/tx.go @@ -0,0 +1,43 @@ +package fee + +import ( + "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/types" +) + +const ( + ByteFees = 0x20 + TypeFees = "fee" +) + +func init() { + basecoin.TxMapper. + RegisterImplementation(&Fee{}, TypeFees, ByteFees) +} + +/**** Fee ****/ + +// Fee attaches a fee payment to the embedded tx +type Fee struct { + Tx basecoin.Tx `json:"tx"` + Fee types.Coin `json:"fee"` + Payer basecoin.Actor `json:"payer"` // the address who pays the fee + // Gas types.Coin `json:"gas"` // ????? +} + +func NewFee(tx basecoin.Tx, fee types.Coin, payer basecoin.Actor) *Fee { + return &Fee{Tx: tx, Fee: fee, Payer: payer} +} + +func (f *Fee) ValidateBasic() error { + // TODO: more checks + return f.Tx.ValidateBasic() +} + +func (f *Fee) Wrap() basecoin.Tx { + return basecoin.Tx{f} +} + +func (f *Fee) Next() basecoin.Tx { + return f.Tx +} diff --git a/txs/base.go b/txs/base.go index 406a270ae..c2463b83c 100644 --- a/txs/base.go +++ b/txs/base.go @@ -3,17 +3,14 @@ package txs import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" - "github.com/tendermint/basecoin/types" "github.com/tendermint/go-wire/data" ) const ( // for utils... - ByteRaw = 0x1 - // TODO: move fees into a module, multiplexer is standard - ByteFees = 0x2 - ByteMulti = 0x3 - ByteChain = 0x4 + ByteRaw = 0x1 + ByteMulti = 0x2 + ByteChain = 0x3 // for signatures ByteSig = 0x16 @@ -23,7 +20,6 @@ const ( const ( // for utils... TypeRaw = "raw" - TypeFees = "fee" TypeMulti = "multi" TypeChain = "chain" @@ -39,7 +35,6 @@ const ( func init() { basecoin.TxMapper. RegisterImplementation(Raw{}, TypeRaw, ByteRaw). - RegisterImplementation(&Fee{}, TypeFees, ByteFees). RegisterImplementation(&MultiTx{}, TypeMulti, ByteMulti). RegisterImplementation(&Chain{}, TypeChain, ByteChain) } @@ -64,33 +59,6 @@ func NewRaw(d []byte) Raw { return Raw{data.Bytes(d)} } -/**** Fee ****/ - -// Fee attaches a fee payment to the embedded tx -type Fee struct { - Tx basecoin.Tx `json:"tx"` - Fee types.Coin `json:"fee"` - Payer basecoin.Actor `json:"payer"` // the address who pays the fee - // Gas types.Coin `json:"gas"` // ????? -} - -func NewFee(tx basecoin.Tx, fee types.Coin, payer basecoin.Actor) *Fee { - return &Fee{Tx: tx, Fee: fee, Payer: payer} -} - -func (f *Fee) ValidateBasic() error { - // TODO: more checks - return f.Tx.ValidateBasic() -} - -func (f *Fee) Wrap() basecoin.Tx { - return basecoin.Tx{f} -} - -func (f *Fee) Next() basecoin.Tx { - return f.Tx -} - /**** MultiTx ******/ type MultiTx struct { Txs []basecoin.Tx `json:"txs"`