Skip to content

Commit

Permalink
refactor(Int): importing from "cosmossdk.io/math"
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanshutr committed Oct 9, 2024
1 parent 17a1ff9 commit c67f568
Show file tree
Hide file tree
Showing 33 changed files with 96 additions and 97 deletions.
3 changes: 2 additions & 1 deletion data/base/acc_address_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package base

import (
"bytes"
"cosmossdk.io/math"
"strings"

sdkTypes "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -27,7 +28,7 @@ func (accAddressData *AccAddressData) ValidateBasic() error {
func (accAddressData *AccAddressData) GetID() ids.DataID {
return baseIDs.GenerateDataID(accAddressData)
}
func (accAddressData *AccAddressData) GetBondWeight() sdkTypes.Int {
func (accAddressData *AccAddressData) GetBondWeight() math.Int {
return dataConstants.AccAddressDataWeight
}
func (accAddressData *AccAddressData) Compare(listableData data.ListableData) int {
Expand Down
4 changes: 2 additions & 2 deletions data/base/any_data.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package base

import (
"cosmossdk.io/math"
"fmt"
"github.com/AssetMantle/schema/data"
dataConstants "github.com/AssetMantle/schema/data/constants"
"github.com/AssetMantle/schema/ids"
baseIDs "github.com/AssetMantle/schema/ids/base"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"strings"
)

Expand Down Expand Up @@ -130,7 +130,7 @@ func (x *AnyData) GenerateHashID() ids.HashID {
func (x *AnyData) ToAnyData() data.AnyData {
return x
}
func (x *AnyData) GetBondWeight() sdkTypes.Int {
func (x *AnyData) GetBondWeight() math.Int {
return x.Impl.(dataGetter).get().GetBondWeight()
}

Expand Down
4 changes: 2 additions & 2 deletions data/base/any_listable_data.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package base

import (
"cosmossdk.io/math"
"github.com/AssetMantle/schema/data"
"github.com/AssetMantle/schema/ids"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
)

type listableDataGetter interface {
Expand Down Expand Up @@ -45,7 +45,7 @@ func (anyListableData *AnyListableData) Get() data.Data {
func (anyListableData *AnyListableData) GetID() ids.DataID {
return anyListableData.Impl.(listableDataGetter).get().GetID()
}
func (anyListableData *AnyListableData) GetBondWeight() sdkTypes.Int {
func (anyListableData *AnyListableData) GetBondWeight() math.Int {
return anyListableData.Impl.(listableDataGetter).get().GetBondWeight()
}
func (anyListableData *AnyListableData) ValidateBasic() error {
Expand Down
5 changes: 2 additions & 3 deletions data/base/boolean_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
package base

import (
"cosmossdk.io/math"
"strconv"
"strings"

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

"github.com/AssetMantle/schema/data"
dataConstants "github.com/AssetMantle/schema/data/constants"
"github.com/AssetMantle/schema/ids"
Expand All @@ -23,7 +22,7 @@ func (booleanData *BooleanData) ValidateBasic() error {
func (booleanData *BooleanData) GetID() ids.DataID {
return baseIDs.GenerateDataID(booleanData)
}
func (booleanData *BooleanData) GetBondWeight() sdkTypes.Int {
func (booleanData *BooleanData) GetBondWeight() math.Int {
return dataConstants.BooleanDataWeight
}
func (booleanData *BooleanData) Compare(listableData data.ListableData) int {
Expand Down
3 changes: 2 additions & 1 deletion data/base/dec_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package base

import (
"cosmossdk.io/math"
"fmt"
"github.com/AssetMantle/schema/data"
dataConstants "github.com/AssetMantle/schema/data/constants"
Expand All @@ -27,7 +28,7 @@ func (decData *DecData) ValidateBasic() error {
func (decData *DecData) GetID() ids.DataID {
return baseIDs.GenerateDataID(decData)
}
func (decData *DecData) GetBondWeight() sdkTypes.Int {
func (decData *DecData) GetBondWeight() math.Int {
return dataConstants.DecDataWeight
}
func (decData *DecData) Compare(listableData data.ListableData) int {
Expand Down
5 changes: 2 additions & 3 deletions data/base/height_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
package base

import (
"cosmossdk.io/math"
"encoding/binary"
"strconv"
"strings"

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

"github.com/AssetMantle/schema/data"
dataConstants "github.com/AssetMantle/schema/data/constants"
"github.com/AssetMantle/schema/ids"
Expand All @@ -26,7 +25,7 @@ func (heightData *HeightData) ValidateBasic() error {
func (heightData *HeightData) GetID() ids.DataID {
return baseIDs.GenerateDataID(heightData)
}
func (heightData *HeightData) GetBondWeight() sdkTypes.Int {
func (heightData *HeightData) GetBondWeight() math.Int {
return dataConstants.HeightDataWeight
}
func (heightData *HeightData) AsString() string {
Expand Down
5 changes: 2 additions & 3 deletions data/base/id_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
package base

import (
"cosmossdk.io/math"
"strings"

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

"github.com/AssetMantle/schema/data"
dataConstants "github.com/AssetMantle/schema/data/constants"
"github.com/AssetMantle/schema/ids"
Expand All @@ -22,7 +21,7 @@ func (idData *IDData) ValidateBasic() error {
func (idData *IDData) GetID() ids.DataID {
return baseIDs.GenerateDataID(idData)
}
func (idData *IDData) GetBondWeight() sdkTypes.Int {
func (idData *IDData) GetBondWeight() math.Int {
return dataConstants.IDDataWeight
}
func (idData *IDData) AsString() string {
Expand Down
4 changes: 2 additions & 2 deletions data/base/linked_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package base

import (
"bytes"
"cosmossdk.io/math"
"fmt"
"github.com/AssetMantle/schema/data"
dataConstants "github.com/AssetMantle/schema/data/constants"
"github.com/AssetMantle/schema/data/utilities"
"github.com/AssetMantle/schema/ids"
baseIDs "github.com/AssetMantle/schema/ids/base"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"net/url"
"strings"
)
Expand Down Expand Up @@ -52,7 +52,7 @@ func (linkedData *LinkedData) Compare(listableData data.ListableData) int {
func (linkedData *LinkedData) GetID() ids.DataID {
return baseIDs.GenerateDataID(linkedData)
}
func (linkedData *LinkedData) GetBondWeight() sdkTypes.Int {
func (linkedData *LinkedData) GetBondWeight() math.Int {
return dataConstants.LinkedDataWeight
}
func (linkedData *LinkedData) AsString() string {
Expand Down
4 changes: 2 additions & 2 deletions data/base/list_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package base

import (
"bytes"
"cosmossdk.io/math"
"fmt"
"github.com/AssetMantle/schema/data"
dataConstants "github.com/AssetMantle/schema/data/constants"
"github.com/AssetMantle/schema/data/utilities"
"github.com/AssetMantle/schema/ids"
baseIDs "github.com/AssetMantle/schema/ids/base"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"sort"
"strings"
)
Expand Down Expand Up @@ -51,7 +51,7 @@ func (listData *ListData) Get() []data.AnyListableData {

return anyListableData
}
func (listData *ListData) GetBondWeight() sdkTypes.Int {
func (listData *ListData) GetBondWeight() math.Int {
return dataConstants.ListDataWeight
}
func (listData *ListData) AsString() string {
Expand Down
7 changes: 4 additions & 3 deletions data/base/number_data.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package base

import (
"cosmossdk.io/math"
"fmt"
"github.com/AssetMantle/schema/data"
dataConstants "github.com/AssetMantle/schema/data/constants"
Expand All @@ -22,7 +23,7 @@ func (numberData *NumberData) ValidateBasic() error {
func (numberData *NumberData) GetID() ids.DataID {
return baseIDs.GenerateDataID(numberData)
}
func (numberData *NumberData) GetBondWeight() sdkTypes.Int {
func (numberData *NumberData) GetBondWeight() math.Int {
return dataConstants.NumberDataWeight
}
func (numberData *NumberData) AsString() string {
Expand Down Expand Up @@ -84,7 +85,7 @@ func (numberData *NumberData) Compare(listableData data.ListableData) int {
}
return -1
}
func (numberData *NumberData) Get() sdkTypes.Int {
func (numberData *NumberData) Get() math.Int {
if value, ok := sdkTypes.NewIntFromString(numberData.Value); !ok {
panic("invalid number data")
} else {
Expand All @@ -96,7 +97,7 @@ func PrototypeNumberData() data.NumberData {
return NewNumberData(sdkTypes.ZeroInt()).ZeroValue().(*NumberData)
}

func NewNumberData(value sdkTypes.Int) data.NumberData {
func NewNumberData(value math.Int) data.NumberData {
return &NumberData{
Value: value.String(),
}
Expand Down
4 changes: 2 additions & 2 deletions data/base/number_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func Test_NewNumberData(t *testing.T) {
tests := []struct {
name string
args sdkTypes.Int
args math.Int
want data.Data
}{
{"+ve", sdkTypes.NewInt(10), &NumberData{"10"}},
Expand Down Expand Up @@ -97,7 +97,7 @@ func Test_NumberDataGet(t *testing.T) {
tests := []struct {
name string
args data.NumberData
want sdkTypes.Int
want math.Int
}{
{"+ve", NewNumberData(sdkTypes.NewInt(10)), sdkTypes.NewInt(10)},
}
Expand Down
4 changes: 2 additions & 2 deletions data/base/string_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
package base

import (
"cosmossdk.io/math"
"fmt"
"github.com/AssetMantle/schema/data"
dataConstants "github.com/AssetMantle/schema/data/constants"
"github.com/AssetMantle/schema/ids"
baseIDs "github.com/AssetMantle/schema/ids/base"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"strings"
)

Expand All @@ -29,7 +29,7 @@ func (stringData *StringData) ValidateBasic() error {
func (stringData *StringData) GetID() ids.DataID {
return baseIDs.GenerateDataID(stringData)
}
func (stringData *StringData) GetBondWeight() sdkTypes.Int {
func (stringData *StringData) GetBondWeight() math.Int {
return dataConstants.StringDataWeight
}
func (stringData *StringData) Compare(listableData data.ListableData) int {
Expand Down
4 changes: 2 additions & 2 deletions data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package data

import (
"cosmossdk.io/math"
"github.com/AssetMantle/schema/ids"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
)

// TODO URI and PropertyID Data type
type Data interface {
GetID() ids.DataID
GetBondWeight() sdkTypes.Int
GetBondWeight() math.Int

ValidateBasic() error
Unmarshal([]byte) error
Expand Down
4 changes: 2 additions & 2 deletions data/number_data.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package data

import sdkTypes "github.com/cosmos/cosmos-sdk/types"
import "cosmossdk.io/math"

type NumberData interface {
ListableData
Get() sdkTypes.Int
Get() math.Int
}
4 changes: 2 additions & 2 deletions documents/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package documents

import (
"cosmossdk.io/math"
"github.com/AssetMantle/schema/types"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
)

type Asset interface {
ValidateAsset() error
GetBurnHeight() types.Height
GetLockHeight() types.Height
GetSupply() sdkTypes.Int
GetSupply() math.Int
Document
}
4 changes: 2 additions & 2 deletions documents/base/asset.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package base

import (
"cosmossdk.io/math"
"fmt"
"github.com/AssetMantle/schema/data"
"github.com/AssetMantle/schema/documents"
Expand All @@ -9,7 +10,6 @@ import (
"github.com/AssetMantle/schema/properties/constants"
"github.com/AssetMantle/schema/qualified"
"github.com/AssetMantle/schema/types"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
)

type asset struct {
Expand Down Expand Up @@ -51,7 +51,7 @@ func (asset asset) GetLockHeight() types.Height {

return constants.LockHeightProperty.GetData().Get().(data.HeightData).Get()
}
func (asset asset) GetSupply() sdkTypes.Int {
func (asset asset) GetSupply() math.Int {
if property := asset.GetProperty(constants.SupplyProperty.GetID()); property != nil && property.IsMeta() {
return property.Get().(properties.MetaProperty).GetData().Get().(data.NumberData).Get()
}
Expand Down
2 changes: 1 addition & 1 deletion documents/base/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func Test_asset_GetSupply(t *testing.T) {
tests := []struct {
name string
fields fields
want sdkTypes.Int
want math.Int
}{
{"+ve", fields{testDocument}, sdkTypes.OneInt()},
{"+ve with supply", fields{testDocumentWithSupply}, sdkTypes.NewInt(77)},
Expand Down
4 changes: 2 additions & 2 deletions documents/base/classification.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package base

import (
"cosmossdk.io/math"
"fmt"
"github.com/AssetMantle/schema/data"
"github.com/AssetMantle/schema/documents"
baseIDs "github.com/AssetMantle/schema/ids/base"
"github.com/AssetMantle/schema/properties"
constantProperties "github.com/AssetMantle/schema/properties/constants"
"github.com/AssetMantle/schema/qualified"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
)

type classification struct {
Expand All @@ -28,7 +28,7 @@ func (classification classification) ValidateBasic() error {

return nil
}
func (classification classification) GetBondAmount() sdkTypes.Int {
func (classification classification) GetBondAmount() math.Int {
if property := classification.Document.GetProperty(constantProperties.BondAmountProperty.GetID()); property != nil && property.IsMeta() {
return property.Get().(properties.MetaProperty).GetData().Get().(data.NumberData).Get()
}
Expand Down
2 changes: 1 addition & 1 deletion documents/base/classification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Test_classifiaction_GetSupply(t *testing.T) {
tests := []struct {
name string
fields fields
want sdkTypes.Int
want math.Int
}{
{"+ve", fields{testDocument}, sdkTypes.ZeroInt()},
{"+ve with bondAmount", fields{testDocumentWithSupply}, sdkTypes.NewInt(999)},
Expand Down
3 changes: 2 additions & 1 deletion documents/base/identity.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package base

import (
"cosmossdk.io/math"
"fmt"
"github.com/AssetMantle/schema/data"
baseData "github.com/AssetMantle/schema/data/base"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (identity identity) IsProvisioned(accAddress sdkTypes.AccAddress) bool {
_, isProvisioned := identity.GetAuthentication().Search(baseData.NewAccAddressData(accAddress))
return isProvisioned
}
func (identity identity) GetProvisionedAddressCount() sdkTypes.Int {
func (identity identity) GetProvisionedAddressCount() math.Int {
return sdkTypes.NewInt(int64(len(identity.GetAuthentication().Get())))
}
func (identity identity) ProvisionAddress(accAddresses ...sdkTypes.AccAddress) documents.Identity {
Expand Down
Loading

0 comments on commit c67f568

Please sign in to comment.