Skip to content

Commit

Permalink
feat: #17 Added constructor to take VersionTable
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Sep 22, 2023
1 parent 0ebc21e commit 63eae96
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.bloxbean.cardano.yaci.helper;

import com.bloxbean.cardano.yaci.core.protocol.chainsync.messages.Point;
import com.bloxbean.cardano.yaci.core.protocol.handshake.messages.VersionTable;
import com.bloxbean.cardano.yaci.core.protocol.handshake.util.N2NVersionTableConstant;
import com.bloxbean.cardano.yaci.helper.listener.BlockChainDataListener;
import com.bloxbean.cardano.yaci.helper.listener.BlockFetchAgentListenerAdapter;
import com.bloxbean.cardano.yaci.helper.listener.ChainSyncListenerAdapter;
Expand All @@ -12,8 +14,8 @@
public class BlockSync {
private String host;
private int port;
private long protocolMagic;
private Point wellKnownPoint;
private VersionTable versionTable;

private N2NChainSyncFetcher n2NChainSyncFetcher;

Expand All @@ -25,10 +27,21 @@ public class BlockSync {
* @param wellKnownPoint A wellknown point
*/
public BlockSync(String host, int port, long protocolMagic, Point wellKnownPoint) {
this(host, port, wellKnownPoint, N2NVersionTableConstant.v4AndAbove(protocolMagic));
}

/**
* Construct a BlockSync instance
* @param host Cardano node host
* @param port Cardano node port
* @param wellKnownPoint A wellknown point
* @param versionTable {@link VersionTable} instance
*/
public BlockSync(String host, int port, Point wellKnownPoint, VersionTable versionTable) {
this.host = host;
this.port = port;
this.protocolMagic = protocolMagic;
this.wellKnownPoint = wellKnownPoint;
this.versionTable = versionTable;
}

/**
Expand All @@ -44,7 +57,7 @@ public void startSync(Point point, BlockChainDataListener blockChainDataListener
}

private void initializeAgentAndStart(Point point, BlockChainDataListener blockChainDataListener, boolean syncFromTip) {
n2NChainSyncFetcher = new N2NChainSyncFetcher(host, port, point, protocolMagic, syncFromTip);
n2NChainSyncFetcher = new N2NChainSyncFetcher(host, port, point, versionTable, syncFromTip);

BlockFetchAgentListenerAdapter blockfetchAgentListener = new BlockFetchAgentListenerAdapter(blockChainDataListener);
ChainSyncListenerAdapter chainSyncAgentListener = new ChainSyncListenerAdapter(blockChainDataListener);
Expand Down

0 comments on commit 63eae96

Please sign in to comment.