rename some Tangle getters

This commit is contained in:
Andre Staltz 2023-08-28 15:47:24 +03:00
parent c76584953b
commit 0b7f49846e
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
5 changed files with 14 additions and 17 deletions

View File

@ -702,7 +702,7 @@ function initDB(peer, config) {
tangleTemplates.push(mootID) tangleTemplates.push(mootID)
const tangles = populateTangles(tangleTemplates) const tangles = populateTangles(tangleTemplates)
const accountTangle = new DBTangle(opts.account, records()) const accountTangle = new DBTangle(opts.account, records())
const accountTips = [...accountTangle.getTips()] const accountTips = [...accountTangle.tips]
const fullOpts = { ...opts, tangles, accountTips, keypair } const fullOpts = { ...opts, tangles, accountTips, keypair }
// If opts ask for encryption, encrypt and put ciphertext in opts.data // If opts ask for encryption, encrypt and put ciphertext in opts.data

View File

@ -147,10 +147,9 @@ function create(opts) {
for (const rootID in opts.tangles) { for (const rootID in opts.tangles) {
if ((err = validateMsgID(rootID))) throw err if ((err = validateMsgID(rootID))) throw err
const tangle = opts.tangles[rootID] const tangle = opts.tangles[rootID]
const depth = tangle.getMaxDepth() + 1 const depth = tangle.maxDepth + 1
const tips = tangle.getTips()
const lipmaaSet = tangle.getLipmaaSet(depth) const lipmaaSet = tangle.getLipmaaSet(depth)
const prev = [...union(lipmaaSet, tips)].sort() const prev = [...union(lipmaaSet, tangle.tips)].sort()
tangles[rootID] = { depth, prev } tangles[rootID] = { depth, prev }
} }
} else { } else {

View File

@ -151,7 +151,7 @@ class Tangle {
/** /**
* @returns {Set<string>} * @returns {Set<string>}
*/ */
getTips() { get tips() {
if (!this.#rootMsg) { if (!this.#rootMsg) {
console.trace('Tangle is missing root message') console.trace('Tangle is missing root message')
return new Set() return new Set()
@ -196,14 +196,14 @@ class Tangle {
return isMoot(this.#rootMsg) return isMoot(this.#rootMsg)
} }
getMoot() { get mootDetails() {
if (!this.isFeed()) return null if (!this.isFeed()) return null
if (!this.#rootMsg) { if (!this.#rootMsg) {
console.trace('Tangle is missing root message') console.trace('Tangle is missing root message')
return null return null
} }
const { account, domain } = this.#rootMsg.metadata const { account, domain } = this.#rootMsg.metadata
return { account, domain, id: this.#rootID } return { account, domain, id: this.#rootID }
} }
/** /**
@ -261,7 +261,7 @@ class Tangle {
return this.#depth.size return this.#depth.size
} }
getMaxDepth() { get maxDepth() {
return this.#maxDepth return this.#maxDepth
} }

View File

@ -35,9 +35,7 @@ function validateShape(msg) {
return 'invalid message: must have metadata.dataSize\n' + JSON.stringify(msg) return 'invalid message: must have metadata.dataSize\n' + JSON.stringify(msg)
} }
if (!('account' in msg.metadata)) { if (!('account' in msg.metadata)) {
return ( return 'invalid message: must have metadata.account\n' + JSON.stringify(msg)
'invalid message: must have metadata.account\n' + JSON.stringify(msg)
)
} }
if (!('accountTips' in msg.metadata)) { if (!('accountTips' in msg.metadata)) {
// prettier-ignore // prettier-ignore
@ -163,7 +161,7 @@ function validateSignature(msg) {
} }
/** /**
* @typedef {NonNullable<ReturnType<Tangle['getMoot']>>} FeedDetails * @typedef {NonNullable<Tangle['mootDetails']>} MootDetails
*/ */
/** /**
@ -187,7 +185,7 @@ function validateTangle(msg, tangle, tangleID) {
return `invalid message: depth "${depth}" should have been a positive integer\n` + JSON.stringify(msg) return `invalid message: depth "${depth}" should have been a positive integer\n` + JSON.stringify(msg)
} }
if (tangle.isFeed()) { if (tangle.isFeed()) {
const { account, domain } = /** @type {FeedDetails} */ (tangle.getMoot()) const { account, domain } = /** @type {MootDetails} */ (tangle.mootDetails)
if (domain !== msg.metadata.domain) { if (domain !== msg.metadata.domain) {
// prettier-ignore // prettier-ignore
return `invalid message: domain "${msg.metadata.domain}" should have been feed domain "${domain}"\n` + JSON.stringify(msg) return `invalid message: domain "${msg.metadata.domain}" should have been feed domain "${domain}"\n` + JSON.stringify(msg)

View File

@ -113,8 +113,8 @@ test('Tangle.getDepth', (t) => {
assert.equal(tangle.getDepth(reply3Hi), 3, 'depth of reply3Hi is 3') assert.equal(tangle.getDepth(reply3Hi), 3, 'depth of reply3Hi is 3')
}) })
test('Tangle.getMaxDepth', (t) => { test('Tangle.maxDepth', (t) => {
assert.equal(tangle.getMaxDepth(), 3, 'max depth is 3') assert.equal(tangle.maxDepth, 3, 'max depth is 3')
}) })
test('Tangle.topoSort', (t) => { test('Tangle.topoSort', (t) => {
@ -173,8 +173,8 @@ test('Tangle.precedes', (t) => {
) )
}) })
test('Tangle.getTips', (t) => { test('Tangle.tips', (t) => {
const tips = tangle.getTips() const tips = tangle.tips
assert.equal(tips.size, 2, 'there are 2 tips') assert.equal(tips.size, 2, 'there are 2 tips')
assert.equal(tips.has(reply3Lo), true, 'tips contains reply3Lo') assert.equal(tips.has(reply3Lo), true, 'tips contains reply3Lo')