use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class TxValidator method filterTxs.
/**
* Where the magic occurs, will filter out invalid txs
*/
List<Transaction> filterTxs(List<Transaction> txs) {
List<Transaction> acceptedTxs = new LinkedList<>();
for (Transaction tx : txs) {
String hash = tx.getHash().toJsonString();
AccountState state = repository.getAccountState(tx.getSender());
if (state == null) {
state = new AccountState();
}
BigInteger blockGasLimit = BigIntegers.fromUnsignedByteArray(blockchain.getBestBlock().getGasLimit());
Coin minimumGasPrice = blockchain.getBestBlock().getMinimumGasPrice();
long bestBlockNumber = blockchain.getBestBlock().getNumber();
long basicTxCost = tx.transactionCost(config, blockchain.getBestBlock());
boolean valid = true;
for (TxValidatorStep step : validatorSteps) {
if (!step.validate(tx, state, blockGasLimit, minimumGasPrice, bestBlockNumber, basicTxCost == 0)) {
logger.info("Tx validation failed: validator {} tx={}", step.getClass().getName(), tx.getHash());
valid = false;
break;
}
}
if (!valid) {
continue;
}
acceptedTxs.add(tx);
}
return acceptedTxs;
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class TxsPerAccount method removeNonce.
void removeNonce(BigInteger nonce) {
List<Transaction> newlist = new LinkedList<>();
for (Transaction tx : this.txs) {
if (new BigInteger(1, tx.getNonce()).compareTo(nonce) == 0) {
continue;
}
newlist.add(tx);
}
this.txs = newlist;
if (newlist.isEmpty()) {
this.nextNonce = null;
}
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class TxFilterAccumCostFilter method filter.
@Override
public List<Transaction> filter(AccountState state, TxsPerAccount tpa, Block block) {
Coin accumTxCost = Coin.ZERO;
tpa.getTransactions().sort((t1, t2) -> {
BigInteger n1 = new BigInteger(1, t1.getNonce());
BigInteger n2 = new BigInteger(1, t2.getNonce());
return n1.compareTo(n2);
});
List<Transaction> newTxs = new LinkedList<>();
for (Transaction t : tpa.getTransactions()) {
Coin gasCost = Coin.ZERO;
if (block == null || t.transactionCost(config, block) > 0) {
BigInteger gasLimit = new BigInteger(1, t.getGasLimit());
gasCost = t.getGasPrice().multiply(gasLimit);
}
if (accumTxCost.add(gasCost).compareTo(state.getBalance()) > 0) {
break;
}
accumTxCost = accumTxCost.add(gasCost);
accumTxCost = accumTxCost.add(t.getValue());
newTxs.add(t);
}
return newTxs;
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class TransactionsMessage method getEncodedMessage.
@Override
public byte[] getEncodedMessage() {
List<byte[]> encodedElements = new ArrayList<>();
for (Transaction tx : transactions) {
encodedElements.add(tx.getEncoded());
}
byte[][] encodedElementArray = encodedElements.toArray(new byte[encodedElements.size()][]);
return RLP.encodeList(encodedElementArray);
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class MinerUtilsTest method validTransactionRepositoryNonceTest.
@Test
public void validTransactionRepositoryNonceTest() {
Transaction tx = Tx.create(config, 0, 50000, 5, 0, 0, 0);
// Mockito.when(tx.checkGasPrice(Mockito.any(BigInteger.class))).thenReturn(true);
List<Transaction> txs = new LinkedList<>();
txs.add(tx);
Map<RskAddress, BigInteger> accountNounces = new HashMap();
Repository repository = Mockito.mock(Repository.class);
Mockito.when(repository.getNonce(tx.getSender())).thenReturn(BigInteger.valueOf(0));
Coin minGasPrice = Coin.valueOf(1L);
List<Transaction> res = new MinerUtils().filterTransactions(new LinkedList<>(), txs, accountNounces, repository, minGasPrice);
Assert.assertEquals(1, res.size());
}
Aggregations