use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class Transaction method getSender.
public synchronized RskAddress getSender() {
if (sender != null) {
return sender;
}
try {
ECKey key = ECKey.signatureToKey(getRawHash().getBytes(), getSignature().toBase64());
sender = new RskAddress(key.getAddress());
} catch (SignatureException e) {
logger.error(e.getMessage(), e);
panicProcessor.panic("transaction", e.getMessage());
sender = RskAddress.nullAddress();
}
return sender;
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class BridgeSupportTest method callUpdateCollectionsThrowsCouldNotAdjustDownwards.
@Test
public void callUpdateCollectionsThrowsCouldNotAdjustDownwards() throws IOException, BlockStoreException {
// Federation is the genesis federation ATM
Federation federation = bridgeConstants.getGenesisFederation();
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
provider0.getReleaseRequestQueue().add(new BtcECKey().toAddress(btcParams), Coin.valueOf(37500));
provider0.setFeePerKb(Coin.MILLICOIN);
provider0.getNewFederationBtcUTXOs().add(new UTXO(PegTestUtils.createHash(), 1, Coin.valueOf(1000000), 0, false, ScriptBuilder.createOutputScript(federation.getAddress())));
provider0.save();
track.commit();
track = repository.startTracking();
BlockGenerator blockGenerator = new BlockGenerator();
List<Block> blocks = blockGenerator.getSimpleBlockChain(blockGenerator.getGenesisBlock(), 10);
BlockChainBuilder builder = new BlockChainBuilder();
Blockchain blockchain = builder.setTesting(true).build();
for (Block block : blocks) blockchain.getBlockStore().saveBlock(block, TEST_DIFFICULTY, true);
org.ethereum.core.Block rskCurrentBlock = blocks.get(9);
Transaction tx = Transaction.create(config, TO_ADDRESS, DUST_AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
tx.sign(new ECKey().getPrivKeyBytes());
BridgeSupport bridgeSupport = new BridgeSupport(config, track, mock(BridgeEventLogger.class), PrecompiledContracts.BRIDGE_ADDR, rskCurrentBlock);
bridgeSupport.updateCollections(tx);
bridgeSupport.save();
track.commit();
BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
Assert.assertEquals(1, provider.getReleaseRequestQueue().getEntries().size());
Assert.assertEquals(0, provider.getReleaseTransactionSet().getEntries().size());
Assert.assertEquals(0, provider.getRskTxsWaitingForSignatures().size());
// Check the wallet has not been emptied
Assert.assertFalse(provider.getNewFederationBtcUTXOs().isEmpty());
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class BridgeSupportTest method callUpdateCollectionsFundsEnoughForJustTheSmallerTx.
@Test
public void callUpdateCollectionsFundsEnoughForJustTheSmallerTx() throws IOException, BlockStoreException {
// Federation is the genesis federation ATM
Federation federation = bridgeConstants.getGenesisFederation();
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
provider0.getReleaseRequestQueue().add(new BtcECKey().toAddress(btcParams), Coin.valueOf(30, 0));
provider0.getReleaseRequestQueue().add(new BtcECKey().toAddress(btcParams), Coin.valueOf(20, 0));
provider0.getReleaseRequestQueue().add(new BtcECKey().toAddress(btcParams), Coin.valueOf(10, 0));
provider0.setFeePerKb(Coin.MILLICOIN);
provider0.getNewFederationBtcUTXOs().add(new UTXO(PegTestUtils.createHash(), 1, Coin.valueOf(12, 0), 0, false, ScriptBuilder.createOutputScript(federation.getAddress())));
provider0.save();
track.commit();
track = repository.startTracking();
BlockGenerator blockGenerator = new BlockGenerator();
List<Block> blocks = blockGenerator.getSimpleBlockChain(blockGenerator.getGenesisBlock(), 10);
org.ethereum.core.Block rskCurrentBlock = blocks.get(9);
Transaction tx = Transaction.create(config, TO_ADDRESS, DUST_AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
tx.sign(new ECKey().getPrivKeyBytes());
BridgeSupport bridgeSupport = new BridgeSupport(config, track, mock(BridgeEventLogger.class), PrecompiledContracts.BRIDGE_ADDR, rskCurrentBlock);
bridgeSupport.updateCollections(tx);
bridgeSupport.save();
track.commit();
BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
Assert.assertEquals(2, provider.getReleaseRequestQueue().getEntries().size());
Assert.assertEquals(1, provider.getReleaseTransactionSet().getEntries().size());
Assert.assertEquals(0, provider.getRskTxsWaitingForSignatures().size());
// Check value sent to user is 10 BTC minus fee
Assert.assertEquals(Coin.valueOf(999962800l), provider.getReleaseTransactionSet().getEntries().iterator().next().getTransaction().getOutput(0).getValue());
// Check the wallet has been emptied
Assert.assertTrue(provider.getNewFederationBtcUTXOs().isEmpty());
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class BridgeTest method callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfirmations.
@Test
public void callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfirmations() throws IOException {
BtcTransaction tx1 = createTransaction();
BtcTransaction tx2 = createTransaction();
BtcTransaction tx3 = createTransaction();
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
provider0.getReleaseTransactionSet().add(tx1, 1L);
provider0.getReleaseTransactionSet().add(tx2, 2L);
provider0.getReleaseTransactionSet().add(tx3, 3L);
provider0.save();
track.commit();
track = repository.startTracking();
World world = new World();
List<Block> blocks = new BlockGenerator().getSimpleBlockChain(world.getBlockChain().getBestBlock(), 10);
Transaction rskTx = Transaction.create(config, PrecompiledContracts.BRIDGE_ADDR_STR, AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
rskTx.sign(new ECKey().getPrivKeyBytes());
world.getBlockChain().getBlockStore().saveBlock(blocks.get(1), new BlockDifficulty(BigInteger.ONE), true);
Bridge bridge = new Bridge(config, PrecompiledContracts.BRIDGE_ADDR);
bridge.init(rskTx, blocks.get(9), track, world.getBlockChain().getBlockStore(), null, new LinkedList<>());
bridge.execute(Bridge.UPDATE_COLLECTIONS.encode());
track.commit();
BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
Assert.assertEquals(2, provider.getReleaseTransactionSet().getEntries().size());
Assert.assertEquals(1, provider.getRskTxsWaitingForSignatures().size());
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class TxBuilder method createNewTransaction.
public Transaction createNewTransaction(BigInteger gasPrice, BigInteger gasLimit, BigInteger txNonce) {
String toAddress = Hex.toHexString(new ECKey(Utils.getRandom()).getAddress());
Transaction tx = Transaction.create(config, toAddress, BigInteger.valueOf(1000), txNonce, gasPrice, gasLimit);
tx.sign(privateKeyBytes);
return tx;
}
Aggregations