Skip to content

Commit

Permalink
chore: rename ConstitutionResult to ConstitutionQueryResult, GovState…
Browse files Browse the repository at this point in the history
…Result to GovStateQueryResult
  • Loading branch information
Sotatek-HuyLe3a committed Aug 27, 2024
1 parent 2a13fb2 commit cac8e6f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@AllArgsConstructor
@ToString
// ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs
public class ConstitutionQuery implements EraQuery<ConstitutionResult> {
public class ConstitutionQuery implements EraQuery<ConstitutionQueryResult> {
@NonNull
private Era era;

Expand All @@ -36,7 +36,7 @@ public DataItem serialize(AcceptVersion protocolVersion) {
}

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

int type = ((UnsignedInteger)dataItemList.get(0)).getValue().intValue(); //4
Expand All @@ -45,6 +45,6 @@ public ConstitutionResult deserializeResult(AcceptVersion protocolVersion, DataI
var items = (Array)resultDIList.get(0);

Anchor anchor = AnchorSerializer.INSTANCE.deserializeDI(items.getDataItems().get(0));
return new ConstitutionResult(anchor);
return new ConstitutionQueryResult(anchor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
@Getter
@AllArgsConstructor
@ToString
public class ConstitutionResult implements QueryResult {
public class ConstitutionQueryResult implements QueryResult {
private Anchor anchor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@Getter
@AllArgsConstructor
@ToString
public class GovStateQuery implements EraQuery<GovStateResult> {
public class GovStateQuery implements EraQuery<GovStateQueryResult> {
private Era era;

public GovStateQuery() {
Expand All @@ -51,37 +51,37 @@ public DataItem serialize(AcceptVersion protocolVersion) {
}

@Override
public GovStateResult deserializeResult(AcceptVersion protocolVersion, DataItem[] di) {
GovStateResult govStateResult = new GovStateResult();
public GovStateQueryResult deserializeResult(AcceptVersion protocolVersion, DataItem[] di) {
GovStateQueryResult govStateQueryResult = new GovStateQueryResult();
Array array = (Array) di[0];
Array resultArray = (Array) ((Array) array.getDataItems().get(1)).getDataItems().get(0);

// committee
Array committeeResult = (Array) resultArray.getDataItems().get(1);
Array committeeDI = (Array) committeeResult.getDataItems().get(0);
Committee committee = deserializeCommitteeResult(committeeDI.getDataItems());
govStateResult.setCommittee(committee);
govStateQueryResult.setCommittee(committee);

// constitution
Array constitutionArr = (Array) resultArray.getDataItems().get(2);
var constitutionDI = constitutionArr.getDataItems().get(0);

Constitution constitution = deserializeConstitutionResult(constitutionDI);
govStateResult.setConstitution(constitution);
govStateQueryResult.setConstitution(constitution);

// current protocol params
Array currentPParams = (Array) resultArray.getDataItems().get(3);
List<DataItem> paramsDIList = currentPParams.getDataItems();

ProtocolParamUpdate currentProtocolParam = deserializePPResult(paramsDIList);

govStateResult.setCurrentPParams(currentProtocolParam);
govStateQueryResult.setCurrentPParams(currentProtocolParam);

Array futurePParams = (Array) resultArray.getDataItems().get(5);
if (!futurePParams.getDataItems().isEmpty() && futurePParams.getDataItems().size() > 1) {
List<DataItem> futureParamsDIList = ((Array)futurePParams.getDataItems().get(1)).getDataItems();
ProtocolParamUpdate futureProtocolParam = deserializePPResult(futureParamsDIList);
govStateResult.setFuturePParams(futureProtocolParam);
govStateQueryResult.setFuturePParams(futureProtocolParam);
}

// next ratify state
Expand Down Expand Up @@ -163,14 +163,14 @@ public GovStateResult deserializeResult(AcceptVersion protocolVersion, DataItem[
.expiredGovActions(expiredGovActions)
.build();

govStateResult.setNextRatifyState(nextRatifyState);
govStateQueryResult.setNextRatifyState(nextRatifyState);

// previous protocol params
Array prevPParams = (Array) resultArray.getDataItems().get(4);
paramsDIList = prevPParams.getDataItems();
ProtocolParamUpdate prevProtocolParam = deserializePPResult(paramsDIList);

govStateResult.setPreviousPParams(prevProtocolParam);
govStateQueryResult.setPreviousPParams(prevProtocolParam);

// proposals
Array proposalArr = (Array)((Array) resultArray.getDataItems().get(0)).getDataItems().get(1);
Expand All @@ -184,9 +184,9 @@ public GovStateResult deserializeResult(AcceptVersion protocolVersion, DataItem[
proposals.add(proposal);
}

govStateResult.setProposals(proposals);
govStateQueryResult.setProposals(proposals);

return govStateResult;
return govStateQueryResult;
}

public ProtocolParamUpdate deserializePPResult(List<DataItem> paramsDIList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Getter
@Setter
@ToString
public class GovStateResult implements QueryResult {
public class GovStateQueryResult implements QueryResult {
private Committee committee;
private Constitution constitution;
private ProtocolParamUpdate currentPParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,20 @@ void dRepStakeDistributionQuery() {

@Test
void govStateQuery() {
Mono<GovStateResult> mono = localStateQueryClient.executeQuery(new GovStateQuery(Era.Conway));
Mono<GovStateQueryResult> mono = localStateQueryClient.executeQuery(new GovStateQuery(Era.Conway));
mono = mono.log();

GovStateResult result = mono.block(Duration.ofSeconds(10));
GovStateQueryResult result = mono.block(Duration.ofSeconds(10));
assertThat(result.getCommittee()).isNotNull();
assertThat(result.getCurrentPParams()).isNotNull();
}

@Test
void constitutionQuery() {
Mono<ConstitutionResult> mono = localStateQueryClient.executeQuery(new ConstitutionQuery(Era.Conway));
Mono<ConstitutionQueryResult> mono = localStateQueryClient.executeQuery(new ConstitutionQuery(Era.Conway));
mono = mono.log();

ConstitutionResult result = mono.block(Duration.ofSeconds(5));
ConstitutionQueryResult result = mono.block(Duration.ofSeconds(5));
assertThat(result).isNotNull();
}

Expand Down

0 comments on commit cac8e6f

Please sign in to comment.