2
2
3
3
import com .algorand .algosdk .abi .Method ;
4
4
import com .algorand .algosdk .crypto .Address ;
5
+ import com .algorand .algosdk .crypto .Digest ;
5
6
import com .algorand .algosdk .crypto .TEALProgram ;
6
7
import com .algorand .algosdk .logic .StateSchema ;
8
+ import com .algorand .algosdk .transaction .AppBoxReference ;
7
9
import com .algorand .algosdk .transaction .MethodCallParams ;
8
10
import com .algorand .algosdk .transaction .Transaction ;
9
11
import com .algorand .algosdk .transaction .TxnSigner ;
10
12
13
+ import java .math .BigInteger ;
11
14
import java .util .ArrayList ;
12
15
import java .util .HashSet ;
13
16
import java .util .List ;
@@ -22,6 +25,7 @@ public class MethodCallTransactionBuilder<T extends MethodCallTransactionBuilder
22
25
protected List <Address > foreignAccounts = new ArrayList <>();
23
26
protected List <Long > foreignAssets = new ArrayList <>();
24
27
protected List <Long > foreignApps = new ArrayList <>();
28
+ protected List <AppBoxReference > boxReferences = new ArrayList <>();
25
29
26
30
protected TEALProgram approvalProgram , clearStateProgram ;
27
31
protected StateSchema localStateSchema ;
@@ -62,7 +66,7 @@ public T method(Method method) {
62
66
63
67
/**
64
68
* Specify arguments for the ABI method invocation.
65
- *
69
+ * <p>
66
70
* This will reset the arguments list to what is passed in by the caller.
67
71
*/
68
72
public T methodArguments (List <Object > arguments ) {
@@ -72,7 +76,7 @@ public T methodArguments(List<Object> arguments) {
72
76
73
77
/**
74
78
* Specify arguments for the ABI method invocation.
75
- *
79
+ * <p>
76
80
* This will add the arguments passed in by the caller to the existing list of arguments.
77
81
*/
78
82
public T addMethodArguments (List <Object > arguments ) {
@@ -82,7 +86,7 @@ public T addMethodArguments(List<Object> arguments) {
82
86
83
87
/**
84
88
* Specify arguments for the ABI method invocation.
85
- *
89
+ * <p>
86
90
* This will add the argument passed in by the caller to the existing list of arguments.
87
91
*/
88
92
public T addMethodArgument (Object argument ) {
@@ -125,6 +129,16 @@ public T foreignAssets(List<Long> foreignAssets) {
125
129
return (T ) this ;
126
130
}
127
131
132
+ @ Override
133
+ public T boxReferences (List <AppBoxReference > boxReferences ) {
134
+ if (boxReferences != null )
135
+ // duplicate box references can be meaningful, don't get rid of them
136
+ this .boxReferences = new ArrayList <>(boxReferences );
137
+ else
138
+ this .boxReferences .clear ();
139
+ return (T ) this ;
140
+ }
141
+
128
142
@ Override
129
143
public T approvalProgram (TEALProgram approvalProgram ) {
130
144
this .approvalProgram = approvalProgram ;
@@ -162,10 +176,34 @@ public T extraPages(Long extraPages) {
162
176
* Build a MethodCallParams object.
163
177
*/
164
178
public MethodCallParams build () {
165
- return new MethodCallParams (
166
- appID , method , methodArgs , sender , onCompletion , note , lease , genesisID , genesisHash ,
179
+ return new MethodCallParamsFactory (appID , method , methodArgs , sender , onCompletion , note , lease , genesisID , genesisHash ,
167
180
firstValid , lastValid , fee , flatFee , rekeyTo , signer , foreignAccounts , foreignAssets , foreignApps ,
168
- approvalProgram , clearStateProgram , globalStateSchema , localStateSchema , extraPages
169
- );
181
+ boxReferences , approvalProgram , clearStateProgram , globalStateSchema , localStateSchema , extraPages );
182
+ }
183
+
184
+ /**
185
+ * MethodCallParamsFactory exists only as a way to facilitate construction of
186
+ * `MethodCallParams` instances via a protected constructor.
187
+ * <p>
188
+ * No extension or other modification is intended.
189
+ */
190
+ private static class MethodCallParamsFactory extends MethodCallParams {
191
+
192
+ MethodCallParamsFactory (Long appID , Method method , List <Object > methodArgs , Address sender ,
193
+ Transaction .OnCompletion onCompletion , byte [] note , byte [] lease , String genesisID , Digest genesisHash ,
194
+ BigInteger firstValid , BigInteger lastValid , BigInteger fee , BigInteger flatFee ,
195
+ Address rekeyTo , TxnSigner signer ,
196
+ List <Address > fAccounts , List <Long > fAssets , List <Long > fApps , List <AppBoxReference > boxes ,
197
+ TEALProgram approvalProgram , TEALProgram clearProgram ,
198
+ StateSchema globalStateSchema , StateSchema localStateSchema , Long extraPages ) {
199
+ super (appID , method , methodArgs , sender ,
200
+ onCompletion , note , lease , genesisID , genesisHash ,
201
+ firstValid , lastValid , fee , flatFee ,
202
+ rekeyTo , signer ,
203
+ fAccounts , fAssets , fApps , boxes ,
204
+ approvalProgram , clearProgram ,
205
+ globalStateSchema , localStateSchema , extraPages );
206
+ }
207
+
170
208
}
171
209
}
0 commit comments