Skip to content

Commit 5848990

Browse files
committed
Implement listAssetTransactions
Create new object: AssetTransaction Use it from WalletTransactionCommand
1 parent 8ff523b commit 5848990

File tree

6 files changed

+288
-1
lines changed

6 files changed

+288
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.multichainjavaapi</groupId>
55
<artifactId>MultiChainJavaAPI</artifactId>
6-
<version>0.4.17-SNAPSHOT</version>
6+
<version>0.4.18-SNAPSHOT</version>
77

88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/multichain/command/WalletTransactionCommand.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
import java.util.List;
1212

1313
import multichain.command.builders.QueryBuilderWalletTransaction;
14+
import multichain.object.AssetTransaction;
1415
import multichain.object.BalanceAssetGeneral;
1516
import multichain.object.Transaction;
1617
import multichain.object.TransactionWallet;
1718
import multichain.object.TransactionWalletDetailed;
1819
import multichain.object.TxOut;
20+
import multichain.object.formatters.AssetTransactionFormatter;
1921
import multichain.object.formatters.TransactionFormatter;
2022
import multichain.object.formatters.TxOutFormatter;
2123
import multichain.object.formatters.WalletTransactionFormatter;
@@ -378,6 +380,76 @@ public List<TransactionWallet> listAddressTransactions(String address) throws Mu
378380
return listAddressTransactionsWithoutDetail(address, 10, 0, false);
379381
}
380382

