mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 16:25:21 +00:00
update paychan cmds
This commit is contained in:
parent
da335a91fe
commit
eb927b1fb7
2
Gopkg.lock
generated
2
Gopkg.lock
generated
@ -714,6 +714,7 @@
|
|||||||
"github.com/cosmos/cosmos-sdk/client/keys",
|
"github.com/cosmos/cosmos-sdk/client/keys",
|
||||||
"github.com/cosmos/cosmos-sdk/client/rpc",
|
"github.com/cosmos/cosmos-sdk/client/rpc",
|
||||||
"github.com/cosmos/cosmos-sdk/client/tx",
|
"github.com/cosmos/cosmos-sdk/client/tx",
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/utils",
|
||||||
"github.com/cosmos/cosmos-sdk/server",
|
"github.com/cosmos/cosmos-sdk/server",
|
||||||
"github.com/cosmos/cosmos-sdk/server/config",
|
"github.com/cosmos/cosmos-sdk/server/config",
|
||||||
"github.com/cosmos/cosmos-sdk/types",
|
"github.com/cosmos/cosmos-sdk/types",
|
||||||
@ -721,6 +722,7 @@
|
|||||||
"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",
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/client/cli",
|
"github.com/cosmos/cosmos-sdk/x/auth/client/cli",
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/auth/client/context",
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank",
|
"github.com/cosmos/cosmos-sdk/x/bank",
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/client/cli",
|
"github.com/cosmos/cosmos-sdk/x/bank/client/cli",
|
||||||
"github.com/cosmos/cosmos-sdk/x/mock",
|
"github.com/cosmos/cosmos-sdk/x/mock",
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
|
|
||||||
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
|
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/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/cmd"
|
paychancmd "github.com/kava-labs/kava/internal/x/paychan/client/cli"
|
||||||
|
|
||||||
"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"
|
||||||
|
@ -3,6 +3,7 @@ package cli
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -10,9 +11,11 @@ import (
|
|||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/context"
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||||
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"
|
||||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||||
|
authctx "github.com/cosmos/cosmos-sdk/x/auth/client/context"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/internal/x/paychan"
|
"github.com/kava-labs/kava/internal/x/paychan"
|
||||||
)
|
)
|
||||||
@ -31,13 +34,15 @@ func CreateChannelCmd(cdc *wire.Codec) *cobra.Command {
|
|||||||
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 tx and cli "contexts": structs populated with info from common flags.
|
||||||
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
|
txCtx := authctx.NewTxContextFromCLI().WithCodec(cdc)
|
||||||
// TODO is this needed for channelID
|
cliCtx := context.NewCLIContext().
|
||||||
// ctx.PrintResponse = true
|
WithCodec(cdc).
|
||||||
|
WithLogger(os.Stdout).
|
||||||
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||||
|
|
||||||
// Get sender adress
|
// Get sender address
|
||||||
sender, err := ctx.GetFromAddress()
|
sender, err := cliCtx.GetFromAddress()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -67,11 +72,7 @@ func CreateChannelCmd(cdc *wire.Codec) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build and sign the transaction, then broadcast to the blockchain
|
// Build and sign the transaction, then broadcast to the blockchain
|
||||||
err = ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, []sdk.Msg{msg}, cdc)
|
return utils.SendTx(txCtx, cliCtx, []sdk.Msg{msg})
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().String(flagTo, "", "Recipient address of the payment channel.")
|
cmd.Flags().String(flagTo, "", "Recipient address of the payment channel.")
|
||||||
@ -92,8 +93,11 @@ func GeneratePaymentCmd(cdc *wire.Codec) *cobra.Command {
|
|||||||
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 cli "context": struct populated with info from common flags.
|
||||||
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
|
cliCtx := context.NewCLIContext().
|
||||||
|
WithCodec(cdc).
|
||||||
|
WithLogger(os.Stdout).
|
||||||
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||||
|
|
||||||
// Get the paychan id
|
// Get the paychan id
|
||||||
id := paychan.ChannelID(viper.GetInt64(flagId)) // TODO make this default to pulling id from chain
|
id := paychan.ChannelID(viper.GetInt64(flagId)) // TODO make this default to pulling id from chain
|
||||||
@ -121,8 +125,8 @@ func GeneratePaymentCmd(cdc *wire.Codec) *cobra.Command {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
name := ctx.FromAddressName
|
name := cliCtx.FromAddressName
|
||||||
passphrase, err := ctx.GetPassphraseFromStdin(name)
|
passphrase, err := keys.GetPassphrase(cliCtx.FromAddressName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -169,8 +173,11 @@ func VerifyPaymentCmd(cdc *wire.Codec, paychanStoreName string) *cobra.Command {
|
|||||||
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 cli "context": struct populated with info from common flags.
|
||||||
ctx := context.NewCoreContextFromViper()
|
cliCtx := context.NewCLIContext().
|
||||||
|
WithCodec(cdc).
|
||||||
|
WithLogger(os.Stdout).
|
||||||
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||||
|
|
||||||
// read in update
|
// read in update
|
||||||
bz, err := ioutil.ReadFile(viper.GetString(flagPaymentFile))
|
bz, err := ioutil.ReadFile(viper.GetString(flagPaymentFile))
|
||||||
@ -183,7 +190,7 @@ func VerifyPaymentCmd(cdc *wire.Codec, paychanStoreName string) *cobra.Command {
|
|||||||
cdc.UnmarshalJSON(bz, &update)
|
cdc.UnmarshalJSON(bz, &update)
|
||||||
|
|
||||||
// get the channel from the node
|
// get the channel from the node
|
||||||
res, err := ctx.QueryStore(paychan.GetChannelKey(update.ChannelID), paychanStoreName)
|
res, err := cliCtx.QueryStore(paychan.GetChannelKey(update.ChannelID), paychanStoreName)
|
||||||
if len(res) == 0 || err != nil {
|
if len(res) == 0 || err != nil {
|
||||||
return errors.Errorf("channel with ID '%d' does not exist", update.ChannelID)
|
return errors.Errorf("channel with ID '%d' does not exist", update.ChannelID)
|
||||||
}
|
}
|
||||||
@ -218,12 +225,15 @@ func SubmitPaymentCmd(cdc *wire.Codec) *cobra.Command {
|
|||||||
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 tx and cli "contexts": structs populated with info from common flags.
|
||||||
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
|
txCtx := authctx.NewTxContextFromCLI().WithCodec(cdc)
|
||||||
// ctx.PrintResponse = true TODO is this needed for channelID
|
cliCtx := context.NewCLIContext().
|
||||||
|
WithCodec(cdc).
|
||||||
|
WithLogger(os.Stdout).
|
||||||
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||||
|
|
||||||
// Get sender adress
|
// Get sender address
|
||||||
submitter, err := ctx.GetFromAddress()
|
submitter, err := cliCtx.GetFromAddress()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -248,11 +258,7 @@ func SubmitPaymentCmd(cdc *wire.Codec) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build and sign the transaction, then broadcast to the blockchain
|
// Build and sign the transaction, then broadcast to the blockchain
|
||||||
err = ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, []sdk.Msg{msg}, cdc)
|
return utils.SendTx(txCtx, cliCtx, []sdk.Msg{msg})
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().String(flagPaymentFile, "payment.json", "File to read the payment from.")
|
cmd.Flags().String(flagPaymentFile, "payment.json", "File to read the payment from.")
|
||||||
@ -268,14 +274,17 @@ func GetChannelCmd(cdc *wire.Codec, paychanStoreName string) *cobra.Command {
|
|||||||
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 cli "context": struct populated with info from common flags.
|
||||||
ctx := context.NewCoreContextFromViper()
|
cliCtx := context.NewCLIContext().
|
||||||
|
WithCodec(cdc).
|
||||||
|
WithLogger(os.Stdout).
|
||||||
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||||
|
|
||||||
// Get channel ID
|
// Get channel ID
|
||||||
id := paychan.ChannelID(viper.GetInt64(flagId))
|
id := paychan.ChannelID(viper.GetInt64(flagId))
|
||||||
|
|
||||||
// Get the channel from the node
|
// Get the channel from the node
|
||||||
res, err := ctx.QueryStore(paychan.GetChannelKey(id), paychanStoreName)
|
res, err := cliCtx.QueryStore(paychan.GetChannelKey(id), paychanStoreName)
|
||||||
if len(res) == 0 || err != nil {
|
if len(res) == 0 || err != nil {
|
||||||
return errors.Errorf("channel with ID '%d' does not exist", id)
|
return errors.Errorf("channel with ID '%d' does not exist", id)
|
||||||
}
|
}
|
||||||
@ -291,11 +300,11 @@ func GetChannelCmd(cdc *wire.Codec, paychanStoreName string) *cobra.Command {
|
|||||||
fmt.Println(string(jsonChannel))
|
fmt.Println(string(jsonChannel))
|
||||||
|
|
||||||
// Get any submitted updates from the node
|
// Get any submitted updates from the node
|
||||||
res, err = ctx.QueryStore(paychan.GetSubmittedUpdateKey(id), paychanStoreName)
|
res, err = cliCtx.QueryStore(paychan.GetSubmittedUpdateKey(id), paychanStoreName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Print out the submited update if it exsits
|
// Print out the submitted update if it exists
|
||||||
if len(res) != 0 {
|
if len(res) != 0 {
|
||||||
var submittedUpdate paychan.SubmittedUpdate
|
var submittedUpdate paychan.SubmittedUpdate
|
||||||
cdc.MustUnmarshalBinary(res, &submittedUpdate)
|
cdc.MustUnmarshalBinary(res, &submittedUpdate)
|
||||||
|
Loading…
Reference in New Issue
Block a user