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