diff --git a/lib/operators.js b/lib/operators.js index 08ec72a..1797b14 100644 --- a/lib/operators.js +++ b/lib/operators.js @@ -21,17 +21,15 @@ module.exports = { } const B_TANGLE = B_TANGLE_MAP.get(tangle) - function seekTangleRoot(buffer, start, p) { - if (p < 0) return -1 - p = seekKey2(buffer, 0, B_VALUE, 0) - if (p < 0) return -1 - p = seekKey2(buffer, p, B_CONTENT, 0) - if (p < 0) return -1 - p = seekKey2(buffer, p, B_TANGLES, 0) - if (p < 0) return -1 - p = seekKey2(buffer, p, B_TANGLE, 0) - if (p < 0) return -1 - return seekKey2(buffer, p, B_ROOT, 0) + function seekTangleRoot(buffer, start, pValue) { + if (pValue < 0) return -1 + const pValueContent = seekKey2(buffer, pValue, B_CONTENT, 0) + if (pValueContent < 0) return -1 + const pValueContentTangles = seekKey2(buffer, pValueContent, B_TANGLES, 0) + if (pValueContentTangles < 0) return -1 + const pValueContentTanglesTangle = seekKey2(buffer, pValueContentTangles, B_TANGLE, 0) + if (pValueContentTanglesTangle < 0) return -1 + return seekKey2(buffer, pValueContentTanglesTangle, B_ROOT, 0) } return equal(seekTangleRoot, value, { @@ -47,18 +45,18 @@ module.exports = { }, } -function seekFirstRecp(buffer, start, p) { - if (p < 0) return -1 - p = seekKey2(buffer, p, B_CONTENT, 0) - if (p < 0) return -1 - p = seekKey2(buffer, p, B_RECPS, 0) - if (p < 0) return -1 +function seekFirstRecp(buffer, start, pValue) { + if (pValue < 0) return -1 + const pValueContent = seekKey2(buffer, pValue, B_CONTENT, 0) + if (pValueContent < 0) return -1 + const pValueContentRecps = seekKey2(buffer, pValueContent, B_RECPS, 0) + if (pValueContentRecps < 0) return -1 - let pValueFirstRecp - const error = iterate(buffer, p, (_, pointer) => { - pValueFirstRecp = pointer + let pValueContentRecps0 + const error = iterate(buffer, pValueContentRecps, (_, pointer) => { + pValueContentRecps0 = pointer return true }) if (error === -1) return -1 - return pValueFirstRecp + return pValueContentRecps0 }