Skip to content

Commit

Permalink
Merge pull request #35 from bloxbean/fixes_911
Browse files Browse the repository at this point in the history
New Sanchonet url, Missing Anchor field
  • Loading branch information
satran004 authored Nov 9, 2023
2 parents 39ef1cd + 75fdcd8 commit dc7b457
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Constants {
public final static String PREVIEW_IOHK_RELAY_ADDR = "preview-node.world.dev.cardano.org";
public final static int PREVIEW_IOHK_RELAY_PORT = 30002;

public final static String SANCHONET_PUBLIC_RELAY_ADDR = "sanchonet-node.world.dev.cardano.org";
public final static int SANCHONET_PUBLIC_RELAY_PORT = 30004;
public final static String SANCHONET_PUBLIC_RELAY_ADDR = "sanchonet-node.play.dev.cardano.org";
public final static int SANCHONET_PUBLIC_RELAY_PORT = 3001;

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static Credential fromScriptHash(byte[] scriptHash) {
public static Credential deserialize(Array stakeCredArray) {
List<DataItem> dataItemList = stakeCredArray.getDataItems();
if (dataItemList == null || dataItemList.size() != 2)
throw new CborRuntimeException("StakeCredential deserialization failed. Invalid number of DataItem(s) : "
throw new CborRuntimeException("Credential deserialization failed. Invalid number of DataItem(s) : "
+ (dataItemList != null ? String.valueOf(dataItemList.size()) : null));

UnsignedInteger typeDI = (UnsignedInteger) dataItemList.get(0);
Expand All @@ -70,7 +70,7 @@ public static Credential deserialize(Array stakeCredArray) {
} else if (typeBI.intValue() == 1) {
return Credential.fromScriptHash(hashDI.getBytes());
} else {
throw new CborRuntimeException("StakeCredential deserialization failed. Invalid StakeCredType : "
throw new CborRuntimeException("Credential deserialization failed. Invalid CredType : "
+ typeBI.intValue());
}
}
Expand All @@ -82,7 +82,7 @@ public Array serialize() {
} else if (type == StakeCredType.SCRIPTHASH) {
array.add(new UnsignedInteger(1));
} else {
throw new CborRuntimeException("Invalid stake credential type : " + type);
throw new CborRuntimeException("Invalid credential type : " + type);
}

array.add(new ByteString(HexUtil.decodeHexString(hash)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bloxbean.cardano.yaci.core.model.certs;

import com.bloxbean.cardano.yaci.core.model.Credential;
import com.bloxbean.cardano.yaci.core.model.governance.Anchor;
import lombok.*;

@Getter
Expand All @@ -13,4 +14,5 @@ public class ResignCommitteeColdCert implements Certificate {
private final CertificateType type = CertificateType.RESIGN_COMMITTEE_COLD_CERT;

private Credential committeeColdCredential;
private Anchor anchor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import co.nstant.in.cbor.model.Array;
import co.nstant.in.cbor.model.DataItem;
import co.nstant.in.cbor.model.SimpleValue;
import com.bloxbean.cardano.yaci.core.model.Credential;
import com.bloxbean.cardano.yaci.core.model.certs.ResignCommitteeColdCert;
import com.bloxbean.cardano.yaci.core.model.governance.Anchor;
import com.bloxbean.cardano.yaci.core.protocol.Serializer;

import java.util.List;
Expand All @@ -20,6 +22,13 @@ public ResignCommitteeColdCert deserializeDI(DataItem di) {
List<DataItem> dataItemList = certArray.getDataItems();

Credential committeeColdCred = Credential.deserialize((Array) dataItemList.get(1));
return new ResignCommitteeColdCert(committeeColdCred);

var anchorDI = dataItemList.get(2);
Anchor anchor = null;
if (anchorDI != SimpleValue.NULL) {
anchor = AnchorSerializer.INSTANCE.deserializeDI(anchorDI);
}

return new ResignCommitteeColdCert(committeeColdCred, anchor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public void startSyncFromTip(BlockChainDataListener blockChainDataListener) {
initializeAgentAndStart(wellKnownPoint, blockChainDataListener, true);
}

public void sendKeepAliveMessage(int cookie) {
if (n2NChainSyncFetcher.isRunning())
n2NChainSyncFetcher.sendKeepAliveMessage(cookie);
}

/**
* Stop the fetcher
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class N2NChainSyncFetcher implements Fetcher<Block> {
private KeepAliveAgent keepAliveAgent;
private ChainsyncAgent chainSyncAgent;
private BlockfetchAgent blockFetchAgent;
private TCPNodeClient n2CClient;
private TCPNodeClient n2nClient;

/**
* Construct {@link N2NChainSyncFetcher} to sync the blockchain
Expand Down Expand Up @@ -193,7 +193,7 @@ public void byronEbBlockFound(ByronEbBlock byronEbBlock) {
}
});

n2CClient = new TCPNodeClient(host, port, handshakeAgent, keepAliveAgent,
n2nClient = new TCPNodeClient(host, port, handshakeAgent, keepAliveAgent,
chainSyncAgent, blockFetchAgent);
}

Expand Down Expand Up @@ -224,7 +224,7 @@ public void blockFound(Block block) {
}
});

n2CClient.start();
n2nClient.start();
}

/**
Expand Down Expand Up @@ -253,22 +253,27 @@ public void addChainSyncListener(ChainSyncAgentListener listener) {
chainSyncAgent.addListener(listener);
}

public void sendKeepAliveMessage(int cookie) {
if (n2nClient.isRunning())
keepAliveAgent.sendKeepAlive(cookie);
}

/**
* Check if the connection is alive
*
* @return
*/
@Override
public boolean isRunning() {
return n2CClient.isRunning();
return n2nClient.isRunning();
}

/**
* Shutdown connection
*/
@Override
public void shutdown() {
n2CClient.shutdown();
n2nClient.shutdown();
}

public static void main(String[] args) throws Exception {
Expand Down

0 comments on commit dc7b457

Please sign in to comment.