mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* Add "sweep" command to kaspawallet * minor linting & layout improvements. * contain code in "sweep" * update to sweep.go * formatting and bugs * clean up renaming of ExtractTransaction functions * Nicer formating of display * address reveiw. * one more sweeped -> swept * missed one reveiw comment. (extra mass). * remove redundant code from split function. Co-authored-by: Ori Newman <orinewman1@gmail.com>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/utils"
|
|
)
|
|
|
|
func balance(conf *balanceConfig) error {
|
|
daemonClient, tearDown, err := client.Connect(conf.DaemonAddress)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer tearDown()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), daemonTimeout)
|
|
defer cancel()
|
|
response, err := daemonClient.GetBalance(ctx, &pb.GetBalanceRequest{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
pendingSuffix := ""
|
|
if response.Pending > 0 {
|
|
pendingSuffix = " (pending)"
|
|
}
|
|
if conf.Verbose {
|
|
pendingSuffix = ""
|
|
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))
|
|
}
|
|
println("-----------------------------------------------------------------------------------------------------------")
|
|
print(" ")
|
|
}
|
|
fmt.Printf("Total balance, KAS %s %s%s\n", utils.FormatKas(response.Available), utils.FormatKas(response.Pending), pendingSuffix)
|
|
|
|
return nil
|
|
}
|