Skip to content

Commit

Permalink
add genesis navs
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Jan 16, 2024
1 parent 012eba4 commit 959988e
Show file tree
Hide file tree
Showing 5 changed files with 380 additions and 34 deletions.
18 changes: 18 additions & 0 deletions docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@

- [provenance/metadata/v1/genesis.proto](#provenance/metadata/v1/genesis.proto)
- [GenesisState](#provenance.metadata.v1.GenesisState)
- [MarkerNetAssetValues](#provenance.metadata.v1.MarkerNetAssetValues)

- [provenance/metadata/v1/p8e/p8e.proto](#provenance/metadata/v1/p8e/p8e.proto)
- [Condition](#provenance.metadata.v1.p8e.Condition)
Expand Down Expand Up @@ -6140,6 +6141,23 @@ GenesisState defines the account module's genesis state.
| `record_specifications` | [RecordSpecification](#provenance.metadata.v1.RecordSpecification) | repeated | |
| `o_s_locator_params` | [OSLocatorParams](#provenance.metadata.v1.OSLocatorParams) | | |
| `object_store_locators` | [ObjectStoreLocator](#provenance.metadata.v1.ObjectStoreLocator) | repeated | |
| `net_asset_values` | [MarkerNetAssetValues](#provenance.metadata.v1.MarkerNetAssetValues) | repeated | Net asset values assigned to scopes |






<a name="provenance.metadata.v1.MarkerNetAssetValues"></a>

### MarkerNetAssetValues
MarkerNetAssetValues defines the net asset values for a scope


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | address defines the scope address |
| `net_asset_values` | [NetAssetValue](#provenance.metadata.v1.NetAssetValue) | repeated | net_asset_values that are assigned to scope |



Expand Down
15 changes: 15 additions & 0 deletions proto/provenance/metadata/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,19 @@ message GenesisState {

OSLocatorParams o_s_locator_params = 8 [(gogoproto.nullable) = false];
repeated ObjectStoreLocator object_store_locators = 9 [(gogoproto.nullable) = false];

// Net asset values assigned to scopes
repeated MarkerNetAssetValues net_asset_values = 10 [(gogoproto.nullable) = false];
}

// MarkerNetAssetValues defines the net asset values for a scope
message MarkerNetAssetValues {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// address defines the scope address
string address = 1;

// net_asset_values that are assigned to scope
repeated NetAssetValue net_asset_values = 2 [(gogoproto.nullable) = false];
}
28 changes: 27 additions & 1 deletion x/metadata/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {
}
}
}

for _, mNavs := range data.NetAssetValues {
for _, nav := range mNavs.NetAssetValues {
address, err := types.MetadataAddressFromBech32(mNavs.Address)
if err != nil {
panic(err)

Check warning on line 69 in x/metadata/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/metadata/keeper/genesis.go#L66-L69

Added lines #L66 - L69 were not covered by tests
}
k.SetNetAssetValue(ctx, address, types.NewNetAssetValue(nav.Price, nav.Volume), types.ModuleName)

Check warning on line 71 in x/metadata/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/metadata/keeper/genesis.go#L71

Added line #L71 was not covered by tests
}
}
}

// ExportGenesis exports the current keeper state of the metadata module.ExportGenesis
Expand Down Expand Up @@ -134,5 +144,21 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (data *types.GenesisState) {
panic(err)
}

return types.NewGenesisState(params, oslocatorparams, scopes, sessions, records, scopeSpecs, contractSpecs, recordSpecs, objectStoreLocators)
markerNetAssetValues := make([]types.MarkerNetAssetValues, len(scopes))
for i := range scopes {
var markerNavs types.MarkerNetAssetValues
var navs []types.NetAssetValue
err := k.IterateNetAssetValues(ctx, scopes[i].ScopeId, func(nav types.NetAssetValue) (stop bool) {
navs = append(navs, nav)
return false
})
if err != nil {
panic(err)

Check warning on line 156 in x/metadata/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/metadata/keeper/genesis.go#L147-L156

Added lines #L147 - L156 were not covered by tests
}
markerNavs.Address = scopes[i].ScopeId.String()
markerNavs.NetAssetValues = navs
markerNetAssetValues[i] = markerNavs

Check warning on line 160 in x/metadata/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/metadata/keeper/genesis.go#L158-L160

Added lines #L158 - L160 were not covered by tests
}

return types.NewGenesisState(params, oslocatorparams, scopes, sessions, records, scopeSpecs, contractSpecs, recordSpecs, objectStoreLocators, markerNetAssetValues)

Check warning on line 163 in x/metadata/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/metadata/keeper/genesis.go#L163

Added line #L163 was not covered by tests
}
9 changes: 7 additions & 2 deletions x/metadata/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func NewGenesisState(
contracSpecs []ContractSpecification,
recordSpecs []RecordSpecification,
objectStoreLocators []ObjectStoreLocator,
netAssetValues []MarkerNetAssetValues,

) *GenesisState {
return &GenesisState{
Params: params,
Expand All @@ -27,11 +29,14 @@ func NewGenesisState(
ContractSpecifications: contracSpecs,
RecordSpecifications: recordSpecs,
ObjectStoreLocators: objectStoreLocators,
NetAssetValues: netAssetValues,

Check warning on line 32 in x/metadata/types/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/metadata/types/genesis.go#L32

Added line #L32 was not covered by tests
}
}

// DefaultGenesisState returns a zero-value genesis state.
func DefaultGenesisState() *GenesisState {
return &GenesisState{Params: DefaultParams(),
OSLocatorParams: DefaultOSLocatorParams()}
return &GenesisState{
Params: DefaultParams(),
OSLocatorParams: DefaultOSLocatorParams(),
}

Check warning on line 41 in x/metadata/types/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/metadata/types/genesis.go#L38-L41

Added lines #L38 - L41 were not covered by tests
}
Loading

0 comments on commit 959988e

Please sign in to comment.