Skip to content

Commit

Permalink
Merge branch 'release/1.12.0-beta-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
onetechnical committed Feb 15, 2022
2 parents 15ee9b9 + cd38327 commit 7d2f24a
Show file tree
Hide file tree
Showing 41 changed files with 902 additions and 800 deletions.
23 changes: 23 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2.1

workflows:
version: 2
test:
jobs:
- unit-test
- integration-test

jobs:
unit-test:
docker:
- image: adoptopenjdk/maven-openjdk11
steps:
- checkout
- run: mvn test
integration-test:
machine:
image: "ubuntu-2004:202104-01"
resource_class: medium
steps:
- checkout
- run: make docker-test
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.12.0-beta-1
- Add new key reg txn field (#266)
- C2C Feature and Testing (#290)
- Implement circle ci (#293)
- Update README.md (#297)
- Update langspec for teal6 (#298)

# 1.11.0
- Support Foreign objects as ABI arguments (#283)
- Upgrade `jackson` packages to resolve PRs on vulnerability (#281)
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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 or @unit.feetest or @unit.indexer.logs or @unit.abijson or @unit.atomic_transaction_composer or @unit.transactions.payment"
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.transactions.keyreg 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 or @unit.indexer.logs or @unit.abijson or @unit.atomic_transaction_composer or @unit.transactions.payment"

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 or @abi"
mvn test -Dcucumber.filter.tags="@algod or @assets or @auction or @kmd or @send or @send.keyregtxn or @indexer or @rekey or @applications.verified or @applications or @compile or @dryrun or @indexer.applications or @indexer.231 or @abi or @c2c"

docker-test:
./run_integration_tests.sh
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@

| IMPORTANT <br /> Version 1.1.6 modifies one of the mnemonic words. Please let your users know that if they have the word "setupIfNeeded" in their passphrase, they should change it to "setup". Everything else remains the same.|
|---|

# java-algorand-sdk

[![Build Status](https://travis-ci.com/algorand/java-algorand-sdk.svg?branch=master)](https://travis-ci.com/algorand/java-algorand-sdk?branch=master)
Expand All @@ -23,7 +19,7 @@ Maven:
<dependency>
<groupId>com.algorand</groupId>
<artifactId>algosdk</artifactId>
<version>1.11.0</version>
<version>1.12.0-beta-1</version>
</dependency>
```

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.11.0</version>
<version>1.12.0-beta-1</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/com/algorand/algosdk/abi/ABIType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.algorand.algosdk.abi;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
Expand Down Expand Up @@ -161,27 +160,6 @@ else if (currentIndex != 0 && delta < 0)
return until;
}

/**
* Given an array/list-like object, infer an array of objects
* @param val an array/list-like object
* @return inferred array of objects
* @throws IllegalArgumentException if it cannot infer if the object is list or array
*/
protected static Object[] unifyToArrayOfObjects(Object val) {
if (val.getClass().isArray()) {
if (val instanceof Object[])
return (Object[]) val;
int length = Array.getLength(val);
Object[] outputArray = new Object[length];
for (int i = 0; i < length; ++i)
outputArray[i] = Array.get(val, i);
return outputArray;
} else if (val instanceof List<?>)
return ((List<?>) val).toArray(new Object[0]);
else
throw new IllegalArgumentException("cannot infer type for unify array/list-like object to object array");
}

/**
* Take the first 2 bytes in the byte array
* (consider the byte array to be an encoding for ABI dynamic typed value)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/algorand/algosdk/abi/TypeArrayDynamic.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.algorand.algosdk.abi;

import com.algorand.algosdk.util.Encoder;
import com.algorand.algosdk.util.GenericObjToArray;

import java.math.BigInteger;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -30,7 +31,7 @@ public boolean equals(Object o) {

@Override
public byte[] encode(Object o) {
Object[] objArray = ABIType.unifyToArrayOfObjects(o);
Object[] objArray = GenericObjToArray.unifyToArrayOfObjects(o);

byte[] castedEncode = ABIType.castToTupleType(objArray.length, this.elemType).encode(objArray);
byte[] lengthEncode = Encoder.encodeUintToBytes(BigInteger.valueOf(objArray.length), ABI_DYNAMIC_HEAD_BYTE_LEN);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/algorand/algosdk/abi/TypeArrayStatic.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.algorand.algosdk.abi;

import com.algorand.algosdk.util.GenericObjToArray;

public class TypeArrayStatic extends ABIType {
public final ABIType elemType;
public final int length;
Expand Down Expand Up @@ -29,7 +31,7 @@ public boolean equals(Object o) {

@Override
public byte[] encode(Object o) {
Object[] objArray = ABIType.unifyToArrayOfObjects(o);
Object[] objArray = GenericObjToArray.unifyToArrayOfObjects(o);
if (objArray.length != this.length)
throw new IllegalArgumentException("cannot encode abi static array: length of value != length in array type");
return ABIType.castToTupleType(this.length, this.elemType).encode(objArray);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/algorand/algosdk/abi/TypeTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.algorand.algosdk.algod.client.StringUtil;
import com.algorand.algosdk.util.Encoder;
import com.algorand.algosdk.util.GenericObjToArray;

import java.math.BigInteger;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -42,7 +43,7 @@ public boolean equals(Object o) {

@Override
public byte[] encode(Object o) {
Object[] tupleValues = ABIType.unifyToArrayOfObjects(o);
Object[] tupleValues = GenericObjToArray.unifyToArrayOfObjects(o);

if (tupleValues.length != this.childTypes.size())
throw new IllegalArgumentException("abi tuple child type size != abi tuple element value size");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.algorand.algosdk.builder.transaction;

import com.algorand.algosdk.crypto.MerkleVerifier;
import com.algorand.algosdk.crypto.ParticipationPublicKey;
import com.algorand.algosdk.crypto.VRFPublicKey;
import com.algorand.algosdk.transaction.Transaction;
Expand All @@ -15,11 +16,13 @@
* genesisHash
*
* Optional parameters:
* nonparticipation
* votePK
* selectionPK
* voteFirst
* voteLast
* voteKeyDilution
* stateProofKey
*
* Optional global parameters:
* fee/flatFee
Expand All @@ -30,6 +33,8 @@
*/
@SuppressWarnings("unchecked")
public class KeyRegistrationTransactionBuilder<T extends KeyRegistrationTransactionBuilder<T>> extends TransactionBuilder<T> {
// nonparticipation is an indicator for marking a key registration txn nonparticipating/participating
protected boolean nonparticipation = false;
// votePK is the participation public key used in key registration transactions
protected ParticipationPublicKey votePK = new ParticipationPublicKey();
// selectionPK is the VRF private key used in key registration transactions
Expand All @@ -40,6 +45,8 @@ public class KeyRegistrationTransactionBuilder<T extends KeyRegistrationTransact
protected BigInteger voteLast = BigInteger.valueOf(0);
// voteKeyDilution
protected BigInteger voteKeyDilution = BigInteger.valueOf(0);
// stateProofKey
protected MerkleVerifier stateProofPk = new MerkleVerifier();

/**
* Initialize a {@link KeyRegistrationTransactionBuilder}.
Expand All @@ -64,6 +71,8 @@ protected void applyTo(Transaction txn) {
if (voteFirst != null) txn.voteFirst = voteFirst;
if (voteLast != null) txn.voteLast = voteLast;
if (voteKeyDilution != null) txn.voteKeyDilution = voteKeyDilution;
if (stateProofPk != null) txn.stateProofKey = stateProofPk;
txn.nonpart = nonparticipation;
}

/**
Expand Down Expand Up @@ -94,6 +103,7 @@ public T participationPublicKey(byte[] pk) {
public T participationPublicKeyBase64(String pk) {
this.votePK = new ParticipationPublicKey(Encoder.decodeFromBase64(pk));
return (T) this;

}

/**
Expand Down Expand Up @@ -221,4 +231,45 @@ public T voteKeyDilution(Long voteKeyDilution) {
this.voteKeyDilution = BigInteger.valueOf(voteKeyDilution);
return (T) this;
}

/**
* Set the stateProofKey value. This is used to identify a state proof
* @param stprf The stateProofKey value.
* @return This builder.
*/
public T stateProofKey(MerkleVerifier stprf) {
stateProofPk = stprf;
return (T) this;
}

/**
* Set the stateProofKey value. This is used to identify a state proof
* @param stprf The stateProofKey value.
* @return This builder.
*/
public T stateProofKey(byte[] stprf) {
stateProofPk = new MerkleVerifier(stprf);
return (T) this;
}

/**
* Set the stateProofKey value. This is used to identify a state proof
* @param stprf The stateProofKey value.
* @return This builder.
*/
public T stateProofKeyBase64(String stprf) {
stateProofPk = new MerkleVerifier(Encoder.decodeFromBase64(stprf));
return (T) this;
}

/**
* Set the nonparticipation value. This is used to mark a key registration transaction participating/nonparticipating
* @param nonpart The nonparticipation mark.
* @return This builder.
*/
public T nonparticipation(boolean nonpart) {
this.nonparticipation = nonpart;
return (T) this;
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/algorand/algosdk/crypto/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Address implements Serializable {
// prefix for signing bytes
private static final byte[] BYTES_SIGN_PREFIX = ("MX").getBytes(StandardCharsets.UTF_8);
// prefix for hashing application ID
private static final byte[] APP_ID_PREFIX = ("appID").getBytes(StandardCharsets.UTF_8);
public static final byte[] APP_ID_PREFIX = ("appID").getBytes(StandardCharsets.UTF_8);


/**
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/algorand/algosdk/crypto/MerkleVerifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.algorand.algosdk.crypto;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;

import java.io.Serializable;
import java.util.Arrays;

/**
* A serializable representation of a state proof key.
*/
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class MerkleVerifier implements Serializable {
private static final int KEY_LEN_BYTES = 64;
/**
* The raw bytes.
*/
private byte[] bytes = new byte[KEY_LEN_BYTES];

@JsonCreator
public MerkleVerifier(byte[] bytes) {
if (bytes == null) {
return;
}
if (bytes.length != KEY_LEN_BYTES ) {
throw new IllegalArgumentException("state proof key wrong length");
}
System.arraycopy(bytes, 0, this.bytes, 0, KEY_LEN_BYTES);
}
// default values for serializer to ignore
public MerkleVerifier() {
}

@JsonValue
public byte[] getBytes() {
return this.bytes;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof MerkleVerifier && Arrays.equals(this.bytes, ((MerkleVerifier)obj).bytes)) {
return true;
}
return false;
}
}
Loading

0 comments on commit 7d2f24a

Please sign in to comment.