Skip to content

Commit

Permalink
rpc: export function unmarshall universe ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Oct 10, 2023
1 parent 50a4b9a commit 70a9559
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 10 additions & 11 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2669,7 +2669,7 @@ func unmarshalAssetSyncConfig(
error) {

// Parse the universe ID from the RPC form.
uniID, err := unmarshalUniID(config.Id)
uniID, err := UnmarshalUniID(config.Id)
if err != nil {
return nil, fmt.Errorf("unable to parse universe id: %w",
err)
Expand All @@ -2682,15 +2682,14 @@ func unmarshalAssetSyncConfig(
}, nil
}

// unmarshalUniID parses the RPC universe ID into the native counterpart.
func unmarshalUniID(rpcID *unirpc.ID) (universe.Identifier, error) {
// UnmarshalUniID parses the RPC universe ID into the native counterpart.
func UnmarshalUniID(rpcID *unirpc.ID) (universe.Identifier, error) {
// Unmarshal the proof type.
proofType, err := UnmarshalUniProofType(rpcID.ProofType)
if err != nil {
return universe.Identifier{}, fmt.Errorf("unable to unmarshal "+
"proof type: %w", err)
}

switch {
case rpcID.GetAssetId() != nil:
var assetID asset.ID
Expand Down Expand Up @@ -2756,7 +2755,7 @@ func unmarshalUniID(rpcID *unirpc.ID) (universe.Identifier, error) {
func (r *rpcServer) QueryAssetRoots(ctx context.Context,
req *unirpc.AssetRootQuery) (*unirpc.QueryRootResponse, error) {

universeID, err := unmarshalUniID(req.Id)
universeID, err := UnmarshalUniID(req.Id)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -2814,7 +2813,7 @@ func (r *rpcServer) QueryAssetRoots(ctx context.Context,
func (r *rpcServer) DeleteAssetRoot(ctx context.Context,
req *unirpc.DeleteRootQuery) (*unirpc.DeleteRootResponse, error) {

universeID, err := unmarshalUniID(req.Id)
universeID, err := UnmarshalUniID(req.Id)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -2870,7 +2869,7 @@ func marshalLeafKey(leafKey universe.LeafKey) *unirpc.AssetKey {
func (r *rpcServer) AssetLeafKeys(ctx context.Context,
req *unirpc.ID) (*unirpc.AssetLeafKeyResponse, error) {

universeID, err := unmarshalUniID(req)
universeID, err := UnmarshalUniID(req)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -2932,7 +2931,7 @@ func (r *rpcServer) marshalAssetLeaf(ctx context.Context,
func (r *rpcServer) AssetLeaves(ctx context.Context,
req *unirpc.ID) (*unirpc.AssetLeafResponse, error) {

universeID, err := unmarshalUniID(req)
universeID, err := UnmarshalUniID(req)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -3121,7 +3120,7 @@ func (r *rpcServer) marshalIssuanceProof(ctx context.Context,
func (r *rpcServer) QueryProof(ctx context.Context,
req *unirpc.UniverseKey) (*unirpc.AssetProofResponse, error) {

universeID, err := unmarshalUniID(req.Id)
universeID, err := UnmarshalUniID(req.Id)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -3225,7 +3224,7 @@ func (r *rpcServer) InsertProof(ctx context.Context,
return nil, fmt.Errorf("key cannot be nil")
}

universeID, err := unmarshalUniID(req.Key.Id)
universeID, err := UnmarshalUniID(req.Key.Id)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -3311,7 +3310,7 @@ func unmarshalUniverseSyncType(req unirpc.UniverseSyncMode) (
func unmarshalSyncTargets(targets []*unirpc.SyncTarget) ([]universe.Identifier, error) {
uniIDs := make([]universe.Identifier, 0, len(targets))
for _, target := range targets {
uniID, err := unmarshalUniID(target.Id)
uniID, err := UnmarshalUniID(target.Id)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions universe_rpc_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func unmarshalMerkleSumNode(root *unirpc.MerkleSumNode) mssmt.Node {
func unmarshalUniverseRoot(
root *unirpc.UniverseRoot) (universe.BaseRoot, error) {

id, err := unmarshalUniID(root.Id)
id, err := UnmarshalUniID(root.Id)
if err != nil {
return universe.BaseRoot{}, err
}
Expand All @@ -60,7 +60,7 @@ func unmarshalUniverseRoots(

baseRoots := make([]universe.BaseRoot, 0, len(roots))
for _, root := range roots {
id, err := unmarshalUniID(root.Id)
id, err := UnmarshalUniID(root.Id)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 70a9559

Please sign in to comment.