Skip to content

Commit 86ea00e

Browse files
committed
Add OpenAPI info for transaction submit
1 parent 7dc5971 commit 86ea00e

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

convex-restapi/src/main/java/convex/restapi/api/ChainAPI.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import convex.restapi.model.QueryRequest;
4646
import convex.restapi.model.TransactionPrepareRequest;
4747
import convex.restapi.model.TransactionPrepareResponse;
48+
import convex.restapi.model.TransactionSubmitRequest;
4849
import io.javalin.Javalin;
4950
import io.javalin.http.BadRequestResponse;
5051
import io.javalin.http.Context;
@@ -450,11 +451,34 @@ private static ACell readCode(Object srcValue) {
450451
}
451452
}
452453

454+
@OpenApi(path = ROUTE+"transaction/submit",
455+
methods = HttpMethod.POST,
456+
operationId = "transactionSubmit",
457+
tags= {"Transactions"},
458+
summary="Submit a pre-prepared Convex transaction. If sucessful, will return transaction result.",
459+
requestBody = @OpenApiRequestBody(
460+
description = "Transaction preparation request",
461+
content= @OpenApiContent(
462+
from=TransactionSubmitRequest.class,
463+
type = "application/json"
464+
)),
465+
responses = {
466+
@OpenApiResponse(status = "200",
467+
description = "Transaction executed",
468+
content = {
469+
@OpenApiContent(
470+
from=CVMResult.class,
471+
type = "application/json",
472+
exampleObjects = {
473+
@OpenApiExampleProperty(name = "value", value = "6")
474+
}
475+
)}),
476+
@OpenApiResponse(status = "503",
477+
description = "Transaction service unavailable" )
478+
}
479+
)
453480
public void runTransactionSubmit(Context ctx) {
454481
Map<String, Object> req = getJSONBody(ctx);
455-
Address addr = Address.parse(req.get("address"));
456-
if (addr == null)
457-
throw new BadRequestResponse(jsonError("query requires an 'address' field."));
458482

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

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

493517
// Get the signature
494518
Object sigValue = req.get("sig");
495519
if (!(sigValue instanceof String))
496520
throw new BadRequestResponse(jsonError("Parameter 'sig' must be provided as a String"));
497521
ABlob sigData = Blobs.parse(sigValue);
498522
if ((sigData == null) || (sigData.count() != Ed25519Signature.SIGNATURE_LENGTH)) {
499-
throw new BadRequestResponse(jsonError("Parameter 'sig' must be a 64 byte hex String"));
523+
throw new BadRequestResponse(jsonError("Parameter 'sig' must be a 64 byte hex String (128 hex chars)"));
500524
}
501525
ASignature sig = Ed25519Signature.fromBlob(sigData);
502526

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package convex.restapi.model;
2+
3+
import io.javalin.openapi.OpenApiByFields;
4+
5+
@OpenApiByFields
6+
public class TransactionSubmitRequest {
7+
public String hash;
8+
public String accountKey;
9+
public String sig;
10+
}

0 commit comments

Comments
 (0)