Skip to content

Commit

Permalink
Synced Kaspad latest changes:
Browse files Browse the repository at this point in the history
From 40ec440dcf908dc3eccd1c4f123aee351b0466f7 to HEAD
  • Loading branch information
Pyrinpyi committed Sep 11, 2024
1 parent accd2d6 commit b989c96
Show file tree
Hide file tree
Showing 23 changed files with 590 additions and 183 deletions.
3 changes: 2 additions & 1 deletion app/rpc/rpchandlers/submit_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func HandleSubmitTransaction(context *rpccontext.Context, _ *router.Router, requ
}

log.Debugf("Rejected transaction %s: %s", transactionID, err)
errorMessage := &appmessage.SubmitTransactionResponseMessage{}
// Return the ID also in the case of error, so that clients can match the response to the correct transaction submit request
errorMessage := appmessage.NewSubmitTransactionResponseMessage(transactionID.String())
errorMessage.Error = appmessage.RPCErrorf("Rejected transaction %s: %s", transactionID, err)
return errorMessage, nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/pyrinwallet/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func balance(conf *balanceConfig) error {
println("Address Available Pending")
println("-----------------------------------------------------------------------------------------------------------")
for _, addressBalance := range response.AddressBalances {
fmt.Printf("%s %s %s\n", addressBalance.Address, utils.FormatKas(addressBalance.Available), utils.FormatKas(addressBalance.Pending))
fmt.Printf("%s %s %s\n", addressBalance.Address, utils.FormatPyi(addressBalance.Available), utils.FormatPyi(addressBalance.Pending))
}
println("-----------------------------------------------------------------------------------------------------------")
print(" ")
}
fmt.Printf("Total balance, PYI %s %s%s\n", utils.FormatKas(response.Available), utils.FormatKas(response.Pending), pendingSuffix)
fmt.Printf("Total balance, PYI %s %s%s\n", utils.FormatPyi(response.Available), utils.FormatPyi(response.Pending), pendingSuffix)

return nil
}
31 changes: 23 additions & 8 deletions cmd/pyrinwallet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"os"

"github.com/Pyrinpyi/pyipad/infrastructure/config"
"github.com/pkg/errors"

"github.com/jessevdk/go-flags"
"github.com/pkg/errors"
)

