Expose credit tx to cli and test
This commit is contained in:
@@ -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 <amt><coin>,<amt><coin>...")
|
||||
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 <amt><coin>,<amt><coin>...")
|
||||
}
|
||||
|
||||
// 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 == "" {
|
||||
|
||||
+7
-3
@@ -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"
|
||||
)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
// nolint
|
||||
const (
|
||||
ByteFees = 0x21
|
||||
ByteFees = 0x28
|
||||
TypeFees = NameFee + "/tx"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user