func NewTreeMemoryCache(underlyingDatabase TreeDatabase) (*TreeMemoryCache, error) {
	var preRoot chainhash.Hash

	err := underlyingDatabase.View(func(tx TreeDatabaseTransaction) error {
		root, err := tx.Root()
		if err != nil {
			return err
		}

		if root == nil {
			preRoot = primitives.EmptyTree
			return nil
		}

		preRoot = root.GetHash()

		return nil
	})
	if err != nil {
		return nil, err
	}

	return &TreeMemoryCache{
		underlyingStore: underlyingDatabase,
		root:            preRoot,
		dirty:           make(map[chainhash.Hash]Node),
		dirtyKV:         make(map[chainhash.Hash]chainhash.Hash),
		toRemove:        make(map[chainhash.Hash]struct{}),
		lock:            new(sync.RWMutex),
	}, nil
}
// NewTreeMemoryCache constructs a tree memory cache that can be committed based on an underlying tree (probably on disk).
NewTreeMemoryCache constructs a tree memory cache that can be committed based on an underlying tree (probably on disk).
// NewTreeMemoryCache constructs a tree memory cache that can be committed based on an underlying tree ( probably on disk ) .
func NewTreeMemoryCache(underlyingDatabase TreeDatabase) (*TreeMemoryCache, error) {
	var preRoot chainhash.Hash
	err := underlyingDatabase.View(func(tx TreeDatabaseTransaction) error {
		root, err := tx.Root()
		if err != nil {
			return err
		}
		if root == nil {
			preRoot = primitives.EmptyTree
			return nil
		}
		preRoot = root.GetHash()
		return nil
	})
	if err != nil {
		return nil, err
	}
	return &TreeMemoryCache{
		underlyingStore: underlyingDatabase,
		root:            preRoot,
		dirty:           make(map[chainhash.Hash]Node),
		dirtyKV:         make(map[chainhash.Hash]chainhash.Hash),
		toRemove:        make(map[chainhash.Hash]struct{}),
		lock:            new(sync.RWMutex),
	}, nil
}
func NewTreeMemoryCache ( underlyingDatabase TreeDatabase ) ( * TreeMemoryCache , error ) { var preRoot chainhash . Hash err := underlyingDatabase . View ( func ( tx TreeDatabaseTransaction ) error { root , err := tx . Root ( ) if err != nil { return err } if root == nil { preRoot = primitives . EmptyTree return nil } preRoot = root . GetHash ( ) return nil } ) if err != nil { return nil , err } return & TreeMemoryCache { underlyingStore : underlyingDatabase , root : preRoot , dirty : make ( map [ chainhash . Hash ] Node ) , dirtyKV : make ( map [ chainhash . Hash ] chainhash . Hash ) , toRemove : make ( map [ chainhash . Hash ] struct { } ) , lock : new ( sync . RWMutex ) , } , nil }
NewTreeMemoryCache constructs a tree memory cache that can be committed based on an underlying tree (probably on disk).
NewTreeMemoryCache constructs a tree memory cache that can be committed based on an underlying tree ( probably on disk ) .