Skip to content

Commit 6bdeafb

Browse files
author
[a561842] Hubert Marteau
committed
Fix MultiBalance issues
1 parent ca4005d commit 6bdeafb

File tree

9 files changed

+436
-263
lines changed

9 files changed

+436
-263
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.1-SNAPSHOT</version>
6+
<version>0.4.2-SNAPSHOT</version>
77

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

src/main/java/multichain/command/AddressCommand.java

Lines changed: 143 additions & 116 deletions
Large diffs are not rendered by default.

src/main/java/multichain/command/MultichainException.java

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,68 @@
99

1010
/**
1111
* @author Ub - H. MARTEAU
12-
* @version 1.0
12+
* @version 4.2
1313
*/
1414
public class MultichainException extends Exception {
1515

16+
private String object;
17+
private String reason;
18+
1619
/**
1720
* Serial
1821
*/
1922
private static final long serialVersionUID = 2412952380749244614L;
2023

21-
public MultichainException(String object, String reason) {
22-
System.out.println("Multichain Error / " + object + " {" + reason + "}");
24+
public MultichainException(String excep_object, String excep_reason) {
25+
object = excep_object;
26+
reason = excep_reason;
27+
}
28+
29+
/*
30+
* (non-Javadoc)
31+
*
32+
* @see java.lang.Object#toString()
33+
*/
34+
@Override
35+
public String toString() {
36+
return "MultichainException [\r\n" + " object=" + object + ",\r\n"
37+
+ " reason=" + reason + ",\r\n" + " message=" + getMessage()
38+
+ ",\r\n" + " cause=" + getCause() + "\r\n]";
39+
}
40+
41+
public String toShortString() {
42+
return "MultichainException [\r\n" + " object=" + object + ",\r\n"
43+
+ " reason=" + reason + "\r\n]";
2344
}
45+
46+
/**
47+
* @return the object
48+
*/
49+
public String getObject() {
50+
return object;
51+
}
52+
53+
/**
54+
* @param object
55+
* the object to set
56+
*/
57+
public void setObject(String object) {
58+
this.object = object;
59+
}
60+
61+
/**
62+
* @return the reason
63+
*/
64+
public String getReason() {
65+
return reason;
66+
}
67+
68+
/**
69+
* @param reason
70+
* the reason to set
71+
*/
72+
public void setReason(String reason) {
73+
this.reason = reason;
74+
}
75+
2476
}

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

Lines changed: 105 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,33 @@
1212

1313
/**
1414
* @author Ub - H. MARTEAU
15-
* @version 3.0
15+
* @version 4.2
1616
*/
1717
public class QueryBuilderAddress extends QueryBuilderCommon {
1818

1919
/**
2020
* addmultisigaddress nrequired ["key",...] ( "account" )
2121
*
22-
* Add a nrequired-to-sign multisignature address to the wallet.
23-
* Each key is a address or hex-encoded public key.
24-
* If 'account' is specified, assign address to that account.
22+
* Add a nrequired-to-sign multisignature address to the wallet. Each key is
23+
* a address or hex-encoded public key. If 'account' is specified, assign
24+
* address to that account.
2525
*
26-
* Arguments:
27-
* 1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.
28-
* 2. "keysobject" (string, required) A json array of addresses or hex-encoded public keys
29-
* [
30-
* "address" (string) address or hex-encoded public key
31-
* ...,
32-
* ]
33-
* 3. "account" (string, optional) An account to assign the addresses to.
26+
* Arguments: 1. nrequired (numeric, required) The number of required
27+
* signatures out of the n keys or addresses. 2. "keysobject" (string,
28+
* required) A json array of addresses or hex-encoded public keys [
29+
* "address" (string) address or hex-encoded public key ..., ] 3. "account"
30+
* (string, optional) An account to assign the addresses to.
3431
*
35-
* Result:
36-
* "address" (string) A address associated with the keys.
32+
* Result: "address" (string) A address associated with the keys.
3733
*
3834
*
3935
* @param numberOfSigRequired
4036
* @param publicKeys
4137
* @return the P2SH address
4238
* @throws MultichainException
4339
*/
44-
protected Object executeAddMultiSigAddress(int numberOfSigRequired, String[] publicKeys) throws MultichainException {
40+
protected Object executeAddMultiSigAddress(int numberOfSigRequired, String[] publicKeys)
41+
throws MultichainException {
4542
MultichainTestParameter.valueIsPositive("number of signature required", numberOfSigRequired);
4643
MultichainTestParameter.isNotNullOrEmpty("publicKeys", publicKeys);
4744
MultichainTestParameter.arrayNotContainNullOrEmptyValues("publicKeys", publicKeys);
@@ -55,22 +52,17 @@ protected Object executeAddMultiSigAddress(int numberOfSigRequired, String[] pub
5552
/**
5653
* createmultisig nrequired ["key",...]
5754
*
58-
* Creates a multi-signature address with n signature of m keys required.
59-
* It returns a json object with the address and redeemScript.
55+
* Creates a multi-signature address with n signature of m keys required. It
56+
* returns a json object with the address and redeemScript.
6057
*
61-
* Arguments:
62-
* 1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.
63-
* 2. "keys" (string, required) A json array of keys which are addresses or hex-encoded public keys
64-
* [
65-
* "key" (string) address or hex-encoded public key
66-
* ,...
67-
* ]
58+
* Arguments: 1. nrequired (numeric, required) The number of required
59+
* signatures out of the n keys or addresses. 2. "keys" (string, required) A
60+
* json array of keys which are addresses or hex-encoded public keys [ "key"
61+
* (string) address or hex-encoded public key ,... ]
6862
*
69-
* Result:
70-
* {
71-
* "address":"multisigaddress", (string) The value of the new multisig address.
72-
* "redeemScript":"script" (string) The string value of the hex-encoded redemption script.
73-
* }
63+
* Result: { "address":"multisigaddress", (string) The value of the new
64+
* multisig address. "redeemScript":"script" (string) The string value of
65+
* the hex-encoded redemption script. }
7466
*
7567
*
7668
* @param numberOfSigRequired
@@ -96,11 +88,11 @@ protected Object executeCreateMultiSig(int numberOfSigRequired, String[] publicK
9688
*
9789
* Returns asset balances for specified address
9890
*
99-
* Arguments:
100-
* 1. "address" (string, required) Address to return balance for.
101-
* 2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.
102-
* 3. includeLocked (bool, optional, default=false) Also take locked outputs into account
103-
* Results are an array of Objects with totals and details for each asset.
91+
* Arguments: 1. "address" (string, required) Address to return balance for.
92+
* 2. minconf (numeric, optional, default=1) Only include transactions
93+
* confirmed at least this many times. 3. includeLocked (bool, optional,
94+
* default=false) Also take locked outputs into account Results are an array
95+
* of Objects with totals and details for each asset.
10496
*
10597
* @param address
10698
* @return a list of all the asset balances for address in this node’s
@@ -117,16 +109,11 @@ protected Object executeGetAddressBalances(String address) throws MultichainExce
117109
*
118110
* Returns the list of all addresses in the wallet.
119111
*
120-
* Arguments:
121-
* 1. "verbose" (boolean, optional, default=false) The account name.
112+
* Arguments: 1. "verbose" (boolean, optional, default=false) The account
113+
* name.
122114
*
123-
* Result:
124-
* [ (json array of )
125-
* "address" (string) an address
126-
* or
127-
* "address-datails" (object) address details if verbose=true
128-
* ,...
129-
* ]
115+
* Result: [ (json array of ) "address" (string) an address or
116+
* "address-datails" (object) address details if verbose=true ,... ]
130117
*
131118
* @param verbose
132119
* t verbose to true to get more information about each address,
@@ -141,41 +128,81 @@ protected Object executeGetAddresses(boolean verbose) throws MultichainException
141128
/**
142129
* Returns a list of balances of all addresses in this node’s wallet
143130
*
144-
* getmultibalances ("address(es)" assets minconf includeLocked includeWatchonly)
131+
* getmultibalances ("address(es)" assets minconf includeLocked
132+
* includeWatchonly)
145133
*
146134
* Returns asset balances for specified address
147135
*
148-
* Arguments:
149-
* 1. "address(es)" (string, optional) Address(es) to return balance for, comma delimited. Default - all
150-
* or
151-
* 1. "address(es)" (array, optional) A json array of addresses to return balance for
152-
* 2. "assets" (array, optional) A json array of asset identifiers to return balance for, default - all []
153-
* 3. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.
154-
* 4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly addresses (see
155-
* 'importaddress')
156-
* 5. includeLocked (bool, optional, default=false) Also take locked outputs into account
157-
* Results are an Object of balance arrays with totals and details for each asset.
136+
* Arguments: 1. "address(es)" (string, optional) Address(es) to return
137+
* balance for, comma delimited. Default - all or 1. "address(es)" (array,
138+
* optional) A json array of addresses to return balance for 2. "assets"
139+
* (array, optional) A json array of asset identifiers to return balance
140+
* for, default - all [] 3. minconf (numeric, optional, default=1) Only
141+
* include transactions confirmed at least this many times. 4.
142+
* includeWatchonly (bool, optional, default=false) Include transactions to
143+
* watchonly addresses (see 'importaddress') 5. includeLocked (bool,
144+
* optional, default=false) Also take locked outputs into account Results
145+
* are an Object of balance arrays with totals and details for each asset.
146+
*
147+
* @return Balances
148+
*/
149+
protected Object executeGetMultiBalances(String[] addresses, String[] assets) throws MultichainException {
150+
MultichainTestParameter.isNotNullOrEmpty("addresses", addresses);
151+
MultichainTestParameter.arrayNotContainNullOrEmptyValues("addresses", addresses);
152+
MultichainTestParameter.isNotNullOrEmpty("assets", assets);
153+
MultichainTestParameter.arrayNotContainNullOrEmptyValues("assets", assets);
154+
return execute(CommandEnum.GETMULTIBALANCES, formatJson(addresses), formatJson(assets));
155+
}
156+
157+
/**
158+
* Returns a list of balances of all addresses in this node’s wallet
159+
*
160+
* getmultibalances ("address(es)" assets minconf includeLocked
161+
* includeWatchonly)
162+
*
163+
* Returns asset balances for specified address
164+
*
165+
* Arguments: 1. "address(es)" (string, optional) Address(es) to return
166+
* balance for, comma delimited. Default - all or 1. "address(es)" (array,
167+
* optional) A json array of addresses to return balance for 2. "assets"
168+
* (array, optional) A json array of asset identifiers to return balance
169+
* for, default - all [] 3. minconf (numeric, optional, default=1) Only
170+
* include transactions confirmed at least this many times. 4.
171+
* includeWatchonly (bool, optional, default=false) Include transactions to
172+
* watchonly addresses (see 'importaddress') 5. includeLocked (bool,
173+
* optional, default=false) Also take locked outputs into account Results
174+
* are an Object of balance arrays with totals and details for each asset.
158175
*
159176
* @return Balances
160177
*/
161178
protected Object executeGetMultiBalances(String[] addresses) throws MultichainException {
179+
MultichainTestParameter.isNotNullOrEmpty("addresses", addresses);
180+
MultichainTestParameter.arrayNotContainNullOrEmptyValues("addresses", addresses);
162181
return execute(CommandEnum.GETMULTIBALANCES, formatJson(addresses));
163182
}
164183

184+
protected Object executeGetMultiBalances(String address) throws MultichainException {
185+
return execute(CommandEnum.GETMULTIBALANCES, address);
186+
}
187+
188+
protected Object executeGetMultiBalances() throws MultichainException {
189+
return execute(CommandEnum.GETMULTIBALANCES);
190+
}
191+
165192
/**
166193
* getnewaddress ( "account" )
167194
*
168-
* Returns a new address for receiving payments.
169-
* If 'account' is specified (recommended), it is added to the address book
170-
* so payments received with the address will be credited to 'account'.
195+
* Returns a new address for receiving payments. If 'account' is specified
196+
* (recommended), it is added to the address book so payments received with
197+
* the address will be credited to 'account'.
171198
*
172-
* Arguments:
173-
* 1. "account" (string, optional) The account name for the address to be linked to. if not provided, the default
174-
* account "" is used. It can also be set to the empty string "" to represent the default account. The account does
175-
* not need to exist, it will be created if there is no account by the given name.
199+
* Arguments: 1. "account" (string, optional) The account name for the
200+
* address to be linked to. if not provided, the default account "" is used.
201+
* It can also be set to the empty string "" to represent the default
202+
* account. The account does not need to exist, it will be created if there
203+
* is no account by the given name.
176204
*
177-
* Result:
178-
* "address" (string) The new address
205+
* Result: "address" (string) The new address
179206
*
180207
* @return a new address whose private key is added to the wallet.
181208
* @throws MultichainException
@@ -191,12 +218,12 @@ protected Object executeGetNewAddress() throws MultichainException {
191218
*
192219
* importaddress "address" ( "label" rescan )
193220
*
194-
* Adds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend.
221+
* Adds an address or script (in hex) that can be watched as if it were in
222+
* your wallet but cannot be used to spend.
195223
*
196-
* Arguments:
197-
* 1. "address" (string, required) The address
198-
* 2. "label" (string, optional, default="") An optional label
199-
* 3. rescan (boolean, optional, default=true) Rescan the wallet for transactions
224+
* Arguments: 1. "address" (string, required) The address 2. "label"
225+
* (string, optional, default="") An optional label 3. rescan (boolean,
226+
* optional, default=true) Rescan the wallet for transactions
200227
*
201228
* Note: This call can take minutes to complete if rescan is true.
202229
*
@@ -221,19 +248,16 @@ protected Object executeImportAddress(String address, String label, boolean resc
221248
*
222249
* Return information about the given address.
223250
*
224-
* Arguments:
225-
* 1. "address" (string, required) The address to validate
226-
*
227-
* Result:
228-
* {
229-
* "isvalid" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.
230-
* "address" : "address", (string) The address validated
231-
* "ismine" : true|false, (boolean) If the address is yours or not
232-
* "isscript" : true|false, (boolean) If the key is a script
233-
* "pubkey" : "publickeyhex", (string) The hex value of the raw public key
234-
* "iscompressed" : true|false, (boolean) If the address is compressed
235-
* "account" : "account" (string) The account associated with the address, "" is the default account
236-
* }
251+
* Arguments: 1. "address" (string, required) The address to validate
252+
*
253+
* Result: { "isvalid" : true|false, (boolean) If the address is valid or
254+
* not. If not, this is the only property returned. "address" : "address",
255+
* (string) The address validated "ismine" : true|false, (boolean) If the
256+
* address is yours or not "isscript" : true|false, (boolean) If the key is
257+
* a script "pubkey" : "publickeyhex", (string) The hex value of the raw
258+
* public key "iscompressed" : true|false, (boolean) If the address is
259+
* compressed "account" : "account" (string) The account associated with the
260+
* address, "" is the default account }
237261
*
238262
*
239263
* @param address

src/main/java/multichain/object/BalanceAsset.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* @author Ub - H. MARTEAU
15-
* @version 1.0
15+
* @version 4.2
1616
*/
1717
public class BalanceAsset extends BalanceAssetBase {
1818
String assetref;
@@ -35,7 +35,7 @@ public class BalanceAsset extends BalanceAssetBase {
3535
public String toString() {
3636
return "BalanceAsset [assetref=" + assetref + ", multiple=" + multiple + ", units=" + units + ", open=" + open
3737
+ ", details=" + details + ", type=" + type + ", raw=" + raw + ", issuetxid=" + issuetxid
38-
+ ", addresses=" + addresses + ", issue=" + issue + "]";
38+
+ ", addresses=" + addresses + ", issue=" + issue + " " + super.toString() + "]";
3939
}
4040

4141
/**

0 commit comments

Comments
 (0)