mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Extend statedb and use prefixes, add debugapi
In statedb:
- Store all values using prefixes for keys to allow iteration
- Add methods MTGetRoot, GetAccounts
Implement debugapi, an http server with debugging endpoints:
- debugAPI.GET("sdb/batchnum", a.handleCurrentBatch)
- debugAPI.GET("sdb/mtroot", a.handleMTRoot)
- debugAPI.GET("sdb/accounts", a.handleAccounts)
- debugAPI.GET("sdb/accounts/:Idx", a.handleAccount)
This commit is contained in:
@@ -51,12 +51,12 @@ func (s *StateDB) setIdxByEthAddrBJJ(idx common.Idx, addr ethCommon.Address, pk
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = tx.Put(k, idxBytes[:])
|
||||
err = tx.Put(append(PrefixKeyAddrBJJ, k...), idxBytes[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// store Addr-idx
|
||||
err = tx.Put(addr.Bytes(), idxBytes[:])
|
||||
err = tx.Put(append(PrefixKeyAddr, addr.Bytes()...), idxBytes[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func (s *StateDB) setIdxByEthAddrBJJ(idx common.Idx, addr ethCommon.Address, pk
|
||||
// Ethereum Address. Will return common.Idx(0) and error in case that Idx is
|
||||
// not found in the StateDB.
|
||||
func (s *StateDB) GetIdxByEthAddr(addr ethCommon.Address) (common.Idx, error) {
|
||||
b, err := s.db.Get(addr.Bytes())
|
||||
b, err := s.db.Get(append(PrefixKeyAddr, addr.Bytes()...))
|
||||
if err != nil {
|
||||
return common.Idx(0), ErrToIdxNotFound
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func (s *StateDB) GetIdxByEthAddrBJJ(addr ethCommon.Address, pk *babyjub.PublicK
|
||||
} else if !bytes.Equal(addr.Bytes(), common.EmptyAddr.Bytes()) && pk != nil {
|
||||
// case ToEthAddr!=0 && ToBJJ!=0
|
||||
k := concatEthAddrBJJ(addr, pk)
|
||||
b, err := s.db.Get(k)
|
||||
b, err := s.db.Get(append(PrefixKeyAddrBJJ, k...))
|
||||
if err != nil {
|
||||
return common.Idx(0), ErrToIdxNotFound
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user