use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class RemascFeesPayer method logPayment.
private void logPayment(byte[] blockHash, Coin value, RskAddress toAddress, List<LogInfo> logs) {
byte[] loggerContractAddress = this.contractAddress.getBytes();
List<DataWord> topics = Arrays.asList(RemascContract.MINING_FEE_TOPIC, new DataWord(toAddress.getBytes()));
byte[] data = RLP.encodeList(RLP.encodeElement(blockHash), RLP.encodeCoin(value));
logs.add(new LogInfo(loggerContractAddress, topics, data));
}
use of org.ethereum.vm.DataWord 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 org.ethereum.vm.DataWord in project rskj by rsksmart.
the class RemascStorageProvider method saveBrokenSelectionRule.
private void saveBrokenSelectionRule() {
if (brokenSelectionRule == null) {
return;
}
DataWord address = new DataWord(BROKEN_SELECTION_RULE_KEY.getBytes(StandardCharsets.UTF_8));
byte[] bytes = new byte[1];
bytes[0] = (byte) (this.brokenSelectionRule ? 1 : 0);
this.repository.addStorageBytes(this.contractAddress, address, bytes);
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class RemascStorageProvider method saveRewardBalance.
private void saveRewardBalance() {
if (rewardBalance == null) {
return;
}
DataWord address = new DataWord(REWARD_BALANCE_KEY.getBytes(StandardCharsets.UTF_8));
this.repository.addStorageRow(this.contractAddress, address, new DataWord(this.rewardBalance.getBytes()));
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class BridgeStorageProviderTest method getNewFederation_nullBytes.
@Test
public void getNewFederation_nullBytes() throws IOException {
List<Integer> storageBytesCalls = new ArrayList<>();
List<Integer> deserializeCalls = new ArrayList<>();
Context contextMock = mock(Context.class);
PowerMockito.mockStatic(BridgeSerializationUtils.class);
Repository repositoryMock = mock(Repository.class);
BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
Whitebox.setInternalState(storageProvider, "btcContext", contextMock);
when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> {
storageBytesCalls.add(0);
RskAddress contractAddress = invocation.getArgumentAt(0, RskAddress.class);
DataWord address = invocation.getArgumentAt(1, DataWord.class);
// Make sure the bytes are get from the correct address in the repo
Assert.assertTrue(Arrays.equals(new byte[] { (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd }, contractAddress.getBytes()));
Assert.assertEquals(new DataWord("newFederation".getBytes(StandardCharsets.UTF_8)), address);
return null;
});
PowerMockito.when(BridgeSerializationUtils.deserializeFederation(any(byte[].class), any(Context.class))).then((InvocationOnMock invocation) -> {
deserializeCalls.add(0);
return null;
});
Assert.assertEquals(null, storageProvider.getNewFederation());
Assert.assertEquals(null, storageProvider.getNewFederation());
// 2 for the calls to getStorageBytes
Assert.assertEquals(2, storageBytesCalls.size());
// 2 for the calls to getStorageBytes
Assert.assertEquals(0, deserializeCalls.size());
}
Aggregations