Skip to content

Commit

Permalink
Merge branch 'release/1.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
onetechnical committed Jun 23, 2021
2 parents 26f0553 + d9085ed commit fa70f8e
Show file tree
Hide file tree
Showing 18 changed files with 431 additions and 56 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 1.7.0
- Implement dynamic opcode accounting, backward jumps, loops, callsub, retsub
- Implement ability to pool fees
- Update asset URL length to 96 bytes
- Implement ability to pay for extra pages
- Don't override values with lookupParams/suggestedParams

# 1.6.0
- Add static qualifiers to json creators for onCompletion enum serialization.
- Add static qualifiers to json creators for onCompletion enum serialization.
- Bump guava from 28.2-android to 29.0-android in /generator.
- Bump guava from 28.2-android to 29.0-android.
- Corrected Exception message for Keccak-256 hash function.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
unit:
mvn test -Dcucumber.filter.tags="@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.indexer.rekey or @unit.transactions or @unit.responses or @unit.applications or @unit.dryrun or @unit.tealsign or @unit.responses.messagepack or @unit.responses.231 or @unit.responses.messagepack.231"
mvn test -Dcucumber.filter.tags="@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.indexer.rekey or @unit.transactions or @unit.responses or @unit.applications or @unit.dryrun or @unit.tealsign or @unit.responses.messagepack or @unit.responses.231 or @unit.responses.messagepack.231 or @unit.feetest"

integration:
mvn test -Dcucumber.filter.tags="@algod or @assets or @auction or @kmd or @send or @template or @indexer or @rekey or @applications.verified or @applications or @compile or @dryrun or @indexer.applications or @applications.evaldelta or @indexer.231"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Maven:
<dependency>
<groupId>com.algorand</groupId>
<artifactId>algosdk</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<dependency>
<groupId>com.algorand</groupId>
<artifactId>algosdk</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
</dependency>

