Search in sources :

Example 41 with ECKey

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;
}
Also used : RskAddress(co.rsk.core.RskAddress) ECKey(org.ethereum.crypto.ECKey) SignatureException(java.security.SignatureException)

Example 42 with ECKey

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());
}
Also used : ECKey(org.ethereum.crypto.ECKey) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) org.ethereum.core(org.ethereum.core) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) RepositoryImpl(co.rsk.db.RepositoryImpl) BridgeEventLogger(co.rsk.peg.utils.BridgeEventLogger) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with ECKey

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());
}
Also used : ECKey(org.ethereum.crypto.ECKey) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) org.ethereum.core(org.ethereum.core) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) RepositoryImpl(co.rsk.db.RepositoryImpl) BridgeEventLogger(co.rsk.peg.utils.BridgeEventLogger) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 with ECKey

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());
}
Also used : SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) ECKey(org.ethereum.crypto.ECKey) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockDifficulty(co.rsk.core.BlockDifficulty) SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) RepositoryImpl(co.rsk.db.RepositoryImpl) Test(org.junit.Test)

Example 45 with ECKey

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;
}
Also used : Transaction(org.ethereum.core.Transaction) ECKey(org.ethereum.crypto.ECKey)

Aggregations

ECKey (org.ethereum.crypto.ECKey)76 Test (org.junit.Test)43 BigInteger (java.math.BigInteger)17 NodeDistanceTable (co.rsk.net.discovery.table.NodeDistanceTable)10 ArrayList (java.util.ArrayList)10 Node (org.ethereum.net.rlpx.Node)10 InetSocketAddress (java.net.InetSocketAddress)9 Transaction (org.ethereum.core.Transaction)8 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)7 RepositoryImpl (co.rsk.db.RepositoryImpl)7 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)7 Channel (io.netty.channel.Channel)7 org.ethereum.core (org.ethereum.core)7 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)6 BridgeEventLogger (co.rsk.peg.utils.BridgeEventLogger)6 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)4 Account (org.ethereum.core.Account)4 RskAddress (co.rsk.core.RskAddress)3