const (
Expand All @@ -22,6 +21,8 @@ const (
newAddressSubCmd = "new-address"
dumpUnencryptedDataSubCmd = "dump-unencrypted-data"
startDaemonSubCmd = "start-daemon"
versionSubCmd = "version"
getDaemonVersionSubCmd = "get-daemon-version"
)

const (
Expand All @@ -30,6 +31,7 @@ const (
)

type configFlags struct {
ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"`
config.NetworkFlags
}

Expand Down Expand Up @@ -57,7 +59,7 @@ type sendConfig struct {
DaemonAddress string `long:"daemonaddress" short:"d" description:"Wallet daemon server to connect to"`
ToAddress string `long:"to-address" short:"t" description:"The public address to send Pyrin to" required:"true"`
FromAddresses []string `long:"from-address" short:"a" description:"Specific public address to send Pyrin from. Use multiple times to accept several addresses" required:"false"`
SendAmount float64 `long:"send-amount" short:"v" description:"An amount to send in Pyrin (e.g. 1234.12345678)"`
SendAmount string `long:"send-amount" short:"v" description:"An amount to send in Pyrin (e.g. 1234.12345678)"`
IsSendAll bool `long:"send-all" description:"Send all the Pyrin in the wallet (mutually exclusive with --send-amount)"`
UseExistingChangeAddress bool `long:"use-existing-change-address" short:"u" description:"Will use an existing change address (in case no change address was ever used, it will use a new one)"`
Verbose bool `long:"show-serialized" short:"s" description:"Show a list of hex encoded sent transactions"`
Expand All @@ -74,7 +76,7 @@ type createUnsignedTransactionConfig struct {
DaemonAddress string `long:"daemonaddress" short:"d" description:"Wallet daemon server to connect to"`
ToAddress string `long:"to-address" short:"t" description:"The public address to send Pyrin to" required:"true"`
FromAddresses []string `long:"from-address" short:"a" description:"Specific public address to send Pyrin from. Use multiple times to accept several addresses" required:"false"`
SendAmount float64 `long:"send-amount" short:"v" description:"An amount to send in Pyrin (e.g. 1234.12345678)"`
SendAmount string `long:"send-amount" short:"v" description:"An amount to send in Pyrin (e.g. 1234.12345678)"`
IsSendAll bool `long:"send-all" description:"Send all the Pyrin in the wallet (mutually exclusive with --send-amount)"`
UseExistingChangeAddress bool `long:"use-existing-change-address" short:"u" description:"Will use an existing change address (in case no change address was ever used, it will use a new one)"`
config.NetworkFlags
Expand Down Expand Up @@ -129,6 +131,13 @@ type dumpUnencryptedDataConfig struct {
config.NetworkFlags
}

type versionConfig struct {
}

type getDaemonVersionConfig struct {
DaemonAddress string `long:"daemonaddress" short:"d" description:"Wallet daemon server to connect to"`
}

func parseCommandLine() (subCommand string, config interface{}) {
cfg := &configFlags{}
parser := flags.NewParser(cfg, flags.PrintErrors|flags.HelpFlag)
Expand Down Expand Up @@ -185,6 +194,9 @@ func parseCommandLine() (subCommand string, config interface{}) {
Listen: defaultListen,
}
parser.AddCommand(startDaemonSubCmd, "Start the wallet daemon", "Start the wallet daemon", startDaemonConf)
parser.AddCommand(versionSubCmd, "Get the wallet version", "Get the wallet version", &versionConfig{})
getDaemonVersionConf := &getDaemonVersionConfig{DaemonAddress: defaultListen}
parser.AddCommand(getDaemonVersionSubCmd, "Get the wallet daemon version", "Get the wallet daemon version", getDaemonVersionConf)

_, err := parser.Parse()
if err != nil {
Expand Down Expand Up @@ -290,23 +302,26 @@ func parseCommandLine() (subCommand string, config interface{}) {
printErrorAndExit(err)
}
config = startDaemonConf
case versionSubCmd:
case getDaemonVersionSubCmd:
config = getDaemonVersionConf
}

return parser.Command.Active.Name, config
}

func validateCreateUnsignedTransactionConf(conf *createUnsignedTransactionConfig) error {
if (!conf.IsSendAll && conf.SendAmount == 0) ||
(conf.IsSendAll && conf.SendAmount > 0) {
if (!conf.IsSendAll && conf.SendAmount == "") ||
(conf.IsSendAll && conf.SendAmount != "") {

return errors.New("exactly one of '--send-amount' or '--all' must be specified")
}
return nil
}

func validateSendConfig(conf *sendConfig) error {
if (!conf.IsSendAll && conf.SendAmount == 0) ||
(conf.IsSendAll && conf.SendAmount > 0) {
if (!conf.IsSendAll && conf.SendAmount == "") ||
(conf.IsSendAll && conf.SendAmount != "") {

return errors.New("exactly one of '--send-amount' or '--all' must be specified")
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/pyrinwallet/create_unsigned_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
"context"
"fmt"
"github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/utils"
"os"

"github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/daemon/client"
"github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/daemon/pb"
"github.com/Pyrinpyi/pyipad/domain/consensus/utils/constants"
)

func createUnsignedTransaction(conf *createUnsignedTransactionConfig) error {
Expand All @@ -20,7 +20,12 @@ func createUnsignedTransaction(conf *createUnsignedTransactionConfig) error {
ctx, cancel := context.WithTimeout(context.Background(), daemonTimeout)
defer cancel()

sendAmountLeor := uint64(conf.SendAmount * constants.LeorPerPyrin)
sendAmountLeor, err := utils.PyiToLeor(conf.SendAmount)

if err != nil {
return err
}

response, err := daemonClient.CreateUnsignedTransactions(ctx, &pb.CreateUnsignedTransactionsRequest{
From: conf.FromAddresses,
Address: conf.ToAddress,
Expand Down
Loading

0 comments on commit b989c96

Please sign in to comment.