Skip to content

Commit

Permalink
Add OpenAPI info for transaction submit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Aug 12, 2024
1 parent 7dc5971 commit 86ea00e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
36 changes: 30 additions & 6 deletions convex-restapi/src/main/java/convex/restapi/api/ChainAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import convex.restapi.model.QueryRequest;
import convex.restapi.model.TransactionPrepareRequest;
import convex.restapi.model.TransactionPrepareResponse;
import convex.restapi.model.TransactionSubmitRequest;
import io.javalin.Javalin;
import io.javalin.http.BadRequestResponse;
import io.javalin.http.Context;
Expand Down Expand Up @@ -450,11 +451,34 @@ private static ACell readCode(Object srcValue) {
}
}

@OpenApi(path = ROUTE+"transaction/submit",
methods = HttpMethod.POST,
operationId = "transactionSubmit",
tags= {"Transactions"},
summary="Submit a pre-prepared Convex transaction. If sucessful, will return transaction result.",
requestBody = @OpenApiRequestBody(
description = "Transaction preparation request",
content= @OpenApiContent(
from=TransactionSubmitRequest.class,
type = "application/json"
)),
responses = {
@OpenApiResponse(status = "200",
description = "Transaction executed",
content = {
@OpenApiContent(
from=CVMResult.class,
type = "application/json",
exampleObjects = {
@OpenApiExampleProperty(name = "value", value = "6")
}
)}),
@OpenApiResponse(status = "503",
description = "Transaction service unavailable" )
}
)
public void runTransactionSubmit(Context ctx) {
Map<String, Object> req = getJSONBody(ctx);
Address addr = Address.parse(req.get("address"));
if (addr == null)
throw new BadRequestResponse(jsonError("query requires an 'address' field."));

// Get the transaction hash
Object hashValue = req.get("hash");
Expand All @@ -463,7 +487,7 @@ public void runTransactionSubmit(Context ctx) {
Blob h = Blob.parse((String) hashValue);
if (h == null)
throw new BadRequestResponse(
jsonError("Parameter 'hash' did not parse correctly, must be 64 hex characters."));
jsonError("Parameter 'hash' did not parse correctly, must be a hex string."));

ATransaction trans = null;
try {
Expand All @@ -488,15 +512,15 @@ public void runTransactionSubmit(Context ctx) {
AccountKey key = AccountKey.parse(keyValue);
if (key == null)
throw new BadRequestResponse(
jsonError("Parameter 'accountKey' did not parse correctly, must be 64 hex characters."));
jsonError("Parameter 'accountKey' did not parse correctly, must be 64 hex characters (32 bytes)."));

// Get the signature
Object sigValue = req.get("sig");
if (!(sigValue instanceof String))
throw new BadRequestResponse(jsonError("Parameter 'sig' must be provided as a String"));
ABlob sigData = Blobs.parse(sigValue);
if ((sigData == null) || (sigData.count() != Ed25519Signature.SIGNATURE_LENGTH)) {
throw new BadRequestResponse(jsonError("Parameter 'sig' must be a 64 byte hex String"));
throw new BadRequestResponse(jsonError("Parameter 'sig' must be a 64 byte hex String (128 hex chars)"));
}
ASignature sig = Ed25519Signature.fromBlob(sigData);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package convex.restapi.model;

import io.javalin.openapi.OpenApiByFields;

@OpenApiByFields
public class TransactionSubmitRequest {
public String hash;
public String accountKey;
public String sig;
}

0 comments on commit 86ea00e

Please sign in to comment.