Skip to content

Commit

Permalink
Code refactor: moving all module key id composites to schema/ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanshutr committed Aug 1, 2022
1 parent c4fca92 commit e76f043
Show file tree
Hide file tree
Showing 150 changed files with 778 additions and 2,899 deletions.
12 changes: 6 additions & 6 deletions modules/assets/internal/mappable/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (

"github.com/AssetMantle/modules/modules/assets/internal/key"
"github.com/AssetMantle/modules/schema/helpers"
base2 "github.com/AssetMantle/modules/schema/ids/base"
"github.com/AssetMantle/modules/schema/lists"
"github.com/AssetMantle/modules/schema/ids"
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
"github.com/AssetMantle/modules/schema/mappables"
"github.com/AssetMantle/modules/schema/properties"
"github.com/AssetMantle/modules/schema/properties/constants"
"github.com/AssetMantle/modules/schema/qualified"
"github.com/AssetMantle/modules/schema/qualified/base"
baseQualified "github.com/AssetMantle/modules/schema/qualified/base"
codecUtilities "github.com/AssetMantle/modules/utilities/codec"
)

Expand Down Expand Up @@ -46,15 +46,15 @@ func (asset asset) GetSupply() properties.Property {
return constants.Supply
}
func (asset asset) GetKey() helpers.Key {
return key.NewKey(base2.NewAssetID(asset.GetClassificationID(), asset.GetImmutables()))
return key.NewKey(baseIDs.NewAssetID(asset.GetClassificationID(), asset.GetImmutables()))
}
func (asset) RegisterCodec(codec *codec.Codec) {
codecUtilities.RegisterModuleConcrete(codec, asset{})
}

func NewAsset(classification mappables.Classification, immutableProperties lists.PropertyList, mutableProperties lists.PropertyList) mappables.Asset {
func NewAsset(classificationID ids.ClassificationID, immutables qualified.Immutables, mutables qualified.Mutables) mappables.Asset {
return asset{
Document: base.NewDocument(classification, immutableProperties, mutableProperties),
Document: baseQualified.NewDocument(classificationID, immutables, mutables),
}
}

Expand Down
5 changes: 3 additions & 2 deletions modules/assets/internal/simulator/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
baseHelpers "github.com/AssetMantle/modules/schema/helpers/base"
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
parameters2 "github.com/AssetMantle/modules/schema/parameters"
baseQualified "github.com/AssetMantle/modules/schema/qualified/base"
baseSimulation "github.com/AssetMantle/modules/simulation/schema/types/base"
)

Expand All @@ -38,8 +39,8 @@ func (simulator) RandomizedGenesisState(simulationState *module.SimulationState)
mappableList := make([]helpers.Mappable, simulationState.Rand.Intn(99))

for i := range mappableList {
immutableProperties := baseSimulation.GenerateRandomProperties(simulationState.Rand)
mappableList[i] = mappable.NewAsset(baseIDs.NewAssetID(baseSimulation.GenerateRandomID(simulationState.Rand), immutableProperties), immutableProperties, baseSimulation.GenerateRandomProperties(simulationState.Rand))
immutables := baseQualified.NewImmutables(baseSimulation.GenerateRandomProperties(simulationState.Rand))
mappableList[i] = mappable.NewAsset(baseIDs.NewAssetID(baseSimulation.GenerateRandomID(simulationState.Rand), immutables), immutables, baseQualified.NewMutables(baseSimulation.GenerateRandomProperties(simulationState.Rand)))
}

genesisState := baseHelpers.NewGenesis(key.Prototype, mappable.Prototype, nil, parameters.Prototype().GetList()).Initialize(mappableList, []parameters2.Parameter{dummy.Parameter.Mutate(Data)})
Expand Down
9 changes: 5 additions & 4 deletions modules/assets/internal/transactions/define/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/AssetMantle/modules/schema/errors/constants"
"github.com/AssetMantle/modules/schema/helpers"
baseLists "github.com/AssetMantle/modules/schema/lists/base"
"github.com/AssetMantle/modules/schema/qualified/base"
)

