-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from bloxbean/sanchonet
Add Conway era support (In Progress)
- Loading branch information
Showing
115 changed files
with
3,788 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core/src/main/java/com/bloxbean/cardano/yaci/core/common/TxBodyType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
core/src/main/java/com/bloxbean/cardano/yaci/core/model/Credential.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
core/src/main/java/com/bloxbean/cardano/yaci/core/model/CredentialType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
34 changes: 33 additions & 1 deletion
34
core/src/main/java/com/bloxbean/cardano/yaci/core/model/Datum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
core/src/main/java/com/bloxbean/cardano/yaci/core/model/DrepVoteThresholds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
core/src/main/java/com/bloxbean/cardano/yaci/core/model/PoolVotingThresholds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.