wallet: improve wallet balance output

eg.

Total Balance:  241.848409 XMR

0       Address 53G25UfvJkvKZpJk3LgKTebdLwcxVQxSrWcwLHJUtWYHPZX6PrwggUN1PisbZG81YkJNVEgpCUMBKE8Dkaqn4CpsPUA91AX
~       Label:          Primary account
~       UTXOs           35
~       Balance:        241.848409 XMR

Signed-off-by: Ciro S. Costa <utxobr@protonmail.com>
This commit is contained in:
Ciro S. Costa 2021-07-20 19:06:15 -04:00
parent 2b2bf3eba6
commit da578aee01
3 changed files with 70 additions and 60 deletions

View file

@ -59,40 +59,49 @@ func (c *getBalanceCommand) RunE(_ *cobra.Command, _ []string) error {
// nolint:forbidigo
func (c *getBalanceCommand) pretty(v *wallet.GetBalanceResult) {
c.prettyTotal(v)
for _, saddr := range v.PerSubaddress {
c.prettySubAddress(saddr)
}
}
func (c *getBalanceCommand) prettyTotal(v *wallet.GetBalanceResult) {
table := display.NewTable()
table.AddRow("BALANCE", fmt.Sprintf("%f XMR",
table.AddRow("Total Balance:", fmt.Sprintf("%f XMR",
float64(v.Balance)/float64(constant.XMR)))
if v.BlocksToUnlock > 0 {
table.AddRow("UNLOCKED BALANCE", fmt.Sprintf("%f XMR",
table.AddRow("Total Unlocked Balance:", fmt.Sprintf("%f XMR",
float64(v.UnlockedBalance)/float64(constant.XMR)))
table.AddRow("BLOCKS TO UNLOCK", v.BlocksToUnlock)
table.AddRow("TIME TO UNLOCK (s)", v.TimeToUnlock)
table.AddRow("Total Blocks to Unlock:", v.BlocksToUnlock)
table.AddRow("Total Time to Unlock (s):", v.TimeToUnlock)
}
if v.MultisigImportNeeded {
table.AddRow("MULTISIG IMPORT NEEDED", v.MultisigImportNeeded)
table.AddRow("Multisig Import Needed:", v.MultisigImportNeeded)
}
fmt.Println(table)
}
func (c *getBalanceCommand) prettySubAddress(saddr wallet.SubAddress) {
table := display.NewTable()
table.AddRow("")
table.AddRow(saddr.AccountIndex, "Address", saddr.Address)
table.AddRow("~", "Label:", saddr.Label)
table.AddRow("~", "UTXOs", saddr.NumUnspentOutputs)
table.AddRow("~", "Balance:", fmt.Sprintf("%f XMR",
float64(saddr.Balance)/float64(constant.XMR)))
for _, saddr := range v.PerSubaddress {
table.AddRow("", "ACCOUNT IDX", saddr.AccountIndex)
table.AddRow("", "ADDRESS IDX", saddr.AddressIndex)
table.AddRow("", "ADDRESS", saddr.Address)
table.AddRow("", "LABEL", saddr.Label)
table.AddRow("", "UTXOs", saddr.NumUnspentOutputs)
table.AddRow("", "BALANCE", fmt.Sprintf("%f XMR",
float64(saddr.Balance)/float64(constant.XMR)))
if saddr.BlocksToUnlock > 0 {
table.AddRow("", "BLOCKS TO UNLOCK", saddr.BlocksToUnlock)
table.AddRow("", "TIME TO UNLOCK", saddr.TimeToUnlock)
table.AddRow("", "UNLOCKED BALANCE", fmt.Sprintf("%f XMR",
float64(saddr.UnlockedBalance)/float64(constant.XMR)))
}
if saddr.BlocksToUnlock > 0 {
table.AddRow("~", "Blocks to Unlock:", saddr.BlocksToUnlock)
table.AddRow("~", "Time to Unlock:", saddr.TimeToUnlock)
table.AddRow("~", "Unlocked Balance:", fmt.Sprintf("%f XMR",
float64(saddr.UnlockedBalance)/float64(constant.XMR)))
}
fmt.Println(table)

View file

@ -27,8 +27,7 @@ func JSON(v interface{}) error {
func NewTable() *uitable.Table {
table := uitable.New()
table.MaxColWidth = 80
table.Wrap = true
table.MaxColWidth = 160
return table
}

View file

@ -19,44 +19,7 @@ type GetBalanceResult struct {
// PerSubaddress is an array of subaddress information; Balance
// information for each subaddress in an account.
//
PerSubaddress []struct {
// AccountIndex is the index of the account.
//
AccountIndex uint `json:"account_index"`
// Address at this index. Base58 representation of the public
// keys.
//
Address string `json:"address"`
// AddressIndex is the index of the subaddress in the account.
//
AddressIndex uint `json:"address_index"`
// Balance is the balance for the subaddress.
//
Balance uint64 `json:"balance"`
// BlocksToUnlock TODO
//
BlocksToUnlock uint `json:"blocks_to_unlock"`
// Label TODO
//
Label string `json:"label"`
// NumUnspentOutputs TODO
//
NumUnspentOutputs uint `json:"num_unspent_outputs"`
// TimeToUnlock TODO
//
TimeToUnlock uint `json:"time_to_unlock"`
// UnlockedBalance TODO
//
UnlockedBalance int64 `json:"unlocked_balance"`
} `json:"per_subaddress"`
PerSubaddress []SubAddress `json:"per_subaddress"`
// TimeToUnlock TODO
//
@ -66,3 +29,42 @@ type GetBalanceResult struct {
//
UnlockedBalance int64 `json:"unlocked_balance"`
}
type SubAddress struct {
// AccountIndex is the index of the account.
//
AccountIndex uint `json:"account_index"`
// Address at this index. Base58 representation of the public
// keys.
//
Address string `json:"address"`
// AddressIndex is the index of the subaddress in the account.
//
AddressIndex uint `json:"address_index"`
// Balance is the balance for the subaddress.
//
Balance uint64 `json:"balance"`
// BlocksToUnlock TODO
//
BlocksToUnlock uint `json:"blocks_to_unlock"`
// Label TODO
//
Label string `json:"label"`
// NumUnspentOutputs TODO
//
NumUnspentOutputs uint `json:"num_unspent_outputs"`
// TimeToUnlock TODO
//
TimeToUnlock uint `json:"time_to_unlock"`
// UnlockedBalance TODO
//
UnlockedBalance int64 `json:"unlocked_balance"`
}