⚠️ Project is no longer maintained⚠️
Tree Hugger depends on Planaria APIs which are now deprecated. For this reason Tree Hugger is no longer maintained and this repo has been archived.
Tree Hugger is a small JavaScript library for traversing the Metanet. It is a higher-level interface over the top of the MOM API, providing a simple API for finding Metanet nodes and traversing tree structures.
Tree Hugger works in both NodeJS and browser environments.
Install with npm or yarn.
npm install meta-tree-hugger
# or
yarn add meta-tree-huggerInclude Tree Hugger in your NodeJS project:
importTreeHuggerfrom'meta-tree-hugger'... or in a browser:
<scriptsrc="https://unpkg.com/meta-tree-hugger/dist/tree-hugger.min.js"></script>Lookup a Metanet node either by it's node id or txid. All query functions are asyncronous and return a Promise.
// Find a single nodeawaitTreeHugger.findNodeById(id)awaitTreeHugger.findNodeByTxid(txid)// returns a <MetaNode> object// Find a collection of nodesawaitTreeHugger.findNodesByAddress(address)awaitTreeHugger.findNodesByParentId(id)awaitTreeHugger.findNodeAndDescendants(id)// Returns flat, topologically ordered array// [<MetaNode>, <MetaNode>, <MetaNode>, ...]// Optional second parameter allows defining additional// bitquery configawaitTreeHugger.findNodesByParentId(id,{limit: 10})// For more complex custom queriesawaitTreeHugger.findSingleNode({find: {"node.id": id},project: {node: 1,parent: 1}})// For complex queriesawaitTreeHugger.findAllNodes({find: {mem: 1,"$and": [{"ancestor.tx": id,},{child: {"$exists": true,"$eq": []}}]},sort: {"blk.i": -1,i: -1}})From any MetaNode instance, the tree can be traversed in any direction.
awaitnode.root()awaitnode.parent()awaitnode.ancestors()awaitnode.siblings()awaitnode.children()awaitnode.descendants()awaitnode.versions()awaitnode.selfAndAncestors()awaitnode.selfAndSiblings()awaitnode.selfAndChildren()awaitnode.selfAndDescendants()awaitnode.selfAndVersions()// All traversal methods accept an optional parameter// which can be used to define additional bitquery configawaitnode.selfAndDescendants({limit: 10})A MetaNode instance has the following attributes:
node.id// Metanet node id - hash(address + txid)node.txid// Transaction idnode.address// Metanet node addressnode.isRoot// Booleannode.isChild// Booleannode.isLeaf// Booleannode.tx// Access the Planaria tx objectnode.inputs// Shortcut to node.tx.innode.outputs// Shortcut to node.tx.outnode.opReturn// Shortcut to the OP_RETURN tapeTree Hugger is open source and released under the MIT License.
Copyright (c) 2019 libitx.