Skip to content

Commit

Permalink
feat: #17 Initial update for Conway network protocol, VotingProcedure…
Browse files Browse the repository at this point in the history
…s cddl object
  • Loading branch information
satran004 committed Sep 22, 2023
1 parent 5bab519 commit 0ebc21e
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ public class Constants {
public final static Point WELL_KNOWN_TESTNET_POINT = new Point(13694363, "b596f9739b647ab5af901c8fc6f75791e262b0aeba81994a1d622543459734f2");
public final static Point WELL_KNOWN_PREPROD_POINT = new Point(87480, "528c3e6a00c82dd5331b116103b6e427acf447891ce3ade6c4c7a61d2f0a2b1c");
public final static Point WELL_KNOWN_PREVIEW_POINT = new Point(8000, "70da683c00985e23903da00656fae96644e1f31dce914aab4ed50e35e4c4842d");
public final static Point WELL_KNOWN_SANCHONET_POINT = new Point(8569937, "8264c74dcdf7afc02e0c176090af367b2662326d623a478710d54e22bf749ebd");

public final static long MAINNET_PROTOCOL_MAGIC = NetworkType.MAINNET.getProtocolMagic();
public final static long LEGACY_TESTNET_PROTOCOL_MAGIC = NetworkType.LEGACY_TESTNET.getProtocolMagic();
public final static long PREPROD_PROTOCOL_MAGIC = NetworkType.PREPROD.getProtocolMagic();
public final static long PREVIEW_PROTOCOL_MAGIC = NetworkType.PREVIEW.getProtocolMagic();
public final static long SANCHONET_PROTOCOL_MAGIC = NetworkType.SANCHONET.getProtocolMagic();

public final static String TESTNET_IOHK_RELAY_ADDR = "relays-new.cardano-testnet.iohkdev.io";
public final static int TESTNET_IOHK_RELAY_PORT = 3001;
Expand All @@ -25,4 +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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.bloxbean.cardano.yaci.core.protocol.handshake.util.N2NVersionTableConstant;

public enum NetworkType {
MAINNET(764824073), LEGACY_TESTNET(1097911063), PREPROD(1), PREVIEW(2);
MAINNET(764824073), LEGACY_TESTNET(1097911063), PREPROD(1), PREVIEW(2), SANCHONET(4);

long protocolMagic;
NetworkType(long protocolMagic) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public enum Era {
Allegra(3),
Mary(4),
Alonzo(5),
Babbage(6);
Babbage(6),
CONWAY(7);

public final int value;
Era(int value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bloxbean.cardano.yaci.core.model;

import com.bloxbean.cardano.yaci.core.model.certs.Certificate;
import com.bloxbean.cardano.yaci.core.model.conway.VotingProcedures;
import lombok.*;

import java.math.BigInteger;
Expand Down Expand Up @@ -42,4 +43,7 @@ public class TransactionBody {
private TransactionOutput collateralReturn;
private BigInteger totalCollateral;
private Set<TransactionInput> referenceInputs;

//conway
private VotingProcedures votingProcedures;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.bloxbean.cardano.yaci.core.model.conway;

import lombok.*;

/**
* anchor =
* [ anchor_url : url
* , anchor_data_hash : $hash32
* ]
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EqualsAndHashCode
@Builder
public class Anchor {
private String anchor_url;
private String anchor_data_hash;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.bloxbean.cardano.yaci.core.model.conway;

import lombok.*;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EqualsAndHashCode
@Builder
public class GovActionId {
private String transactionId;
private Integer gov_action_index;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.bloxbean.cardano.yaci.core.model.conway;

public enum Vote {
NO(0), YES(1), ABSTAIN(2);

private final int value;
Vote(int value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.bloxbean.cardano.yaci.core.model.conway;

import lombok.*;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EqualsAndHashCode
@Builder
public class Voter {
private VoterType type;
private String hash; //key hash or script hash
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bloxbean.cardano.yaci.core.model.conway;

public enum VoterType {
CONSTITUTIONAL_COMMITTEE_HOT_KEY_HASH, //0
CONSTITUTIONAL_COMMITTEE_HOT_SCRIPT_HASH, //1
DREP_KEY_HASH, //2
DREP_SCRIPT_HASH, //3
STAKING_POOL_KEY_HASH, //4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.bloxbean.cardano.yaci.core.model.conway;

import lombok.*;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EqualsAndHashCode
@Builder
/**
* voting_procedure =
* [ vote, anchor / null]
*/
public class VotingProcedure {
private Vote vote;
private Anchor anchor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.bloxbean.cardano.yaci.core.model.conway;

import lombok.*;

import java.util.Map;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EqualsAndHashCode
@Builder
/**
* voting_procedures = { + voter => { + gov_action_id => voting_procedure } }
*/
public class VotingProcedures {
private Map<Voter, Map<GovActionId, VotingProcedure>> voting;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.bloxbean.cardano.client.api.util.AssetUtil;
import com.bloxbean.cardano.yaci.core.model.*;
import com.bloxbean.cardano.yaci.core.model.certs.Certificate;
import com.bloxbean.cardano.yaci.core.model.conway.VotingProcedures;
import com.bloxbean.cardano.yaci.core.protocol.Serializer;
import com.bloxbean.cardano.yaci.core.util.CborSerializationUtil;
import com.bloxbean.cardano.yaci.core.util.HexUtil;
Expand Down Expand Up @@ -209,6 +210,16 @@ public TransactionBody deserializeDI(DataItem di) {
transactionBodyBuilder.referenceInputs(referenceInputs);
}

//TODO voting procedures 19
DataItem votingProceduresDI = bodyMap.get(new UnsignedInteger(19));
if (votingProceduresDI != null) {
VotingProcedures votingProcedures = VotingProceduresSerializer.INSTANCE.deserializeDI(votingProceduresDI);
transactionBodyBuilder.votingProcedures(votingProcedures);
}
//TODO proposal procedure 20
//TODO Current Treasury Value 21
//TODO Positive Coin 22

return transactionBodyBuilder.build();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.bloxbean.cardano.yaci.core.model.serializers;

import co.nstant.in.cbor.model.DataItem;
import com.bloxbean.cardano.yaci.core.model.conway.VotingProcedures;
import com.bloxbean.cardano.yaci.core.protocol.Serializer;

public enum VotingProceduresSerializer implements Serializer<VotingProcedures> {
INSTANCE;

@Override
public VotingProcedures deserializeDI(DataItem di) {
System.out.println("VotingProceduresSerializer.deserializeDI ------");
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
@ToString
public class N2NVersionData extends VersionData {
private Boolean initiatorAndResponderDiffusionMode;
private Integer peerSharing;
private Boolean query;
private Integer peerSharing = 0;
private Boolean query = Boolean.FALSE;

public N2NVersionData(long networkMagic, Boolean initiatorAndResponderDiffusionMode) {
super(networkMagic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public DataItem serializeDI(VersionTable versionTable) {
Array versionDataArray = new Array();
versionDataArray.add(new UnsignedInteger(versionData.getNetworkMagic()));
versionDataArray.add(versionData.getInitiatorAndResponderDiffusionMode() ? SimpleValue.TRUE : SimpleValue.FALSE);

//TODO -- check with existing node versions
versionDataArray.add(versionData.getPeerSharing() == null? new UnsignedInteger(0) : new UnsignedInteger(versionData.getPeerSharing()));
versionDataArray.add(versionData.getQuery() ? SimpleValue.TRUE : SimpleValue.FALSE);
cborMap.put(new UnsignedInteger(entry.getKey()), versionDataArray);
} else if (entry.getValue() instanceof OldN2CVersionData) {
cborMap.put(new UnsignedInteger(entry.getKey()), new UnsignedInteger(entry.getValue().getNetworkMagic()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class N2NVersionTableConstant {
public final static long PROTOCOL_V8 = 8;
public final static long PROTOCOL_V9 = 9;
public final static long PROTOCOL_V10 = 10;
public final static long PROTOCOL_V11 = 11;
public final static long PROTOCOL_V12 = 12;

public static VersionTable v4AndAbove(long networkMagic) {
N2NVersionData versionData = new N2NVersionData(networkMagic, false);
Expand All @@ -27,6 +29,8 @@ public static VersionTable v4AndAbove(long networkMagic) {
versionTableMap.put(PROTOCOL_V8, versionData);
versionTableMap.put(PROTOCOL_V9, versionData);
versionTableMap.put(PROTOCOL_V10, versionData);
versionTableMap.put(PROTOCOL_V11, versionData);
versionTableMap.put(PROTOCOL_V12, versionData);

return new VersionTable(versionTableMap);
}
Expand All @@ -40,6 +44,8 @@ public static VersionTable v6AndAbove(long networkMagic) {
versionTableMap.put(PROTOCOL_V8, versionData);
versionTableMap.put(PROTOCOL_V9, versionData);
versionTableMap.put(PROTOCOL_V10, versionData);
versionTableMap.put(PROTOCOL_V11, versionData);
versionTableMap.put(PROTOCOL_V12, versionData);

return new VersionTable(versionTableMap);
}
Expand All @@ -52,6 +58,8 @@ public static VersionTable v7AndAbove(long networkMagic) {
versionTableMap.put(PROTOCOL_V8, versionData);
versionTableMap.put(PROTOCOL_V9, versionData);
versionTableMap.put(PROTOCOL_V10, versionData);
versionTableMap.put(PROTOCOL_V11, versionData);
versionTableMap.put(PROTOCOL_V12, versionData);

return new VersionTable(versionTableMap);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.bloxbean.cardano.yaci.helper;

import com.bloxbean.cardano.yaci.core.common.Constants;
import com.bloxbean.cardano.yaci.core.model.Block;
import com.bloxbean.cardano.yaci.core.model.Era;
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.helper.listener.BlockChainDataListener;
import com.bloxbean.cardano.yaci.helper.model.Transaction;
import org.junit.jupiter.api.Test;

import java.util.List;

public class ConwayBlockSyncIT extends BaseTest{

@Test
void syncTest() throws Exception {
BlockSync blockSync = new BlockSync(Constants.SANCHONET_PUBLIC_RELAY_ADDR, Constants.SANCHONET_PUBLIC_RELAY_PORT, Constants.SANCHONET_PROTOCOL_MAGIC, Constants.WELL_KNOWN_SANCHONET_POINT);

blockSync.startSync(Point.ORIGIN, new BlockChainDataListener() {
public void onBlock(Era era, Block block, List<Transaction> transactions) {
System.out.println(block.getHeader().getHeaderBody().getBlockNumber());
System.out.println("# of transactions >> " + transactions.size());
}

@Override
public void onByronBlock(ByronMainBlock byronBlock) {
System.out.println("Byron block: " + byronBlock);
}

@Override
public void onByronEbBlock(ByronEbBlock byronEbBlock) {
System.out.println("Byron EB block: " + byronEbBlock);
}
});

while (true)
Thread.sleep(5000);
}
}

0 comments on commit 0ebc21e

Please sign in to comment.