add paychan module to app

This commit is contained in:
rhuairahrighairigh 2018-07-15 15:08:08 +01:00
parent 68b9591042
commit 266d61eb4b
3 changed files with 20 additions and 13 deletions

View File

@ -17,7 +17,7 @@ import (
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
//ibccmd "github.com/cosmos/cosmos-sdk/x/ibc/client/cli" //ibccmd "github.com/cosmos/cosmos-sdk/x/ibc/client/cli"
//stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli" //stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
paychancmd "github.com/kava-labs/kava/internal/x/paychan/client/cli" paychancmd "github.com/kava-labs/kava/internal/x/paychan/client/cmd"
"github.com/kava-labs/kava/internal/app" "github.com/kava-labs/kava/internal/app"
"github.com/kava-labs/kava/internal/lcd" "github.com/kava-labs/kava/internal/lcd"
@ -70,7 +70,7 @@ func main() {
Use: "paychan", Use: "paychan",
Short: "Payment channel subcommands", Short: "Payment channel subcommands",
} }
stakeCmd.AddCommand( paychanCmd.AddCommand(
client.PostCommands( client.PostCommands(
paychancmd.CreatePaychanCmd(cdc), paychancmd.CreatePaychanCmd(cdc),
paychancmd.GenerateNewStateCmd(cdc), paychancmd.GenerateNewStateCmd(cdc),

View File

@ -18,6 +18,7 @@ import (
//"github.com/cosmos/cosmos-sdk/x/slashing" //"github.com/cosmos/cosmos-sdk/x/slashing"
//"github.com/cosmos/cosmos-sdk/x/stake" //"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/kava-labs/kava/internal/types" "github.com/kava-labs/kava/internal/types"
"github.com/kava-labs/kava/internal/x/paychan"
) )
const ( const (
@ -32,6 +33,7 @@ type KavaApp struct {
// keys to access the substores // keys to access the substores
keyMain *sdk.KVStoreKey keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey keyAccount *sdk.KVStoreKey
keyPaychan *sdk.KVStoreKey
//keyIBC *sdk.KVStoreKey //keyIBC *sdk.KVStoreKey
//keyStake *sdk.KVStoreKey //keyStake *sdk.KVStoreKey
//keySlashing *sdk.KVStoreKey //keySlashing *sdk.KVStoreKey
@ -40,6 +42,7 @@ type KavaApp struct {
accountMapper auth.AccountMapper accountMapper auth.AccountMapper
feeCollectionKeeper auth.FeeCollectionKeeper feeCollectionKeeper auth.FeeCollectionKeeper
coinKeeper bank.Keeper coinKeeper bank.Keeper
paychanKeeper paychan.Keeper
//ibcMapper ibc.Mapper //ibcMapper ibc.Mapper
//stakeKeeper stake.Keeper //stakeKeeper stake.Keeper
//slashingKeeper slashing.Keeper //slashingKeeper slashing.Keeper
@ -56,6 +59,7 @@ func NewKavaApp(logger log.Logger, db dbm.DB) *KavaApp {
cdc: cdc, cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"), keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"), keyAccount: sdk.NewKVStoreKey("acc"),
keyPaychan: sdk.NewKVStoreKey("paychan"),
//keyIBC: sdk.NewKVStoreKey("ibc"), //keyIBC: sdk.NewKVStoreKey("ibc"),
//keyStake: sdk.NewKVStoreKey("stake"), //keyStake: sdk.NewKVStoreKey("stake"),
//keySlashing: sdk.NewKVStoreKey("slashing"), //keySlashing: sdk.NewKVStoreKey("slashing"),
@ -70,6 +74,7 @@ func NewKavaApp(logger log.Logger, db dbm.DB) *KavaApp {
// add accountMapper/handlers // add accountMapper/handlers
app.coinKeeper = bank.NewKeeper(app.accountMapper) app.coinKeeper = bank.NewKeeper(app.accountMapper)
app.paychanKeeper = paychan.NewKeeper(app.cdc, app.keyPaychan, app.coinKeeper)
//app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace)) //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.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.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.RegisterCodespace(slashing.DefaultCodespace))
@ -77,7 +82,8 @@ func NewKavaApp(logger log.Logger, db dbm.DB) *KavaApp {
// register message routes // register message routes
app.Router(). app.Router().
AddRoute("auth", auth.NewHandler(app.accountMapper)). AddRoute("auth", auth.NewHandler(app.accountMapper)).
AddRoute("bank", bank.NewHandler(app.coinKeeper)) AddRoute("bank", bank.NewHandler(app.coinKeeper)).
AddRoute("paychan", paychan.NewHandler(app.paychanKeeper))
//AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)). //AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)).
//AddRoute("stake", stake.NewHandler(app.stakeKeeper)) //AddRoute("stake", stake.NewHandler(app.stakeKeeper))
@ -86,7 +92,7 @@ func NewKavaApp(logger log.Logger, db dbm.DB) *KavaApp {
app.SetBeginBlocker(app.BeginBlocker) app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker) app.SetEndBlocker(app.EndBlocker)
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, app.feeCollectionKeeper)) app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, app.feeCollectionKeeper))
app.MountStoresIAVL(app.keyMain, app.keyAccount) //, app.keyIBC, app.keyStake, app.keySlashing) app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyPaychan) //, app.keyIBC, app.keyStake, app.keySlashing)
err := app.LoadLatestVersion(app.keyMain) err := app.LoadLatestVersion(app.keyMain)
if err != nil { if err != nil {
cmn.Exit(err.Error()) cmn.Exit(err.Error())
@ -100,6 +106,7 @@ func MakeCodec() *wire.Codec {
wire.RegisterCrypto(cdc) // Register crypto. wire.RegisterCrypto(cdc) // Register crypto.
sdk.RegisterWire(cdc) // Register Msgs sdk.RegisterWire(cdc) // Register Msgs
bank.RegisterWire(cdc) bank.RegisterWire(cdc)
paychan.RegisterWire(cdc)
//stake.RegisterWire(cdc) //stake.RegisterWire(cdc)
//slashing.RegisterWire(cdc) //slashing.RegisterWire(cdc)
//ibc.RegisterWire(cdc) //ibc.RegisterWire(cdc)

View File

@ -13,6 +13,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/kava-labs/kava/internal/x/paychan" "github.com/kava-labs/kava/internal/x/paychan"
) )
@ -44,7 +45,7 @@ func CreatePaychanCmd(cdc *wire.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
// Create a "client context" stuct populated with info from common flags // Create a "client context" stuct populated with info from common flags
ctx := context.NewCoreContextFromViper() ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// Get sender adress // Get sender adress
senderAddress, err := ctx.GetFromAddress() senderAddress, err := ctx.GetFromAddress()
@ -95,12 +96,12 @@ func GenerateNewStateCmd(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "new-state", Use: "new-state",
Short: "Generate a new payment channel state.", Short: "Generate a new payment channel state.",
Long: "Generate a new state for an existing payment channel and print it out. The new state is represented as a half signed close transaction.", Long: "Generate a new state for an existing payment channel and print it out. The new state is represented as a half signed close transaction, signed by the sender.",
Args: cobra.NoArgs, Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
// Create a "client context" stuct populated with info from common flags // Create a "client context" stuct populated with info from common flags
ctx := context.NewCoreContextFromViper() ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// Get sender adress // Get sender adress
senderAddress, err := ctx.GetFromAddress() senderAddress, err := ctx.GetFromAddress()
@ -141,8 +142,8 @@ func GenerateNewStateCmd(cdc *wire.Codec) *cobra.Command {
// Print out the signed msg // Print out the signed msg
fmt.Println("txBytes:", txBytes) fmt.Println("txBytes:", txBytes)
encodedTxBytes := make([]byte, base64.StdEncoding.EncodedLen(len(txBytes))) //encodedTxBytes := make([]byte, base64.StdEncoding.EncodedLen(len(txBytes)))
base64.StdEncoding.Encode(encodedTxBytes, txBytes) encodedTxBytes := base64.StdEncoding.EncodeToString(txBytes)
fmt.Println("base64TxBytes:", encodedTxBytes) fmt.Println("base64TxBytes:", encodedTxBytes)
return nil return nil
}, },
@ -159,10 +160,10 @@ func ClosePaychanCmd(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "close", Use: "close",
Short: "Close a payment channel, given a state", Short: "Close a payment channel, given a state",
Long: "Close an existing payment channel with a state received from a sender.", Long: "Close an existing payment channel with a state received from a sender. This signs it as the receiver before submitting to the blockchain.",
Args: cobra.NoArgs, Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper() ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// Get the sender-signed close tx // Get the sender-signed close tx
state := viper.GetString(flagState) state := viper.GetString(flagState)
@ -171,7 +172,7 @@ func ClosePaychanCmd(cdc *wire.Codec) *cobra.Command {
return err return err
} }
stdTx := auth.StdTx{} stdTx := auth.StdTx{}
cdc.UnmarshalBinary(txBytes, stdTx) cdc.UnmarshalBinary(txBytes, &stdTx)
// Sign close tx // Sign close tx
@ -187,7 +188,6 @@ func ClosePaychanCmd(cdc *wire.Codec) *cobra.Command {
} }
// Append signature to close tx // Append signature to close tx
stdTx.Signatures = append(stdTx.Signatures, sig) stdTx.Signatures = append(stdTx.Signatures, sig)
// encode close tx // encode close tx
txBytes, err = cdc.MarshalBinary(stdTx) txBytes, err = cdc.MarshalBinary(stdTx)