Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new methods to BlockChainDataListener #22

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group = com.bloxbean.cardano
artifactId = yaci
version = 0.2.2-SNAPSHOT
version = 0.2.2
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import com.bloxbean.cardano.yaci.core.model.BlockHeader;
import com.bloxbean.cardano.yaci.core.model.Era;
import com.bloxbean.cardano.yaci.core.protocol.chainsync.messages.Point;
import com.bloxbean.cardano.yaci.core.protocol.chainsync.messages.Tip;
import com.bloxbean.cardano.yaci.helper.listener.BlockChainDataListener;
import com.bloxbean.cardano.yaci.helper.model.Transaction;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

Expand Down Expand Up @@ -60,7 +62,7 @@ public void onBlock(Block block) {
countDownLatch.countDown();
}

@Override
@Override
public void onTransactions(Era era, BlockHeader blockHeader, List<Transaction> transactions) {
System.out.println("# of transactions >> " + transactions.size());
noOfTxs.set(transactions.size());
Expand All @@ -72,4 +74,44 @@ public void onTransactions(Era era, BlockHeader blockHeader, List<Transaction> t
assertThat(blockNo.get()).isEqualTo(292458);
assertThat(noOfTxs.get()).isGreaterThanOrEqualTo(1);
}

@Test
void intersactNotFound() throws InterruptedException {
BlockSync blockSync = new BlockSync(node, nodePort, protocolMagic, Constants.WELL_KNOWN_PREPROD_POINT);

AtomicBoolean success = new AtomicBoolean(false);
CountDownLatch countDownLatch = new CountDownLatch(1);
blockSync.startSync(new Point(38474115, "784e0c913ce6378208f4fc1abf2ce74e817048306247e0ecffa6dac676ce8c65"),
new BlockChainDataListener() {
@Override
public void intersactNotFound(Tip tip) {
System.out.println(">>> Intersection not found");
success.set(true);
countDownLatch.countDown();
}
});

countDownLatch.await(60, TimeUnit.SECONDS);
assertThat(success.get()).isTrue();
}

@Test
void intersactFound() throws InterruptedException {
BlockSync blockSync = new BlockSync(node, nodePort, protocolMagic, Constants.WELL_KNOWN_PREPROD_POINT);

AtomicBoolean success = new AtomicBoolean(false);
CountDownLatch countDownLatch = new CountDownLatch(1);
blockSync.startSync(new Point(38481569, "cf884b8e61126190f6e59d71ad53c561f620cf65ed09aff468149b32b537a804"),
new BlockChainDataListener() {
@Override
public void intersactFound(Tip tip, Point point) {
System.out.println("Intersection found");
success.set(true);
countDownLatch.countDown();
}
});

countDownLatch.await(60, TimeUnit.SECONDS);
assertThat(success.get()).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.bloxbean.cardano.yaci.core.model.byron.ByronEbBlock;
import com.bloxbean.cardano.yaci.core.model.byron.ByronMainBlock;
import com.bloxbean.cardano.yaci.core.protocol.chainsync.messages.Point;
import com.bloxbean.cardano.yaci.core.protocol.chainsync.messages.Tip;
import com.bloxbean.cardano.yaci.helper.model.Transaction;

import java.util.List;
Expand All @@ -20,4 +21,17 @@ default void onTransactions(Era era, BlockHeader blockHeader, List<Transaction>

default void batchDone() {}
default void noBlockFound(Point from, Point to) {}

/**
* Called when an intersection is found. This is available only for {@link com.bloxbean.cardano.yaci.helper.BlockSync} (Block sync protocol)
* @param tip
* @param point
*/
default void intersactFound(Tip tip, Point point) {}

/**
* Called when an intersection is not found. This is available only for {@link com.bloxbean.cardano.yaci.helper.BlockSync} (Block sync protocol)
* @param tip
*/
default void intersactNotFound(Tip tip) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public ChainSyncListenerAdapter(BlockChainDataListener blockChainDataListener) {
}

public void intersactFound(Tip tip, Point point) {

blockChainDataListener.intersactFound(tip, point);
}

public void intersactNotFound(Tip tip) {

blockChainDataListener.intersactNotFound(tip);
}

public void rollforward(Tip tip, BlockHeader blockHeader) {
Expand Down
Loading