Skip to content

Commit

Permalink
add scope net asset value query
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Jan 23, 2024
1 parent f11c3da commit c219d33
Show file tree
Hide file tree
Showing 8 changed files with 945 additions and 228 deletions.
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

169 changes: 142 additions & 27 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39670,6 +39670,82 @@ paths:
format: boolean
tags:
- Query
'/provenance/metadata/v1/netassetvalues/{id}':
get:
summary: ScopeNetAssetValues returns net asset values for scope
operationId: ScopeNetAssetValues
responses:
'200':
description: A successful response.
schema:
type: object
properties:
net_asset_values:
type: array
items:
type: object
properties:
price:
title: price is the complete value of the asset's volume
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the
custom method

signatures required by gogoproto.
volume:
type: string
format: uint64
title: >-
volume is the number of tokens of the marker that were
purchased for the price
updated_block_height:
type: string
format: uint64
title: updated_block_height is the block height of last update
title: NetAssetValue defines a scope's net asset value
title: net asset values for scope
description: >-
QueryNetAssetValuesRequest is the response type for the
Query/NetAssetValues method.
default:
description: An unexpected error response
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: id
description: scopeid metadata address
in: path
required: true
type: string
tags:
- Query
'/provenance/metadata/v1/ownership/{address}':
get:
summary: >-
Expand Down Expand Up @@ -85796,6 +85872,33 @@ definitions:
on or off chain) to define an input

