45
45
import convex .restapi .model .QueryRequest ;
46
46
import convex .restapi .model .TransactionPrepareRequest ;
47
47
import convex .restapi .model .TransactionPrepareResponse ;
48
+ import convex .restapi .model .TransactionSubmitRequest ;
48
49
import io .javalin .Javalin ;
49
50
import io .javalin .http .BadRequestResponse ;
50
51
import io .javalin .http .Context ;
@@ -450,11 +451,34 @@ private static ACell readCode(Object srcValue) {
450
451
}
451
452
}
452
453
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
+ )
453
480
public void runTransactionSubmit (Context ctx ) {
454
481
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." ));
458
482
459
483
// Get the transaction hash
460
484
Object hashValue = req .get ("hash" );
@@ -463,7 +487,7 @@ public void runTransactionSubmit(Context ctx) {
463
487
Blob h = Blob .parse ((String ) hashValue );
464
488
if (h == null )
465
489
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 ." ));
467
491
468
492
ATransaction trans = null ;
469
493
try {
@@ -488,15 +512,15 @@ public void runTransactionSubmit(Context ctx) {
488
512
AccountKey key = AccountKey .parse (keyValue );
489
513
if (key == null )
490
514
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) ." ));
492
516
493
517
// Get the signature
494
518
Object sigValue = req .get ("sig" );
495
519
if (!(sigValue instanceof String ))
496
520
throw new BadRequestResponse (jsonError ("Parameter 'sig' must be provided as a String" ));
497
521
ABlob sigData = Blobs .parse (sigValue );
498
522
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) " ));
500
524
}
501
525
ASignature sig = Ed25519Signature .fromBlob (sigData );
502
526
0 commit comments