Skip to content

Commit

Permalink
feat(cmd): pactus-wallet add info commands
Browse files Browse the repository at this point in the history
  • Loading branch information
maxipaz committed Sep 4, 2024
1 parent 1c6ddfe commit 88482d2
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/wallet/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func buildShowHistoryCmd(parentCmd *cobra.Command) {
wlt, err := openWallet()
cmd.FatalErrorCheck(err)

history := wlt.GetHistory(addr)
history := wlt.History(addr)
for i, h := range history {
if h.Time != nil {
cmd.PrintInfoMsgf("%d %v %v %v %s\t%v",
Expand Down
28 changes: 28 additions & 0 deletions cmd/wallet/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"time"

"github.com/pactus-project/pactus/cmd"
"github.com/spf13/cobra"
)

// buildInfoCmd builds all sub-commands related to the wallet information.
func buildInfoCmd(parentCmd *cobra.Command) {
infoCmd := &cobra.Command{
Use: "info",
Short: "retrieving the wallet information.",
}

parentCmd.AddCommand(infoCmd)

infoCmd.Run = func(_ *cobra.Command, _ []string) {
wlt, err := openWallet()
cmd.FatalErrorCheck(err)

cmd.PrintInfoMsgf("version: %d", wlt.Version())
cmd.PrintInfoMsgf("created at: %s", wlt.CreationTime().Format(time.RFC3339))
cmd.PrintInfoMsgf("is encrtypted: %t", wlt.IsEncrypted())
cmd.PrintInfoMsgf("network: %s", wlt.Network().String())
}
}
1 change: 1 addition & 0 deletions cmd/wallet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func main() {
buildAllTransactionCmd(rootCmd)
buildAllAddrCmd(rootCmd)
buildAllHistoryCmd(rootCmd)
buildInfoCmd(rootCmd)

err := rootCmd.Execute()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions wallet/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func TestGetHistory(t *testing.T) {
td := setup(t)
defer td.Close()

history := td.wallet.GetHistory(td.RandAccAddress().String())
history := td.wallet.History(td.RandAccAddress().String())
assert.Empty(t, history)
}

Expand All @@ -23,6 +23,6 @@ func TestAddDuplicatedTrx(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, trx.ID().String(), id)

history := td.wallet.GetHistory(trx.Payload().Signer().String())
history := td.wallet.History(trx.Payload().Signer().String())
assert.Equal(t, id, history[0].TxID)
}
2 changes: 1 addition & 1 deletion wallet/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (wm *Manager) AddressHistory(
return nil, status.Errorf(codes.NotFound, "wallet is not loaded")
}

return wlt.GetHistory(address), nil
return wlt.History(address), nil
}

func (wm *Manager) SignMessage(walletName, password, addr, msg string) (string, error) {
Expand Down
14 changes: 13 additions & 1 deletion wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (w *Wallet) AddTransaction(id tx.ID) error {
return nil
}

func (w *Wallet) GetHistory(addr string) []HistoryInfo {
func (w *Wallet) History(addr string) []HistoryInfo {
return w.store.History.getAddrHistory(addr)
}

Expand All @@ -502,3 +502,15 @@ func (w *Wallet) SignMessage(password, addr, msg string) (string, error) {

return prv.Sign([]byte(msg)).String(), nil
}

func (w *Wallet) Version() int {
return w.store.Version
}

func (w *Wallet) CreationTime() time.Time {
return w.store.CreatedAt
}

func (w *Wallet) Network() genesis.ChainType {
return w.store.Network
}

0 comments on commit 88482d2

Please sign in to comment.