use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class Bridge method getFederatorPublicKeyOfType.
public byte[] getFederatorPublicKeyOfType(Object[] args) throws VMException {
logger.trace("getFederatorPublicKeyOfType");
int index = ((BigInteger) args[0]).intValue();
FederationMember.KeyType keyType;
try {
keyType = FederationMember.KeyType.byValue((String) args[1]);
} catch (Exception e) {
logger.warn("Exception in getFederatorPublicKeyOfType", e);
throw new VMException("Exception in getFederatorPublicKeyOfType", e);
}
return bridgeSupport.getFederatorPublicKeyOfType(index, keyType);
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class Bridge method receiveHeaders.
public void receiveHeaders(Object[] args) throws VMException {
logger.trace("receiveHeaders");
Object[] btcBlockSerializedArray = (Object[]) args[0];
// a simple size check. If this check fails, just fail.
if (Arrays.stream(btcBlockSerializedArray).anyMatch(bytes -> !BtcTransactionFormatUtils.isBlockHeaderSize(((byte[]) bytes).length, activations))) {
// This exception type bypasses bridge teardown, signalling no work done
// and preventing the overhead of saving bridge storage
logger.warn("Unexpected BTC header(s) received (size mismatch). Aborting processing.");
throw new BridgeIllegalArgumentException("Unexpected BTC header(s) received (size mismatch). Aborting processing.");
}
BtcBlock[] btcBlockArray = new BtcBlock[btcBlockSerializedArray.length];
for (int i = 0; i < btcBlockSerializedArray.length; i++) {
byte[] btcBlockSerialized = (byte[]) btcBlockSerializedArray[i];
try {
BtcBlock header = bridgeConstants.getBtcParams().getDefaultSerializer().makeBlock(btcBlockSerialized);
btcBlockArray[i] = header;
} catch (ProtocolException e) {
throw new BridgeIllegalArgumentException("Block " + i + " could not be parsed " + ByteUtil.toHexString(btcBlockSerialized), e);
}
}
try {
bridgeSupport.receiveHeaders(btcBlockArray);
} catch (Exception e) {
logger.warn("Exception adding header", e);
throw new VMException("Exception adding header", e);
}
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class Bridge method getBtcTransactionConfirmations.
public int getBtcTransactionConfirmations(Object[] args) throws VMException {
logger.trace("getBtcTransactionConfirmations");
try {
Sha256Hash btcTxHash = Sha256Hash.wrap((byte[]) args[0]);
Sha256Hash btcBlockHash = Sha256Hash.wrap((byte[]) args[1]);
int merkleBranchPath = ((BigInteger) args[2]).intValue();
Object[] merkleBranchHashesArray = (Object[]) args[3];
List<Sha256Hash> merkleBranchHashes = Arrays.stream(merkleBranchHashesArray).map(hash -> Sha256Hash.wrap((byte[]) hash)).collect(Collectors.toList());
MerkleBranch merkleBranch = new MerkleBranch(merkleBranchHashes, merkleBranchPath);
return bridgeSupport.getBtcTransactionConfirmations(btcTxHash, btcBlockHash, merkleBranch);
} catch (Exception e) {
logger.warn("Exception in getBtcTransactionConfirmations", e);
throw new VMException("Exception in getBtcTransactionConfirmations", e);
}
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class VoteFeePerKbChangeTest method voteFeePerKbChange_unauthorized.
@Test
public void voteFeePerKbChange_unauthorized() throws VMException {
BridgeStorageProviderInitializer storageInitializer = Helper.buildNoopInitializer();
Coin genesisFeePerKB = BridgeRegTestConstants.getInstance().getGenesisFeePerKb();
ABIEncoder abiEncoder = (int executionIndex) -> Bridge.VOTE_FEE_PER_KB.encode(BigInteger.valueOf(Helper.randomCoin(Coin.MILLICOIN, 1, 100).getValue()));
TxBuilder txBuilder = (int executionIndex) -> {
String generator = "unauthorized";
ECKey sender = ECKey.fromPrivate(HashUtil.keccak256(generator.getBytes(StandardCharsets.UTF_8)));
return Helper.buildTx(sender);
};
ExecutionStats stats = new ExecutionStats("voteFeePerKbChange_unauthorized");
executeAndAverage("voteFeePerKbChange_unauthorized", 1000, abiEncoder, storageInitializer, txBuilder, Helper.getRandomHeightProvider(10), stats, ((environment, callResult) -> {
Assert.assertEquals(genesisFeePerKB.getValue(), ((Bridge) environment.getContract()).getFeePerKb(null));
}));
BridgePerformanceTest.addStats(stats);
}
Aggregations