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(wallet): adding all account address functions #1128

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 1 addition & 2 deletions cmd/gtk/dialog_transaction_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func broadcastTransactionBond(wlt *wallet.Wallet) {
getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon())
getButtonObj(builder, "id_button_send").SetImage(SendIcon())

// TODO: we need something like: wlt.AllAccountAddresses()
for _, ai := range wlt.AddressInfos() {
for _, ai := range wlt.AllAccountAddresses() {
senderEntry.Append(ai.Address, ai.Address)
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/gtk/dialog_transaction_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func broadcastTransactionTransfer(wlt *wallet.Wallet) {
getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon())
getButtonObj(builder, "id_button_send").SetImage(SendIcon())

// TODO: we need something like: wlt.AllAccountAddresses()
for _, i := range wlt.AddressInfos() {
for _, i := range wlt.AllAccountAddresses() {
senderEntry.Append(i.Address, i.Address)
}
senderEntry.SetActive(0)
Expand Down
15 changes: 15 additions & 0 deletions wallet/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,21 @@ func (v *Vault) AllValidatorAddresses() []AddressInfo {
return addrs
}

func (v *Vault) AllAccountAddresses() []AddressInfo {
addrs := make([]AddressInfo, 0, v.AddressCount()/2)
for _, addrInfo := range v.Addresses {
addrPath, _ := addresspath.NewPathFromString(addrInfo.Path)
if addrPath.AddressType() != H(crypto.AddressTypeValidator) {
addrs = append(addrs, addrInfo)
}
}

v.SortAddressesByAddressIndex(addrs...)
v.SortAddressesByPurpose(addrs...)

return addrs
}

func (v *Vault) AllImportedPrivateKeysAddresses() []AddressInfo {
addrs := make([]AddressInfo, 0, v.AddressCount()/2)
for _, addrInfo := range v.Addresses {
Expand Down
17 changes: 17 additions & 0 deletions wallet/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ func TestSortAddressInfo(t *testing.T) {
assert.Equal(t, "m/65535'/21888'/2'/0'", infos[len(infos)-1].Path)
}

func TestAllAccountAddresses(t *testing.T) {
td := setup(t)

assert.Equal(t, td.vault.AddressCount(), 6)

accountAddrs := td.vault.AllAccountAddresses()
for _, i := range accountAddrs {
info := td.vault.AddressInfo(i.Address)
kehiy marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, i.Address, info.Address)

addr, err := crypto.AddressFromString(info.Address)
assert.NoError(t, err)

assert.True(t, addr.Type() == crypto.AddressTypeBLSAccount)
}
}

func TestAllValidatorAddresses(t *testing.T) {
td := setup(t)

Expand Down
4 changes: 4 additions & 0 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@
return w.store.Vault.AllValidatorAddresses()
}

func (w *Wallet) AllAccountAddresses() []vault.AddressInfo {
return w.store.Vault.AllAccountAddresses()

Check warning on line 405 in wallet/wallet.go

View check run for this annotation

Codecov / codecov/patch

wallet/wallet.go#L405

Added line #L405 was not covered by tests
}

func (w *Wallet) AddressFromPath(p string) *vault.AddressInfo {
return w.store.Vault.AddressFromPath(p)
}
Expand Down
Loading