use of co.rsk.core.Coin in project rskj by rsksmart.
the class RemascStorageProvider method getRewardBalance.
public Coin getRewardBalance() {
if (rewardBalance != null) {
return rewardBalance;
}
DataWord address = new DataWord(REWARD_BALANCE_KEY.getBytes(StandardCharsets.UTF_8));
DataWord value = this.repository.getStorageValue(this.contractAddress, address);
if (value == null) {
return Coin.ZERO;
}
return new Coin(value.getData());
}
use of co.rsk.core.Coin 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 co.rsk.core.Coin 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 co.rsk.core.Coin in project rskj by rsksmart.
the class TxValidatorAccountBalanceValidator method validate.
@Override
public boolean validate(Transaction tx, AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx) {
BigInteger txGasLimit = tx.getGasLimitAsInteger();
Coin maximumPrice = tx.getGasPrice().multiply(txGasLimit);
return isFreeTx || state.getBalance().compareTo(maximumPrice) >= 0;
}
use of co.rsk.core.Coin 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