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"
//ibccmd "github.com/cosmos/cosmos-sdk/x/ibc/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/lcd"
@ -70,7 +70,7 @@ func main() {
Use: "paychan",
Short: "Payment channel subcommands",
}
stakeCmd.AddCommand(
paychanCmd.AddCommand(
client.PostCommands(
paychancmd.CreatePaychanCmd(cdc),
paychancmd.GenerateNewStateCmd(cdc),

View File

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

View File

@ -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"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"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 {
// Create a "client context" stuct populated with info from common flags
ctx := context.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// Get sender adress
senderAddress, err := ctx.GetFromAddress()
@ -95,12 +96,12 @@ func GenerateNewStateCmd(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "new-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,
RunE: func(cmd *cobra.Command, args []string) error {
// Create a "client context" stuct populated with info from common flags
ctx := context.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// Get sender adress
senderAddress, err := ctx.GetFromAddress()
@ -141,8 +142,8 @@ func GenerateNewStateCmd(cdc *wire.Codec) *cobra.Command {
// Print out the signed msg
fmt.Println("txBytes:", txBytes)
encodedTxBytes := make([]byte, base64.StdEncoding.EncodedLen(len(txBytes)))
base64.StdEncoding.Encode(encodedTxBytes, txBytes)
//encodedTxBytes := make([]byte, base64.StdEncoding.EncodedLen(len(txBytes)))
encodedTxBytes := base64.StdEncoding.EncodeToString(txBytes)
fmt.Println("base64TxBytes:", encodedTxBytes)
return nil
},
@ -159,10 +160,10 @@ func ClosePaychanCmd(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "close",
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,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// Get the sender-signed close tx
state := viper.GetString(flagState)
@ -171,7 +172,7 @@ func ClosePaychanCmd(cdc *wire.Codec) *cobra.Command {
return err
}
stdTx := auth.StdTx{}
cdc.UnmarshalBinary(txBytes, stdTx)
cdc.UnmarshalBinary(txBytes, &stdTx)
// Sign close tx
@ -187,7 +188,6 @@ func ClosePaychanCmd(cdc *wire.Codec) *cobra.Command {
}
// Append signature to close tx
stdTx.Signatures = append(stdTx.Signatures, sig)
// encode close tx
txBytes, err = cdc.MarshalBinary(stdTx)