mirror of
https://github.com/Xahau/Validation-Ledger-Tx-Store-to-xPOP.git
synced 2025-11-20 11:45:51 +00:00
Store xPOPs
This commit is contained in:
@@ -51,13 +51,11 @@ const onTransaction = async ({
|
|||||||
* generate an xPOP.
|
* generate an xPOP.
|
||||||
*/
|
*/
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
console.log(
|
await xpop({
|
||||||
await xpop({
|
ledgerIndex: transaction.ledger_index,
|
||||||
ledgerIndex: transaction.ledger_index,
|
networkId,
|
||||||
networkId,
|
txHash: tx.hash,
|
||||||
txHash: tx.hash,
|
})
|
||||||
})
|
|
||||||
)
|
|
||||||
}, 500)
|
}, 500)
|
||||||
// ^^ To check: is this enough? If e.g. retrieving the ledger info
|
// ^^ To check: is this enough? If e.g. retrieving the ledger info
|
||||||
// would take longer this may not be enough. Best solution:
|
// would take longer this may not be enough. Best solution:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import { xpop } from './xpopV1.mjs'
|
import { xpop } from './xpopV1.mjs'
|
||||||
import { readFile, readdir } from 'fs'
|
import { writeFile, readFile, readdir } from 'fs'
|
||||||
import { ledgerIndexToFolders } from '../lib/ledgerIndexToFolders.mjs'
|
import { ledgerIndexToFolders } from '../lib/ledgerIndexToFolders.mjs'
|
||||||
import { dirExists } from '../lib/dirExists.mjs'
|
import { dirExists } from '../lib/dirExists.mjs'
|
||||||
|
|
||||||
@@ -60,8 +60,19 @@ const generateV1 = async ({
|
|||||||
Promise.all(validationFiles.map(f => catjson(relativeStorDir + '/' + f))),
|
Promise.all(validationFiles.map(f => catjson(relativeStorDir + '/' + f))),
|
||||||
catjson(relativeStorDir + '/tx_' + txHash + '.json'),
|
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) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
throw new Error('Not all files required for xPOP generation found')
|
throw new Error('Not all files required for xPOP generation found')
|
||||||
|
|||||||
@@ -10,13 +10,6 @@ const xpop = async ({
|
|||||||
validations,
|
validations,
|
||||||
tx,
|
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 proof = create_proof(binary?.transactions, tx?.transaction?.hash)
|
||||||
const computed_transactions_root = hash_proof(proof)
|
const computed_transactions_root = hash_proof(proof)
|
||||||
|
|
||||||
@@ -61,12 +54,7 @@ const xpop = async ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const xpopJson = JSON.stringify(xpopObj)
|
return JSON.stringify(xpopObj)
|
||||||
const xpopHex = Buffer.from(xpopJson, 'utf-8').toString('hex')
|
|
||||||
|
|
||||||
// TODO: STORE
|
|
||||||
|
|
||||||
return xpopHex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
Reference in New Issue
Block a user