Skip to content

Commit

Permalink
chore: #84 Add 'script' field in result class of local constitution q…
Browse files Browse the repository at this point in the history
…uery
  • Loading branch information
Sotatek-HuyLe3a committed Sep 20, 2024
1 parent 8d1a62b commit d3efb78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,14 +36,20 @@ public DataItem serialize(AcceptVersion protocolVersion) {

@Override
public ConstitutionQueryResult deserializeResult(AcceptVersion protocolVersion, DataItem[] di) {
List<DataItem> dataItemList = ((Array)di[0]).getDataItems();
List<DataItem> dataItemList = ((Array) di[0]).getDataItems();

int type = ((UnsignedInteger)dataItemList.get(0)).getValue().intValue(); //4
int type = ((UnsignedInteger) dataItemList.get(0)).getValue().intValue(); //4

List<DataItem> resultDIList = ((Array)dataItemList.get(1)).getDataItems();
var items = (Array)resultDIList.get(0);
List<DataItem> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
@ToString
public class ConstitutionQueryResult implements QueryResult {
private Anchor anchor;
private String script;
}

0 comments on commit d3efb78

Please sign in to comment.