Skip to content

Commit

Permalink
Merge pull request #26 from bloxbean/sanchonet
Browse files Browse the repository at this point in the history
Add Conway era support (In Progress)
  • Loading branch information
satran004 committed Jan 15, 2024
2 parents 43122bd + f5561bc commit c85477f
Show file tree
Hide file tree
Showing 115 changed files with 3,788 additions and 64 deletions.
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'maven-publish'
id 'signing'
id 'org.unbroken-dome.test-sets' version("4.0.0")
id 'org.ajoberstar.grgit' version '5.2.0'
}

repositories {
Expand Down Expand Up @@ -90,6 +91,11 @@ if (isReleaseVersion && !project.hasProperty("skipSigning")) {
}
}

def commit_id=getCheckedOutGitCommitHash()
if (project.version.endsWith("-SNAPSHOT")) {
version = "${project.version}".replace("-SNAPSHOT", "-${commit_id}-SNAPSHOT")
}

subprojects {
apply plugin: 'java-library'
apply plugin: 'maven-publish'
Expand All @@ -104,6 +110,11 @@ subprojects {
//Jars are with yaci prefix
archivesBaseName = 'yaci-' + project.name

// def commit_id=getCheckedOutGitCommitHash()
if (project.version.endsWith("-SNAPSHOT")) {
version = "${project.version}".replace("-SNAPSHOT", "-${commit_id}-SNAPSHOT")
}

dependencies {
api libs.slf4j.api

Expand Down Expand Up @@ -218,3 +229,6 @@ subprojects {
}
}

def getCheckedOutGitCommitHash() {
grgit.head().abbreviatedId
}
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(20, "6a7d97aae2a65ca790fd14802808b7fce00a3362bd7b21c4ed4ccb4296783b98");

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.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 @@ -19,6 +19,8 @@ public static Era getEra(int value) {
return Era.Alonzo;
case 6:
return Era.Babbage;
case 7:
return Era.CONWAY;
default:
return null;
}
Expand Down
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
@@ -1,7 +1,7 @@
package com.bloxbean.cardano.yaci.core.common;

public enum TxBodyType {
ALONZO(4), BABBAGE(5);
ALONZO(4), BABBAGE(5), CONWAY(6);

public final int value;
TxBodyType(int value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class Amount {
private String policyId;
//utf-8 assetname
private String assetName;
private byte[] assetNameBytes;
private BigInteger quantity;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.bloxbean.cardano.yaci.core.model;

import co.nstant.in.cbor.model.Array;
import co.nstant.in.cbor.model.ByteString;
import co.nstant.in.cbor.model.DataItem;
import co.nstant.in.cbor.model.UnsignedInteger;
import com.bloxbean.cardano.client.crypto.Blake2bUtil;
import com.bloxbean.cardano.client.crypto.VerificationKey;
import com.bloxbean.cardano.yaci.core.exception.CborRuntimeException;
import com.bloxbean.cardano.yaci.core.model.certs.StakeCredType;
import com.bloxbean.cardano.yaci.core.util.CborSerializationUtil;
import com.bloxbean.cardano.yaci.core.util.HexUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;

import java.math.BigInteger;
import java.util.List;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class Credential {
private StakeCredType type;
private String hash;

private Credential(StakeCredType type, byte[] hashBytes) {
this.type = type;
if (hashBytes != null)
this.hash = HexUtil.encodeHexString(hashBytes);
else
this.hash = null;
}

public static Credential fromKey(VerificationKey vkey) {
Credential stakeCredential = fromKey(vkey.getBytes());
return stakeCredential;
}

public static Credential fromKey(byte[] key) {
byte[] keyHash = Blake2bUtil.blake2bHash224(key);
Credential stakeCredential = new Credential(StakeCredType.ADDR_KEYHASH, keyHash);
return stakeCredential;
}

public static Credential fromKeyHash(byte[] keyHash) {
Credential stakeCredential = new Credential(StakeCredType.ADDR_KEYHASH, keyHash);
return stakeCredential;
}

public static Credential fromScriptHash(byte[] scriptHash) {
Credential stakeCredential = new Credential(StakeCredType.SCRIPTHASH, scriptHash);
return stakeCredential;
}

public static Credential deserialize(Array stakeCredArray) {
List<DataItem> dataItemList = stakeCredArray.getDataItems();
if (dataItemList == null || dataItemList.size() != 2)
throw new CborRuntimeException("Credential deserialization failed. Invalid number of DataItem(s) : "
+ (dataItemList != null ? String.valueOf(dataItemList.size()) : null));

UnsignedInteger typeDI = (UnsignedInteger) dataItemList.get(0);
ByteString hashDI = (ByteString) dataItemList.get(1);

BigInteger typeBI = typeDI.getValue();
if (typeBI.intValue() == 0) {
return Credential.fromKeyHash(hashDI.getBytes());
} else if (typeBI.intValue() == 1) {
return Credential.fromScriptHash(hashDI.getBytes());
} else {
throw new CborRuntimeException("Credential deserialization failed. Invalid CredType : "
+ typeBI.intValue());
}
}

public Array serialize() {
Array array = new Array();
if (type == StakeCredType.ADDR_KEYHASH) {
array.add(new UnsignedInteger(0));
} else if (type == StakeCredType.SCRIPTHASH) {
array.add(new UnsignedInteger(1));
} else {
throw new CborRuntimeException("Invalid credential type : " + type);
}

array.add(new ByteString(HexUtil.decodeHexString(hash)));
return array;
}

@JsonIgnore
public String getCborHex() {
return HexUtil.encodeHexString(CborSerializationUtil.serialize(serialize()));
}

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

public enum CredentialType {
ADDR_KEYHASH, SCRIPTHASH
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
package com.bloxbean.cardano.yaci.core.model;

import co.nstant.in.cbor.CborException;
import co.nstant.in.cbor.model.DataItem;
import com.bloxbean.cardano.client.crypto.Blake2bUtil;
import com.bloxbean.cardano.client.exception.CborDeserializationException;
import com.bloxbean.cardano.client.plutus.spec.PlutusData;
import com.bloxbean.cardano.client.util.JsonUtil;
import com.bloxbean.cardano.yaci.core.util.CborSerializationUtil;
import com.bloxbean.cardano.yaci.core.util.HexUtil;
import lombok.*;

import java.util.Objects;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Builder
@Builder(toBuilder = true)
public class Datum {
private String hash;
private String cbor;
private String json;

public static Datum from(DataItem plutusDataDI)
throws CborDeserializationException, CborException {
PlutusData plutusData = PlutusData.deserialize(plutusDataDI);
if (Objects.isNull(plutusData)) {
return null;
}

var cbor = CborSerializationUtil.serialize(plutusDataDI, false);
var datumHash = HexUtil.encodeHexString(Blake2bUtil.blake2bHash256(cbor));
return Datum.builder()
.hash(datumHash)
.cbor(HexUtil.encodeHexString(cbor))
.json(JsonUtil.getPrettyJson(plutusData))
.build();
}

public static String cborToHash(byte[] cborByte) {
return HexUtil.encodeHexString(Blake2bUtil.blake2bHash256(cborByte));
}

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

import lombok.*;

import java.math.BigDecimal;

/**
* drep_voting_thresholds =
* [ unit_interval ; motion no confidence
* , unit_interval ; committee normal
* , unit_interval ; committee no confidence
* , unit_interval ; update constitution
* , unit_interval ; hard fork initiation
* , unit_interval ; PP network group
* , unit_interval ; PP economic group
* , unit_interval ; PP technical group
* , unit_interval ; PP governance group
* , unit_interval ; treasury withdrawal
* ]
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
public class DrepVoteThresholds {
private BigDecimal motionNoConfidence;
private BigDecimal committeeNormal;
private BigDecimal committeeNoConfidence;
private BigDecimal updateConstitution;
private BigDecimal hardForkInitiation;
private BigDecimal ppNetworkGroup;
private BigDecimal ppEconomicGroup;
private BigDecimal ppTechnicalGroup;
private BigDecimal ppGovernanceGroup;
private BigDecimal treasuryWithdrawal;
}
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
@@ -0,0 +1,25 @@
package com.bloxbean.cardano.yaci.core.model;

import lombok.*;

import java.math.BigDecimal;

/**
* pool_voting_thresholds =
* [ unit_interval ; motion no confidence
* , unit_interval ; committee normal
* , unit_interval ; committee no confidence
* , unit_interval ; hard fork initiation
* ]
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
public class PoolVotingThresholds {
private BigDecimal motionNoConfidence;
private BigDecimal committeeNormal;
private BigDecimal committeeNoConfidence;
private BigDecimal hardForkInitiation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public class ProtocolParamUpdate {
// private String coinsPerUtxoSize;
// @Deprecated
// private String coinsPerUtxoWord;

//Conway era fields
private PoolVotingThresholds poolVotingThresholds; //25
private DrepVoteThresholds dRepVoteThresholds; //26
private Integer minCommitteeSize; //27
private Integer committeeTermLimit; //28
private Integer governanceActionValidityPeriod; //29
private BigInteger governanceActionDeposit; //30
private BigInteger drepDeposit; //31
private Integer drepInactivityPeriod; //32
}
Loading

0 comments on commit c85477f

Please sign in to comment.