Skip to content

Commit

Permalink
feat: #17 Governance CDDL object and new certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Sep 26, 2023
1 parent ee17522 commit 818c704
Show file tree
Hide file tree
Showing 59 changed files with 1,434 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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 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();
Expand Down
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("StakeCredential 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("StakeCredential deserialization failed. Invalid StakeCredType : "
+ 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 stake 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,7 +1,8 @@
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 com.bloxbean.cardano.yaci.core.model.governance.ProposalProcedure;
import com.bloxbean.cardano.yaci.core.model.governance.VotingProcedures;
import lombok.*;

import java.math.BigInteger;
Expand Down Expand Up @@ -44,6 +45,9 @@ public class TransactionBody {
private BigInteger totalCollateral;
private Set<TransactionInput> referenceInputs;

//conway
//Conway
private VotingProcedures votingProcedures;
private List<ProposalProcedure> proposalProcedures;
private BigInteger currentTreasuryValue;
private BigInteger donation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ public class Witnesses {
private List<Redeemer> redeemers = new ArrayList<>();

private List<PlutusScript> plutusV2Scripts = new ArrayList<>();
private List<PlutusScript> plutusV3Scripts = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bloxbean.cardano.yaci.core.model.certs;

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

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class AuthCommitteeHotCert implements Certificate {
private final CertificateType type = CertificateType.AUTH_COMMITTEE_HOT_CERT;

private Credential committeeColdCredential;
private Credential committeeHotCredential;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
package com.bloxbean.cardano.yaci.core.model.certs;

public enum CertificateType {
STAKE_REGISTRATION, STAKE_DEREGISTRATION, STAKE_DELEGATION, POOL_REGISTRATION, POOL_RETIREMENT, GENESIS_KEY_DELEGATION,
MOVE_INSTATENEOUS_REWARDS_CERT
STAKE_REGISTRATION,
STAKE_DEREGISTRATION,
STAKE_DELEGATION,
POOL_REGISTRATION,
POOL_RETIREMENT,
GENESIS_KEY_DELEGATION,
MOVE_INSTATENEOUS_REWARDS_CERT,

//conway
//Delegation certs
REG_CERT,
UNREG_CERT,
VOTE_DELEG_CERT,
STAKE_VOTE_DELEG_CERT,
STAKE_REG_DELEG_CERT,
VOTE_REG_DELEG_CERT,
STAKE_VOTE_REG_DELEG_CERT,

//Gov certs
AUTH_COMMITTEE_HOT_CERT,
RESIGN_COMMITTEE_COLD_CERT,
REG_DREP_CERT,
UNREG_DREP_CERT,
UPDATE_DREP_CERT
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.bloxbean.cardano.yaci.core.model.certs;

import lombok.*;

import java.math.BigInteger;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class RegCert implements Certificate {
private final CertificateType type = CertificateType.REG_CERT;

private StakeCredential stakeCredential;
private BigInteger coin;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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.*;

import java.math.BigInteger;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class RegDrepCert implements Certificate {
private final CertificateType type = CertificateType.REG_DREP_CERT;

private Credential drepCredential;
private BigInteger coin;
private Anchor anchor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bloxbean.cardano.yaci.core.model.certs;

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

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class ResignCommitteeColdCert implements Certificate {
private final CertificateType type = CertificateType.RESIGN_COMMITTEE_COLD_CERT;

private Credential committeeColdCredential;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bloxbean.cardano.yaci.core.model.certs;

import lombok.*;

import java.math.BigInteger;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class StakeRegDelegCert implements Certificate {
private final CertificateType type = CertificateType.STAKE_REG_DELEG_CERT;

private StakeCredential stakeCredential;
private String poolKeyHash;
private BigInteger coin;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.bloxbean.cardano.yaci.core.model.certs;

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

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class StakeVoteDelegCert implements Certificate {
private final CertificateType type = CertificateType.STAKE_VOTE_DELEG_CERT;

private StakeCredential stakeCredential;
private String poolKeyHash;
private Drep drep;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.bloxbean.cardano.yaci.core.model.certs;

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

import java.math.BigInteger;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class StakeVoteRegDelegCert implements Certificate {
private final CertificateType type = CertificateType.STAKE_VOTE_REG_DELEG_CERT;

private StakeCredential stakeCredential;
private String poolKeyHash;
private Drep drep;
private BigInteger coin;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.bloxbean.cardano.yaci.core.model.certs;

import lombok.*;

import java.math.BigInteger;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class UnregCert implements Certificate {
private final CertificateType type = CertificateType.UNREG_CERT;

private StakeCredential stakeCredential;
private BigInteger coin;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bloxbean.cardano.yaci.core.model.certs;

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

import java.math.BigInteger;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class UnregDrepCert implements Certificate {
private final CertificateType type = CertificateType.UNREG_DREP_CERT;

private Credential drepCredential;
private BigInteger coin;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class UpdateDrepCert implements Certificate {
private final CertificateType type = CertificateType.UPDATE_DREP_CERT;

private Credential drepCredential;
private Anchor anchor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bloxbean.cardano.yaci.core.model.certs;

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

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public class VoteDelegCert implements Certificate {
private final CertificateType type = CertificateType.VOTE_DELEG_CERT;

private StakeCredential stakeCredential;
private Drep drep;
}
Loading

0 comments on commit 818c704

Please sign in to comment.