Skip to content

Commit

Permalink
Merge pull request #445 from lightninglabs/bug-fixes
Browse files Browse the repository at this point in the history
Fix REST parameter issue in GET call
  • Loading branch information
Roasbeef authored Aug 9, 2023
2 parents b4c8186 + f632208 commit 7077464
Show file tree
Hide file tree
Showing 7 changed files with 445 additions and 122 deletions.
38 changes: 38 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,25 @@ func (r *rpcServer) FetchAssetMeta(ctx context.Context,
ctx, assetID,
)

case in.GetAssetIdStr() != "":
if len(in.GetAssetIdStr()) != hex.EncodedLen(sha256.Size) {
return nil, fmt.Errorf("asset ID must be 32 bytes")
}

var assetIDBytes []byte
assetIDBytes, err = hex.DecodeString(in.GetAssetIdStr())
if err != nil {
return nil, fmt.Errorf("error hex decoding asset ID: "+
"%w", err)
}

var assetID asset.ID
copy(assetID[:], assetIDBytes)

assetMeta, err = r.cfg.AssetStore.FetchAssetMetaForAsset(
ctx, assetID,
)

case in.GetMetaHash() != nil:
if len(in.GetMetaHash()) != sha256.Size {
return nil, fmt.Errorf("meta hash must be 32 bytes")
Expand All @@ -2265,6 +2284,25 @@ func (r *rpcServer) FetchAssetMeta(ctx context.Context,
ctx, metaHash,
)

case in.GetMetaHashStr() != "":
if len(in.GetMetaHashStr()) != hex.EncodedLen(sha256.Size) {
return nil, fmt.Errorf("meta hash must be 32 bytes")
}

var metaHashBytes []byte
metaHashBytes, err = hex.DecodeString(in.GetMetaHashStr())
if err != nil {
return nil, fmt.Errorf("error hex decoding meta hash: "+
"%w", err)
}

var metaHash [asset.MetaHashLen]byte
copy(metaHash[:], metaHashBytes)

assetMeta, err = r.cfg.AssetStore.FetchAssetMetaByHash(
ctx, metaHash,
)

default:
return nil, fmt.Errorf("either asset ID or meta hash must " +
"be set")
Expand Down
265 changes: 151 additions & 114 deletions taprpc/taprootassets.pb.go

Large diffs are not rendered by default.

179 changes: 175 additions & 4 deletions taprpc/taprootassets.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions taprpc/taprootassets.proto
Original file line number Diff line number Diff line change
Expand Up @@ -872,5 +872,11 @@ message FetchAssetMetaRequest {

// The 32-byte meta hash of the asset meta.
bytes meta_hash = 2;

// The hex encoded asset ID of the asset to fetch the meta for.
string asset_id_str = 3;

// The hex encoded meta hash of the asset meta.
string meta_hash_str = 4;
}
}
Loading

0 comments on commit 7077464

Please sign in to comment.