383+
/**
384+
* {@link #listAssetTransactions(String, boolean) with verbose at false}
385+
* @param assetIdentifier
386+
* @return
387+
* @throws MultichainException
388+
*/
389+
public List<AssetTransaction> listAssetTransactions(String assetIdentifier) throws MultichainException {
390+
return listAssetTransactions(assetIdentifier, false, 10, 0, false);
391+
}
392+
393+
/**
394+
* {@link #listAssetTransactions(String, boolean, long)} with count at 10}
395+
* @param assetIdentifier
396+
* @return
397+
* @throws MultichainException
398+
*/
399+
public List<AssetTransaction> listAssetTransactions(String assetIdentifier, boolean verbose) throws MultichainException {
400+
return listAssetTransactions(assetIdentifier, verbose, 10, 0, false);
401+
}
402+
403+
/**
404+
* {@link #listAssetTransactions(String, boolean, long, long, boolean)} with start at 0 and localOrdering at false}
405+
* @param assetIdentifier
406+
* @return
407+
* @throws MultichainException
408+
*/
409+
public List<AssetTransaction> listAssetTransactions(String assetIdentifier, boolean verbose, long count) throws MultichainException {
410+
return listAssetTransactions(assetIdentifier, verbose, count, 0, false);
411+
}
412+
413+
/**
414+
*
415+
* lisassettransactions "asset-identifier" (verbose count start local-ordering)
416+
*
417+
* Returns up to 'count' most recent transactions skipping the first 'from'
418+
* transactions for account 'account'.
419+
*
420+
* Arguments: 1. "address" (string, required) Address to list transactions
421+
* for. 2. count (numeric, optional, default=10) The number of transactions
422+
* to return 3. skip (numeric, optional, default=0) The number of
423+
* transactions to skip 4. verbose (bool, optional, default=false) If true,
424+
* returns detailed array of inputs and outputs and raw hex of transactions
425+
*
426+
* Lists transactions involving asset.
427+
*
428+
* Arguments:
429+
* 1. "asset-identifier" (string, required) Asset identifier - one of the following: asset txid, asset reference, asset name.
430+
* 2. verbose (boolean, optional, default=false) If true, returns information about transaction
431+
* 3. count (number, optional, default=10) The number of transactions to display
432+
* 4. start (number, optional, default=-count - last) Start from specific transaction, 0 based, if negative - from the end
433+
* 5. local-ordering (boolean, optional, default=false) If true, transactions appear in the order they were processed by the wallet,
434+
* if false - in the order they appear in blockchain
435+
*
436+
* Result:
437+
* "stream-items" (array) List of transactions.
438+
*
439+
* @param assetIdentifier
440+
* @param verbose
441+
* @param count
442+
* @param start
443+
* @param localOrdering
444+
* @return
445+
* @throws MultichainException
446+
*/
447+
public List<AssetTransaction> listAssetTransactions(String assetIdentifier, boolean verbose, long count, long start, boolean localOrdering) throws MultichainException {
448+
Object objectAssetTransaction = executeListAssetTransactions(assetIdentifier, verbose, count, start, localOrdering);
449+
List<AssetTransaction> listAssetTransaction = AssetTransactionFormatter.formatListAssetTransaction((List<Object>) objectAssetTransaction);
450+
return listAssetTransaction;
451+
}
452+
381453
/**
382454
*
383455
* listwallettransactions ( count skip includeWatchonly verbose)

src/main/java/multichain/command/builders/QueryBuilderCommon.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ protected enum CommandEnum {
101101
ISSUEMORE,
102102
ISSUEMOREFROM,
103103
LISTADDRESSTRANSACTIONS,
104+
LISTASSETTRANSACTIONS,
104105
LISTASSETS,
105106
LISTLOCKUNPSENT,
106107
LISTPERMISSIONS,

src/main/java/multichain/command/builders/QueryBuilderWalletTransaction.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,46 @@ protected Object executeListAddressTransactions(String address, long count, long
256256
return execute(CommandEnum.LISTADDRESSTRANSACTIONS, address, count, skip, verbose);
257257
}
258258

259+
/**
260+
*
261+
* lisassettransactions "asset-identifier" (verbose count start local-ordering)
262+
*
263+
* Returns up to 'count' most recent transactions skipping the first 'from'
264+
* transactions for account 'account'.
265+
*
266+
* Arguments: 1. "address" (string, required) Address to list transactions
267+
* for. 2. count (numeric, optional, default=10) The number of transactions
268+
* to return 3. skip (numeric, optional, default=0) The number of
269+
* transactions to skip 4. verbose (bool, optional, default=false) If true,
270+
* returns detailed array of inputs and outputs and raw hex of transactions
271+
*
272+
* Lists transactions involving asset.
273+
*
274+
* Arguments:
275+
* 1. "asset-identifier" (string, required) Asset identifier - one of the following: asset txid, asset reference, asset name.
276+
* 2. verbose (boolean, optional, default=false) If true, returns information about transaction
277+
* 3. count (number, optional, default=10) The number of transactions to display
278+
* 4. start (number, optional, default=-count - last) Start from specific transaction, 0 based, if negative - from the end
279+
* 5. local-ordering (boolean, optional, default=false) If true, transactions appear in the order they were processed by the wallet,
280+
* if false - in the order they appear in blockchain
281+
*
282+
* Result:
283+
* "stream-items" (array) List of transactions.
284+
*
285+
* @param assetIdentifier
286+
* @param verbose
287+
* @param count
288+
* @param start
289+
* @param localOrdering
290+
* @return
291+
* @throws MultichainException
292+
*/
293+
protected Object executeListAssetTransactions(String assetIdentifier, boolean verbose, long count, long start, boolean localOrdering) throws MultichainException {
294+
MultichainTestParameter.isNotNullOrEmpty("assetIdentifier", assetIdentifier);
295+
MultichainTestParameter.valueIsPositive("count", count);
296+
return execute(CommandEnum.LISTASSETTRANSACTIONS, assetIdentifier, verbose, count, start, localOrdering);
297+
}
298+
259299
/**
260300
*
261301
* listwallettransactions ( count skip includeWatchonly verbose)
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package multichain.object;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
/**
7+
* @version 4.18
8+
*/
9+
public class AssetTransaction {
10+
11+
Map<String, Double> addresses;
12+
List<Item> items;
13+
List<String> data;
14+
Long confirmations;
15+
String blockhash;
16+
Long blockindex;
17+
Long blocktime;
18+
String txid;
19+
Boolean valid;
20+
Long time;
21+
Long timereceived;
22+
List<TransactionWalletVin> vin;
23+
List<TransactionWalletVout> vout;
24+
25+
public AssetTransaction() {
26+
}
27+
28+
public Map<String, Double> getAddresses() {
29+
return addresses;
30+
}
31+
32+
public void setAddresses(Map<String, Double> addresses) {
33+
this.addresses = addresses;
34+
}
35+
36+
public List<Item> getItems() {
37+
return items;
38+
}
39+
40+
public void setItems(List<Item> items) {
41+
this.items = items;
42+
}
43+
44+
public List<String> getData() {
45+
return data;
46+
}
47+
48+
public void setData(List<String> data) {
49+
this.data = data;
50+
}
51+
52+
public Long getConfirmations() {
53+
return confirmations;
54+
}
55+
56+
public void setConfirmations(Long confirmations) {
57+
this.confirmations = confirmations;
58+
}
59+
60+
public String getBlockhash() {
61+
return blockhash;
62+
}
63+
64+
public void setBlockhash(String blockhash) {
65+
this.blockhash = blockhash;
66+
}
67+
68+
public Long getBlockindex() {
69+
return blockindex;
70+
}
71+
72+
public void setBlockindex(Long blockindex) {
73+
this.blockindex = blockindex;
74+
}
75+
76+
public Long getBlocktime() {
77+
return blocktime;
78+
}
79+
80+
public void setBlocktime(Long blocktime) {
81+
this.blocktime = blocktime;
82+
}
83+
84+
public String getTxid() {
85+
return txid;
86+
}
87+
88+
public void setTxid(String txid) {
89+
this.txid = txid;
90+
}
91+
92+
public Boolean getValid() {
93+
return valid;
94+
}
95+
96+
public void setValid(Boolean valid) {
97+
this.valid = valid;
98+
}
99+
100+
public Long getTime() {
101+
return time;
102+
}
103+
104+
public void setTime(Long time) {
105+
this.time = time;
106+
}
107+
108+
public Long getTimereceived() {
109+
return timereceived;
110+
}
111+
112+
public void setTimereceived(Long timereceived) {
113+
this.timereceived = timereceived;
114+
}
115+
116+
public List<TransactionWalletVin> getVin() {
117+
return vin;
118+
}
119+
120+
public void setVin(List<TransactionWalletVin> vin) {
121+
this.vin = vin;
122+
}
123+
124+
public List<TransactionWalletVout> getVout() {
125+
return vout;
126+
}
127+
128+
public void setVout(List<TransactionWalletVout> vout) {
129+
this.vout = vout;
130+
}
131+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2017 Worldline, Inc.
3+
*
4+
* MultiChainJavaAPI code distributed under the GPLv3 license, see COPYING file.
5+
* https://github.com/SimplyUb/MultiChainJavaAPI/blob/master/LICENSE
6+
*
7+
*/
8+
package multichain.object.formatters;
9+
10+
import com.google.gson.Gson;
11+
import com.google.gson.GsonBuilder;
12+
import com.google.gson.internal.LinkedTreeMap;
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
import multichain.object.AssetTransaction;
16+
17+
/**
18+
* @version 4.18
19+
*/
20+
public class AssetTransactionFormatter {
21+
public final static List<AssetTransaction> formatListAssetTransaction(List<Object> objectAssetTransactions) {
22+
List<AssetTransaction> assetTransactionList = new ArrayList<AssetTransaction>();
23+
if (objectAssetTransactions != null) {
24+
for (Object objectAssetTransaction : objectAssetTransactions) {
25+
assetTransactionList.add(formatAssetTransaction(objectAssetTransaction));
26+
}
27+
}
28+
return assetTransactionList;
29+
}
30+
31+
public final static AssetTransaction formatAssetTransaction(Object objectAssetTransaction) {
32+
AssetTransaction assetTransaction = new AssetTransaction();
33+
if (objectAssetTransaction != null && LinkedTreeMap.class.isInstance(objectAssetTransaction)) {
34+
GsonBuilder builder = new GsonBuilder();
35+
Gson gson = builder.create();
36+
37+
String jsonValue = gson.toJson(objectAssetTransaction);
38+
assetTransaction = gson.fromJson(jsonValue, AssetTransaction.class);
39+
}
40+
return assetTransaction;
41+
}
42+
43+
}

0 commit comments

Comments
 (0)