Coverage Summary for Class: MutableTrie (co.rsk.trie)

Class
MutableTrie


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2019 RSK Labs Ltd. 4  * 5  * This program is free software: you can redistribute it and/or modify 6  * it under the terms of the GNU Lesser General Public License as published by 7  * the Free Software Foundation, either version 3 of the License, or 8  * (at your option) any later version. 9  * 10  * This program is distributed in the hope that it will be useful, 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13  * GNU Lesser General Public License for more details. 14  * 15  * You should have received a copy of the GNU Lesser General Public License 16  * along with this program. If not, see <http://www.gnu.org/licenses/>. 17  */ 18  19 package co.rsk.trie; 20  21 import co.rsk.core.RskAddress; 22 import co.rsk.core.types.ints.Uint24; 23 import co.rsk.crypto.Keccak256; 24 import org.ethereum.db.ByteArrayWrapper; 25 import org.ethereum.vm.DataWord; 26  27 import javax.annotation.Nullable; 28 import java.util.Iterator; 29 import java.util.Optional; 30 import java.util.Set; 31  32 /** 33  * Every operation of a MutableTrie mutates the parent trie top node and therefore its stateRoot. 34  */ 35 public interface MutableTrie { 36  Keccak256 getHash(); 37  38  @Nullable 39  byte[] get(byte[] key); 40  41  void put(byte[] key, byte[] value); 42  43  void put(String key, byte[] value); 44  45  // This method optimizes cache-to-cache transfers 46  void put(ByteArrayWrapper key, byte[] value); 47  48  // the key has to match exactly an account key 49  // it won't work if it is used with an storage key or any other 50  void deleteRecursive(byte[] key); 51  52  void save(); 53  54  void commit(); 55  56  void rollback(); 57  58  // TODO(mc) this method is only used from tests 59  Set<ByteArrayWrapper> collectKeys(int size); 60  61  Trie getTrie(); 62  63  // This is for optimizing EXTCODESIZE. It returns the size of the value 64  // without the need to retrieve the value itself. Implementors can fallback to 65  // getting the value and then returning its size. 66  Uint24 getValueLength(byte[] key); 67  68  // This is for optimizing EXTCODEHASH. It returns the hash of the value 69  // without the need to retrieve the value itself. 70  Optional<Keccak256> getValueHash(byte[] key); 71  72  // the key has to match exactly an account key 73  // it won't work if it is used with an storage key or any other 74  Iterator<DataWord> getStorageKeys(RskAddress addr); 75 }