diff --git a/python-regression/IXI/export-spent/README.md b/python-regression/IXI/export-spent/README.md new file mode 100644 index 0000000000..2376791f62 --- /dev/null +++ b/python-regression/IXI/export-spent/README.md @@ -0,0 +1,18 @@ +# Spent + +Copy or clone source code into your `ixi` directory such that it can be found as `ixi/Spent/{index.js, package.json}`. +Your node may be running at this time, and it will hot-load the script. +After you've cloned it, and with a running iri node, run the following command to generate the spent addresses file: + +``` +curl http://localhost:14265 -X POST -H 'X-IOTA-API-Version: 1.4.1' -H 'Content-Type: application/json' -d '{"command": "Spent.generateSpentAddressesFile"}' +``` + +Generated file will start with the timestamp of generation start. +Every next line is a human-readable line with the hash of a spent address. + +----- + +#### Troubleshooting: + + diff --git a/python-regression/IXI/export-spent/index.js b/python-regression/IXI/export-spent/index.js new file mode 100644 index 0000000000..e2c63efe4c --- /dev/null +++ b/python-regression/IXI/export-spent/index.js @@ -0,0 +1,79 @@ +var System = java.lang.System; + +var spentAddressProvider = IOTA.spentAddressesProvider + +var iri = com.iota.iri; +var Callable = iri.service.CallableRequest; +var Response = iri.service.dto.IXIResponse; +var ErrorResponse = iri.service.dto.ErrorResponse; + +var fileName = "spentAddresses.txt"; + +// Log using logger of the ixi class +var log = org.slf4j.LoggerFactory.getLogger(iri.IXI.class); + +/* +curl http://localhost:14265 -X POST -H 'X-IOTA-API-Version: 1.4.1' -H 'Content-Type: application/json' -d '{"command": "Spent.generateSpentAddressesFile"}' +*/ +function generate(request) { + var file = new java.io.File(fileName); + if (file.exists()){ + if (file.isDirectory()){ + log.error("Found a directory called {}, aborting!"); + return ErrorResponse.create("Failed to create spent address due to {} beeing a folder", fileName); + } else { + log.info("{} already exists.. Overwriting!", fileName); + } + } else { + file.createNewFile(); + } + + var hashes = spentAddressProvider.getAllAddresses(); + var writer; + var checksum; + try { + // False for always overwriting + writer = new java.io.FileWriter(file, false); + + var separator = System.getProperty("line.separator"); + + // Start with the time + writer.write(System.currentTimeMillis() + separator); + + // Create a digest + var digest = java.security.MessageDigest.getInstance("SHA-256"); + for (var i=0; i