parameter
provenance.metadata.v1.NetAssetValue:
type: object
properties:
price:
title: price is the complete value of the asset's volume
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
volume:
type: string
format: uint64
title: >-
volume is the number of tokens of the marker that were purchased for
the price
updated_block_height:
type: string
format: uint64
title: updated_block_height is the block height of last update
title: NetAssetValue defines a scope's net asset value
provenance.metadata.v1.OSAllLocatorsRequest:
type: object
properties:
Expand Down Expand Up @@ -86612,6 +86715,45 @@ definitions:
include_request is a flag for whether to include this request in
your result.
description: QueryParamsResponse is the response type for the Query/Params RPC method.
provenance.metadata.v1.QueryScopeNetAssetValuesResponse:
type: object
properties:
net_asset_values:
type: array
items:
type: object
properties:
price:
title: price is the complete value of the asset's volume
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
volume:
type: string
format: uint64
title: >-
volume is the number of tokens of the marker that were purchased
for the price
updated_block_height:
type: string
format: uint64
title: updated_block_height is the block height of last update
title: NetAssetValue defines a scope's net asset value
title: net asset values for scope
description: >-
QueryNetAssetValuesRequest is the response type for the
Query/NetAssetValues method.
provenance.metadata.v1.Record:
type: object
properties:
Expand Down Expand Up @@ -93957,33 +94099,6 @@ definitions:
description: >-
MsgWriteSessionResponse is the response type for the Msg/WriteSession RPC
method.
provenance.metadata.v1.NetAssetValue:
type: object
properties:
price:
title: price is the complete value of the asset's volume
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
volume:
type: string
format: uint64
title: >-
volume is the number of tokens of the marker that were purchased for
the price
updated_block_height:
type: string
format: uint64
title: updated_block_height is the block height of last update
title: NetAssetValue defines a scope's net asset value
provenance.metadata.v1.SessionIdComponents:
type: object
properties:
Expand Down
33 changes: 33 additions & 0 deletions docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@
- [OwnershipResponse](#provenance.metadata.v1.OwnershipResponse)
- [QueryParamsRequest](#provenance.metadata.v1.QueryParamsRequest)
- [QueryParamsResponse](#provenance.metadata.v1.QueryParamsResponse)
- [QueryScopeNetAssetValuesRequest](#provenance.metadata.v1.QueryScopeNetAssetValuesRequest)
- [QueryScopeNetAssetValuesResponse](#provenance.metadata.v1.QueryScopeNetAssetValuesResponse)
- [RecordSpecificationRequest](#provenance.metadata.v1.RecordSpecificationRequest)
- [RecordSpecificationResponse](#provenance.metadata.v1.RecordSpecificationResponse)
- [RecordSpecificationWrapper](#provenance.metadata.v1.RecordSpecificationWrapper)
Expand Down Expand Up @@ -7008,6 +7010,36 @@ QueryParamsResponse is the response type for the Query/Params RPC method.



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

### QueryScopeNetAssetValuesRequest
QueryNetAssetValuesRequest is the request type for the Query/NetAssetValues method.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `id` | [string](#string) | | scopeid metadata address |






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

### QueryScopeNetAssetValuesResponse
QueryNetAssetValuesRequest is the response type for the Query/NetAssetValues method.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `net_asset_values` | [NetAssetValue](#provenance.metadata.v1.NetAssetValue) | repeated | net asset values for scope |






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

### RecordSpecificationRequest
Expand Down Expand Up @@ -7592,6 +7624,7 @@ The specification_id can either be a uuid, e.g. def6bc0a-c9dd-4874-948f-5206e606
| `OSLocatorsByScope` | [OSLocatorsByScopeRequest](#provenance.metadata.v1.OSLocatorsByScopeRequest) | [OSLocatorsByScopeResponse](#provenance.metadata.v1.OSLocatorsByScopeResponse) | OSLocatorsByScope returns all ObjectStoreLocator entries for a for all signer's present in the specified scope. | GET|/provenance/metadata/v1/locator/scope/{scope_id}|
| `OSAllLocators` | [OSAllLocatorsRequest](#provenance.metadata.v1.OSAllLocatorsRequest) | [OSAllLocatorsResponse](#provenance.metadata.v1.OSAllLocatorsResponse) | OSAllLocators returns all ObjectStoreLocator entries. | GET|/provenance/metadata/v1/locators/all|
| `AccountData` | [AccountDataRequest](#provenance.metadata.v1.AccountDataRequest) | [AccountDataResponse](#provenance.metadata.v1.AccountDataResponse) | AccountData gets the account data associated with a metadata address. Currently, only scope ids are supported. | GET|/provenance/metadata/v1/accountdata/{metadata_addr}|
| `ScopeNetAssetValues` | [QueryScopeNetAssetValuesRequest](#provenance.metadata.v1.QueryScopeNetAssetValuesRequest) | [QueryScopeNetAssetValuesResponse](#provenance.metadata.v1.QueryScopeNetAssetValuesResponse) | ScopeNetAssetValues returns net asset values for scope | GET|/provenance/metadata/v1/netassetvalues/{id}|

<!-- end services -->

Expand Down
17 changes: 17 additions & 0 deletions proto/provenance/metadata/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ service Query {
rpc AccountData(AccountDataRequest) returns (AccountDataResponse) {
option (google.api.http).get = "/provenance/metadata/v1/accountdata/{metadata_addr}";
}

// ScopeNetAssetValues returns net asset values for scope
rpc ScopeNetAssetValues(QueryScopeNetAssetValuesRequest) returns (QueryScopeNetAssetValuesResponse) {
option (google.api.http).get = "/provenance/metadata/v1/netassetvalues/{id}";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
Expand Down Expand Up @@ -847,3 +852,15 @@ message AccountDataResponse {
// The accountdata for the requested metadata address.
string value = 1;
}

// QueryNetAssetValuesRequest is the request type for the Query/NetAssetValues method.
message QueryScopeNetAssetValuesRequest {
// scopeid metadata address
string id = 1;
}

// QueryNetAssetValuesRequest is the response type for the Query/NetAssetValues method.
message QueryScopeNetAssetValuesResponse {
// net asset values for scope
repeated NetAssetValue net_asset_values = 1 [(gogoproto.nullable) = false];
}
33 changes: 33 additions & 0 deletions x/metadata/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"context"
"errors"
"fmt"
"regexp"
Expand Down Expand Up @@ -58,6 +59,7 @@ func GetQueryCmd() *cobra.Command {
GetValueOwnershipCmd(),
GetOSLocatorCmd(),
GetAccountDataCmd(),
NetAssetValuesCmd(),
)
return queryCmd
}
Expand Down Expand Up @@ -1109,6 +1111,37 @@ func outputOSLocatorsAll(cmd *cobra.Command) error {
return clientCtx.PrintProto(res)
}

// NetAssetValuesCmd is the CLI command for querying a scope's net asset values.
func NetAssetValuesCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "net-asset-values [scope-id]",
Aliases: []string{"nav", "navs"},
Short: "Get scopes's net asset values'",
Example: fmt.Sprintf(`$ %s query metadata net-asset-values scope1qzge0zaztu65tx5x5llv5xc9ztsqxlkwel`, version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
id := strings.TrimSpace(args[0])

var response *types.QueryScopeNetAssetValuesResponse
if response, err = queryClient.ScopeNetAssetValues(
context.Background(),
&types.QueryScopeNetAssetValuesRequest{Id: id},
); err != nil {
fmt.Printf("failed to query scope %q net asset values details: %v\n", id, err)
return nil
}
return clientCtx.PrintProto(response)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

// ------------ private generic helper functions ------------

// trimSpaceAndJoin trims leading and trailing whitespace from each arg,
Expand Down
23 changes: 23 additions & 0 deletions x/metadata/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"time"

"github.com/google/uuid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/cosmos/cosmos-sdk/store/prefix"
"github.com/cosmos/cosmos-sdk/telemetry"
Expand Down Expand Up @@ -1351,6 +1353,27 @@ func ParseRecordSpecID(specID string, name string) (types.MetadataAddress, error
return types.RecordSpecMetadataAddress(uid, name), nil
}

// NetAssetValues query for returning net asset values for a marker
func (k Keeper) ScopeNetAssetValues(c context.Context, req *types.QueryScopeNetAssetValuesRequest) (*types.QueryScopeNetAssetValuesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)

scopeID := types.MetadataAddress(req.Id)

var navs []types.NetAssetValue
err := k.IterateNetAssetValues(ctx, scopeID, func(nav types.NetAssetValue) (stop bool) {
navs = append(navs, nav)
return false
})
if err != nil {
return nil, err
}

return &types.QueryScopeNetAssetValuesResponse{NetAssetValues: navs}, nil
}

// hasPageRequest is just for use with the getPageRequest func below.
type hasPageRequest interface {
GetPagination() *query.PageRequest
Expand Down
Loading

0 comments on commit c219d33

Please sign in to comment.