Skip to content

Commit 871e82f

Browse files
author
[a561842] Hubert Marteau
committed
4.6 fix bugs hubert-marteau#24 & should fix hubert-marteau#23
1 parent dcc7862 commit 871e82f

File tree

5 files changed

+61
-63
lines changed

5 files changed

+61
-63
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>MultiChainJavaAPI</groupId>
55
<artifactId>MultiChainJavaAPI</artifactId>
6-
<version>0.4.5-SNAPSHOT</version>
6+
<version>0.4.6-SNAPSHOT</version>
77

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

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* @author Ub - H. MARTEAU
26-
* @version 4.4
26+
* @version 4.6
2727
*/
2828
public class WalletTransactionCommand extends QueryBuilderWalletTransaction {
2929

@@ -323,7 +323,16 @@ public TransactionWallet getWalletTransactionWithoutDetail(String txid) throws M
323323
* @throws MultichainException
324324
*/
325325
@SuppressWarnings("unchecked")
326-
public List<TransactionWallet> listAddressTransactions(String address, long count, long skip, boolean verbose) throws MultichainException {
326+
public List<TransactionWalletDetailed> listAddressTransactions(String address, long count, long skip, boolean verbose) throws MultichainException {
327+
List<TransactionWalletDetailed> listTransactionWallet = new ArrayList<TransactionWalletDetailed>();
328+
329+
Object objectTransactionWallet = executeListAddressTransactions(address, count, skip, verbose);
330+
listTransactionWallet = WalletTransactionFormatter.formatListTransactionWalletDetailed((List<Object>) objectTransactionWallet);
331+
332+
return listTransactionWallet;
333+
}
334+
335+
public List<TransactionWallet> listAddressTransactionsWithoutDetail(String address, long count, long skip, boolean verbose) throws MultichainException {
327336
List<TransactionWallet> listTransactionWallet = new ArrayList<TransactionWallet>();
328337

329338
Object objectTransactionWallet = executeListAddressTransactions(address, count, skip, verbose);
@@ -343,7 +352,7 @@ public List<TransactionWallet> listAddressTransactions(String address, long coun
343352
* @throws MultichainException
344353
*/
345354
public List<TransactionWallet> listAddressTransactions(String address, long count, long skip) throws MultichainException {
346-
return listAddressTransactions(address, count, skip, false);
355+
return listAddressTransactionsWithoutDetail(address, count, skip, false);
347356
}
348357

349358
/**
@@ -355,7 +364,7 @@ public List<TransactionWallet> listAddressTransactions(String address, long coun
355364
* @throws MultichainException
356365
*/
357366
public List<TransactionWallet> listAddressTransactions(String address, long count) throws MultichainException {
358-
return listAddressTransactions(address, count, 0, false);
367+
return listAddressTransactionsWithoutDetail(address, count, 0, false);
359368
}
360369

361370
/**
@@ -367,7 +376,7 @@ public List<TransactionWallet> listAddressTransactions(String address, long coun
367376
* @throws MultichainException
368377
*/
369378
public List<TransactionWallet> listAddressTransactions(String address) throws MultichainException {
370-
return listAddressTransactions(address, 10, 0, false);
379+
return listAddressTransactionsWithoutDetail(address, 10, 0, false);
371380
}
372381

373382
/**

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
*/
88
package multichain.command.builders;
99

10+
import java.util.ArrayList;
11+
import java.util.Arrays;
12+
import java.util.List;
13+
1014
import multichain.command.MultichainException;
1115
import multichain.command.tools.MultichainTestParameter;
1216

1317
/**
1418
* @author Ub - H. MARTEAU
15-
* @version 4.3
19+
* @version 4.6
1620
*/
1721
public class QueryBuilderAddress extends QueryBuilderCommon {
1822

@@ -58,13 +62,13 @@ protected Object executeCreateKeyPairs(int numberOfPairs) throws MultichainExcep
5862
* @return the P2SH address
5963
* @throws MultichainException
6064
*/
61-
protected Object executeAddMultiSigAddress( int numberOfSigRequired,
62-
String[] publicKeys) throws MultichainException {
65+
protected Object executeAddMultiSigAddress(int numberOfSigRequired, String[] publicKeys) throws MultichainException {
6366
MultichainTestParameter.valueIsPositive("number of signature required", numberOfSigRequired);
6467
MultichainTestParameter.isNotNullOrEmpty("publicKeys", publicKeys);
6568
MultichainTestParameter.arrayNotContainNullOrEmptyValues("publicKeys", publicKeys);
6669
if (publicKeys.length >= numberOfSigRequired) {
67-
return execute(CommandEnum.ADDMULTISIGADDRESS, numberOfSigRequired, formatJson(publicKeys));
70+
List<String> publicKeysList = new ArrayList<>(Arrays.asList(publicKeys));
71+
return execute(CommandEnum.ADDMULTISIGADDRESS, numberOfSigRequired, publicKeysList);
6872
} else {
6973
throw new MultichainException("number of signature", "is greater than the size of public keys");
7074
}
@@ -97,7 +101,8 @@ protected Object executeCreateMultiSig(int numberOfSigRequired, String[] publicK
97101
MultichainTestParameter.isNotNullOrEmpty("public Keys", publicKeys);
98102
MultichainTestParameter.arrayNotContainNullOrEmptyValues("public Keys", publicKeys);
99103
if (publicKeys.length >= numberOfSigRequired) {
100-
return execute(CommandEnum.CREATEMULTISIG, numberOfSigRequired, formatJson(publicKeys));
104+
List<String> publicKeysList = new ArrayList<>(Arrays.asList(publicKeys));
105+
return execute(CommandEnum.CREATEMULTISIG, numberOfSigRequired, publicKeysList);
101106
} else {
102107
throw new MultichainException("number of signature", "is greater than the size of public keys");
103108
}
@@ -172,7 +177,9 @@ protected Object executeGetMultiBalances(String[] addresses, String[] assets) th
172177
MultichainTestParameter.arrayNotContainNullOrEmptyValues("addresses", addresses);
173178
MultichainTestParameter.isNotNullOrEmpty("assets", assets);
174179
MultichainTestParameter.arrayNotContainNullOrEmptyValues("assets", assets);
175-
return execute(CommandEnum.GETMULTIBALANCES, formatJson(addresses), formatJson(assets));
180+
181+
List<String> addressesList = new ArrayList<>(Arrays.asList(addresses));
182+
return execute(CommandEnum.GETMULTIBALANCES, addressesList, formatJson(assets));
176183
}
177184

178185
/**
@@ -199,7 +206,9 @@ protected Object executeGetMultiBalances(String[] addresses, String[] assets) th
199206
protected Object executeGetMultiBalances(String[] addresses) throws MultichainException {
200207
MultichainTestParameter.isNotNullOrEmpty("addresses", addresses);
201208
MultichainTestParameter.arrayNotContainNullOrEmptyValues("addresses", addresses);
202-
return execute(CommandEnum.GETMULTIBALANCES, formatJson(addresses));
209+
210+
List<String> addressesList = new ArrayList<>(Arrays.asList(addresses));
211+
return execute(CommandEnum.GETMULTIBALANCES, addressesList);
203212
}
204213

205214
protected Object executeGetMultiBalances(String address) throws MultichainException {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
import java.util.UUID;
1818

1919
import org.apache.http.HttpEntity;
20-
import org.apache.http.HttpResponse;
2120
import org.apache.http.auth.AuthScope;
2221
import org.apache.http.auth.UsernamePasswordCredentials;
2322
import org.apache.http.client.ClientProtocolException;
2423
import org.apache.http.client.CredentialsProvider;
24+
import org.apache.http.client.methods.CloseableHttpResponse;
2525
import org.apache.http.client.methods.HttpPost;
2626
import org.apache.http.entity.StringEntity;
2727
import org.apache.http.impl.client.BasicCredentialsProvider;
@@ -39,7 +39,7 @@
3939

4040
/**
4141
* @author Ub - H. MARTEAU & Jagrut KOSTI
42-
* @version 4.3
42+
* @version 4.6
4343
*/
4444
abstract class QueryBuilderCommon extends GsonFormatters {
4545

@@ -192,15 +192,15 @@ protected StringEntity prepareRpcEntity(Map<String, Object> entityValues) throws
192192
}
193193

194194
private Object executeRequest() throws IOException, ClientProtocolException, MultichainException {
195-
HttpResponse response = httpclient.execute(httppost);
195+
CloseableHttpResponse response = httpclient.execute(httppost);
196196
int statusCode = response.getStatusLine().getStatusCode();
197197
if (statusCode >= 400) {
198-
throw new MultichainException("code :" + statusCode,
199-
"message : " + response.getStatusLine().getReasonPhrase());
198+
throw new MultichainException("code :" + statusCode, "message : " + response.getStatusLine().getReasonPhrase());
200199
}
201200
HttpEntity entity = response.getEntity();
202201

203202
String rpcAnswer = EntityUtils.toString(entity);
203+
response.close();
204204

205205
final Gson gson = new GsonBuilder().create();
206206
final MultiChainRPCAnswer multiChainRPCAnswer = gson.fromJson(rpcAnswer, MultiChainRPCAnswer.class);

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

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
/**
3131
* @author Ub - H. MARTEAU
32-
* @version 4.4
32+
* @version 4.6
3333
*/
3434
public class QueryBuilderWalletTransaction extends QueryBuilderCommon {
3535
/**
@@ -76,9 +76,7 @@ public class QueryBuilderWalletTransaction extends QueryBuilderCommon {
7676
* @return
7777
* @throws MultichainException
7878
*/
79-
protected Object executeGetAddressTransaction( String address,
80-
String txid,
81-
boolean verbose) throws MultichainException {
79+
protected Object executeGetAddressTransaction(String address, String txid, boolean verbose) throws MultichainException {
8280
MultichainTestParameter.isNotNullOrEmpty("address", address);
8381
MultichainTestParameter.isNotNullOrEmpty("txid", txid);
8482
return execute(CommandEnum.GETADDRESSTRANSACTION, address, txid, verbose);
@@ -197,9 +195,7 @@ protected Object executeGetTxOut(String txid, int vout, boolean includemempool)
197195
* @return
198196
* @throws MultichainException
199197
*/
200-
protected Object executeGetWalletTransaction( String txid,
201-
boolean includeWatchOnly,
202-
boolean verbose) throws MultichainException {
198+
protected Object executeGetWalletTransaction(String txid, boolean includeWatchOnly, boolean verbose) throws MultichainException {
203199
return execute(CommandEnum.GETWALLETTRANSACTION, txid, includeWatchOnly, verbose);
204200

205201
}
@@ -253,10 +249,7 @@ protected Object executeGetWalletTransaction( String txid,
253249
* @return
254250
* @throws MultichainException
255251
*/
256-
protected Object executeListAddressTransactions(String address,
257-
long count,
258-
long skip,
259-
boolean verbose) throws MultichainException {
252+
protected Object executeListAddressTransactions(String address, long count, long skip, boolean verbose) throws MultichainException {
260253
MultichainTestParameter.isNotNullOrEmpty("address", address);
261254
MultichainTestParameter.valueIsPositive("count", count);
262255
MultichainTestParameter.valueIsNotNegative("skip", skip);
@@ -308,10 +301,7 @@ protected Object executeListAddressTransactions(String address,
308301
* @return
309302
* @throws MultichainException
310303
*/
311-
protected Object executeListWalletTransaction( long count,
312-
long skip,
313-
boolean includeWatchonly,
314-
boolean verbose) throws MultichainException {
304+
protected Object executeListWalletTransaction(long count, long skip, boolean includeWatchonly, boolean verbose) throws MultichainException {
315305
MultichainTestParameter.valueIsPositive("count", count);
316306
MultichainTestParameter.valueIsNotNegative("skip", skip);
317307
return execute(CommandEnum.LISTWALLETTRANSACTIONS, count, skip, includeWatchonly, verbose);
@@ -345,19 +335,20 @@ protected Object executeListWalletTransaction( long count,
345335
* @return transactionId
346336
* @throws MultichainException
347337
*/
348-
protected Object executeSendFromAddress(String fromAddress,
349-
String toAddress,
350-
List<BalanceAssetBase> assets) throws MultichainException {
338+
protected Object executeSendFromAddress(String fromAddress, String toAddress, List<BalanceAssetBase> assets) throws MultichainException {
351339
MultichainTestParameter.isNotNullOrEmpty("fromAddress", fromAddress);
352340
MultichainTestParameter.isNotNullOrEmpty("toAddress", toAddress);
353341
if (assets == null || assets.isEmpty()) {
354342
throw new MultichainException("assets", "assets needed to be sent");
355343
}
344+
345+
Map<String, Double> mapAssets = new HashMap<String, Double>();
356346
for (BalanceAssetBase asset : assets) {
357347
asset.isFilled();
348+
mapAssets.put(asset.getName(), new Double(asset.getQty()));
358349
}
359350

360-
return execute(CommandEnum.SENDFROMADDRESS, fromAddress, toAddress, assets);
351+
return execute(CommandEnum.SENDFROMADDRESS, fromAddress, toAddress, mapAssets);
361352
}
362353

363354
/**
@@ -388,9 +379,7 @@ protected Object executeSendFromAddress(String fromAddress,
388379
* @return transactionId
389380
* @throws MultichainException
390381
*/
391-
protected Object executeSendFromAddress(String fromAddress,
392-
String toAddress,
393-
double amount) throws MultichainException {
382+
protected Object executeSendFromAddress(String fromAddress, String toAddress, double amount) throws MultichainException {
394383
MultichainTestParameter.isNotNullOrEmpty("fromAddress", fromAddress);
395384
MultichainTestParameter.isNotNullOrEmpty("toAddress", toAddress);
396385
MultichainTestParameter.valueIsPositive("amount", amount);
@@ -430,11 +419,13 @@ protected Object executeSendToAddress(String address, List<BalanceAssetBase> ass
430419
if (assets == null || assets.isEmpty()) {
431420
throw new MultichainException("assets", "assets needed to be sent");
432421
}
422+
Map<String, Double> mapAssets = new HashMap<String, Double>();
433423
for (BalanceAssetBase asset : assets) {
434424
asset.isFilled();
425+
mapAssets.put(asset.getName(), new Double(asset.getQty()));
435426
}
436427

437-
return execute(CommandEnum.SENDTOADDRESS, address, formatJson(assets));
428+
return execute(CommandEnum.SENDTOADDRESS, address, mapAssets);
438429
}
439430

440431
/**
@@ -494,19 +485,19 @@ protected Object executeSendToAddress(String address, double amount) throws Mult
494485
* @return
495486
* @throws MultichainException
496487
*/
497-
protected Object executeSendWithMetaData( String address,
498-
List<BalanceAssetBase> assets,
499-
String hexMetaData) throws MultichainException {
488+
protected Object executeSendWithMetaData(String address, List<BalanceAssetBase> assets, String hexMetaData) throws MultichainException {
500489
MultichainTestParameter.isNotNullOrEmpty("address", address);
501490
MultichainTestParameter.isNotNullOrEmpty("hexMetaData", hexMetaData);
502491
if (assets == null || assets.isEmpty()) {
503492
throw new MultichainException("assets", "assets needed to be sent");
504493
}
494+
Map<String, Double> mapAssets = new HashMap<String, Double>();
505495
for (BalanceAssetBase asset : assets) {
506496
asset.isFilled();
497+
mapAssets.put(asset.getName(), new Double(asset.getQty()));
507498
}
508499

509-
return execute(CommandEnum.SENDWITHMETADATA, address, formatJson(assets), hexMetaData);
500+
return execute(CommandEnum.SENDWITHMETADATA, address, mapAssets, hexMetaData);
510501
}
511502

512503
/**
@@ -532,9 +523,7 @@ protected Object executeSendWithMetaData( String address,
532523
* @return
533524
* @throws MultichainException
534525
*/
535-
protected Object executeSendWithMetaData( String address,
536-
double amount,
537-
String hexMetaData) throws MultichainException {
526+
protected Object executeSendWithMetaData(String address, double amount, String hexMetaData) throws MultichainException {
538527
MultichainTestParameter.isNotNullOrEmpty("address", address);
539528
MultichainTestParameter.isNotNullOrEmpty("hexMetaData", hexMetaData);
540529
MultichainTestParameter.valueIsPositive("amount", amount);
@@ -568,10 +557,7 @@ protected Object executeSendWithMetaData( String address,
568557
* @return
569558
* @throws MultichainException
570559
*/
571-
protected Object executeSendWithMetaDataFrom( String fromAddress,
572-
String toAddress,
573-
List<BalanceAssetBase> assets,
574-
String hexMetaData) throws MultichainException {
560+
protected Object executeSendWithMetaDataFrom(String fromAddress, String toAddress, List<BalanceAssetBase> assets, String hexMetaData) throws MultichainException {
575561
MultichainTestParameter.isNotNullOrEmpty("fromAddress", fromAddress);
576562
MultichainTestParameter.isNotNullOrEmpty("toAddress", toAddress);
577563
MultichainTestParameter.isNotNullOrEmpty("hexMetaData", hexMetaData);
@@ -582,9 +568,10 @@ protected Object executeSendWithMetaDataFrom( String fromAddress,
582568
for (BalanceAssetBase asset : assets) {
583569
asset.isFilled();
584570
}
585-
Map<String, Object> mapAssets = new HashMap<String, Object>();
571+
Map<String, Double> mapAssets = new HashMap<String, Double>();
586572
for (BalanceAssetBase asset : assets) {
587-
mapAssets.put(asset.getName(), asset.getIssueqty());
573+
asset.isFilled();
574+
mapAssets.put(asset.getName(), new Double(asset.getQty()));
588575
}
589576

590577
return execute(CommandEnum.SENDWITHMETADATAFROM, fromAddress, toAddress, mapAssets, hexMetaData);
@@ -616,10 +603,7 @@ protected Object executeSendWithMetaDataFrom( String fromAddress,
616603
* @return
617604
* @throws MultichainException
618605
*/
619-
protected Object executeSendWithMetaDataFrom( String fromAddress,
620-
String toAddress,
621-
double amount,
622-
String hexMetaData) throws MultichainException {
606+
protected Object executeSendWithMetaDataFrom(String fromAddress, String toAddress, double amount, String hexMetaData) throws MultichainException {
623607
MultichainTestParameter.isNotNullOrEmpty("fromAddress", fromAddress);
624608
MultichainTestParameter.isNotNullOrEmpty("toAddress", toAddress);
625609
MultichainTestParameter.isNotNullOrEmpty("hexMetaData", hexMetaData);
@@ -628,11 +612,7 @@ protected Object executeSendWithMetaDataFrom( String fromAddress,
628612
return execute(CommandEnum.SENDWITHMETADATAFROM, fromAddress, toAddress, String.valueOf(amount), hexMetaData);
629613
}
630614

631-
protected Object executeSendWithDataFrom( String fromAddress,
632-
String toAddress,
633-
String assetName,
634-
Integer assetValue,
635-
String metadata) throws MultichainException {
615+
protected Object executeSendWithDataFrom(String fromAddress, String toAddress, String assetName, Integer assetValue, String metadata) throws MultichainException {
636616
MultichainTestParameter.isNotNullOrEmpty("fromAddress", fromAddress);
637617
MultichainTestParameter.isNotNullOrEmpty("toAddress", toAddress);
638618
MultichainTestParameter.isNotNullOrEmpty("metadata", metadata);

0 commit comments

Comments
 (0)