Skip to content

Commit

Permalink
Add Pair type support and serialization logic
Browse files Browse the repository at this point in the history
Added the Pair type to Type and JavaType enums. Updated BlueprintSchema, ConverterCodeGenerator, and ClassDefinitionGenerator to handle Pair serialization and deserialization. Introduced unit tests to verify Pair functionality.
  • Loading branch information
satran004 committed Oct 2, 2024
1 parent b573d4c commit 3218990
Show file tree
Hide file tree
Showing 21 changed files with 942 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.bloxbean.cardano.client.plutus.annotation.processor.it;

import com.bloxbean.cardano.client.plutus.annotation.Blueprint;

@Blueprint(fileInResources = "blueprint/basic_pair.json", packageName = "com.bloxbean.cardano.client.plutus.annotation.blueprint.basicpair")
public class BasicPair {
}
167 changes: 167 additions & 0 deletions annotation-processor/src/it/resources/blueprint/basic_pair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{
"preamble": {
"title": "satya/hello6",
"description": "Aiken contracts for project 'satya/hello6'",
"version": "0.0.0",
"plutusVersion": "v3",
"compiler": {
"name": "Aiken",
"version": "v1.1.3+3d77b5c"
},
"license": "Apache-2.0"
},
"validators": [
{
"title": "hello6.option_test.spend",
"datum": {
"title": "datum",
"schema": {
"$ref": "#/definitions/hello6~1Datum"
}
},
"redeemer": {
"title": "redeemer",
"schema": {
"$ref": "#/definitions/hello6~1Redeemer"
}
},
"compiledCode": "5901e201010032323232323225333002323232323253323300830013009375400426464646464a66601a6004601c6ea80204c8c8c8c8c8c94ccc058c0600084c8c94ccc054c0280044c8c94ccc068c0700085401058dd7180d000980b9baa00715333015300e001153330183017375400e2a0042c2c602a6ea80184c8cc020c0580104c8cc00400400c88c94ccc06800854ccc05cc030c060dd500689919299980c9807180d1baa001132533301a003100114a066e3cdd7180e980d9baa00148810548656c6c6f0016301c301a375402666e1cdd6980d980c9baa301b3019375401a90020b09919199119299980e180880089919299981098118010998090008a8020b1810800980f1baa0031533301c30150011533301f301e37540062a0042c2c60386ea8008c06c0084c00cc078010dd6980c800980d80118010011bad3014003163756602c002602c00464a666028602c602c002266ec0c054004c054c05800458dd6180a000980a001180900098079baa008162232533300f300400115333012301137540062a0042c2a66601e60100022a66602460226ea800c540085858c03cdd50011b8748000c038c03c008c034004c028dd50011b874800858c028c02c008c024004c024008c01c004c010dd50008a4c26cacae6955ceaab9e5573eae855d101",
"hash": "7d6957063c7c52d9de05a799a33996d36c98427f06c9cc51d2dc77c8"
},
{
"title": "hello6.option_test.else",
"compiledCode": "5901e201010032323232323225333002323232323253323300830013009375400426464646464a66601a6004601c6ea80204c8c8c8c8c8c94ccc058c0600084c8c94ccc054c0280044c8c94ccc068c0700085401058dd7180d000980b9baa00715333015300e001153330183017375400e2a0042c2c602a6ea80184c8cc020c0580104c8cc00400400c88c94ccc06800854ccc05cc030c060dd500689919299980c9807180d1baa001132533301a003100114a066e3cdd7180e980d9baa00148810548656c6c6f0016301c301a375402666e1cdd6980d980c9baa301b3019375401a90020b09919199119299980e180880089919299981098118010998090008a8020b1810800980f1baa0031533301c30150011533301f301e37540062a0042c2c60386ea8008c06c0084c00cc078010dd6980c800980d80118010011bad3014003163756602c002602c00464a666028602c602c002266ec0c054004c054c05800458dd6180a000980a001180900098079baa008162232533300f300400115333012301137540062a0042c2a66601e60100022a66602460226ea800c540085858c03cdd50011b8748000c038c03c008c034004c028dd50011b874800858c028c02c008c024004c024008c01c004c010dd50008a4c26cacae6955ceaab9e5573eae855d101",
"hash": "7d6957063c7c52d9de05a799a33996d36c98427f06c9cc51d2dc77c8"
}
],
"definitions": {
"ByteArray": {
"dataType": "bytes"
},
"Int": {
"dataType": "integer"
},
"List$Pair$Int_Option$hello6/Action": {
"dataType": "map",
"keys": {
"$ref": "#/definitions/Int"
},
"values": {
"$ref": "#/definitions/Option$hello6~1Action"
}
},
"Option$ByteArray": {
"title": "Option",
"anyOf": [
{
"title": "Some",
"description": "An optional value.",
"dataType": "constructor",
"index": 0,
"fields": [
{
"$ref": "#/definitions/ByteArray"
}
]
},
{
"title": "None",
"description": "Nothing.",
"dataType": "constructor",
"index": 1,
"fields": []
}
]
},
"Option$hello6/Action": {
"title": "Option",
"anyOf": [
{
"title": "Some",
"description": "An optional value.",
"dataType": "constructor",
"index": 0,
"fields": [
{
"$ref": "#/definitions/hello6~1Action"
}
]
},
{
"title": "None",
"description": "Nothing.",
"dataType": "constructor",
"index": 1,
"fields": []
}
]
},
"Pair$Int_hello6/Action": {
"title": "Pair",
"dataType": "#pair",
"left": {
"$ref": "#/definitions/Int"
},
"right": {
"$ref": "#/definitions/hello6~1Action"
}
},
"hello6/Action": {
"title": "Action",
"anyOf": [
{
"title": "Mint",
"dataType": "constructor",
"index": 0,
"fields": []
},
{
"title": "Burn",
"dataType": "constructor",
"index": 1,
"fields": []
}
]
},
"hello6/Datum": {
"title": "Datum",
"anyOf": [
{
"title": "Datum",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "count",
"$ref": "#/definitions/Int"
}
]
}
]
},
"hello6/Redeemer": {
"title": "Redeemer",
"anyOf": [
{
"title": "Redeemer",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "msg",
"$ref": "#/definitions/Option$ByteArray"
},
{
"title": "p",
"$ref": "#/definitions/Pair$Int_hello6~1Action"
},
{
"title": "l",
"$ref": "#/definitions/List$Pair$Int_Option$hello6~1Action"
}
]
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.bloxbean.cardano.client.plutus.annotation.processor.exception.NotSupportedException;
import com.bloxbean.cardano.client.plutus.annotation.processor.model.*;
import com.bloxbean.cardano.client.plutus.spec.PlutusData;
import com.bloxbean.cardano.client.plutus.blueprint.type.Pair;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
Expand Down Expand Up @@ -224,6 +225,17 @@ private FieldType detectFieldType(TypeName typeName, TypeMirror typeMirror) thro
fieldType.setType(Type.OPTIONAL);
fieldType.setJavaType(JavaType.OPTIONAL);
fieldType.getGenericTypes().add(detectFieldType(itemType, null));
} else if (typeName instanceof ParameterizedTypeName
&& ((ParameterizedTypeName) typeName).rawType.equals(ClassName.get(Pair.class))) {
ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName;
TypeName firstElementType = parameterizedTypeName.typeArguments.get(0);
TypeName secondElementType = parameterizedTypeName.typeArguments.get(1);

fieldType.setType(Type.PAIR);
fieldType.setJavaType(JavaType.PAIR);
fieldType.getGenericTypes().add(detectFieldType(firstElementType, null));
fieldType.getGenericTypes().add(detectFieldType(secondElementType, null));

} else {
if (isSupportedType(typeName, typeMirror)) {
fieldType.setType(Type.CONSTRUCTOR);
Expand Down
Loading

0 comments on commit 3218990

Please sign in to comment.