MCPcopy
hub / github.com/canopy-network/canopy / getNode

Method getNode

store/smt.go:606–626  ·  view source on GitHub ↗

getNode() retrieves a node object from the database

(key []byte)

Source from the content-addressed store, hash-verified

604
605// getNode() retrieves a node object from the database
606func (s *SMT) getNode(key []byte) (n *node, err lib.ErrorI) {
607 // check cache
608 n, found := s.nodeCache[string(key)]
609 if found {
610 return n, nil
611 }
612 // initialize a reference to a node object
613 n = newNode()
614 // get the bytes of the node from the kv store
615 nodeBytes, err := s.store.Get(lib.JoinLenPrefix(key))
616 if err != nil || nodeBytes == nil {
617 return
618 }
619 // convert the node bytes into a node object
620 if err = lib.Unmarshal(nodeBytes, n); err != nil {
621 return
622 }
623 // set the key in the node for convenience
624 n.Key.fromBytes(key)
625 return
626}
627
628// validateTarget() checks the target to ensure it's not a reserved key like root, minimum or maximum
629func (s *SMT) validateTarget(n *node) lib.ErrorI {

Callers 5

traverseMethod · 0.95
updateParentValueMethod · 0.95
getSubtreeRootsMethod · 0.95
GetMerkleProofMethod · 0.95
NewSMTFunction · 0.80

Calls 5

JoinLenPrefixFunction · 0.92
UnmarshalFunction · 0.92
newNodeFunction · 0.85
fromBytesMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected