diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go index 490da2989..934b3df2b 100644 --- a/cmd/basecli/main.go +++ b/cmd/basecli/main.go @@ -65,6 +65,7 @@ func main() { txcmd.RootCmd.AddCommand( // This is the default transaction, optional in your app coincmd.SendTxCmd, + coincmd.CreditTxCmd, // this enables creating roles rolecmd.CreateRoleTxCmd, // these are for handling ibc diff --git a/cmd/basecoin/commands/init.go b/cmd/basecoin/commands/init.go index bd63ca2ad..ce9bcff40 100644 --- a/cmd/basecoin/commands/init.go +++ b/cmd/basecoin/commands/init.go @@ -122,7 +122,7 @@ func GetGenesisJSON(chainID, addr string) string { ] }], "plugin_options": [ - "coin/issuer", {"app": "sigs", "address": "%s"} + "coin/issuer", {"app": "sigs", "addr": "%s"} ] } }`, chainID, addr, addr) diff --git a/modules/coin/commands/tx.go b/modules/coin/commands/tx.go index 4f130ed8b..aa23fab82 100644 --- a/modules/coin/commands/tx.go +++ b/modules/coin/commands/tx.go @@ -17,6 +17,13 @@ var SendTxCmd = &cobra.Command{ RunE: commands.RequireInit(sendTxCmd), } +// CreditTxCmd is CLI command to issue credit to one account +var CreditTxCmd = &cobra.Command{ + Use: "credit", + Short: "issue credit to one account", + RunE: commands.RequireInit(creditTxCmd), +} + //nolint const ( FlagTo = "to" @@ -29,9 +36,12 @@ func init() { flags.String(FlagTo, "", "Destination address for the bits") flags.String(FlagAmount, "", "Coins to send in the format ,...") flags.String(FlagFrom, "", "Address sending coins, if not first signer") + + fs2 := CreditTxCmd.Flags() + fs2.String(FlagTo, "", "Destination address for the bits") + fs2.String(FlagAmount, "", "Coins to send in the format ,...") } -// sendTxCmd is an example of how to make a tx func sendTxCmd(cmd *cobra.Command, args []string) error { tx, err := readSendTxFlags() if err != nil { @@ -62,6 +72,30 @@ func readSendTxFlags() (tx basecoin.Tx, err error) { return } +func creditTxCmd(cmd *cobra.Command, args []string) error { + tx, err := readCreditTxFlags() + if err != nil { + return err + } + return txcmd.DoTx(tx) +} + +func readCreditTxFlags() (tx basecoin.Tx, err error) { + // parse to address + toAddr, err := commands.ParseActor(viper.GetString(FlagTo)) + if err != nil { + return tx, err + } + + amount, err := coin.ParseCoins(viper.GetString(FlagAmount)) + if err != nil { + return tx, err + } + + tx = coin.CreditTx{Debitor: toAddr, Credit: amount}.Wrap() + return +} + func readFromAddr() (basecoin.Actor, error) { from := viper.GetString(FlagFrom) if from == "" { diff --git a/modules/coin/tx.go b/modules/coin/tx.go index 9dfcffc11..bc5f77e44 100644 --- a/modules/coin/tx.go +++ b/modules/coin/tx.go @@ -7,13 +7,17 @@ import ( ) func init() { - basecoin.TxMapper.RegisterImplementation(SendTx{}, TypeSend, ByteSend) + basecoin.TxMapper. + RegisterImplementation(SendTx{}, TypeSend, ByteSend). + RegisterImplementation(CreditTx{}, TypeCredit, ByteCredit) } // we reserve the 0x20-0x3f range for standard modules const ( - ByteSend = 0x20 - TypeSend = NameCoin + "/send" + ByteSend = 0x20 + TypeSend = NameCoin + "/send" + ByteCredit = 0x21 + TypeCredit = NameCoin + "/credit" ) //----------------------------------------------------------------------------- diff --git a/modules/fee/tx.go b/modules/fee/tx.go index d2f61f732..20ce861fd 100644 --- a/modules/fee/tx.go +++ b/modules/fee/tx.go @@ -7,7 +7,7 @@ import ( // nolint const ( - ByteFees = 0x21 + ByteFees = 0x28 TypeFees = NameFee + "/tx" ) diff --git a/tests/cli/basictx.sh b/tests/cli/basictx.sh index d6ab7ea9e..dadc833c7 100755 --- a/tests/cli/basictx.sh +++ b/tests/cli/basictx.sh @@ -83,6 +83,23 @@ test02SendTxWithFee() { } +test03CreditTx() { + SENDER=$(getAddr $RICH) + RECV=$(getAddr $POOR) + + # make sure we are controlled by permissions (only rich can issue credit) + assertFalse "line=${LINENO}, bad password" "echo qwertyuiop | ${CLIENT_EXE} tx credit --amount=1000mycoin --sequence=1 --to=$RECV --name=$POOR" + TX=$(echo qwertyuiop | ${CLIENT_EXE} tx credit --amount=1000mycoin --sequence=3 --to=$RECV --name=$RICH) + txSucceeded $? "$TX" "$RECV" + HASH=$(echo $TX | jq .hash | tr -d \") + TX_HEIGHT=$(echo $TX | jq .height) + + # receiver got cash, sender didn't lose any (1000 more than last check) + checkAccount $RECV "2082" + checkAccount $SENDER "9007199254739900" +} + + # Load common then run these tests with shunit2! DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory . $DIR/common.sh