Skip to content

Commit

Permalink
Merge branch 'main' into test/update-crypto-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad authored Sep 23, 2024
2 parents 403549d + 864cd2d commit 2bfe541
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/wallet/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func buildNewAddressCmd(parentCmd *cobra.Command) {
parentCmd.AddCommand(newAddressCmd)

addressType := newAddressCmd.Flags().String("type",
wallet.AddressTypeBLSAccount, "the type of address: bls_account or validator")
wallet.AddressTypeBLSAccount, "the type of address: bls_account, ed25519_account and validator")

newAddressCmd.Run = func(_ *cobra.Command, _ []string) {
var addressInfo *vault.AddressInfo
Expand Down
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: 4 additions & 0 deletions cmd/wallet/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func buildTransferTxCmd(parentCmd *cobra.Command) {
cmd.PrintInfoMsgf("To : %s", to)
cmd.PrintInfoMsgf("Amount: %s", amt)
cmd.PrintInfoMsgf("Fee : %s", trx.Fee())
cmd.PrintInfoMsgf("Memo : %s", trx.Memo())

signAndPublishTx(wlt, trx, *noConfirmOpt, *passOpt)
}
Expand Down Expand Up @@ -106,6 +107,7 @@ func buildBondTxCmd(parentCmd *cobra.Command) {
cmd.PrintInfoMsgf("Validator: %s", to)
cmd.PrintInfoMsgf("Stake : %s", amt)
cmd.PrintInfoMsgf("Fee : %s", trx.Fee())
cmd.PrintInfoMsgf("Memo : %s", trx.Memo())

signAndPublishTx(wlt, trx, *noConfirmOpt, *passOpt)
}
Expand Down Expand Up @@ -145,6 +147,7 @@ func buildUnbondTxCmd(parentCmd *cobra.Command) {
cmd.PrintInfoMsgf("You are going to sign this \033[1mUnbond\033[0m transition:")
cmd.PrintInfoMsgf("Validator: %s", from)
cmd.PrintInfoMsgf("Fee : %s", trx.Fee())
cmd.PrintInfoMsgf("Memo : %s", trx.Memo())

signAndPublishTx(wlt, trx, *noConfirmOpt, *passOpt)
}
Expand Down Expand Up @@ -189,6 +192,7 @@ func buildWithdrawTxCmd(parentCmd *cobra.Command) {
cmd.PrintInfoMsgf("Account : %s", to)
cmd.PrintInfoMsgf("Amount : %s", amt)
cmd.PrintInfoMsgf("Fee : %s", trx.Fee())
cmd.PrintInfoMsgf("Memo : %s", trx.Memo())

signAndPublishTx(wlt, trx, *noConfirmOpt, *passOpt)
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ func checkConsensus(td *testData, height uint32, byzVotes []*vote.Vote) (
m := rndMsg.message.(*message.QueryProposalMessage)
if m.Height == height {
for _, cons := range instances {
p := cons.HandleQueryProposal(m.Height, m.Round)
p := cons.Proposal()
if p != nil {
td.consMessages = append(td.consMessages, consMessage{
sender: cons.valKey.Address(),
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 2bfe541

Please sign in to comment.