mirror of
https://github.com/Xahau/Validation-Ledger-Tx-Store-to-xPOP.git
synced 2025-11-19 19:25:52 +00:00
Dir exists separate fn
This commit is contained in:
7
lib/dirExists.mjs
Normal file
7
lib/dirExists.mjs
Normal file
@@ -0,0 +1,7 @@
|
||||
import { stat } from 'fs'
|
||||
|
||||
const dirExists = async storeDir => await new Promise(resolve => stat(storeDir, staterr => resolve(!staterr)))
|
||||
|
||||
export {
|
||||
dirExists,
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { writeFile } from 'fs'
|
||||
import { stat } from 'fs'
|
||||
import { ledgerIndexToFolders } from './ledgerIndexToFolders.mjs'
|
||||
import { computeBinaryTransactionHash } from './computeBinaryTransactionHash.mjs'
|
||||
import { dirExists } from './dirExists.mjs'
|
||||
import 'dotenv/config'
|
||||
|
||||
const obtainedHumanReadableLedgers = []
|
||||
@@ -17,9 +17,7 @@ const onLedger = async ({
|
||||
const relativeStoreDir = 'store/' + networkId + '/' + ledgerIndexToFolders(ledger.ledger_index)
|
||||
const storeDir = new URL('../' + relativeStoreDir, import.meta.url).pathname
|
||||
|
||||
const dirExists = await new Promise(resolve => stat(storeDir, staterr => resolve(!staterr)))
|
||||
|
||||
if (dirExists) {
|
||||
if (await dirExists(storeDir)) {
|
||||
;[
|
||||
...(
|
||||
obtainedBinaryTxLedgers.indexOf(ledger.ledger_index) < 0
|
||||
@@ -66,7 +64,7 @@ const onLedger = async ({
|
||||
/**
|
||||
* Merge transaction hashes with the raw tx data
|
||||
*/
|
||||
results.ledger.transactions.map(t => {
|
||||
;(results?.ledger?.transactions || []).map(t => {
|
||||
return Object.assign(t, { tx_id: computeBinaryTransactionHash(t.tx_blob), })
|
||||
})
|
||||
|
||||
@@ -79,6 +77,7 @@ const onLedger = async ({
|
||||
if (
|
||||
results?.ledger?.parent_hash
|
||||
&& obtainedHumanReadableLedgers.indexOf(ledger.ledger_index) < 0
|
||||
&& results?.ledger?.ledger_hash === ledger?.ledger_hash
|
||||
) {
|
||||
/**
|
||||
* See comment above "Store in array" ... - first one will be stored
|
||||
|
||||
Reference in New Issue
Block a user