@@ -201,6 +201,56 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fP
201
201
return result;
202
202
}
203
203
204
+ UniValue dumpbeaconcontracts (const UniValue& params, bool fHelp )
205
+ {
206
+ if (fHelp || params.size () != 1 )
207
+ throw runtime_error (
208
+ " dumpbeaconcontracts <file>\n "
209
+ " \n "
210
+ " <file> Output file.\n "
211
+ " \n "
212
+ " Dumps current beacon storage and all beacon contracts in the chain to a file.\n " );
213
+
214
+ std::string path = params[0 ].get_str ();
215
+ if (path.empty () || fs::exists (path))
216
+ throw runtime_error (" Invalid path" );
217
+
218
+ CBlock block;
219
+ std::vector<CTransaction> vtx;
220
+ std::vector<GRC::Cpid> active_beacons;
221
+ std::vector<CKeyID> pending_beacons;
222
+ CAutoFile file (fsbridge::fopen (path, " wb" ), SER_DISK, PROTOCOL_VERSION);
223
+
224
+ LOCK (cs_main);
225
+
226
+ CBlockIndex* pblockindex = pindexGenesisBlock;
227
+ while (pblockindex != nullptr ) {
228
+ block.ReadFromDisk (pblockindex);
229
+ for (auto & tx : block.vtx ) {
230
+ for (const auto & contract : tx.GetContracts ()) {
231
+ if (contract.m_type == GRC::ContractType::BEACON) {
232
+ vtx.push_back (tx);
233
+ break ;
234
+ }
235
+ }
236
+ }
237
+ pblockindex = pblockindex->pnext ;
238
+ }
239
+
240
+ for (const auto & x : GRC::GetBeaconRegistry ().Beacons ()) {
241
+ active_beacons.push_back (x.first );
242
+ }
243
+
244
+ for (const auto & x : GRC::GetBeaconRegistry ().PendingBeacons ()) {
245
+ pending_beacons.push_back (x.first );
246
+ }
247
+
248
+ file << vtx;
249
+ file << active_beacons;
250
+ file << pending_beacons;
251
+
252
+ return UniValue (UniValue::VOBJ);
253
+ }
204
254
205
255
UniValue showblock (const UniValue& params, bool fHelp )
206
256
{
0 commit comments