type transactionKeeper struct {
Expand All @@ -36,21 +37,21 @@ func (transactionKeeper transactionKeeper) Transact(context sdkTypes.Context, ms
return newTransactionResponse(err)
}

immutableProperties := baseLists.NewPropertyList(append(immutableMetaProperties.GetList(), message.ImmutableProperties.GetList()...)...)
immutables := base.NewImmutables(baseLists.NewPropertyList(append(immutableMetaProperties.GetList(), message.ImmutableProperties.GetList()...)...))

mutableMetaProperties, err := scrub.GetPropertiesFromResponse(transactionKeeper.scrubAuxiliary.GetKeeper().Help(context, scrub.NewAuxiliaryRequest(message.MutableMetaProperties.GetList()...)))
if err != nil {
return newTransactionResponse(err)
}

mutableProperties := baseLists.NewPropertyList(append(mutableMetaProperties.GetList(), message.MutableProperties.GetList()...)...)
mutables := base.NewMutables(baseLists.NewPropertyList(append(mutableMetaProperties.GetList(), message.MutableProperties.GetList()...)...))

classificationID, err := define.GetClassificationIDFromResponse(transactionKeeper.defineAuxiliary.GetKeeper().Help(context, define.NewAuxiliaryRequest(immutableProperties, mutableProperties)))
classificationID, err := define.GetClassificationIDFromResponse(transactionKeeper.defineAuxiliary.GetKeeper().Help(context, define.NewAuxiliaryRequest(immutables, mutables)))
if err != nil {
return newTransactionResponse(err)
}

if auxiliaryResponse := transactionKeeper.superAuxiliary.GetKeeper().Help(context, super.NewAuxiliaryRequest(classificationID, message.FromID, mutableProperties)); !auxiliaryResponse.IsSuccessful() {
if auxiliaryResponse := transactionKeeper.superAuxiliary.GetKeeper().Help(context, super.NewAuxiliaryRequest(classificationID, message.FromID, mutables)); !auxiliaryResponse.IsSuccessful() {
return newTransactionResponse(auxiliaryResponse.GetError())
}

Expand Down
4 changes: 2 additions & 2 deletions modules/assets/internal/transactions/define/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

type message struct {
From sdkTypes.AccAddress `json:"from" valid:"required~required field from missing"`
FromID ids.ID `json:"fromID" valid:"required~required field fromID missing"`
FromID ids.IdentityID `json:"fromID" valid:"required~required field fromID missing"`
ImmutableMetaProperties lists.MetaPropertyList `json:"immutableMetaProperties" valid:"required~required field immutableMetaProperties missing"`
ImmutableProperties lists.PropertyList `json:"immutableProperties" valid:"required~required field immutableProperties missing"`
MutableMetaProperties lists.MetaPropertyList `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing"`
Expand Down Expand Up @@ -58,7 +58,7 @@ func messageFromInterface(msg sdkTypes.Msg) message {
func messagePrototype() helpers.Message {
return message{}
}
func newMessage(from sdkTypes.AccAddress, fromID ids.ID, immutableMetaProperties lists.MetaPropertyList, immutableProperties lists.PropertyList, mutableMetaProperties lists.MetaPropertyList, mutableProperties lists.PropertyList) sdkTypes.Msg {
func newMessage(from sdkTypes.AccAddress, fromID ids.IdentityID, immutableMetaProperties lists.MetaPropertyList, immutableProperties lists.PropertyList, mutableMetaProperties lists.MetaPropertyList, mutableProperties lists.PropertyList) sdkTypes.Msg {
return message{
From: from,
FromID: fromID,
Expand Down
15 changes: 8 additions & 7 deletions modules/assets/internal/transactions/mint/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
"github.com/AssetMantle/modules/schema/lists/base"
"github.com/AssetMantle/modules/schema/properties/constants"
baseQualified "github.com/AssetMantle/modules/schema/qualified/base"
)

type transactionKeeper struct {
Expand Down Expand Up @@ -49,12 +50,12 @@ func (transactionKeeper transactionKeeper) Transact(context sdkTypes.Context, ms
return newTransactionResponse(err)
}

immutableProperties := base.NewPropertyList(append(immutableMetaProperties.GetList(), message.ImmutableProperties.GetList()...)...)
immutables := baseQualified.NewImmutables(base.NewPropertyList(append(immutableMetaProperties.GetList(), message.ImmutableProperties.GetList()...)...))

assetID := baseIDs.NewAssetID(message.ClassificationID, immutableProperties)
assetID := baseIDs.NewAssetID(message.ClassificationID, immutables)

assets := transactionKeeper.mapper.NewCollection(context).Fetch(key.FromID(assetID))
if assets.Get(key.FromID(assetID)) != nil {
assets := transactionKeeper.mapper.NewCollection(context).Fetch(key.NewKey(assetID))
if assets.Get(key.NewKey(assetID)) != nil {
return newTransactionResponse(errorConstants.EntityAlreadyExists)
}

Expand All @@ -63,9 +64,9 @@ func (transactionKeeper transactionKeeper) Transact(context sdkTypes.Context, ms
return newTransactionResponse(err)
}

mutableProperties := base.NewPropertyList(append(mutableMetaProperties.GetList(), message.MutableProperties.GetList()...)...)
mutables := baseQualified.NewMutables(base.NewPropertyList(append(mutableMetaProperties.GetList(), message.MutableProperties.GetList()...)...))

if auxiliaryResponse := transactionKeeper.conformAuxiliary.GetKeeper().Help(context, conform.NewAuxiliaryRequest(message.ClassificationID, immutableProperties, mutableProperties)); !auxiliaryResponse.IsSuccessful() {
if auxiliaryResponse := transactionKeeper.conformAuxiliary.GetKeeper().Help(context, conform.NewAuxiliaryRequest(message.ClassificationID, immutables, mutables)); !auxiliaryResponse.IsSuccessful() {
return newTransactionResponse(auxiliaryResponse.GetError())
}

Expand All @@ -79,7 +80,7 @@ func (transactionKeeper transactionKeeper) Transact(context sdkTypes.Context, ms
return newTransactionResponse(auxiliaryResponse.GetError())
}

assets.Add(mappable.NewAsset(assetID, immutableProperties, mutableProperties))
assets.Add(mappable.NewAsset(assetID, immutables, mutables))

return newTransactionResponse(nil)
}
Expand Down
13 changes: 7 additions & 6 deletions modules/assets/internal/transactions/mutate/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/AssetMantle/modules/schema/helpers"
baseLists "github.com/AssetMantle/modules/schema/lists/base"
"github.com/AssetMantle/modules/schema/mappables"
"github.com/AssetMantle/modules/schema/qualified/base"
)

type transactionKeeper struct {
Expand All @@ -34,9 +35,9 @@ func (transactionKeeper transactionKeeper) Transact(context sdkTypes.Context, ms
return newTransactionResponse(auxiliaryResponse.GetError())
}

assets := transactionKeeper.mapper.NewCollection(context).Fetch(key.FromID(message.AssetID))
assets := transactionKeeper.mapper.NewCollection(context).Fetch(key.NewKey(message.AssetID))

asset := assets.Get(key.FromID(message.AssetID))
asset := assets.Get(key.NewKey(message.AssetID))
if asset == nil {
return newTransactionResponse(constants.EntityNotFound)
}
Expand All @@ -46,17 +47,17 @@ func (transactionKeeper transactionKeeper) Transact(context sdkTypes.Context, ms
return newTransactionResponse(err)
}

mutableProperties := baseLists.NewPropertyList(append(mutableMetaProperties.GetList(), message.MutableProperties.GetList()...)...)
mutables := base.NewMutables(baseLists.NewPropertyList(append(mutableMetaProperties.GetList(), message.MutableProperties.GetList()...)...))

if auxiliaryResponse := transactionKeeper.conformAuxiliary.GetKeeper().Help(context, conform.NewAuxiliaryRequest(asset.(mappables.Asset).GetClassificationID(), nil, mutableProperties)); !auxiliaryResponse.IsSuccessful() {
if auxiliaryResponse := transactionKeeper.conformAuxiliary.GetKeeper().Help(context, conform.NewAuxiliaryRequest(asset.(mappables.Asset).GetClassificationID(), nil, mutables)); !auxiliaryResponse.IsSuccessful() {
return newTransactionResponse(auxiliaryResponse.GetError())
}

if auxiliaryResponse := transactionKeeper.maintainAuxiliary.GetKeeper().Help(context, maintain.NewAuxiliaryRequest(asset.(mappables.Asset).GetClassificationID(), message.FromID, mutableProperties)); !auxiliaryResponse.IsSuccessful() {
if auxiliaryResponse := transactionKeeper.maintainAuxiliary.GetKeeper().Help(context, maintain.NewAuxiliaryRequest(asset.(mappables.Asset).GetClassificationID(), message.FromID, mutables.GetMutablePropertyList())); !auxiliaryResponse.IsSuccessful() {
return newTransactionResponse(auxiliaryResponse.GetError())
}

assets.Mutate(mappable.NewAsset(asset.(mappables.Asset).GetHashID(), asset.(mappables.Asset).GetImmutables(), asset.(mappables.Asset).GetImmutables().Mutate(mutableProperties.GetList()...)))
assets.Mutate(mappable.NewAsset(asset.(mappables.Asset).GenerateHashID(), asset.(mappables.Asset).GetImmutables(), base.NewMutables(asset.(mappables.Asset).GetImmutables().GetImmutablePropertyList().Mutate(mutables.GetMutablePropertyList().GetList()...))))

return newTransactionResponse(nil)
}
Expand Down
157 changes: 0 additions & 157 deletions modules/assets/internal/transactions/mutate/keeper_test.go

This file was deleted.

6 changes: 3 additions & 3 deletions modules/assets/internal/transactions/mutate/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

type message struct {
From sdkTypes.AccAddress `json:"from" valid:"required~required field from missing"`
FromID ids.ID `json:"fromID" valid:"required~required field fromID missing"`
AssetID ids.ID `json:"assetID" valid:"required~required field assetID missing"`
FromID ids.IdentityID `json:"fromID" valid:"required~required field fromID missing"`
AssetID ids.AssetID `json:"assetID" valid:"required~required field assetID missing"`
MutableMetaProperties lists.MetaPropertyList `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing"`
MutableProperties lists.PropertyList `json:"mutableProperties" valid:"required~required field mutableProperties missing"`
}
Expand Down Expand Up @@ -57,7 +57,7 @@ func messageFromInterface(msg sdkTypes.Msg) message {
func messagePrototype() helpers.Message {
return message{}
}
func newMessage(from sdkTypes.AccAddress, fromID ids.ID, assetID ids.ID, mutableMetaProperties lists.MetaPropertyList, mutableProperties lists.PropertyList) sdkTypes.Msg {
func newMessage(from sdkTypes.AccAddress, fromID ids.IdentityID, assetID ids.AssetID, mutableMetaProperties lists.MetaPropertyList, mutableProperties lists.PropertyList) sdkTypes.Msg {
return message{
From: from,
FromID: fromID,
Expand Down
Loading

0 comments on commit e76f043

Please sign in to comment.