Tree Hugger
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.
Installation
Install with npm
or yarn
.
npm install meta-tree-hugger# or yarn add meta-tree-hugger
Include Tree Hugger in your NodeJS project:
... or in a browser:
Find a Metanet node
Lookup a Metanet node either by it's node id
or txid
. All query functions are asyncronous and return a Promise
.
// Find a single nodeawait TreeHuggerawait TreeHugger// returns a <MetaNode> object // Find a collection of nodesawait TreeHuggerawait TreeHuggerawait TreeHugger// Returns flat, topologically ordered array// [<MetaNode>, <MetaNode>, <MetaNode>, ...] // Optional second parameter allows defining additional// bitquery configawait TreeHugger // For more complex custom queriesawait TreeHugger // For complex queriesawait TreeHugger
Traverse the tree
From any MetaNode
instance, the tree can be traversed in any direction.
await nodeawait nodeparentawait nodeawait nodeawait nodeawait nodeawait nodeawait nodeawait nodeawait nodeawait nodeawait node // All traversal methods accept an optional parameter// which can be used to define additional bitquery configawait node
Node attributes
A MetaNode
instance has the following attributes:
nodeid // Metanet node id - hash(address + txid)nodetxid // Transaction idnodeaddress // Metanet node address nodeisRoot // BooleannodeisChild // BooleannodeisLeaf // Boolean nodetx // Access the Planaria tx object nodeinputs // Shortcut to node.tx.innodeoutputs // Shortcut to node.tx.outnodeopReturn // Shortcut to the OP_RETURN tape
License
Tree Hugger is open source and released under the MIT License.
Copyright (c) 2019 libitx.