8
8
#include " ledger/LedgerTxnImpl.h"
9
9
#include " ledger/LedgerTypeUtils.h"
10
10
#include " main/Config.h"
11
+ #include " util/ArchivalProofs.h"
11
12
#include " util/Logging.h"
12
13
#include " util/UnorderedSet.h"
13
14
#include " util/XDRStream.h" // IWYU pragma: keep
@@ -77,6 +78,8 @@ QueryServer::QueryServer(const std::string& address, unsigned short port,
77
78
mServer .add404 (std::bind (&QueryServer::notFound, this , _1, _2, _3));
78
79
addRoute (" getledgerentryraw" , &QueryServer::getLedgerEntryRaw);
79
80
addRoute (" getledgerentry" , &QueryServer::getLedgerEntry);
81
+ addRoute (" getrestoreproof" , &QueryServer::getRestoreProof);
82
+ addRoute (" getcreationproof" , &QueryServer::getCreationProof);
80
83
81
84
auto workerPids = mServer .start ();
82
85
for (auto pid : workerPids)
@@ -412,4 +415,92 @@ QueryServer::getLedgerEntry(std::string const& params, std::string const& body,
412
415
retStr = Json::FastWriter ().write (root);
413
416
return true ;
414
417
}
418
+
419
+ bool
420
+ QueryServer::getRestoreProof (std::string const & params, std::string const & body,
421
+ std::string& retStr)
422
+ {
423
+ ZoneScoped;
424
+ Json::Value root;
425
+
426
+ std::map<std::string, std::vector<std::string>> paramMap;
427
+ httpThreaded::server::server::parsePostParams (body, paramMap);
428
+
429
+ auto keys = paramMap[" key" ];
430
+ auto snapshotLedger = parseOptionalParam<uint32_t >(paramMap, " ledgerSeq" );
431
+ if (keys.empty ())
432
+ {
433
+ throw std::invalid_argument (
434
+ " Must specify ledger key in POST body: key=<LedgerKey in base64 "
435
+ " XDR format>" );
436
+ }
437
+
438
+ xdr::xvector<ArchivalProof> proof;
439
+ auto & hotBL = mHotArchiveBucketListSnapshots .at (std::this_thread::get_id ());
440
+ for (auto const & key : keys)
441
+ {
442
+ LedgerKey lk;
443
+ fromOpaqueBase64 (lk, key);
444
+ if (!isPersistentEntry (lk))
445
+ {
446
+ throw std::invalid_argument (
447
+ " Only persistent entries require restoration proofs" );
448
+ }
449
+
450
+ if (!addRestorationProof (hotBL, lk, proof, snapshotLedger))
451
+ {
452
+ throw std::invalid_argument (" No valid proof exists for key" );
453
+ }
454
+ }
455
+
456
+ root[" ledger" ] = hotBL->getLedgerSeq ();
457
+ root[" proof" ] = toOpaqueBase64 (proof);
458
+
459
+ retStr = Json::FastWriter ().write (root);
460
+ return true ;
461
+ }
462
+
463
+ bool
464
+ QueryServer::getCreationProof (std::string const & params,
465
+ std::string const & body, std::string& retStr)
466
+ {
467
+ ZoneScoped;
468
+ Json::Value root;
469
+
470
+ std::map<std::string, std::vector<std::string>> paramMap;
471
+ httpThreaded::server::server::parsePostParams (body, paramMap);
472
+
473
+ auto keys = paramMap[" key" ];
474
+ auto snapshotLedger = parseOptionalParam<uint32_t >(paramMap, " ledgerSeq" );
475
+ if (keys.empty ())
476
+ {
477
+ throw std::invalid_argument (
478
+ " Must specify ledger key in POST body: key=<LedgerKey in base64 "
479
+ " XDR format>" );
480
+ }
481
+
482
+ auto & hotBL = mHotArchiveBucketListSnapshots .at (std::this_thread::get_id ());
483
+ xdr::xvector<ArchivalProof> proof;
484
+ for (auto const & key : keys)
485
+ {
486
+ LedgerKey lk;
487
+ fromOpaqueBase64 (lk, key);
488
+ if (!isPersistentEntry (lk) || lk.type () != CONTRACT_DATA)
489
+ {
490
+ throw std::invalid_argument (" Only persistent contract data entries "
491
+ " require creation proofs" );
492
+ }
493
+
494
+ if (!addCreationProof (mSimulateFilterMiss , lk, proof))
495
+ {
496
+ throw std::invalid_argument (" No valid proof exists for key" );
497
+ }
498
+ }
499
+
500
+ root[" ledger" ] = snapshotLedger ? *snapshotLedger : hotBL->getLedgerSeq ();
501
+ root[" proof" ] = toOpaqueBase64 (proof);
502
+
503
+ retStr = Json::FastWriter ().write (root);
504
+ return true ;
505
+ }
415
506
}
0 commit comments