add get-accounts; add addr shortener

$ monero wallet get-accounts
Total Balance:          390.31 ɱ
Total Unlocked Balance: 390.31 ɱ

        LABEL           TAG     ADDR            BALANCE         UNLOCKED BALANCE
0       Primary account         53G25..A91AX    389.31 ɱ        389.31 ɱ
1       test                    72vD5..43SXV    1.00 ɱ          1.00 ɱ

Signed-off-by: Ciro S. Costa <utxobr@protonmail.com>
This commit is contained in:
Ciro S. Costa 2021-07-22 07:48:48 -04:00
parent 44b1bdf069
commit 680c4ce417
42 changed files with 255 additions and 86 deletions

View file

@ -34,10 +34,10 @@ func (c *generateBlocksCommand) Cmd() *cobra.Command {
}
func (c *generateBlocksCommand) RunE(cmd *cobra.Command, args []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -28,10 +28,10 @@ func (c *getAlternateChainsCommand) Cmd() *cobra.Command {
}
func (c *getAlternateChainsCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -30,10 +30,10 @@ func (c *getBansCommand) Cmd() *cobra.Command {
}
func (c *getBansCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -46,10 +46,10 @@ func (c *getBlockCommand) Cmd() *cobra.Command {
}
func (c *getBlockCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -28,10 +28,10 @@ func (c *getBlockCountCommand) Cmd() *cobra.Command {
}
func (c *getBlockCountCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -37,10 +37,10 @@ func (c *getBlockHeaderCommand) Cmd() *cobra.Command {
}
func (c *getBlockHeaderCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -36,10 +36,10 @@ func (c *getBlockHeadersRangeCommand) Cmd() *cobra.Command {
}
func (c *getBlockHeadersRangeCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -40,10 +40,10 @@ func (c *getBlockTemplateCommand) Cmd() *cobra.Command {
}
func (c *getBlockTemplateCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -37,10 +37,10 @@ func (c *getCoinbaseTxSumCommand) Cmd() *cobra.Command {
}
func (c *getCoinbaseTxSumCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -31,10 +31,10 @@ func (c *getConnectionsCommand) Cmd() *cobra.Command {
}
func (c *getConnectionsCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -32,10 +32,10 @@ func (c *getFeeEstimateCommand) Cmd() *cobra.Command {
}
func (c *getFeeEstimateCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -30,10 +30,10 @@ including the hash of the most recent block.`,
}
func (c *getHeightCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -28,10 +28,10 @@ func (c *getInfoCommand) Cmd() *cobra.Command {
}
func (c *getInfoCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -28,10 +28,10 @@ func (c *getLastBlockHeaderCommand) Cmd() *cobra.Command {
}
func (c *getLastBlockHeaderCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -30,10 +30,10 @@ func (c *getNetStatsCommand) Cmd() *cobra.Command {
}
func (c *getNetStatsCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -37,10 +37,10 @@ func (c *getOutsCommand) Cmd() *cobra.Command {
}
func (c *getOutsCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -31,10 +31,10 @@ func (c *getPeerListCommand) Cmd() *cobra.Command {
}
func (c *getPeerListCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -44,10 +44,10 @@ func (c *getPublicNodesCommand) Cmd() *cobra.Command {
}
func (c *getPublicNodesCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -45,10 +45,10 @@ func (c *getTransactionCommand) Cmd() *cobra.Command {
}
func (c *getTransactionCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -35,10 +35,10 @@ func (c *getTransactionPoolCommand) Cmd() *cobra.Command {
}
func (c *getTransactionPoolCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -34,10 +34,10 @@ func (c *getTransactionPoolStatsCommand) Cmd() *cobra.Command {
}
func (c *getTransactionPoolStatsCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -28,10 +28,10 @@ func (c *getVersionCommand) Cmd() *cobra.Command {
}
func (c *getVersionCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -28,10 +28,10 @@ func (c *hardForkInfoCommand) Cmd() *cobra.Command {
}
func (c *hardForkInfoCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -28,10 +28,10 @@ func (c *miningStatusCommand) Cmd() *cobra.Command {
}
func (c *miningStatusCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -27,10 +27,10 @@ func (c *onGetBlockHashCommand) Cmd() *cobra.Command {
}
func (c *onGetBlockHashCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -33,10 +33,10 @@ func (c *relayTxCommand) Cmd() *cobra.Command {
}
func (c *relayTxCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -30,10 +30,10 @@ func (c *rpcAccessTrackingCommand) Cmd() *cobra.Command {
}
func (c *rpcAccessTrackingCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -45,10 +45,10 @@ func (c *setBansCommand) Cmd() *cobra.Command {
}
func (c *setBansCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -47,10 +47,10 @@ func (c *startMiningCommand) Cmd() *cobra.Command {
}
func (c *startMiningCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -33,10 +33,10 @@ func (c *stopMiningCommand) Cmd() *cobra.Command {
}
func (c *stopMiningCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -29,10 +29,10 @@ func (c *syncInfoCommand) Cmd() *cobra.Command {
}
func (c *syncInfoCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.Client()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -32,10 +32,10 @@ func (c *autoRefreshCommand) Cmd() *cobra.Command {
}
func (c *autoRefreshCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.WalletClient()
client, err := options.RootOpts.WalletClient()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -39,10 +39,10 @@ func (c *createAddressCommand) Cmd() *cobra.Command {
}
func (c *createAddressCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.WalletClient()
client, err := options.RootOpts.WalletClient()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -0,0 +1,101 @@
package wallet
import (
"fmt"
"github.com/spf13/cobra"
"github.com/cirocosta/go-monero/cmd/monero/display"
"github.com/cirocosta/go-monero/cmd/monero/options"
"github.com/cirocosta/go-monero/pkg/rpc/wallet"
)
type getAccountsCommand struct {
Tag string
StrictBalances bool
JSON bool
}
func (c *getAccountsCommand) Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "get-accounts",
Short: "retrieve wallet's accounts",
RunE: c.RunE,
}
cmd.Flags().BoolVar(&c.JSON, "json",
false, "whether or not to output the result as json")
cmd.Flags().StringVar(&c.Tag, "tag",
"", "only display accounts with this tag")
cmd.Flags().BoolVar(&c.StrictBalances, "strict-balances",
false, "todo")
return cmd
}
func (c *getAccountsCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOpts.WalletClient()
if err != nil {
return fmt.Errorf("client: %w", err)
}
params := wallet.GetAccountsRequestParameters{
Tag: c.Tag,
StrictBalances: c.StrictBalances,
}
resp, err := client.GetAccounts(ctx, params)
if err != nil {
return fmt.Errorf("get accounts: %w", err)
}
if c.JSON {
return display.JSON(resp)
}
c.pretty(resp)
return nil
}
func (c *getAccountsCommand) pretty(v *wallet.GetAccountsResult) {
c.prettySummary(v)
c.prettyAccounts(v)
}
// nolint:forbidigo
func (c *getAccountsCommand) prettySummary(v *wallet.GetAccountsResult) {
table := display.NewTable()
table.AddRow("Total Balance:", display.XMR(v.TotalBalance))
table.AddRow("Total Unlocked Balance:", display.XMR(v.TotalUnlockedBalance))
table.AddRow("")
fmt.Println(table)
}
// nolint:forbidigo
func (c *getAccountsCommand) prettyAccounts(v *wallet.GetAccountsResult) {
table := display.NewTable()
table.AddRow("", "LABEL", "TAG", "ADDR", "BALANCE", "UNLOCKED BALANCE")
for _, account := range v.SubaddressAccounts {
table.AddRow(
account.AccountIndex,
account.Label,
account.Tag,
options.RootOpts.AddrFmter()(account.BaseAddress),
display.XMR(account.Balance),
display.XMR(account.UnlockedBalance),
)
}
fmt.Println(table)
}
func init() {
RootCommand.AddCommand((&getAccountsCommand{}).Cmd())
}

View file

@ -36,10 +36,10 @@ func (c *getAddressCommand) Cmd() *cobra.Command {
}
func (c *getAddressCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.WalletClient()
client, err := options.RootOpts.WalletClient()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -45,10 +45,10 @@ func (c *getBalanceCommand) Cmd() *cobra.Command {
}
func (c *getBalanceCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.WalletClient()
client, err := options.RootOpts.WalletClient()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -28,10 +28,10 @@ func (c *getHeightCommand) Cmd() *cobra.Command {
}
func (c *getHeightCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.WalletClient()
client, err := options.RootOpts.WalletClient()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -33,10 +33,10 @@ func (c *refreshCommand) Cmd() *cobra.Command {
}
func (c *refreshCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOptions.Context()
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOptions.WalletClient()
client, err := options.RootOpts.WalletClient()
if err != nil {
return fmt.Errorf("client: %w", err)
}

View file

@ -6,6 +6,8 @@ import (
"os"
"github.com/gosuri/uitable"
"github.com/cirocosta/go-monero/pkg/constant"
)
// JSON pushes to stdout a pretty printed representation of a given value `v`.
@ -31,3 +33,15 @@ func NewTable() *uitable.Table {
return table
}
func XMR(v uint64) string {
return fmt.Sprintf("%.2f ɱ", float64(v)/float64(constant.XMR))
}
func ShortenAddress(addr string) string {
if len(addr) < 10 {
return addr
}
return addr[:5] + ".." + addr[len(addr)-5:]
}

View file

@ -8,15 +8,16 @@ import (
"github.com/spf13/cobra"
"github.com/cirocosta/go-monero/cmd/monero/display"
mhttp "github.com/cirocosta/go-monero/pkg/http"
"github.com/cirocosta/go-monero/pkg/rpc"
"github.com/cirocosta/go-monero/pkg/rpc/daemon"
"github.com/cirocosta/go-monero/pkg/rpc/wallet"
)
// RootOptions are global options available to all commands under this package.
// RootOpts are global options available to all commands under this package.
//
var RootOptions = &options{}
var RootOpts = &options{}
// options is a set of flags that are shared between all commands in this
// package.
@ -24,6 +25,20 @@ var RootOptions = &options{}
type options struct {
address string
mhttp.ClientConfig
shortenAddresses bool
}
// AddrFmter provides the function that should be used when displaying
// addresses based on the adddresses formatting option.
//
func (o *options) AddrFmter() func(string) string {
if !o.shortenAddresses {
return func(s string) string {
return s
}
}
return display.ShortenAddress
}
// Context generates a new `context.Context` already honouring the deadline
@ -87,47 +102,54 @@ func (o *options) WalletClient() (*wallet.Client, error) {
// can be filled either via comand arguments or environment variables.
//
func Bind(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&RootOptions.Verbose,
cmd.PersistentFlags().BoolVarP(&RootOpts.Verbose,
"verbose", "v",
false,
"dump http requests and responses to stderr")
cmd.PersistentFlags().StringVarP(&RootOptions.address,
cmd.PersistentFlags().BoolVar(&RootOpts.shortenAddresses,
"shorten-addresses",
true,
"whether addresses should be shortened when displaying "+
"pretty results")
cmd.PersistentFlags().StringVarP(&RootOpts.address,
"address", "a",
"http://localhost:18081",
"full address of the monero node to reach out to [MONERO_ADDRESS]")
"full address of the monero node to reach out to "+
"[MONERO_ADDRESS]")
cmd.PersistentFlags().StringVarP(&RootOptions.Username,
cmd.PersistentFlags().StringVarP(&RootOpts.Username,
"username", "u",
"",
"name of the user to use during rpc auth")
cmd.PersistentFlags().StringVarP(&RootOptions.Password,
cmd.PersistentFlags().StringVarP(&RootOpts.Password,
"password", "p",
"",
"password to supply for rpc auth")
cmd.PersistentFlags().BoolVarP(&RootOptions.TLSSkipVerify,
cmd.PersistentFlags().BoolVarP(&RootOpts.TLSSkipVerify,
"tls-skip-verify", "k",
false,
"skip verification of certificate chain and host name")
cmd.PersistentFlags().StringVar(&RootOptions.TLSClientCert,
cmd.PersistentFlags().StringVar(&RootOpts.TLSClientCert,
"tls-client-cert",
"",
"tls client certificate to use when connecting")
cmd.PersistentFlags().StringVar(&RootOptions.TLSClientKey,
cmd.PersistentFlags().StringVar(&RootOpts.TLSClientKey,
"tls-client-key",
"",
"tls client key to use when connecting")
cmd.PersistentFlags().StringVar(&RootOptions.TLSCACert,
cmd.PersistentFlags().StringVar(&RootOpts.TLSCACert,
"tls-ca-cert",
"",
"certificate authority to load")
cmd.PersistentFlags().DurationVar(&RootOptions.RequestTimeout,
cmd.PersistentFlags().DurationVar(&RootOpts.RequestTimeout,
"request-timeout",
1*time.Minute,
"max wait time until considering the request a failure")

View file

@ -8,12 +8,25 @@ import (
const (
methodAutoRefresh = "auto_refresh"
methodCreateAddress = "create_address"
methodGetAccounts = "get_accounts"
methodGetAddress = "get_address"
methodGetBalance = "get_balance"
methodGetHeight = "get_height"
methodRefresh = "refresh"
)
func (c *Client) GetAccounts(
ctx context.Context, params GetAccountsRequestParameters,
) (*GetAccountsResult, error) {
resp := &GetAccountsResult{}
if err := c.JSONRPC(ctx, methodGetAccounts, params, resp); err != nil {
return nil, fmt.Errorf("jsonrpc: %w", err)
}
return resp, nil
}
func (c *Client) GetAddress(
ctx context.Context, params GetAddressRequestParameters,
) (*GetAddressResult, error) {

View file

@ -1,5 +1,24 @@
package wallet
type GetAccountsRequestParameters struct {
Tag string `json:"tag,omitempty"`
StrictBalances bool `json:"strict_balances,omitempty"`
}
type GetAccountsResult struct {
SubaddressAccounts []struct {
AccountIndex uint `json:"account_index"`
Balance uint64 `json:"balance"`
BaseAddress string `json:"base_address"`
Label string `json:"label"`
Tag string `json:"tag"`
UnlockedBalance uint64 `json:"unlocked_balance"`
} `json:"subaddress_accounts"`
TotalBalance uint64 `json:"total_balance"`
TotalUnlockedBalance uint64 `json:"total_unlocked_balance"`
}
type GetAddressRequestParameters struct {
AccountIndex uint `json:"account_index"`
AddressIndices []uint `json:"address_indices"`