Store xPOPs

This commit is contained in:
Wietse Wind
2023-10-05 02:05:25 +02:00
parent c0b824aa2b
commit 1599aaa65e
3 changed files with 19 additions and 22 deletions

View File

@@ -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:

View File

@@ -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')

View File

@@ -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 {