mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Idx to 6 bytes (48 bits)
This commit is contained in:
@@ -235,7 +235,11 @@ func (s *StateDB) GetAccount(idx common.Idx) (*common.Account, error) {
|
||||
// getAccountInTreeDB is abstracted from StateDB to be used from StateDB and
|
||||
// from ExitTree. GetAccount returns the account for the given Idx
|
||||
func getAccountInTreeDB(sto db.Storage, idx common.Idx) (*common.Account, error) {
|
||||
vBytes, err := sto.Get(idx.Bytes())
|
||||
idxBytes, err := idx.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vBytes, err := sto.Get(idxBytes[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -282,7 +286,11 @@ func createAccountInTreeDB(sto db.Storage, mt *merkletree.MerkleTree, idx common
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = tx.Get(idx.Bytes())
|
||||
idxBytes, err := idx.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = tx.Get(idxBytes[:])
|
||||
if err != db.ErrNotFound {
|
||||
return nil, ErrAccountAlreadyExists
|
||||
}
|
||||
@@ -291,7 +299,7 @@ func createAccountInTreeDB(sto db.Storage, mt *merkletree.MerkleTree, idx common
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = tx.Put(idx.Bytes(), v.Bytes())
|
||||
err = tx.Put(idxBytes[:], v.Bytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -337,7 +345,11 @@ func updateAccountInTreeDB(sto db.Storage, mt *merkletree.MerkleTree, idx common
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = tx.Put(idx.Bytes(), v.Bytes())
|
||||
idxBytes, err := idx.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = tx.Put(idxBytes[:], v.Bytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -678,7 +678,11 @@ func (s *StateDB) setIdx(idx common.Idx) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = tx.Put(keyidx, idx.Bytes())
|
||||
idxBytes, err := idx.Bytes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = tx.Put(keyidx, idxBytes[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -46,12 +46,16 @@ func (s *StateDB) setIdxByEthAddrBJJ(idx common.Idx, addr ethCommon.Address, pk
|
||||
}
|
||||
k := concatEthAddrBJJ(addr, pk)
|
||||
// store Addr&BJJ-idx
|
||||
err = tx.Put(k, idx.Bytes())
|
||||
idxBytes, err := idx.Bytes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = tx.Put(k, idxBytes[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// store Addr-idx
|
||||
err = tx.Put(addr.Bytes(), idx.Bytes())
|
||||
err = tx.Put(addr.Bytes(), idxBytes[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user