Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: #84 Add 'script' field in result class of local constitution query #85

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading