1
+ import Model .*;
1
2
import com .eclipsesource .v8 .*;
2
3
import com .eclipsesource .v8 .utils .V8ObjectUtils ;
3
- import com .sun .org .apache .xpath .internal .operations .Mult ;
4
4
5
5
6
6
import java .io .IOException ;
@@ -111,20 +111,13 @@ public static CreateTransactionHelperObject updateLeafToRoot(MultisigAddress roo
111
111
* @return
112
112
*/
113
113
public static ArrayList <Transaction > prepare (ArrayList <String > settlementAddresses , ArrayList <Integer > deposits , int index , ArrayList <Transfer > transfers ) {
114
- V8Array settlementAddressesJS = V8ObjectUtils .toV8Array (engine , settlementAddresses );
115
- V8Array depositJS = V8ObjectUtils .toV8Array (engine , deposits );
116
- List <Object > transferObj = new ArrayList <Object >();
117
- for (Transfer t : transfers ) {
118
- transferObj .add (t .toMap ());
119
- }
120
- V8Array transferJS = V8ObjectUtils .toV8Array (engine , transferObj );
121
114
122
115
// Now put all params into JS ready array.
123
- List <Object > params = new ArrayList <Object >();
124
- params .add (settlementAddressesJS );
125
- params .add (depositJS );
116
+ List <Object > params = new ArrayList <>();
117
+ params .add (V8ObjectUtils . toV8Array ( engine , settlementAddresses ) );
118
+ params .add (V8ObjectUtils . toV8Array ( engine , deposits ) );
126
119
params .add (index );
127
- params .add (transferJS );
120
+ params .add (V8Converter . transferListToV8Array ( engine , transfers ) );
128
121
129
122
// Call js function.
130
123
V8Array ret = transfer .executeArrayFunction ("prepare" , V8ObjectUtils .toV8Array (engine , params ));
@@ -153,111 +146,37 @@ public static ArrayList<Transaction> prepare(ArrayList<String> settlementAddress
153
146
* @param root
154
147
* @param remainderAddress
155
148
* @param history
156
- * @param transfers
149
+ * @param transactions
157
150
* @param close
158
151
* @return
159
152
*/
160
153
public static ArrayList <Bundle > compose (int balance ,
161
- List <Integer > deposits ,
162
- List <Bundle > outputs ,
163
- MultisigAddress root ,
164
- MultisigAddress remainderAddress ,
165
- List <Bundle > history ,
166
- List <Transaction > transfers ,
167
- boolean close ) {
168
- V8Array depositsJS = V8ObjectUtils .toV8Array (engine , deposits );
169
- // Outputs
170
- List <Object > outputsObj = new ArrayList <Object >();
171
- for (Bundle t : outputs ) {
172
- outputsObj .add (t .toMap ());
173
- }
174
- V8Array outputsJS = V8ObjectUtils .toV8Array (engine , outputsObj );
175
- V8Object rootJS = V8ObjectUtils .toV8Object (engine , root .toMap ());
176
- V8Object remainderJS = V8ObjectUtils .toV8Object (engine , remainderAddress .toMap ());
177
-
178
- List <Object > historyObj = new ArrayList <Object >();
179
- for (Bundle t : history ) {
180
- historyObj .add (t .toMap ());
181
- }
182
- V8Array historyJS = V8ObjectUtils .toV8Array (engine , historyObj );
154
+ List <Integer > deposits ,
155
+ ArrayList <Bundle > outputs ,
156
+ MultisigAddress root ,
157
+ MultisigAddress remainderAddress ,
158
+ ArrayList <Bundle > history ,
159
+ ArrayList <Transaction > transactions ,
160
+ boolean close ) {
183
161
184
162
185
- List <Object > transfersObj = new ArrayList <Object >();
186
- for (Transaction t : transfers ) {
187
- transfersObj .add (t .toMap ());
188
- }
189
- V8Array transfersJS = V8ObjectUtils .toV8Array (engine , transfersObj );
190
163
191
164
// Create params.
192
165
// Now put all params into JS ready array.
193
166
List <Object > params = new ArrayList <Object >();
194
167
params .add (balance );
195
- params .add (depositsJS );
196
- params .add (outputsJS );
197
- params .add (rootJS );
198
- params .add (remainderJS );
199
- params .add (history );
200
- params .add (transfersJS );
168
+ params .add (V8ObjectUtils . toV8Array ( engine , deposits ) );
169
+ params .add (V8Converter . bundleListToV8Array ( engine , outputs ) );
170
+ params .add (V8Converter . multisigToV8Object ( engine , root ) );
171
+ params .add (V8Converter . multisigToV8Object ( engine , remainderAddress ) );
172
+ params .add (V8Converter . bundleListToV8Array ( engine , history ) );
173
+ params .add (V8Converter . transactionListToV8Array ( engine , transactions ) );
201
174
202
175
// Call js function.
203
176
V8Array ret = transfer .executeArrayFunction ("compose" , V8ObjectUtils .toV8Array (engine , params ));
204
177
List <Object > transfersReturnJS = V8ObjectUtils .toList (ret );
205
178
206
- // Parse return as array of bundles
207
- ArrayList <Bundle > returnBundles = new ArrayList <Bundle >();
208
- for (Object returnEntry : transfersReturnJS ) {
209
- ArrayList <Object > b = (ArrayList <Object >) returnEntry ;
210
-
211
- ArrayList <Transaction > returnedTransactions = new ArrayList <>();
212
-
213
- for (Object parsedObjects : b ) {
214
- Map <String , Object > bundleData = (Map <String , Object >) parsedObjects ;
215
- String signatureMessageFragment = (String ) bundleData .get ("signatureMessageFragment" );
216
- String bundle = (String ) bundleData .get ("bundle" );
217
- String address = (String ) bundleData .get ("address" );
218
- String attachmentTimestampLowerBound = (String ) bundleData .get ("attachmentTimestampLowerBound" );
219
- String attachmentTimestampUpperBound = (String ) bundleData .get ("attachmentTimestampUpperBound" );
220
- String trunkTransaction = (String ) bundleData .get ("trunkTransaction" );
221
- String attachmentTimestamp = (String ) bundleData .get ("attachmentTimestamp" );
222
- Integer timestamp = (Integer ) bundleData .get ("timestamp" );
223
- String tag = (String ) bundleData .get ("tag" );
224
- String branchTransaction = (String ) bundleData .get ("branchTransaction" );
225
- String nonce = (String ) bundleData .get ("nonce" );
226
- String obsoleteTag = (String ) bundleData .get ("obsoleteTag" );
227
-
228
- Integer currentIndex = (Integer ) bundleData .get ("currentIndex" );
229
- Integer value = (Integer ) bundleData .get ("value" );
230
- Integer lastIndex = (Integer ) bundleData .get ("lastIndex" );
231
-
232
- Transaction parsedTransaction = new Transaction (
233
- address ,
234
- bundle ,
235
- value .intValue (),
236
- obsoleteTag ,
237
- tag ,
238
- timestamp ,
239
- signatureMessageFragment ,
240
- trunkTransaction ,
241
- branchTransaction ,
242
-
243
- attachmentTimestamp ,
244
- attachmentTimestampUpperBound ,
245
- attachmentTimestampLowerBound ,
246
- nonce
247
- );
248
-
249
- returnedTransactions .add (parsedTransaction );
250
-
251
- System .out .println ("Created bundle transaction: " + parsedTransaction .toString ());
252
- }
253
-
254
- Bundle bundle = new Bundle (returnedTransactions );
255
- returnBundles .add (bundle );
256
- }
257
-
258
- System .out .println ("Created bundles: " + returnBundles .size ());
259
-
260
- return returnBundles ;
179
+ return V8Converter .bundleListFromV8Array (ret );
261
180
}
262
181
263
182
/**
@@ -267,38 +186,18 @@ public static ArrayList<Bundle> compose(int balance,
267
186
* @param bundles
268
187
* @return
269
188
*/
270
- public static Object sign (MultisigAddress root , String seed , ArrayList <Bundle > bundles ) {
271
- Map <String , Object > multisig = root .toMap ();
272
- V8Object rootJS = V8ObjectUtils .toV8Object (engine , multisig );
273
-
274
- List <Object > bundleTmp = new ArrayList <Object >();
275
- for (Bundle b : bundles ) {
276
- List <Object > transactions = new ArrayList <Object >();
277
- for (Transaction t : b .getBundles ()) {
278
- transactions .add (t .toMap ());
279
- }
280
- bundleTmp .add (transactions );
281
- }
282
- V8Array bundlesJS = V8ObjectUtils .toV8Array (engine , bundleTmp );
189
+ public static ArrayList <Signature > sign (MultisigAddress root , String seed , ArrayList <Bundle > bundles ) {
283
190
284
191
// Create params.
285
192
// Now put all params into JS ready array.
286
193
List <Object > params = new ArrayList <>();
287
- params .add (rootJS );
194
+ params .add (V8Converter . multisigToV8Object ( engine , root ) );
288
195
params .add (seed );
289
- params .add (bundlesJS );
196
+ params .add (V8Converter . bundleListToV8Array ( engine , bundles ) );
290
197
291
- V8Array signatures = transfer .executeArrayFunction ("sign" , V8ObjectUtils .toV8Array (engine , params ));
198
+ V8Array returnArray = transfer .executeArrayFunction ("sign" , V8ObjectUtils .toV8Array (engine , params ));
292
199
293
- for (Object o : V8ObjectUtils .toList (signatures )) {
294
- Map <String , Object > returnValues = (Map <String , Object >) o ;
295
- for (Map .Entry <String , Object > entry : returnValues .entrySet ()) {
296
- System .out .println (entry .getKey () + " : " + entry .getValue ());
297
- }
298
- }
299
-
300
- // TODO: add singature object.
301
- return signatures ;
200
+ return V8Converter .v8ArrayToSignatureList (returnArray );
302
201
}
303
202
304
203
/**
@@ -307,8 +206,14 @@ public static Object sign(MultisigAddress root, String seed, ArrayList<Bundle> b
307
206
* @param signatures
308
207
* @return
309
208
*/
310
- public static Object appliedSignatures (ArrayList <Object > bundles , ArrayList <Object > signatures ) {
311
- return null ;
209
+ public static ArrayList <Bundle > appliedSignatures (ArrayList <Bundle > bundles , ArrayList <Signature > signatures ) {
210
+ List <Object > params = new ArrayList <>();
211
+ params .add (V8Converter .bundleListToV8Array (engine , bundles ));
212
+ params .add (V8Converter .signatureListToV8Array (engine , signatures ));
213
+
214
+ V8Array returnArray = transfer .executeArrayFunction ("appliedSignatures" , V8ObjectUtils .toV8Array (engine , params ));
215
+ // Parse returns
216
+ return V8Converter .bundleListFromV8Array (returnArray );
312
217
}
313
218
314
219
/**
@@ -326,15 +231,29 @@ public static Object getDiff(ArrayList<Object> root, ArrayList<Object> remainder
326
231
/**
327
232
*
328
233
* @param root
329
- * @param deposit
234
+ * @param deposits
330
235
* @param outputs
331
236
* @param remainderAddress
332
237
* @param transfers
333
238
* @param signedBundles
334
239
* @return
335
240
*/
336
- public static Object applayTransfers (Object root , Object deposit , Object outputs , Object remainderAddress , Object transfers , Object signedBundles ) {
337
- return null ;
241
+ public static void applayTransfers (MultisigAddress root ,
242
+ ArrayList <Integer > deposits ,
243
+ ArrayList <Bundle > outputs ,
244
+ MultisigAddress remainderAddress ,
245
+ ArrayList <Bundle > transfers ,
246
+ ArrayList <Bundle > signedBundles ) {
247
+ // Construct Java params
248
+ List <Object > params = new ArrayList <>();
249
+ params .add (V8Converter .multisigToV8Object (engine , root ));
250
+ params .add (V8ObjectUtils .toV8Array (engine , deposits ));
251
+ params .add (V8Converter .bundleListToV8Array (engine , outputs ));
252
+ params .add (V8Converter .multisigToV8Object (engine , remainderAddress ));
253
+ params .add (V8Converter .bundleListToV8Array (engine , transfers ));
254
+ params .add (V8Converter .bundleListToV8Array (engine , signedBundles ));
255
+
256
+ transfer .executeFunction ("applyTransfers" , V8ObjectUtils .toV8Array (engine , params ));
338
257
}
339
258
340
259
/**
0 commit comments