use of co.rsk.bitcoinj.core.Context 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);
}
use of co.rsk.bitcoinj.core.Context 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);
}
use of co.rsk.bitcoinj.core.Context in project rskj by rsksmart.
the class Web3RskImpl method mnr_submitBitcoinBlock.
public SubmittedBlockInfo mnr_submitBitcoinBlock(String bitcoinBlockHex) {
logger.debug("mnr_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);
}
use of co.rsk.bitcoinj.core.Context in project rskj by rsksmart.
the class BtcBlockchainTest method buildInitializer.
private BridgeStorageProviderInitializer buildInitializer() {
final int minBtcBlocks = 1000;
final int maxBtcBlocks = 2000;
return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
BtcBlockStore btcBlockStore = new RepositoryBlockStore(new RskSystemProperties(), repository, PrecompiledContracts.BRIDGE_ADDR);
Context btcContext = new Context(networkParameters);
BtcBlockChain btcBlockChain;
try {
btcBlockChain = new BtcBlockChain(btcContext, btcBlockStore);
} catch (BlockStoreException e) {
throw new RuntimeException("Error initializing btc blockchain for tests");
}
int blocksToGenerate = Helper.randomInRange(minBtcBlocks, maxBtcBlocks);
Helper.generateAndAddBlocks(btcBlockChain, blocksToGenerate);
};
}
use of co.rsk.bitcoinj.core.Context in project rskj by rsksmart.
the class ReceiveHeadersTest method receiveHeaders.
@Test
public void receiveHeaders() throws IOException {
final int minBtcBlocks = 1000;
final int maxBtcBlocks = 2000;
BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
BtcBlockStore btcBlockStore = new RepositoryBlockStore(new RskSystemProperties(), repository, PrecompiledContracts.BRIDGE_ADDR);
Context btcContext = new Context(networkParameters);
BtcBlockChain btcBlockChain;
try {
btcBlockChain = new BtcBlockChain(btcContext, btcBlockStore);
} catch (BlockStoreException e) {
throw new RuntimeException("Error initializing btc blockchain for tests");
}
int blocksToGenerate = Helper.randomInRange(minBtcBlocks, maxBtcBlocks);
BtcBlock lastBlock = Helper.generateAndAddBlocks(btcBlockChain, blocksToGenerate);
blockToTry = Helper.generateBtcBlock(lastBlock);
};
ABIEncoder abiEncoder = (int executionIndex) -> {
List<BtcBlock> headersToSendToBridge = new ArrayList<>();
// Send just one header (that's the only case we're interested in measuring atm
headersToSendToBridge.add(blockToTry);
Object[] headersEncoded = headersToSendToBridge.stream().map(h -> h.bitcoinSerialize()).toArray();
return Bridge.RECEIVE_HEADERS.encode(new Object[] { headersEncoded });
};
ExecutionStats stats = new ExecutionStats("receiveHeaders");
executeAndAverage("receiveHeaders", 200, abiEncoder, storageInitializer, Helper.getZeroValueRandomSenderTxBuilder(), Helper.getRandomHeightProvider(10), stats);
BridgePerformanceTest.addStats(stats);
}
Aggregations