<!-- testing -->
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.algorand</groupId>
<artifactId>algosdk</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public class ApplicationCreateTransactionBuilder<T extends ApplicationCreateTransactionBuilder<T>> extends ApplicationUpdateTransactionBuilder<T> {
private StateSchema localStateSchema;
private StateSchema globalStateSchema;
private Long extraPages = 0L;

/**
* Initialize a {@link ApplicationCreateTransactionBuilder}.
Expand All @@ -24,6 +25,7 @@ public ApplicationCreateTransactionBuilder() {
protected void applyTo(Transaction txn) {
txn.localStateSchema = localStateSchema;
txn.globalStateSchema = globalStateSchema;
txn.extraPages = extraPages;

super.applyTo(txn);
}
Expand Down Expand Up @@ -71,4 +73,16 @@ public T globalStateSchema(StateSchema globalStateSchema) {
this.globalStateSchema = globalStateSchema;
return (T) this;
}

/**
* extraPages allows you to rent extra pages of memory for the application. Each page is 2048 bytes of shared
* memory between approval and clear state programs. extraPages parameter must be an integer between 0 and 3 inclusive.
*/
public T extraPages(Long extraPages) {
if (extraPages == null || extraPages < 0 || extraPages > 3) {
throw new IllegalArgumentException("extraPages must be an integer between 0 and 3 inclusive");
}
this.extraPages = extraPages;
return (T) this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,14 @@ public T assetName(String assetName) {
}

/**
* Set url. This value must be between 0 and 32 characters (inclusive).
* Set url. This value must be between 0 and 96 characters (inclusive).
* @param url The asset url.
* @return this builder.
*/
public T url(String url) {
if (url != null && url.length() > 96) {
throw new IllegalArgumentException("url length must be between 0 and 96 characters (inclusive).");
}
this.url = url;
return (T) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,31 @@ final public Transaction build() {
if(fee != null && flatFee != null) {
throw new IllegalArgumentException("Cannot set both fee and flatFee.");
}
if(fee == null && flatFee == null){
txn.fee = Account.MIN_TX_FEE_UALGOS;
return txn;
}
if(fee != null) {
try {
Account.setFeeByFeePerByte(txn, fee);
} catch (NoSuchAlgorithmException e) {
throw new UnsupportedOperationException(e);
}
if (txn.fee == null || txn.fee.equals(BigInteger.valueOf(0))) {
txn.fee = Account.MIN_TX_FEE_UALGOS;
}
}
if (flatFee != null) {
txn.fee = flatFee;
}
if (txn.fee == null || txn.fee == BigInteger.valueOf(0)) {
txn.fee = Account.MIN_TX_FEE_UALGOS;
}


return txn;
}

/**
* Query the V1 REST API with {@link AlgodApi} for Transaction Parameters:
* Initialize fee, genesisID, genesisHash, firstValid, lastValid using {@link TransactionParams}.
* Initialize fee, genesisID, genesisHash, firstValid, lastValid by querying algod if not already set.
* @param client The backend client connection.
* @return This builder.
* @throws ApiException When the client fails to retrieve {@link TransactionParams} from the backend.
Expand All @@ -101,22 +106,32 @@ public T lookupParams(AlgodApi client) throws ApiException {
}

/**
* Initialize fee, genesisID, genesisHash, firstValid and lastValid using {@link TransactionParams}.
* Initialize fee, genesisID, genesisHash, firstValid, lastValid using {@link TransactionParams} if not already set.
* @param params The suggested transaction parameters.
* @return This builder.
*/
public T suggestedParams(TransactionParams params) {
fee(params.getFee());
genesisID(params.getGenesisID());
genesisHash(params.getGenesishashb64());
firstValid(params.getLastRound());
lastValid(params.getLastRound().add(BigInteger.valueOf(1000L)));
if (this.fee == null) {
fee(params.getFee());
}
if (this.genesisID == null) {
genesisID(params.getGenesisID());
}
if (this.genesisHash == null) {
genesisHash(params.getGenesishashb64());
}
if (this.firstValid == null) {
firstValid(params.getLastRound());
}
if (this.lastValid == null) {
lastValid(params.getLastRound().add(BigInteger.valueOf(1000L)));
}
return (T) this;
}

/**
* Query the V2 REST API with {@link com.algorand.algosdk.v2.client.common.AlgodClient} for Transaction Parameters:
* Initialize fee, genesisID, genesisHash, firstValid, lastValid using {@link TransactionParametersResponse}.
* Initialize fee, genesisID, genesisHash, firstValid, lastValid using {@link TransactionParametersResponse} if not already set.
* @param client The backend client connection.
* @return This builder.
* @throws ApiException When the client fails to retrieve {@link TransactionParametersResponse} from the backend.
Expand Down Expand Up @@ -210,7 +225,9 @@ public T fee(Long fee) {
}

/**
* Set the flatFee. This value will be used for the transaction fee, or 1000, whichever is higher.
* Set the flatFee. This value will be used for the transaction fee.
* This fee may fall to zero but a group of N atomic transactions must
* still have a fee of at least N*MinTxnFee.
* This field cannot be combined with fee.
* @param flatFee The flatFee to use for the transaction.
* @return This builder.
Expand All @@ -221,7 +238,9 @@ public T flatFee(BigInteger flatFee) {
}

/**
* Set the flatFee. This value will be used for the transaction fee, or 1000, whichever is higher.
* Set the flatFee. This value will be used for the transaction fee.
* This fee may fall to zero but a group of N atomic transactions must
* still have a fee of at least N*MinTxnFee.
* This field cannot be combined with fee.
* @param flatFee The flatFee to use for the transaction.
* @return This builder.
Expand All @@ -233,7 +252,9 @@ public T flatFee(Integer flatFee) {
}

/**
* Set the flatFee. This value will be used for the transaction fee, or 1000, whichever is higher.
* Set the flatFee. This value will be used for the transaction fee.
* This fee may fall to zero but a group of N atomic transactions must
* still have a fee of at least N*MinTxnFee.
* This field cannot be combined with fee.
* @param flatFee The flatFee to use for the transaction.
* @return This builder.
Expand Down Expand Up @@ -516,4 +537,3 @@ public T groupB64(String group) {
return (T) this;
}
}

10 changes: 5 additions & 5 deletions src/main/java/com/algorand/algosdk/crypto/TEALProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public TEALProgram() {
@JsonCreator
public TEALProgram(byte[] program) {
if (program == null) return;
try {
Logic.readProgram(program, null);
} catch (Exception e) {
throw new RuntimeException(e);
}
// try {
// Logic.readProgram(program, null);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
this.program = Arrays.copyOf(program, program.length);
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/algorand/algosdk/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ public static ProgramData readProgram(byte[] program, List<byte[]> args) throws
}
pc += size;
}

if (cost > MAX_COST) {
throw new IllegalArgumentException("program too costly to run");
// costs calculated dynamically starting in v4
if (version < 4 && cost > MAX_COST) {
throw new IllegalArgumentException("program too costly for Teal version < 4. consider using v4.");
}

return new ProgramData(true, ints, bytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public AssetParams(
}

if(url != null) {
if (url.length() > 32) throw new RuntimeException("asset url cannot be greater than 32 characters");
if (url.length() > 96) throw new RuntimeException("url length must be between 0 and 96 characters (inclusive).");
this.url = url;
}

Expand Down
26 changes: 17 additions & 9 deletions src/main/java/com/algorand/algosdk/transaction/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Transaction implements Serializable {
@JsonProperty("snd")
public Address sender = new Address();
@JsonProperty("fee")
public BigInteger fee = Account.MIN_TX_FEE_UALGOS;
public BigInteger fee = BigInteger.ZERO;
@JsonProperty("fv")
public BigInteger firstValid = BigInteger.valueOf(0);
@JsonProperty("lv")
Expand Down Expand Up @@ -150,6 +150,9 @@ public class Transaction implements Serializable {
@JsonProperty("apsu")
public TEALProgram clearStateProgram = null;

@JsonProperty("apep")
public Long extraPages = 0L;

/**
* Create a payment transaction
* @param fromAddr source address
Expand Down Expand Up @@ -272,6 +275,7 @@ public static Transaction createPaymentTransaction(Address sender, BigInteger fe
null,
null,
null,
null,
null);
}

Expand Down Expand Up @@ -374,6 +378,7 @@ public static Transaction createKeyRegistrationTransaction(Address sender, BigIn
null,
null,
null,
null,
null);
}

Expand Down Expand Up @@ -496,6 +501,7 @@ public static Transaction createAssetCreateTransaction(Address sender, BigIntege
null,
null,
null,
null,
null);
}

Expand Down Expand Up @@ -645,7 +651,8 @@ private Transaction(@JsonProperty("type") Type type,
@JsonProperty("apgs") StateSchema globalStateSchema,
@JsonProperty("apid") Long applicationId,
@JsonProperty("apls") StateSchema localStateSchema,
@JsonProperty("apsu") byte[] clearStateProgram
@JsonProperty("apsu") byte[] clearStateProgram,
@JsonProperty("apep") Long extraPages
) throws IOException {
this(
type,
Expand Down Expand Up @@ -692,7 +699,8 @@ private Transaction(@JsonProperty("type") Type type,
globalStateSchema,
applicationId,
localStateSchema,
clearStateProgram == null ? null : new TEALProgram(clearStateProgram)
clearStateProgram == null ? null : new TEALProgram(clearStateProgram),
extraPages
);
}

Expand Down Expand Up @@ -747,7 +755,8 @@ public Transaction(
StateSchema globalStateSchema,
Long applicationId,
StateSchema localStateSchema,
TEALProgram clearStateProgram
TEALProgram clearStateProgram,
Long extraPages
) {
if (type != null) this.type = type;
if (sender != null) this.sender = sender;
Expand Down Expand Up @@ -788,13 +797,11 @@ public Transaction(
if (applicationId != null) this.applicationId = applicationId;
if (localStateSchema != null) this.localStateSchema = globalStateSchema;
if (clearStateProgram != null) this.clearStateProgram = clearStateProgram;
if (extraPages != null) this.extraPages = extraPages;
}

// Used by Jackson to determine "default" values.
public Transaction() {
// Override the default to 0 so that it will be serialized
this.fee = BigInteger.valueOf(0);
}
public Transaction() {}

/**
* Base constructor with flat fee for asset xfer/freeze/destroy transactions.
Expand Down Expand Up @@ -1280,7 +1287,8 @@ public boolean equals(Object o) {
assetFreezeID.equals(that.assetFreezeID) &&
freezeState == that.freezeState &&
rekeyTo.equals(that.rekeyTo) &&
Arrays.equals(lease, ((Transaction) o).lease);
Arrays.equals(lease, ((Transaction) o).lease) &&
extraPages.equals(that.extraPages);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/langspec.json

Large diffs are not rendered by default.

Loading

0 comments on commit fa70f8e

Please sign in to comment.