Skip to content

Commit

Permalink
chore: removed address related get methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ironman0x7b2 committed Feb 9, 2025
1 parent db06968 commit c4701eb
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 332 deletions.
7 changes: 6 additions & 1 deletion x/deposit/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import (

// SetDeposit stores a deposit in the module's KVStore.
func (k *Keeper) SetDeposit(ctx sdk.Context, deposit v1.Deposit) {
addr, err := sdk.AccAddressFromBech32(deposit.Address)
if err != nil {
panic(err)
}

store := k.Store(ctx)
key := types.DepositKey(deposit.GetAddress())
key := types.DepositKey(addr)
value := k.cdc.MustMarshal(&deposit)

store.Set(key, value)
Expand Down
13 changes: 0 additions & 13 deletions x/deposit/types/v1/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (m *Deposit) GetAddress() sdk.AccAddress {
if m.Address == "" {
return nil
}

addr, err := sdk.AccAddressFromBech32(m.Address)
if err != nil {
panic(err)
}

return addr
}

func (m *Deposit) Validate() error {
if m.Address == "" {
return fmt.Errorf("address cannot be empty")
Expand Down
37 changes: 0 additions & 37 deletions x/deposit/types/v1/deposit_test.go
Original file line number Diff line number Diff line change
@@ -1,50 +1,13 @@
package v1

import (
"reflect"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"

base "github.com/sentinel-official/hub/v12/types"
)

func TestDeposit_GetAddress(t *testing.T) {
type fields struct {
Address string
}
tests := []struct {
name string
fields fields
want sdk.AccAddress
}{
{
"empty",
fields{
Address: base.TestAddrEmpty,
},
nil,
},
{
"20 bytes",
fields{
Address: base.TestBech32AccAddr20Bytes,
},
sdk.AccAddress{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := &Deposit{
Address: tt.fields.Address,
}
if got := d.GetAddress(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAddress() = %v, want %v", got, tt.want)
}
})
}
}

func TestDeposit_Validate(t *testing.T) {
type fields struct {
Address string
Expand Down
14 changes: 12 additions & 2 deletions x/node/keeper/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ import (

// SetActiveNode stores an active node in the module's KVStore.
func (k *Keeper) SetActiveNode(ctx sdk.Context, node v3.Node) {
addr, err := base.NodeAddressFromBech32(node.Address)
if err != nil {
panic(err)
}

store := k.Store(ctx)
key := types.ActiveNodeKey(node.GetAddress())
key := types.ActiveNodeKey(addr)
value := k.cdc.MustMarshal(&node)

store.Set(key, value)
Expand Down Expand Up @@ -55,8 +60,13 @@ func (k *Keeper) DeleteActiveNode(ctx sdk.Context, addr base.NodeAddress) {

// SetInactiveNode stores an inactive node in the module's KVStore.
func (k *Keeper) SetInactiveNode(ctx sdk.Context, node v3.Node) {
addr, err := base.NodeAddressFromBech32(node.Address)
if err != nil {
panic(err)
}

store := k.Store(ctx)
key := types.InactiveNodeKey(node.GetAddress())
key := types.InactiveNodeKey(addr)
value := k.cdc.MustMarshal(&node)

store.Set(key, value)
Expand Down
13 changes: 0 additions & 13 deletions x/node/types/v2/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ import (
v1base "github.com/sentinel-official/hub/v12/types/v1"
)

func (m *Node) GetAddress() base.NodeAddress {
if m.Address == "" {
return nil
}

addr, err := base.NodeAddressFromBech32(m.Address)
if err != nil {
panic(err)
}

return addr
}

func (m *Node) Validate() error {
if m.Address == "" {
return fmt.Errorf("address cannot be empty")
Expand Down
36 changes: 0 additions & 36 deletions x/node/types/v2/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,6 @@ import (
v1base "github.com/sentinel-official/hub/v12/types/v1"
)

func TestNode_GetAddress(t *testing.T) {
type fields struct {
Address string
}
tests := []struct {
name string
fields fields
want base.NodeAddress
}{
{
"address empty",
fields{
Address: base.TestAddrEmpty,
},
nil,
},
{
"address 20 bytes",
fields{
Address: base.TestBech32NodeAddr20Bytes,
},
base.NodeAddress{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := &Node{
Address: tt.fields.Address,
}
if got := m.GetAddress(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAddress() = %v, want %v", got, tt.want)
}
})
}
}

func TestNode_GigabytePrice(t *testing.T) {
type fields struct {
GigabytePrices sdk.Coins
Expand Down
13 changes: 0 additions & 13 deletions x/node/types/v3/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,6 @@ func (m *Node) GetHourlyPrices() v1base.Prices {
return m.HourlyPrices
}

func (m *Node) GetAddress() base.NodeAddress {
if m.Address == "" {
return nil
}

addr, err := base.NodeAddressFromBech32(m.Address)
if err != nil {
panic(err)
}

return addr
}

func (m *Node) Validate() error {
if m.Address == "" {
return fmt.Errorf("address cannot be empty")
Expand Down
14 changes: 12 additions & 2 deletions x/provider/keeper/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import (

// SetActiveProvider stores an active provider in the module's KVStore.
func (k *Keeper) SetActiveProvider(ctx sdk.Context, v v2.Provider) {
addr, err := base.ProvAddressFromBech32(v.Address)
if err != nil {
panic(err)
}

store := k.Store(ctx)
key := types.ActiveProviderKey(v.GetAddress())
key := types.ActiveProviderKey(addr)
value := k.cdc.MustMarshal(&v)

store.Set(key, value)
Expand Down Expand Up @@ -53,8 +58,13 @@ func (k *Keeper) DeleteActiveProvider(ctx sdk.Context, addr base.ProvAddress) {

// SetInactiveProvider stores an inactive provider in the module's KVStore.
func (k *Keeper) SetInactiveProvider(ctx sdk.Context, v v2.Provider) {
addr, err := base.ProvAddressFromBech32(v.Address)
if err != nil {
panic(err)
}

store := k.Store(ctx)
key := types.InactiveProviderKey(v.GetAddress())
key := types.InactiveProviderKey(addr)
value := k.cdc.MustMarshal(&v)

store.Set(key, value)
Expand Down
13 changes: 0 additions & 13 deletions x/provider/types/v2/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ import (
v1base "github.com/sentinel-official/hub/v12/types/v1"
)

func (m *Provider) GetAddress() base.ProvAddress {
if m.Address == "" {
return nil
}

addr, err := base.ProvAddressFromBech32(m.Address)
if err != nil {
panic(err)
}

return addr
}

func (m *Provider) Validate() error {
if m.Address == "" {
return fmt.Errorf("address cannot be empty")
Expand Down
45 changes: 0 additions & 45 deletions x/provider/types/v2/provider_test.go
Original file line number Diff line number Diff line change
@@ -1,58 +1,13 @@
package v2

import (
"reflect"
"strings"
"testing"

base "github.com/sentinel-official/hub/v12/types"
v1base "github.com/sentinel-official/hub/v12/types/v1"
)

func TestProvider_GetAddress(t *testing.T) {
type fields struct {
Address string
Name string
Identity string
Website string
Description string
}
tests := []struct {
name string
fields fields
want base.ProvAddress
}{
{
"empty",
fields{
Address: base.TestAddrEmpty,
},
nil,
},
{
"20 bytes",
fields{
Address: base.TestBech32ProvAddr20Bytes,
},
base.ProvAddress{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &Provider{
Address: tt.fields.Address,
Name: tt.fields.Name,
Identity: tt.fields.Identity,
Website: tt.fields.Website,
Description: tt.fields.Description,
}
if got := p.GetAddress(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAddress() = %v, want %v", got, tt.want)
}
})
}
}

func TestProvider_Validate(t *testing.T) {
type fields struct {
Address string
Expand Down
26 changes: 0 additions & 26 deletions x/session/types/v2/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,6 @@ import (
v1base "github.com/sentinel-official/hub/v12/types/v1"
)

func (m *Session) GetAddress() sdk.AccAddress {
if m.Address == "" {
return nil
}

addr, err := sdk.AccAddressFromBech32(m.Address)
if err != nil {
panic(err)
}

return addr
}

func (m *Session) GetNodeAddress() base.NodeAddress {
if m.NodeAddress == "" {
return nil
}

addr, err := base.NodeAddressFromBech32(m.NodeAddress)
if err != nil {
panic(err)
}

return addr
}

func (m *Session) Validate() error {
if m.ID == 0 {
return fmt.Errorf("id cannot be zero")
Expand Down
7 changes: 6 additions & 1 deletion x/subscription/keeper/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import (

// SetAllocation sets the allocation for a given ID and address in the KVStore.
func (k *Keeper) SetAllocation(ctx sdk.Context, alloc v2.Allocation) {
addr, err := sdk.AccAddressFromBech32(alloc.Address)
if err != nil {
panic(err)
}

store := k.Store(ctx)
key := types.AllocationKey(alloc.ID, alloc.GetAddress())
key := types.AllocationKey(alloc.ID, addr)
value := k.cdc.MustMarshal(&alloc)

store.Set(key, value)
Expand Down
13 changes: 0 additions & 13 deletions x/subscription/types/v2/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (m *Allocation) GetAddress() sdk.AccAddress {
if m.Address == "" {
return nil
}

addr, err := sdk.AccAddressFromBech32(m.Address)
if err != nil {
panic(err)
}

return addr
}

func (m *Allocation) Validate() error {
if m.Address == "" {
return fmt.Errorf("address cannot be empty")
Expand Down
Loading

0 comments on commit c4701eb

Please sign in to comment.