Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mint: fix REST encoding of mint RPC #319

Merged
merged 3 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/tapcli/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ func listBatches(ctx *cli.Context) error {
}

resp, err := client.ListBatches(ctxc, &mintrpc.ListBatchRequest{
BatchKey: batchKey,
Filter: &mintrpc.ListBatchRequest_BatchKey{
BatchKey: batchKey,
},
})
if err != nil {
return fmt.Errorf("unable to list batches: %w", err)
Expand Down
4 changes: 3 additions & 1 deletion itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ func testMintAssetNameCollisionError(t *harnessTest) {
// the batch state.
cancelBatch, err := t.tapd.ListBatches(
ctxt, &mintrpc.ListBatchRequest{
BatchKey: collideBatchKey.BatchKey,
Filter: &mintrpc.ListBatchRequest_BatchKey{
BatchKey: collideBatchKey.BatchKey,
},
})
require.NoError(t.t, err)

Expand Down
21 changes: 19 additions & 2 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,25 @@ func (r *rpcServer) ListBatches(_ context.Context,
err error
)

if len(req.BatchKey) != 0 {
batchKey, err = btcec.ParsePubKey(req.BatchKey)
switch {
case len(req.GetBatchKey()) > 0 && len(req.GetBatchKeyStr()) > 0:
return nil, fmt.Errorf("cannot specify both batch_key and " +
"batch_key_string")

case len(req.GetBatchKey()) > 0:
batchKey, err = btcec.ParsePubKey(req.GetBatchKey())
if err != nil {
return nil, fmt.Errorf("invalid batch key: %w", err)
}

case len(req.GetBatchKeyStr()) > 0:
batchKeyBytes, err := hex.DecodeString(req.GetBatchKeyStr())
if err != nil {
return nil, fmt.Errorf("invalid batch key string: %w",
err)
}

batchKey, err = btcec.ParsePubKey(batchKeyBytes)
if err != nil {
return nil, fmt.Errorf("invalid batch key: %w", err)
}
Expand Down
149 changes: 97 additions & 52 deletions taprpc/mintrpc/mint.pb.go

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

32 changes: 30 additions & 2 deletions taprpc/mintrpc/mint.pb.gw.go

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

13 changes: 10 additions & 3 deletions taprpc/mintrpc/mint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,16 @@ message CancelBatchResponse {
}

message ListBatchRequest {
// The optional batch key of the batch to list. When using REST this field
// must be encoded as base64url.
bytes batch_key = 1;
// The optional batch key of the batch to list.
oneof filter {
// The optional batch key of the batch to list, specified as raw bytes
// (gRPC only).
bytes batch_key = 1;

// The optional batch key of the batch to list, specified as a hex
// encoded string (use this for REST).
string batch_key_str = 2;
}
}

message ListBatchResponse {
Expand Down
9 changes: 8 additions & 1 deletion taprpc/mintrpc/mint.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@
"parameters": [
{
"name": "batch_key",
"description": "The optional batch key of the batch to list. When using REST this field\nmust be encoded as base64url.",
"description": "The optional batch key of the batch to list, specified as raw bytes\n(gRPC only).",
"in": "path",
"required": true,
"type": "string",
"format": "byte"
},
{
"name": "batch_key_str",
"description": "The optional batch key of the batch to list, specified as a hex\nencoded string (use this for REST).",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
Expand Down
9 changes: 5 additions & 4 deletions taprpc/universerpc/universe.pb.go

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

9 changes: 5 additions & 4 deletions taprpc/universerpc/universe.proto
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,17 @@ message MerkleSumNode {

message ID {
oneof id {
// The 32-byte asset ID.
// The 32-byte asset ID specified as raw bytes (gRPC only).
bytes asset_id = 1;

// The 32-byte asset ID encoded as a hex string.
// The 32-byte asset ID encoded as a hex string (use this for REST).
string asset_id_str = 2;

// The 32-byte asset group key.
// The 32-byte asset group key specified as raw bytes (gRPC only).
bytes group_key = 3;

// The 32-byte asset group key encoded as hex string.
// The 32-byte asset group key encoded as hex string (use this for
// REST).
string group_key_str = 4;
}
}
Expand Down
Loading