Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd): pactus-wallet add info commands #1496

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading