diff --git a/lib/onTransaction.mjs b/lib/onTransaction.mjs index 58e56ec..4069f1d 100644 --- a/lib/onTransaction.mjs +++ b/lib/onTransaction.mjs @@ -51,13 +51,11 @@ const onTransaction = async ({ * generate an xPOP. */ setTimeout(async () => { - console.log( - await xpop({ - ledgerIndex: transaction.ledger_index, - networkId, - txHash: tx.hash, - }) - ) + await xpop({ + ledgerIndex: transaction.ledger_index, + networkId, + txHash: tx.hash, + }) }, 500) // ^^ To check: is this enough? If e.g. retrieving the ledger info // would take longer this may not be enough. Best solution: diff --git a/xpop/generateV1.mjs b/xpop/generateV1.mjs index 95f508c..06b62fc 100644 --- a/xpop/generateV1.mjs +++ b/xpop/generateV1.mjs @@ -1,6 +1,6 @@ import assert from 'assert' import { xpop } from './xpopV1.mjs' -import { readFile, readdir } from 'fs' +import { writeFile, readFile, readdir } from 'fs' import { ledgerIndexToFolders } from '../lib/ledgerIndexToFolders.mjs' import { dirExists } from '../lib/dirExists.mjs' @@ -60,8 +60,19 @@ const generateV1 = async ({ Promise.all(validationFiles.map(f => catjson(relativeStorDir + '/' + f))), catjson(relativeStorDir + '/tx_' + txHash + '.json'), ]) + + const xpopJson = await xpop({ vl, ledger: { json, binary, }, validations, tx, }) + const xpopFilename = 'xpop_' + txHash + '.json' + + writeFile(storeDir + '/' + xpopFilename, Buffer.from(xpopJson, 'utf8'), err => { + if (err) { + console.log(' !!!->> Error writing xpop-file @ ' + storeDir) + } else { + console.log(' ---->> xPOP stored @ ' + relativeStorDir + '/' + xpopFilename + ', strlen: ' + xpopJson.length) + } + }) - return await xpop({ vl, ledger: { json, binary, }, validations, tx, }) + return Buffer.from(xpopJson, 'utf-8').toString('hex') } catch (e) { console.log(e) throw new Error('Not all files required for xPOP generation found') diff --git a/xpop/xpopV1.mjs b/xpop/xpopV1.mjs index ecf5aa3..07be250 100644 --- a/xpop/xpopV1.mjs +++ b/xpop/xpopV1.mjs @@ -10,13 +10,6 @@ const xpop = async ({ validations, tx, }) => { - // console.log(vl, json, binary, validations, tx) - - // console.log(json) - // console.log(tx) - - const x = {} - const proof = create_proof(binary?.transactions, tx?.transaction?.hash) const computed_transactions_root = hash_proof(proof) @@ -61,12 +54,7 @@ const xpop = async ({ } } - const xpopJson = JSON.stringify(xpopObj) - const xpopHex = Buffer.from(xpopJson, 'utf-8').toString('hex') - - // TODO: STORE - - return xpopHex + return JSON.stringify(xpopObj) } export {