substrate-light-ui
substrate-light-ui copied to clipboard
Export wasm light client's IndexedDB to a JSON file
It's super annoying during development when the client goes Idle and we need to restart from block 0.
Something like this supposedly works in electron and could work from a browser as well with some tweaks to ditch the node dependencies. But I think we just need to sync with the electron app, then run this script, and find a way to import it from browser. From what I've read, anything over 5MB will be problematic but I'm more than happy to try regardless
snippet from https://github.com/Polarisation/indexeddb-export-import
// export indexed db to json string
var Dexie = require("Dexie");
var IDBExportImport = require("indexeddb-export-import")
var db = new Dexie("Kusama CC3", 1);
db.version(1).stores({
things : "id++, thing_name, thing_description",
});
db.open().then(function() {
var idb_db = db.backendDB(); // get native IDBDatabase object from Dexie wrapper
// export to JSON, clear database, and import from JSON
IDBExportImport.exportToJsonString(idb_db, function(err, jsonString) {
if(err)
console.error(err);
else {
console.log("Exported as JSON: " + jsonString);
IDBExportImport.clearDatabase(idb_db, function(err) {
if(!err) // cleared data successfully
IDBExportImport.importFromJsonString(idb_db, jsonString, function(err) {
if (!err)
console.log("Imported data successfully");
});
});
}
});
}).catch(function(e) {
console.error("Could not connect. " + e);
});