Search in sources :

Example 1 with BtcBlock

use of co.rsk.bitcoinj.core.BtcBlock in project rskj by rsksmart.

the class Web3RskImpl method mnr_submitBitcoinBlockTransactions.

public SubmittedBlockInfo mnr_submitBitcoinBlockTransactions(String blockHashHex, String blockHeaderHex, String coinbaseHex, String txnHashesHex) {
    logger.debug("mnr_submitBitcoinBlockTransactions(): {}, {}, {}, {}", blockHashHex, blockHeaderHex, coinbaseHex, txnHashesHex);
    NetworkParameters params = RegTestParams.get();
    new Context(params);
    BtcBlock bitcoinBlockWithHeaderOnly = getBtcBlock(blockHeaderHex, params);
    BtcTransaction coinbase = new BtcTransaction(params, Hex.decode(coinbaseHex));
    String blockHashForMergedMining = extractBlockHashForMergedMining(coinbase);
    List<String> txnHashes = parseHashes(txnHashesHex);
    SubmitBlockResult result = minerServer.submitBitcoinBlockTransactions(blockHashForMergedMining, bitcoinBlockWithHeaderOnly, coinbase, txnHashes);
    return parseResultAndReturn(result);
}
Also used : Context(co.rsk.bitcoinj.core.Context) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) BtcBlock(co.rsk.bitcoinj.core.BtcBlock)

Example 2 with BtcBlock

use of co.rsk.bitcoinj.core.BtcBlock in project rskj by rsksmart.

the class Web3RskImpl method mnr_submitBitcoinBlockPartialMerkle.

public SubmittedBlockInfo mnr_submitBitcoinBlockPartialMerkle(String blockHashHex, String blockHeaderHex, String coinbaseHex, String merkleHashesHex, String blockTxnCountHex) {
    logger.debug("mnr_submitBitcoinBlockPartialMerkle(): {}, {}, {}, {}, {}", blockHashHex, blockHeaderHex, coinbaseHex, merkleHashesHex, blockTxnCountHex);
    NetworkParameters params = RegTestParams.get();
    new Context(params);
    BtcBlock bitcoinBlockWithHeaderOnly = getBtcBlock(blockHeaderHex, params);
    BtcTransaction coinbase = new BtcTransaction(params, Hex.decode(coinbaseHex));
    String blockHashForMergedMining = extractBlockHashForMergedMining(coinbase);
    List<String> merkleHashes = parseHashes(merkleHashesHex);
    int txnCount = Integer.parseInt(blockTxnCountHex, 16);
    SubmitBlockResult result = minerServer.submitBitcoinBlockPartialMerkle(blockHashForMergedMining, bitcoinBlockWithHeaderOnly, coinbase, merkleHashes, txnCount);
    return parseResultAndReturn(result);
}
Also used : Context(co.rsk.bitcoinj.core.Context) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) BtcBlock(co.rsk.bitcoinj.core.BtcBlock)

Example 3 with BtcBlock

use of co.rsk.bitcoinj.core.BtcBlock in project rskj by rsksmart.

the class MnrModuleImpl method submitBitcoinBlockTransactions.

@Override
public SubmittedBlockInfo submitBitcoinBlockTransactions(String blockHashHex, String blockHeaderHex, String coinbaseHex, String txnHashesHex) {
    logger.debug("submitBitcoinBlockTransactions(): {}, {}, {}, {}", blockHashHex, blockHeaderHex, coinbaseHex, txnHashesHex);
    NetworkParameters params = RegTestParams.get();
    new Context(params);
    BtcBlock bitcoinBlockWithHeaderOnly = getBtcBlock(blockHeaderHex, params);
    BtcTransaction coinbase = new BtcTransaction(params, Hex.decode(coinbaseHex));
    String blockHashForMergedMining = extractBlockHashForMergedMining(coinbase);
    List<String> txnHashes = parseHashes(txnHashesHex);
    SubmitBlockResult result = minerServer.submitBitcoinBlockTransactions(blockHashForMergedMining, bitcoinBlockWithHeaderOnly, coinbase, txnHashes);
    return parseResultAndReturn(result);
}
Also used : Context(co.rsk.bitcoinj.core.Context) SubmitBlockResult(co.rsk.mine.SubmitBlockResult) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) BtcBlock(co.rsk.bitcoinj.core.BtcBlock)

Example 4 with BtcBlock

use of co.rsk.bitcoinj.core.BtcBlock in project rskj by rsksmart.

the class GetBtcBlockchainBlockHeaderByHeightTest method getBtcBlockchainBlockHeaderByHeightTest_success.

private void getBtcBlockchainBlockHeaderByHeightTest_success(int times, ExecutionStats stats) throws VMException {
    BridgeStorageProviderInitializer storageInitializer = generateInitializerForTest(1000, 2000);
    executeAndAverage("getBtcBlockchainBlockHeaderByHeightTest_success", times, getABIEncoder(), storageInitializer, Helper.getZeroValueRandomSenderTxBuilder(), Helper.getRandomHeightProvider(10), stats, (environment, executionResult) -> {
        BtcBlock btcBlock = byteArrayToBlockHeader(getByteFromResult(executionResult));
        Assert.assertEquals(btcBlock.getHash(), expectedBlock.getHash());
    });
}
Also used : BtcBlock(co.rsk.bitcoinj.core.BtcBlock)

Example 5 with BtcBlock

use of co.rsk.bitcoinj.core.BtcBlock in project rskj by rsksmart.

the class GetBtcBlockchainParentBlockHeaderByHashTest method getBtcBlockchainParentBlockHeaderByHashTest_success.

private void getBtcBlockchainParentBlockHeaderByHashTest_success(int times, ExecutionStats stats) throws VMException {
    BridgeStorageProviderInitializer storageInitializer = generateInitializerForTest(1000, 2000);
    executeAndAverage("getBtcBlockchainParentBlockHeaderByHashTest_success", times, getABIEncoder(), storageInitializer, Helper.getZeroValueRandomSenderTxBuilder(), Helper.getRandomHeightProvider(10), stats, (environment, executionResult) -> {
        BtcBlock btcBlock = byteArrayToBlockHeader(getByteFromResult(executionResult));
        Assert.assertEquals(expectedBlock.getHash(), btcBlock.getHash());
    });
}
Also used : BtcBlock(co.rsk.bitcoinj.core.BtcBlock)

Aggregations

BtcBlock (co.rsk.bitcoinj.core.BtcBlock)37 Test (org.junit.Test)17 StoredBlock (co.rsk.bitcoinj.core.StoredBlock)16 NetworkParameters (co.rsk.bitcoinj.core.NetworkParameters)11 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)10 Sha256Hash (co.rsk.bitcoinj.core.Sha256Hash)9 Repository (org.ethereum.core.Repository)8 Context (co.rsk.bitcoinj.core.Context)7 BigInteger (java.math.BigInteger)7 MutableRepository (org.ethereum.db.MutableRepository)6 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)4 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)3 SubmitBlockResult (co.rsk.mine.SubmitBlockResult)3 InputStream (java.io.InputStream)3 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)3 MessageSerializer (co.rsk.bitcoinj.core.MessageSerializer)2 VerificationException (co.rsk.bitcoinj.core.VerificationException)2 BlockMiner (co.rsk.blockchain.utils.BlockMiner)2 RskSystemProperties (co.rsk.config.RskSystemProperties)2 Keccak256 (co.rsk.crypto.Keccak256)2