add API tangle.root

This commit is contained in:
Andre Staltz 2023-10-19 15:10:24 +03:00
parent 05e16a7037
commit 75b36e9730
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 11 additions and 1 deletions

View File

@ -222,6 +222,14 @@ class Tangle {
return 'weave'
}
get root() {
if (!this.#rootMsg) {
console.trace('Tangle is missing root message')
return null
}
return this.#rootMsg
}
/**
* @param {string} msgID
*/

View File

@ -16,9 +16,11 @@ test('simple multi-author tangle', (t) => {
const mootA = MsgV3.createMoot(accountA, 'post', keypairA)
const mootAID = MsgV3.getMsgID(mootA)
const tangleA = new MsgV3.Tangle(mootAID)
assert.equal(tangleA.id, mootAID, 'tangle.id')
tangleA.add(mootAID, mootA)
assert.equal(tangleA.id, mootAID, 'tangle.id')
assert.equal(tangleA.root, mootA, 'tangle.root')
const mootB = MsgV3.createMoot(accountB, 'post', keypairB)
const mootBID = MsgV3.getMsgID(mootB)
const tangleB = new MsgV3.Tangle(mootBID)