use of co.rsk.bitcoinj.core.NetworkParameters in project rskj by rsksmart.
the class BlockHeaderContractTest method mineBlock.
private Block mineBlock(Block parent, RskAddress coinbase) {
NetworkParameters networkParameters = RegTestParams.get();
BlockGenerator blockGenerator = new BlockGenerator(config.getNetworkConstants(), config.getActivationConfig());
Block childBlock = blockGenerator.createChildBlock(parent, new ArrayList<>(), new ArrayList<>(), parent.getDifficulty().asBigInteger().longValue(), MIN_GAS_PRICE, parent.getGasLimit(), coinbase);
Block newBlock = blockFactory.cloneBlockForModification(childBlock);
byte[] prefix = new byte[1000];
byte[] compressedTag = Arrays.concatenate(prefix, RskMiningConstants.RSK_TAG);
byte[] mergedMiningHash = childBlock.getHashForMergedMining();
BtcTransaction mergedMiningCoinbaseTransaction = MinerUtils.getBitcoinMergedMiningCoinbaseTransaction(networkParameters, mergedMiningHash);
BtcBlock mergedMiningBlock = MinerUtils.getBitcoinMergedMiningBlock(networkParameters, mergedMiningCoinbaseTransaction);
BigInteger targetDifficulty = DifficultyUtils.difficultyToTarget(parent.getDifficulty());
new BlockMiner(config.getActivationConfig()).findNonce(mergedMiningBlock, targetDifficulty);
newBlock.setBitcoinMergedMiningHeader(mergedMiningBlock.cloneAsHeader().bitcoinSerialize());
byte[] merkleProof = MinerUtils.buildMerkleProof(config.getActivationConfig(), pb -> pb.buildFromBlock(mergedMiningBlock), newBlock.getNumber());
newBlock.setBitcoinMergedMiningMerkleProof(merkleProof);
byte[] additionalTag = Arrays.concatenate(ADDITIONAL_TAG, mergedMiningHash);
byte[] mergedMiningTx = org.bouncycastle.util.Arrays.concatenate(compressedTag, mergedMiningHash, additionalTag);
newBlock.setBitcoinMergedMiningCoinbaseTransaction(mergedMiningTx);
return newBlock;
}
use of co.rsk.bitcoinj.core.NetworkParameters 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.NetworkParameters in project rskj by rsksmart.
the class ReleaseBtcTest method releaseBtc.
@Test
public void releaseBtc() throws IOException {
int minCentsBtc = 5;
int maxCentsBtc = 100;
final NetworkParameters parameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
ReleaseRequestQueue queue;
try {
queue = provider.getReleaseRequestQueue();
} catch (Exception e) {
throw new RuntimeException("Unable to gather release request queue");
}
for (int i = 0; i < Helper.randomInRange(10, 100); i++) {
Coin value = Coin.CENT.multiply(Helper.randomInRange(minCentsBtc, maxCentsBtc));
queue.add(new BtcECKey().toAddress(parameters), value);
}
};
final byte[] releaseBtcEncoded = Bridge.RELEASE_BTC.encode();
ABIEncoder abiEncoder = (int executionIndex) -> releaseBtcEncoded;
TxBuilder txBuilder = (int executionIndex) -> {
long satoshis = Coin.CENT.multiply(Helper.randomInRange(minCentsBtc, maxCentsBtc)).getValue();
BigInteger weis = Denomination.satoshisToWeis(BigInteger.valueOf(satoshis));
ECKey sender = new ECKey();
return Helper.buildSendValueTx(sender, weis);
};
ExecutionStats stats = new ExecutionStats("releaseBtc");
executeAndAverage("releaseBtc", 1000, abiEncoder, storageInitializer, txBuilder, Helper.getRandomHeightProvider(10), stats);
BridgePerformanceTest.addStats(stats);
}
Aggregations