Search in sources :

Example 16 with NetworkParameters

use of co.rsk.bitcoinj.core.NetworkParameters 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 17 with NetworkParameters

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

the class MnrModuleImpl method submitBitcoinBlockPartialMerkle.

@Override
public SubmittedBlockInfo submitBitcoinBlockPartialMerkle(String blockHashHex, String blockHeaderHex, String coinbaseHex, String merkleHashesHex, String blockTxnCountHex) {
    logger.debug("submitBitcoinBlockPartialMerkle(): {}, {}, {}, {}, {}", blockHashHex, blockHeaderHex, coinbaseHex, merkleHashesHex, blockTxnCountHex);
    if (merkleHashesHex.isEmpty()) {
        throw new JsonRpcSubmitBlockException("The list of merkle hashes can't be empty");
    }
    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) SubmitBlockResult(co.rsk.mine.SubmitBlockResult) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) JsonRpcSubmitBlockException(co.rsk.rpc.exception.JsonRpcSubmitBlockException)

Example 18 with NetworkParameters

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

the class MnrModuleImpl method submitBitcoinBlock.

@Override
public SubmittedBlockInfo submitBitcoinBlock(String bitcoinBlockHex) {
    logger.debug("submitBitcoinBlock(): {}", bitcoinBlockHex.length());
    NetworkParameters params = RegTestParams.get();
    new Context(params);
    BtcBlock bitcoinBlock = getBtcBlock(bitcoinBlockHex, params);
    BtcTransaction coinbase = bitcoinBlock.getTransactions().get(0);
    String blockHashForMergedMining = extractBlockHashForMergedMining(coinbase);
    SubmitBlockResult result = minerServer.submitBitcoinBlock(blockHashForMergedMining, bitcoinBlock);
    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 19 with NetworkParameters

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

the class ForkDataDetectionCalculatorTest method setUp.

@BeforeClass
public static void setUp() {
    NetworkParameters params = RegTestParams.get();
    new Context(params);
    serializer = params.getDefaultSerializer();
}
Also used : Context(co.rsk.bitcoinj.core.Context) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) BeforeClass(org.junit.BeforeClass)

Example 20 with NetworkParameters

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

the class BridgeTest method receiveHeader_before_RSKIP200.

@Test
public void receiveHeader_before_RSKIP200() throws VMException {
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(false).when(activations).isActive(eq(RSKIP200), anyLong());
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Bridge bridge = spy(getBridgeInstance(bridgeSupportMock, activations));
    NetworkParameters networkParameters = constants.bridgeConstants.getBtcParams();
    co.rsk.bitcoinj.core.BtcBlock block = new co.rsk.bitcoinj.core.BtcBlock(networkParameters, 1, PegTestUtils.createHash(1), PegTestUtils.createHash(1), 1, Utils.encodeCompactBits(networkParameters.getMaxTarget()), 1, new ArrayList<>()).cloneAsHeader();
    Object[] parameters = new Object[] { block.bitcoinSerialize() };
    byte[] data = Bridge.RECEIVE_HEADER.encode(parameters);
    bridge.execute(data);
    assertNull(bridge.execute(data));
    verify(bridge, never()).receiveHeader(any(Object[].class));
}
Also used : co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) ArrayList(java.util.ArrayList) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Aggregations

NetworkParameters (co.rsk.bitcoinj.core.NetworkParameters)28 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)11 Test (org.junit.Test)9 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)8 Context (co.rsk.bitcoinj.core.Context)7 BigInteger (java.math.BigInteger)6 Address (co.rsk.bitcoinj.core.Address)5 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)5 ECKey (org.ethereum.crypto.ECKey)5 DeterministicKey (co.rsk.bitcoinj.crypto.DeterministicKey)4 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)3 BtcECKey (co.rsk.bitcoinj.core.BtcECKey)3 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)3 RskAddress (co.rsk.core.RskAddress)3 Keccak256 (co.rsk.crypto.Keccak256)3 SubmitBlockResult (co.rsk.mine.SubmitBlockResult)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)3 CallTransaction (org.ethereum.core.CallTransaction)3