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

deltas: Deltas apis #575

Merged
merged 6 commits into from
May 24, 2023
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
@@ -0,0 +1,64 @@
package com.algorand.algosdk.v2.client.algod;

import com.algorand.algosdk.v2.client.common.Client;
import com.algorand.algosdk.v2.client.common.HttpMethod;
import com.algorand.algosdk.v2.client.common.Query;
import com.algorand.algosdk.v2.client.common.QueryData;
import com.algorand.algosdk.v2.client.common.Response;
import com.algorand.algosdk.v2.client.model.LedgerStateDelta;


/**
* Get ledger deltas for a round.
* /v2/deltas/{round}
*/
public class GetLedgerStateDelta extends Query {

private Long round;

/**
* @param round The round for which the deltas are desired.
*/
public GetLedgerStateDelta(Client client, Long round) {
super(client, new HttpMethod("get"));
this.round = round;
}

/**
* Execute the query.
* @return the query response object.
* @throws Exception
*/
@Override
public Response<LedgerStateDelta> execute() throws Exception {
Response<LedgerStateDelta> resp = baseExecute();
resp.setValueType(LedgerStateDelta.class);
return resp;
}

/**
* Execute the query with custom headers, there must be an equal number of keys and values
* or else an error will be generated.
* @param headers an array of header keys
* @param values an array of header values
* @return the query response object.
* @throws Exception
*/
@Override
public Response<LedgerStateDelta> execute(String[] headers, String[] values) throws Exception {
Response<LedgerStateDelta> resp = baseExecute(headers, values);
resp.setValueType(LedgerStateDelta.class);
return resp;
}

protected QueryData getRequestString() {
if (this.round == null) {
throw new RuntimeException("round is not set. It is a required parameter.");
}
addPathSegment(String.valueOf("v2"));
addPathSegment(String.valueOf("deltas"));
addPathSegment(String.valueOf(round));

return qd;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.algorand.algosdk.v2.client.algod;

import com.algorand.algosdk.v2.client.common.Client;
import com.algorand.algosdk.v2.client.common.HttpMethod;
import com.algorand.algosdk.v2.client.common.Query;
import com.algorand.algosdk.v2.client.common.QueryData;
import com.algorand.algosdk.v2.client.common.Response;
import com.algorand.algosdk.v2.client.model.LedgerStateDelta;


/**
* Get a ledger delta for a given transaction group.
* /v2/deltas/txn/group/{id}
*/
public class GetLedgerStateDeltaForTransactionGroup extends Query {

private String id;

/**
* @param id A transaction ID, or transaction group ID
*/
public GetLedgerStateDeltaForTransactionGroup(Client client, String id) {
super(client, new HttpMethod("get"));
this.id = id;
}

/**
* Execute the query.
* @return the query response object.
* @throws Exception
*/
@Override
public Response<LedgerStateDelta> execute() throws Exception {
Response<LedgerStateDelta> resp = baseExecute();
resp.setValueType(LedgerStateDelta.class);
return resp;
}

/**
* Execute the query with custom headers, there must be an equal number of keys and values
* or else an error will be generated.
* @param headers an array of header keys
* @param values an array of header values
* @return the query response object.
* @throws Exception
*/
@Override
public Response<LedgerStateDelta> execute(String[] headers, String[] values) throws Exception {
Response<LedgerStateDelta> resp = baseExecute(headers, values);
resp.setValueType(LedgerStateDelta.class);
return resp;
}

protected QueryData getRequestString() {
if (this.id == null) {
throw new RuntimeException("id is not set. It is a required parameter.");
}
addPathSegment(String.valueOf("v2"));
addPathSegment(String.valueOf("deltas"));
addPathSegment(String.valueOf("txn"));
addPathSegment(String.valueOf("group"));
addPathSegment(String.valueOf(id));

return qd;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.algorand.algosdk.v2.client.algod;

import com.algorand.algosdk.v2.client.common.Client;
import com.algorand.algosdk.v2.client.common.HttpMethod;
import com.algorand.algosdk.v2.client.common.Query;
import com.algorand.algosdk.v2.client.common.QueryData;
import com.algorand.algosdk.v2.client.common.Response;
import com.algorand.algosdk.v2.client.model.TransactionGroupLedgerStateDeltasForRoundResponse;


/**
* Get ledger deltas for transaction groups in a given round.
* /v2/deltas/{round}/txn/group
*/
public class GetTransactionGroupLedgerStateDeltasForRound extends Query {

private Long round;

/**
* @param round The round for which the deltas are desired.
*/
public GetTransactionGroupLedgerStateDeltasForRound(Client client, Long round) {
super(client, new HttpMethod("get"));
this.round = round;
}

/**
* Execute the query.
* @return the query response object.
* @throws Exception
*/
@Override
public Response<TransactionGroupLedgerStateDeltasForRoundResponse> execute() throws Exception {
Response<TransactionGroupLedgerStateDeltasForRoundResponse> resp = baseExecute();
resp.setValueType(TransactionGroupLedgerStateDeltasForRoundResponse.class);
return resp;
}

/**
* Execute the query with custom headers, there must be an equal number of keys and values
* or else an error will be generated.
* @param headers an array of header keys
* @param values an array of header values
* @return the query response object.
* @throws Exception
*/
@Override
public Response<TransactionGroupLedgerStateDeltasForRoundResponse> execute(String[] headers, String[] values) throws Exception {
Response<TransactionGroupLedgerStateDeltasForRoundResponse> resp = baseExecute(headers, values);
resp.setValueType(TransactionGroupLedgerStateDeltasForRoundResponse.class);
return resp;
}

protected QueryData getRequestString() {
if (this.round == null) {
throw new RuntimeException("round is not set. It is a required parameter.");
}
addPathSegment(String.valueOf("v2"));
addPathSegment(String.valueOf("deltas"));
addPathSegment(String.valueOf(round));
addPathSegment(String.valueOf("txn"));
addPathSegment(String.valueOf("group"));

return qd;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import com.algorand.algosdk.v2.client.algod.TransactionParams;
import com.algorand.algosdk.v2.client.algod.GetPendingTransactions;
import com.algorand.algosdk.v2.client.algod.PendingTransactionInformation;
import com.algorand.algosdk.v2.client.algod.GetLedgerStateDelta;
import com.algorand.algosdk.v2.client.algod.GetTransactionGroupLedgerStateDeltasForRound;
import com.algorand.algosdk.v2.client.algod.GetLedgerStateDeltaForTransactionGroup;
import com.algorand.algosdk.v2.client.algod.GetStateProof;
import com.algorand.algosdk.v2.client.algod.GetLightBlockHeaderProof;
import com.algorand.algosdk.v2.client.algod.GetApplicationByID;
Expand Down Expand Up @@ -251,6 +254,30 @@ public PendingTransactionInformation PendingTransactionInformation(String txid)
return new PendingTransactionInformation((Client) this, txid);
}

/**
* Get ledger deltas for a round.
* /v2/deltas/{round}
*/
public GetLedgerStateDelta GetLedgerStateDelta(Long round) {
return new GetLedgerStateDelta((Client) this, round);
}

/**
* Get ledger deltas for transaction groups in a given round.
* /v2/deltas/{round}/txn/group
*/
public GetTransactionGroupLedgerStateDeltasForRound GetTransactionGroupLedgerStateDeltasForRound(Long round) {
return new GetTransactionGroupLedgerStateDeltasForRound((Client) this, round);
}

/**
* Get a ledger delta for a given transaction group.
* /v2/deltas/txn/group/{id}
*/
public GetLedgerStateDeltaForTransactionGroup GetLedgerStateDeltaForTransactionGroup(String id) {
return new GetLedgerStateDeltaForTransactionGroup((Client) this, id);
}

/**
* Get a state proof that covers a given round
* /v2/stateproofs/{round}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.algorand.algosdk.v2.client.model;

import java.util.HashMap;

/**
* Contains a ledger delta
*/
public class LedgerStateDelta extends HashMap<String,Object> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.algorand.algosdk.v2.client.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

import com.algorand.algosdk.v2.client.common.PathResponse;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Contains a ledger delta for a single transaction group
*/
public class LedgerStateDeltaForTransactionGroup extends PathResponse {

/**
* Ledger StateDelta object
*/
@JsonProperty("Delta")
public HashMap<String,Object> delta;

@JsonProperty("Ids")
public List<String> ids = new ArrayList<String>();

@Override
public boolean equals(Object o) {

if (this == o) return true;
if (o == null) return false;

LedgerStateDeltaForTransactionGroup other = (LedgerStateDeltaForTransactionGroup) o;
if (!Objects.deepEquals(this.delta, other.delta)) return false;
if (!Objects.deepEquals(this.ids, other.ids)) return false;

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public class SimulateRequest extends PathResponse {
@JsonProperty("allow-more-logging")
public Boolean allowMoreLogging;

/**
* Applies extra opcode budget during simulation for each transaction group.
*/
@JsonProperty("extra-opcode-budget")
public Long extraOpcodeBudget;

/**
* The transaction groups to simulate.
*/
Expand All @@ -40,6 +46,7 @@ public boolean equals(Object o) {
SimulateRequest other = (SimulateRequest) o;
if (!Objects.deepEquals(this.allowEmptySignatures, other.allowEmptySignatures)) return false;
if (!Objects.deepEquals(this.allowMoreLogging, other.allowMoreLogging)) return false;
if (!Objects.deepEquals(this.extraOpcodeBudget, other.extraOpcodeBudget)) return false;
if (!Objects.deepEquals(this.txnGroups, other.txnGroups)) return false;

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ public class SimulationEvalOverrides extends PathResponse {
@JsonProperty("allow-empty-signatures")
public Boolean allowEmptySignatures;

/**
* The extra opcode budget added to each transaction group during simulation
*/
@JsonProperty("extra-opcode-budget")
public Long extraOpcodeBudget;

/**
* The maximum log calls one can make during simulation
*/
@JsonProperty("max-log-calls")
public java.math.BigInteger maxLogCalls;
public Long maxLogCalls;

/**
* The maximum byte number to log during simulation
*/
@JsonProperty("max-log-size")
public java.math.BigInteger maxLogSize;
public Long maxLogSize;

@Override
public boolean equals(Object o) {
Expand All @@ -39,6 +45,7 @@ public boolean equals(Object o) {

SimulationEvalOverrides other = (SimulationEvalOverrides) o;
if (!Objects.deepEquals(this.allowEmptySignatures, other.allowEmptySignatures)) return false;
if (!Objects.deepEquals(this.extraOpcodeBudget, other.extraOpcodeBudget)) return false;
if (!Objects.deepEquals(this.maxLogCalls, other.maxLogCalls)) return false;
if (!Objects.deepEquals(this.maxLogSize, other.maxLogSize)) return false;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.algorand.algosdk.v2.client.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.algorand.algosdk.v2.client.common.PathResponse;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Response containing all ledger state deltas for transaction groups, with their
* associated Ids, in a single round.
*/
public class TransactionGroupLedgerStateDeltasForRoundResponse extends PathResponse {

@JsonProperty("Deltas")
public List<LedgerStateDeltaForTransactionGroup> deltas = new ArrayList<LedgerStateDeltaForTransactionGroup>();

@Override
public boolean equals(Object o) {

if (this == o) return true;
if (o == null) return false;

TransactionGroupLedgerStateDeltasForRoundResponse other = (TransactionGroupLedgerStateDeltasForRoundResponse) o;
if (!Objects.deepEquals(this.deltas, other.deltas)) return false;

return true;
}
}
15 changes: 15 additions & 0 deletions src/test/java/com/algorand/algosdk/unit/AlgodPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,19 @@ public void getBlockTimestampOffset() {
public void setBlockTimestampOffset(Long round) {
ps.q = algodClient.SetBlockTimeStampOffset(round);
}

@When("we make a GetLedgerStateDelta call against round {long}")
public void we_make_a_get_ledger_state_delta_call_against_round(Long round) {
ps.q = algodClient.GetLedgerStateDelta(round);
}

@When("we make a LedgerStateDeltaForTransactionGroupResponse call for ID {string}")
public void we_make_a_ledger_state_delta_for_transaction_group_response_call_for_id(String id) {
ps.q = algodClient.GetLedgerStateDeltaForTransactionGroup(id);
}

@When("we make a TransactionGroupLedgerStateDeltaForRoundResponse call for round {long}")
public void we_make_a_transaction_group_ledger_state_delta_for_round_response_call_for_round(Long round) {
ps.q = algodClient.GetTransactionGroupLedgerStateDeltasForRound(round);
}
}
Loading