mirror of https://codeberg.org/pzp/pzp-dict.git
Fix minRequiredDepth() validation
This commit is contained in:
parent
afc7766326
commit
fa51c8c423
14
lib/index.js
14
lib/index.js
|
@ -350,18 +350,18 @@ function initDict(peer, config) {
|
||||||
*/
|
*/
|
||||||
function minRequiredDepth(tangleID) {
|
function minRequiredDepth(tangleID) {
|
||||||
assertDBPlugin(peer)
|
assertDBPlugin(peer)
|
||||||
|
const tangle = peer.db.getTangle(tangleID)
|
||||||
|
|
||||||
const rootMsg = peer.db.get(tangleID)
|
|
||||||
if (!rootMsg) throw new Error(`Cannot find tangle root "${tangleID}"`)
|
|
||||||
if (!MsgV3.isMoot(rootMsg)) throw new Error(`"${tangleID}" is not a moot`)
|
|
||||||
|
|
||||||
const domain = rootMsg.metadata.domain
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
if (!domain.startsWith(PREFIX)) throw new Error(`"${tangleID}" is not a dict moot`)
|
if (!tangle || tangle.size === 0) throw new Error(`Tangle "${tangleID}" is locally unknown`)
|
||||||
|
// prettier-ignore
|
||||||
|
if (!MsgV3.isMoot(tangle.root)) throw new Error(`Tangle "${tangleID}" is not a moot`)
|
||||||
|
const domain = tangle.root.metadata.domain
|
||||||
|
// prettier-ignore
|
||||||
|
if (!domain.startsWith(PREFIX)) throw new Error(`Tangle "${tangleID}" is not a Dict moot`)
|
||||||
|
|
||||||
// Discover field roots
|
// Discover field roots
|
||||||
const fieldRoots = new Set()
|
const fieldRoots = new Set()
|
||||||
const tangle = peer.db.getTangle(tangleID)
|
|
||||||
const msgIDs = tangle.topoSort()
|
const msgIDs = tangle.topoSort()
|
||||||
for (const msgID of msgIDs) {
|
for (const msgID of msgIDs) {
|
||||||
const msg = peer.db.get(msgID)
|
const msg = peer.db.get(msgID)
|
||||||
|
|
Loading…
Reference in New Issue