From 043a95d9ef46031e9bc8a5df4e952893a4e585c9 Mon Sep 17 00:00:00 2001 From: Josip Milovac Date: Tue, 10 Jan 2023 17:30:58 +1100 Subject: [PATCH] change store id to be metadata id instead of block id --- blockchain/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/blockchain/index.js b/blockchain/index.js index 2f1c6eb..0b215d6 100644 --- a/blockchain/index.js +++ b/blockchain/index.js @@ -144,8 +144,7 @@ function findChainDifference(oldChain, newChain) { function addBlockMetadata(blockchain, block) { const metadatas = Block.getMetadatas(block); - for (const key in metadatas) { - const metadata = metadatas[key]; + for (const metadata of metadatas) { if (!("SSNmetadata" in metadata)) { //assert? return; @@ -163,7 +162,7 @@ function addBlockMetadata(blockchain, block) { DataFactory.namedNode(quadN.subject.id), DataFactory.namedNode(quadN.predicate.id), DataFactory.namedNode(quadN.object.id), - DataFactory.namedNode(block.hash))); + DataFactory.namedNode(metadata.id))); } }); } @@ -257,7 +256,9 @@ class Blockchain { //fix metadata for (let i = oldChain.length - 1; i >= chainDifference; i--) { - this.store.deleteGraph(oldChain[i].hash); + for (const metadata of Block.getMetadatas(oldChain[i])) { + this.store.deleteGraph(metadata.id); + } } for (let i = chainDifference; i < newChain.length; ++i) { addBlockMetadata(this, newChain[i]);