use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class FamilyUtils method getAncestors.
public static Set<Keccak256> getAncestors(BlockStore blockStore, long blockNumber, byte[] parentHash, int limitNum) {
Set<Keccak256> ret = new HashSet<>();
if (blockStore == null) {
return ret;
}
int limit = (int) max(0, blockNumber - limitNum);
Block it = blockStore.getBlockByHash(parentHash);
while (it != null && it.getNumber() >= limit) {
ret.add(it.getHash());
it = blockStore.getBlockByHash(it.getParentHash().getBytes());
}
return ret;
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class FamilyUtils method getUsedUncles.
public static Set<Keccak256> getUsedUncles(BlockStore blockStore, long blockNumber, byte[] parentHash, int limitNum) {
Set<Keccak256> ret = new HashSet<>();
if (blockStore == null) {
return ret;
}
long minNumber = max(0, blockNumber - limitNum);
Block it = blockStore.getBlockByHash(parentHash);
while (it != null && it.getNumber() >= minNumber) {
for (BlockHeader uncle : it.getUncleList()) {
ret.add(uncle.getHash());
}
it = blockStore.getBlockByHash(it.getParentHash().getBytes());
}
return ret;
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class TransactionPoolImpl method removeTransactions.
@Override
public synchronized void removeTransactions(List<Transaction> txs) {
for (Transaction tx : txs) {
Keccak256 khash = tx.getHash();
pendingTransactions.removeTransactionByHash(khash);
queuedTransactions.removeTransactionByHash(khash);
logger.trace("Clear transaction, hash: [{}]", khash);
}
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class TransactionPoolImpl method addTransaction.
@Override
public synchronized boolean addTransaction(final Transaction tx) {
if (!shouldAcceptTx(tx)) {
return false;
}
Keccak256 hash = tx.getHash();
logger.trace("add transaction {} {}", toBI(tx.getNonce()), tx.getHash());
Long bnumber = Long.valueOf(getCurrentBestBlockNumber());
if (pendingTransactions.hasTransaction(tx)) {
return false;
}
if (queuedTransactions.hasTransaction(tx)) {
return false;
}
transactionBlocks.put(hash, bnumber);
final long timestampSeconds = this.getCurrentTimeInSeconds();
transactionTimes.put(hash, timestampSeconds);
BigInteger txnonce = tx.getNonceAsInteger();
if (!txnonce.equals(this.getNextNonceByAccount(tx.getSender()))) {
this.addQueuedTransaction(tx);
return false;
}
pendingTransactions.addTransaction(tx);
executeTransaction(tx);
if (listener != null) {
EventDispatchThread.invokeLater(() -> {
listener.onPendingTransactionsReceived(Collections.singletonList(tx));
listener.onTransactionPoolChanged(TransactionPoolImpl.this);
});
}
return true;
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class ContractDetailsImpl method decode.
@Override
public final void decode(byte[] rlpBytes) {
ArrayList<RLPElement> rlpData = RLP.decode2(rlpBytes);
RLPList rlpList = (RLPList) rlpData.get(0);
RLPItem rlpAddress = (RLPItem) rlpList.get(0);
RLPItem rlpIsExternalStorage = (RLPItem) rlpList.get(1);
RLPItem rlpStorage = (RLPItem) rlpList.get(2);
RLPElement rlpCode = rlpList.get(3);
RLPList rlpKeys = (RLPList) rlpList.get(4);
this.address = rlpAddress.getRLPData();
this.externalStorage = rlpIsExternalStorage.getRLPData() != null;
this.originalExternalStorage = this.externalStorage;
if (this.externalStorage) {
Keccak256 snapshotHash = new Keccak256(rlpStorage.getRLPData());
this.trie = new TrieImpl(new TrieStoreImpl(levelDbByName(config, getDataSourceName())), true).getSnapshotTo(snapshotHash);
} else {
this.trie = TrieImpl.deserialize(rlpStorage.getRLPData());
}
this.code = (rlpCode.getRLPData() == null) ? EMPTY_BYTE_ARRAY : rlpCode.getRLPData();
for (RLPElement key : rlpKeys) {
addKey(key.getRLPData());
}
logger.trace("decoding contract details from bytes, hash {}, address {}, storage size {}, has external storage {}", this.getStorageHashAsString(), this.getAddressAsString(), this.getStorageSize(), this.hasExternalStorage());
}
Aggregations