use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class Bridge method registerBtcTransaction.
public void registerBtcTransaction(Object[] args) throws VMException {
logger.trace("registerBtcTransaction");
byte[] btcTxSerialized = (byte[]) args[0];
int height = ((BigInteger) args[1]).intValue();
byte[] pmtSerialized = (byte[]) args[2];
try {
bridgeSupport.registerBtcTransaction(rskTx, btcTxSerialized, height, pmtSerialized);
} catch (IOException | BlockStoreException e) {
logger.warn("Exception in registerBtcTransaction", e);
throw new VMException("Exception in registerBtcTransaction", e);
}
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class Bridge method addSignature.
public void addSignature(Object[] args) throws VMException {
logger.trace("addSignature");
byte[] federatorPublicKeySerialized = (byte[]) args[0];
BtcECKey federatorPublicKey;
try {
federatorPublicKey = BtcECKey.fromPublicOnly(federatorPublicKeySerialized);
} catch (Exception e) {
throw new BridgeIllegalArgumentException("Public key could not be parsed " + ByteUtil.toHexString(federatorPublicKeySerialized), e);
}
Object[] signaturesObjectArray = (Object[]) args[1];
if (signaturesObjectArray.length == 0) {
throw new BridgeIllegalArgumentException("Signatures array is empty");
}
List<byte[]> signatures = new ArrayList<>();
for (Object signatureObject : signaturesObjectArray) {
byte[] signatureByteArray = (byte[]) signatureObject;
try {
BtcECKey.ECDSASignature.decodeFromDER((byte[]) signatureObject);
} catch (Exception e) {
throw new BridgeIllegalArgumentException("Signature could not be parsed " + ByteUtil.toHexString(signatureByteArray), e);
}
signatures.add(signatureByteArray);
}
byte[] rskTxHash = (byte[]) args[2];
if (rskTxHash.length != 32) {
throw new BridgeIllegalArgumentException("Invalid rsk tx hash " + ByteUtil.toHexString(rskTxHash));
}
try {
bridgeSupport.addSignature(federatorPublicKey, signatures, rskTxHash);
} catch (BridgeIllegalArgumentException e) {
throw e;
} catch (Exception e) {
logger.warn("Exception in addSignature", e);
throw new VMException("Exception in addSignature", e);
}
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class Bridge method getBtcBlockchainBlockLocator.
/**
* @deprecated
* @param args
* @return
*/
@Deprecated
public Object[] getBtcBlockchainBlockLocator(Object[] args) throws VMException {
logger.trace("getBtcBlockchainBlockLocator");
try {
List<Sha256Hash> blockLocatorList = bridgeSupport.getBtcBlockchainBlockLocator();
Object[] blockLocatorArray = new Object[blockLocatorList.size()];
int i = 0;
for (Sha256Hash blockHash : blockLocatorList) {
blockLocatorArray[i] = blockHash.toString();
i++;
}
return blockLocatorArray;
} catch (Exception e) {
logger.warn("Exception in getBtcBlockchainBlockLocator", e);
throw new VMException("Exception in getBtcBlockchainBlockLocator", e);
}
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class Bridge method receiveHeader.
public int receiveHeader(Object[] args) throws VMException {
logger.trace("receiveHeader");
byte[] headerArg = (byte[]) args[0];
if (!BtcTransactionFormatUtils.isBlockHeaderSize(headerArg.length, activations)) {
logger.warn("Unexpected BTC header received (size mismatch). Aborting processing.");
return RECEIVE_HEADER_ERROR_SIZE_MISTMATCH;
}
BtcBlock header = bridgeConstants.getBtcParams().getDefaultSerializer().makeBlock(headerArg);
try {
return bridgeSupport.receiveHeader(header);
} catch (Exception e) {
String errorMessage = "Exception adding header in receiveHeader";
logger.warn(errorMessage, e);
throw new VMException(errorMessage, e);
}
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class DeriveExtendedPublicKeyPerformanceTestCase method estimateDeriveExtendedPublicKey.
private ExecutionStats estimateDeriveExtendedPublicKey(int times, int pathLength, EnvironmentBuilder environmentBuilder) throws VMException {
String name = String.format("%s-%d", function.name, pathLength);
ExecutionStats stats = new ExecutionStats(name);
Random rnd = new Random();
byte[] chainCode = new byte[32];
NetworkParameters networkParameters = NetworkParameters.fromID(NetworkParameters.ID_MAINNET);
ABIEncoder abiEncoder = (int executionIndex) -> {
rnd.nextBytes(chainCode);
DeterministicKey key = HDKeyDerivation.createMasterPubKeyFromBytes(new ECKey().getPubKey(true), chainCode);
int[] pathParts = new int[pathLength];
for (int i = 0; i < pathLength; i++) {
pathParts[i] = rnd.nextInt(MAX_CHILD);
}
String path = String.join("/", Arrays.stream(pathParts).mapToObj(i -> String.format("%d", i)).collect(Collectors.toList()));
return function.encode(new Object[] { key.serializePubB58(networkParameters), path });
};
executeAndAverage(name, times, environmentBuilder, abiEncoder, Helper.getZeroValueTxBuilder(new ECKey()), Helper.getRandomHeightProvider(10), stats, (EnvironmentBuilder.Environment environment, byte[] result) -> {
Object[] decodedResult = function.decodeResult(result);
Assert.assertEquals(String.class, decodedResult[0].getClass());
String address = (String) decodedResult[0];
Assert.assertTrue(address.startsWith("xpub"));
});
return stats;
}
Aggregations