Example #1
0
func (m *RadixMap) walk(f WalkFunc, key data.Hash256, depth uint8, fill bool) error {
	if key.IsZero() {
		return nil
	}
	var node *RadixNode
	if fill {
		var err error
		node = &RadixNode{
			Depth: depth,
		}
		node.Node, err = m.db.Get(key)
		if err != nil {
			return err
		}
		m.nodes[key] = node
	} else {
		var ok bool
		node, ok = m.nodes[key]
		if !ok {
			return fmt.Errorf("Missing hash: %s", key.String())
		}
		if err := f(key, node); err != nil {
			return err
		}
	}
	inner, ok := node.Node.(*data.InnerNode)
	if !ok {
		return nil
	}
	return inner.Each(func(pos int, child data.Hash256) error {
		return m.walk(f, child, depth+1, fill)
	})
}
Example #2
0
func NewLedgerStateFromDB(hash data.Hash256, db storage.DB) (*LedgerState, error) {
	node, err := db.Get(hash)
	if err != nil {
		return nil, err
	}
	ledger, ok := node.(*data.Ledger)
	if !ok {
		return nil, fmt.Errorf("NewLedgerStateFromDB: not a ledger:%s", hash.String())
	}
	return &LedgerState{
		Ledger:       ledger,
		AccountState: NewRadixMap(ledger.StateHash, db),
		Transactions: NewRadixMap(ledger.TransactionHash, db),
		Books:        make(map[CurrencyPair]Offers),
	}, nil
}