use of co.rsk.bitcoinj.core.BtcBlock 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);
}
use of co.rsk.bitcoinj.core.BtcBlock 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);
}
use of co.rsk.bitcoinj.core.BtcBlock in project rskj by rsksmart.
the class RepositoryBtcBlockStoreWithCacheTest method ifCacheNullAlwaysGoToDisk.
@Test
public void ifCacheNullAlwaysGoToDisk() throws BlockStoreException {
Repository repository = createRepository();
BtcBlockStoreWithCache btcBlockStore = new RepositoryBtcBlockStoreWithCache(networkParameters, repository.startTracking(), null, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, mock(BridgeStorageProvider.class), mock(ActivationConfig.ForBlock.class));
BtcBlock genesis = networkParameters.getGenesisBlock();
StoredBlock firstStoredBlock = createStoredBlock(genesis, 1, 0);
Sha256Hash firstBlockHash = firstStoredBlock.getHeader().getHash();
btcBlockStore.put(firstStoredBlock);
btcBlockStore.setChainHead(firstStoredBlock);
assertEquals(firstStoredBlock, btcBlockStore.get(firstBlockHash));
assertNull(btcBlockStore.getFromCache(firstBlockHash));
assertEquals(firstStoredBlock, btcBlockStore.getChainHead());
assertEquals(genesis, btcBlockStore.getStoredBlockAtMainChainDepth(1).getHeader());
assertEquals(genesis, btcBlockStore.getStoredBlockAtMainChainHeight(0).getHeader());
}
use of co.rsk.bitcoinj.core.BtcBlock in project rskj by rsksmart.
the class RepositoryBtcBlockStoreWithCacheTest method put_oldBlockShouldNotGoToCache.
@Test
public void put_oldBlockShouldNotGoToCache() throws BlockStoreException {
BtcBlockStoreWithCache btcBlockStore = createBlockStore();
BtcBlock genesis = networkParameters.getGenesisBlock();
// Set chain head at height 6000
StoredBlock storedBlock1 = createStoredBlock(genesis, 6000, 0);
Sha256Hash firstBlockHash = storedBlock1.getHeader().getHash();
btcBlockStore.put(storedBlock1);
btcBlockStore.setChainHead(storedBlock1);
// Store a block of height 1 which is lesser than chainHead - 5000
StoredBlock storedBlock2 = createStoredBlock(genesis, 1, 1);
Sha256Hash secondBlockHash = storedBlock2.getHeader().getHash();
btcBlockStore.put(storedBlock2);
assertEquals(storedBlock1, btcBlockStore.getFromCache(firstBlockHash));
assertNull(btcBlockStore.getFromCache(secondBlockHash));
assertEquals(storedBlock1, btcBlockStore.get(firstBlockHash));
assertEquals(storedBlock2, btcBlockStore.get(secondBlockHash));
assertEquals(storedBlock1, btcBlockStore.getChainHead());
}
use of co.rsk.bitcoinj.core.BtcBlock in project rskj by rsksmart.
the class RepositoryBtcBlockStoreWithCacheTest method getStoredBlockAtMainChainDepth.
@Test
public void getStoredBlockAtMainChainDepth() throws BlockStoreException {
BtcBlockStoreWithCache btcBlockStore = createBlockStore();
BtcBlock genesis = networkParameters.getGenesisBlock();
StoredBlock storedBlock1 = createStoredBlock(genesis, 1, 0);
btcBlockStore.put(storedBlock1);
StoredBlock storedBlock2 = createStoredBlock(storedBlock1.getHeader(), 2, 0);
btcBlockStore.put(storedBlock2);
StoredBlock storedBlock3 = createStoredBlock(storedBlock2.getHeader(), 3, 0);
btcBlockStore.put(storedBlock3);
StoredBlock storedBlock4 = createStoredBlock(storedBlock3.getHeader(), 4, 0);
btcBlockStore.put(storedBlock4);
btcBlockStore.setChainHead(storedBlock4);
assertEquals(storedBlock4, btcBlockStore.getChainHead());
int maxHeight = storedBlock4.getHeight();
// Check getStoredBlockAtMainChainDepth
assertEquals(storedBlock3, btcBlockStore.getStoredBlockAtMainChainDepth(maxHeight - storedBlock3.getHeight()));
assertEquals(storedBlock2, btcBlockStore.getStoredBlockAtMainChainDepth(maxHeight - storedBlock2.getHeight()));
assertEquals(storedBlock1, btcBlockStore.getStoredBlockAtMainChainDepth(maxHeight - storedBlock1.getHeight()));
assertEquals(genesis, btcBlockStore.getStoredBlockAtMainChainDepth(maxHeight).getHeader());
}
Aggregations