From d3efb78582e09a92f5ab29565e6a0bfd53c64146 Mon Sep 17 00:00:00 2001 From: Sotatek-HuyLe3a Date: Fri, 20 Sep 2024 16:48:55 +0700 Subject: [PATCH] chore: #84 Add 'script' field in result class of local constitution query --- .../localstate/queries/ConstitutionQuery.java | 21 ++++++++++++------- .../queries/ConstitutionQueryResult.java | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/bloxbean/cardano/yaci/core/protocol/localstate/queries/ConstitutionQuery.java b/core/src/main/java/com/bloxbean/cardano/yaci/core/protocol/localstate/queries/ConstitutionQuery.java index a83146c..2936dff 100644 --- a/core/src/main/java/com/bloxbean/cardano/yaci/core/protocol/localstate/queries/ConstitutionQuery.java +++ b/core/src/main/java/com/bloxbean/cardano/yaci/core/protocol/localstate/queries/ConstitutionQuery.java @@ -1,13 +1,12 @@ package com.bloxbean.cardano.yaci.core.protocol.localstate.queries; -import co.nstant.in.cbor.model.Array; -import co.nstant.in.cbor.model.DataItem; -import co.nstant.in.cbor.model.UnsignedInteger; +import co.nstant.in.cbor.model.*; import com.bloxbean.cardano.yaci.core.model.governance.Anchor; import com.bloxbean.cardano.yaci.core.model.serializers.governance.AnchorSerializer; import com.bloxbean.cardano.yaci.core.protocol.handshake.messages.AcceptVersion; import com.bloxbean.cardano.yaci.core.protocol.localstate.api.Era; import com.bloxbean.cardano.yaci.core.protocol.localstate.api.EraQuery; +import com.bloxbean.cardano.yaci.core.util.HexUtil; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NonNull; @@ -37,14 +36,20 @@ public DataItem serialize(AcceptVersion protocolVersion) { @Override public ConstitutionQueryResult deserializeResult(AcceptVersion protocolVersion, DataItem[] di) { - List dataItemList = ((Array)di[0]).getDataItems(); + List dataItemList = ((Array) di[0]).getDataItems(); - int type = ((UnsignedInteger)dataItemList.get(0)).getValue().intValue(); //4 + int type = ((UnsignedInteger) dataItemList.get(0)).getValue().intValue(); //4 - List resultDIList = ((Array)dataItemList.get(1)).getDataItems(); - var items = (Array)resultDIList.get(0); + List resultDIList = ((Array) dataItemList.get(1)).getDataItems(); + var items = (Array) resultDIList.get(0); Anchor anchor = AnchorSerializer.INSTANCE.deserializeDI(items.getDataItems().get(0)); - return new ConstitutionQueryResult(anchor); + String script = null; + + if (items.getDataItems().get(1).getMajorType() == MajorType.BYTE_STRING) { + script = HexUtil.encodeHexString(((ByteString) items.getDataItems().get(1)).getBytes()); + } + + return new ConstitutionQueryResult(anchor, script); } } diff --git a/core/src/main/java/com/bloxbean/cardano/yaci/core/protocol/localstate/queries/ConstitutionQueryResult.java b/core/src/main/java/com/bloxbean/cardano/yaci/core/protocol/localstate/queries/ConstitutionQueryResult.java index a338de9..4184c71 100644 --- a/core/src/main/java/com/bloxbean/cardano/yaci/core/protocol/localstate/queries/ConstitutionQueryResult.java +++ b/core/src/main/java/com/bloxbean/cardano/yaci/core/protocol/localstate/queries/ConstitutionQueryResult.java @@ -11,4 +11,5 @@ @ToString public class ConstitutionQueryResult implements QueryResult { private Anchor anchor; + private String script; }