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

Boxes: Add support for Boxes #345

Merged
merged 24 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9c862c5
Run non-Cucumber unit tests during make test
michaeldiamant Jul 1, 2022
d5f71c0
Revert "Run non-Cucumber unit tests during make test"
michaeldiamant Jul 1, 2022
240df9e
Boxes: Support for Box array transaction field (#340)
michaeldiamant Jul 6, 2022
f181828
Boxes: Query algod Box by application ID and Box name (#343)
michaeldiamant Jul 6, 2022
c478da8
Boxes: Add convenience methods for encoding Box names (#346)
michaeldiamant Jul 12, 2022
5a9d077
Boxes: Support GetApplicationBoxes (#347)
michaeldiamant Jul 15, 2022
83fd3eb
Merge develop branch to boxes feature branch (#354)
algochoi Aug 11, 2022
c09d9af
Enhancement: Merge `develop` to `feature/box-storage` (#381)
ahangsu Sep 2, 2022
dae6532
Merge branch 'develop' into feature/box-storage
ahangsu Sep 2, 2022
8c4c723
Box support for Indexer endpoints (#356)
ahangsu Sep 6, 2022
7f6cef9
boxes integration algod test
ahangsu Sep 7, 2022
68fb393
Merge branch 'develop' into feature/box-storage
ahangsu Sep 7, 2022
62d5ed4
Enhancement: Boxes integration test (#385)
ahangsu Sep 15, 2022
5d8130c
remove unnecessary @applications tag
ahangsu Sep 20, 2022
15c2dfb
Remove boxReferences from public Transaction constructor (#399)
michaeldiamant Sep 23, 2022
b5425b7
Add boxReference to Transaction.equals (#400)
michaeldiamant Sep 23, 2022
d0f69df
Re-run code generator (#401)
michaeldiamant Sep 23, 2022
f4c4a86
Box storage changes (#398)
jasonpaulos Sep 23, 2022
89e1622
Rework MethodCallParams to be backwards compatible with Boxes (#408)
michaeldiamant Sep 28, 2022
24bd5b7
Merge in develop
michaeldiamant Oct 31, 2022
fde8156
Regenerate sources from upstream AVM branches
michaeldiamant Oct 31, 2022
9c44b5d
Merge pull request #418 from michaeldiamant/update_again
michaeldiamant Oct 31, 2022
3d824cd
Merge branch 'develop' into feature/box-storage
michaeldiamant Nov 1, 2022
e1156c0
Revert SDK_TESTING_BRANCH to master
michaeldiamant Nov 1, 2022
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
2 changes: 1 addition & 1 deletion .test-env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configs for testing repo download:
SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing"
SDK_TESTING_BRANCH="master"
SDK_TESTING_BRANCH="feature/box-storage"
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
michaeldiamant marked this conversation as resolved.
Show resolved Hide resolved
SDK_TESTING_HARNESS="test-harness"

INSTALL_ONLY=0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.algorand.algosdk.builder.transaction;

import com.algorand.algosdk.crypto.Address;
import com.algorand.algosdk.transaction.AppBoxReference;
import com.algorand.algosdk.transaction.Transaction;
import com.algorand.algosdk.util.Encoder;

Expand All @@ -15,6 +16,7 @@ public abstract class ApplicationBaseTransactionBuilder<T extends ApplicationBas
private List<Address> accounts;
private List<Long> foreignApps;
private List<Long> foreignAssets;
private List<AppBoxReference> appBoxReferences;
private Long applicationId;

/**
Expand All @@ -36,6 +38,7 @@ protected void applyTo(Transaction txn) {
if (accounts != null) txn.accounts = accounts;
if (foreignApps != null) txn.foreignApps = foreignApps;
if (foreignAssets != null) txn.foreignAssets = foreignAssets;
if (appBoxReferences != null) txn.boxReferences = convertBoxes(appBoxReferences, foreignApps, applicationId);
}

@Override
Expand Down Expand Up @@ -63,6 +66,7 @@ public T args(List<byte[]> args) {

/**
* ApplicationArgs lists some transaction-specific arguments accessible from application logic.
*
* @param args List of Base64 encoded strings.
*/
public T argsBase64Encoded(List<String> args) {
Expand Down Expand Up @@ -90,4 +94,17 @@ public T foreignAssets(List<Long> foreignAssets) {
this.foreignAssets = foreignAssets;
return (T) this;
}

private List<Transaction.BoxReference> convertBoxes(List<AppBoxReference> abrs, List<Long> foreignApps, Long curApp) {
ArrayList<Transaction.BoxReference> xs = new ArrayList<>();
for (AppBoxReference abr : abrs) {
xs.add(Transaction.BoxReference.fromAppBoxReference(abr, foreignApps, curApp));
}
return xs;
}

public T boxReferences(List<AppBoxReference> boxReferences) {
this.appBoxReferences = boxReferences;
return (T) this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import java.util.List;

import com.algorand.algosdk.crypto.Address;
import com.algorand.algosdk.transaction.AppBoxReference;

public interface ApplicationCallReferencesSetter<T extends ApplicationCallReferencesSetter<T>> {

/**
* ApplicationID is the application being interacted with, or 0 if creating a new application.
*/
Expand All @@ -27,4 +28,10 @@ public interface ApplicationCallReferencesSetter<T extends ApplicationCallRefere
* application. The access is read-only.
*/
public T foreignAssets(List<Long> foreignAssets);

/**
* BoxReferences lists the boxes whose state may be accessed during evaluation of this application call. The apps
* the boxes belong to must be present in ForeignApps.
*/
public T boxReferences(List<AppBoxReference> boxReferences);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.algorand.algosdk.abi.Method;
import com.algorand.algosdk.crypto.Address;
import com.algorand.algosdk.crypto.Digest;
import com.algorand.algosdk.crypto.TEALProgram;
import com.algorand.algosdk.logic.StateSchema;
import com.algorand.algosdk.transaction.AppBoxReference;
import com.algorand.algosdk.transaction.MethodCallParams;
import com.algorand.algosdk.transaction.Transaction;
import com.algorand.algosdk.transaction.TxnSigner;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -22,6 +25,7 @@ public class MethodCallTransactionBuilder<T extends MethodCallTransactionBuilder
protected List<Address> foreignAccounts = new ArrayList<>();
protected List<Long> foreignAssets = new ArrayList<>();
protected List<Long> foreignApps = new ArrayList<>();
protected List<AppBoxReference> boxReferences = new ArrayList<>();

protected TEALProgram approvalProgram, clearStateProgram;
protected StateSchema localStateSchema;
Expand Down Expand Up @@ -62,7 +66,7 @@ public T method(Method method) {

/**
* Specify arguments for the ABI method invocation.
*
* <p>
* This will reset the arguments list to what is passed in by the caller.
*/
public T methodArguments(List<Object> arguments) {
Expand All @@ -72,7 +76,7 @@ public T methodArguments(List<Object> arguments) {

/**
* Specify arguments for the ABI method invocation.
*
* <p>
* This will add the arguments passed in by the caller to the existing list of arguments.
*/
public T addMethodArguments(List<Object> arguments) {
Expand All @@ -82,7 +86,7 @@ public T addMethodArguments(List<Object> arguments) {

/**
* Specify arguments for the ABI method invocation.
*
* <p>
* This will add the argument passed in by the caller to the existing list of arguments.
*/
public T addMethodArgument(Object argument) {
Expand Down Expand Up @@ -125,6 +129,16 @@ public T foreignAssets(List<Long> foreignAssets) {
return (T) this;
}

@Override
public T boxReferences(List<AppBoxReference> boxReferences) {
if (boxReferences != null)
// duplicate box references can be meaningful, don't get rid of them
this.boxReferences = new ArrayList<>(boxReferences);
else
this.boxReferences.clear();
return (T) this;
}

@Override
public T approvalProgram(TEALProgram approvalProgram) {
this.approvalProgram = approvalProgram;
Expand Down Expand Up @@ -162,10 +176,34 @@ public T extraPages(Long extraPages) {
* Build a MethodCallParams object.
*/
public MethodCallParams build() {
return new MethodCallParams(
appID, method, methodArgs, sender, onCompletion, note, lease, genesisID, genesisHash,
return new MethodCallParamsFactory(appID, method, methodArgs, sender, onCompletion, note, lease, genesisID, genesisHash,
firstValid, lastValid, fee, flatFee, rekeyTo, signer, foreignAccounts, foreignAssets, foreignApps,
approvalProgram, clearStateProgram, globalStateSchema, localStateSchema, extraPages
);
boxReferences, approvalProgram, clearStateProgram, globalStateSchema, localStateSchema, extraPages);
}

/**
* MethodCallParamsFactory exists only as a way to facilitate construction of
* `MethodCallParams` instances via a protected constructor.
* <p>
* No extension or other modification is intended.
*/
private static class MethodCallParamsFactory extends MethodCallParams {

MethodCallParamsFactory(Long appID, Method method, List<Object> methodArgs, Address sender,
Transaction.OnCompletion onCompletion, byte[] note, byte[] lease, String genesisID, Digest genesisHash,
BigInteger firstValid, BigInteger lastValid, BigInteger fee, BigInteger flatFee,
Address rekeyTo, TxnSigner signer,
List<Address> fAccounts, List<Long> fAssets, List<Long> fApps, List<AppBoxReference> boxes,
TEALProgram approvalProgram, TEALProgram clearProgram,
StateSchema globalStateSchema, StateSchema localStateSchema, Long extraPages) {
super(appID, method, methodArgs, sender,
onCompletion, note, lease, genesisID, genesisHash,
firstValid, lastValid, fee, flatFee,
rekeyTo, signer,
fAccounts, fAssets, fApps, boxes,
approvalProgram, clearProgram,
globalStateSchema, localStateSchema, extraPages);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.algorand.algosdk.transaction;

import com.algorand.algosdk.util.BoxQueryEncoding;

import java.util.Arrays;
import java.util.Objects;

public class AppBoxReference {
// the app ID of the app this box belongs to. Instead of serializing this value,
// it's used to calculate the appIdx for AppBoxReference.
private final long appId;

// the name of the box unique to the app it belongs to
private final byte[] name;

public AppBoxReference(long appId, byte[] name) {
this.appId = appId;
this.name = Arrays.copyOf(name, name.length);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AppBoxReference that = (AppBoxReference) o;
return appId == that.appId && Arrays.equals(name, that.name);
}

@Override
public int hashCode() {
int result = Objects.hash(appId);
result = 31 * result + Arrays.hashCode(name);
return result;
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
}

public long getAppId() {
return appId;
}

public byte[] getName() {
return Arrays.copyOf(name, name.length);
}

@Override
public String toString() {
return "AppBoxReference{" +
"appID=" + appId +
", name=" + Arrays.toString(name) +
'}';
}

public String nameQueryEncoded() {
return BoxQueryEncoding.encodeBytes(name);
}
}
Loading