Skip to content

Commit a3c2efb

Browse files
Add files via upload
1 parent 33b8306 commit a3c2efb

File tree

64 files changed

+9696
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+9696
-0
lines changed
Lines changed: 339 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,339 @@
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.command;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
import multichain.command.builders.QueryBuilderAddress;
14+
import multichain.object.Address;
15+
import multichain.object.BalanceAsset;
16+
import multichain.object.MultiBalance;
17+
import multichain.object.formatters.AddressFormatter;
18+
import multichain.object.formatters.BalanceFormatter;
19+
20+
/**
21+
* @author Ub - H. MARTEAU
22+
* @version 1.0
23+
*/
24+
public class AddressCommand extends QueryBuilderAddress {
25+
26+
/**
27+
* addmultisigaddress nrequired ["key",...] ( "account" )
28+
*
29+
* Add a nrequired-to-sign multisignature address to the wallet.
30+
* Each key is a address or hex-encoded public key.
31+
* If 'account' is specified, assign address to that account.
32+
*
33+
* Arguments:
34+
* 1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.
35+
* 2. "keysobject" (string, required) A json array of addresses or hex-encoded public keys
36+
* [
37+
* "address" (string) address or hex-encoded public key
38+
* ...,
39+
* ]
40+
* 3. "account" (string, optional) An account to assign the addresses to.
41+
*
42+
* Result:
43+
* "address" (string) A address associated with the keys.
44+
45+
*
46+
* @param numberOfSigRequired
47+
* @param publicKeys
48+
* @return the P2SH address
49+
* @throws MultichainException
50+
*/
51+
public final static Address addMultiSigAddress(int numberOfSigRequired, String[] publicKeys) throws MultichainException {
52+
Address address = new Address();
53+
54+
String stringAddress = executeAddMultiSigAddress(numberOfSigRequired, publicKeys);
55+
address = validateAddress(stringAddress);
56+
57+
return address;
58+
}
59+
60+
/**
61+
* createmultisig nrequired ["key",...]
62+
*
63+
* Creates a multi-signature address with n signature of m keys required.
64+
* It returns a json object with the address and redeemScript.
65+
*
66+
* Arguments:
67+
* 1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.
68+
* 2. "keys" (string, required) A json array of keys which are addresses or hex-encoded public keys
69+
* [
70+
* "key" (string) address or hex-encoded public key
71+
* ,...
72+
* ]
73+
*
74+
* Result:
75+
* {
76+
* "address":"multisigaddress", (string) The value of the new multisig address.
77+
* "redeemScript":"script" (string) The string value of the hex-encoded redemption script.
78+
* }
79+
*
80+
*
81+
* @param numberOfSigRequired
82+
* @param publicKeys
83+
* @return The P2SH address and corresponding redeem script.
84+
* @throws MultichainException
85+
*/
86+
public static Address createMultiSig(int numberOfSigRequired, String[] publicKeys)
87+
throws MultichainException {
88+
Address address = new Address();
89+
90+
String stringAddress = executeCreateMultiSig(numberOfSigRequired, publicKeys);
91+
address = validateAddress(stringAddress);
92+
93+
return address;
94+
}
95+
96+
97+
/**
98+
* getaddresses ( verbose ) with verbose false
99+
*
100+
* Returns the list of all addresses in the wallet.
101+
*
102+
* Arguments:
103+
* 1. "verbose" (boolean, optional, default=false) The account name.
104+
*
105+
* Result:
106+
* [ (json array of )
107+
* "address" (string) an address
108+
* or
109+
* "address-datails" (object) address details if verbose=true
110+
* ,...
111+
* ]
112+
*
113+
* @return Addresses of the Wallet
114+
* @throws MultichainException
115+
*/
116+
public final static List<String> getAddressesStringList() throws MultichainException {
117+
List<String> addresses = new ArrayList<String>();
118+
119+
String stringAddresses = executeGetAddresses(false);
120+
addresses = AddressFormatter.formatAddressesStringList(stringAddresses);
121+
122+
return addresses;
123+
}
124+
125+
126+
127+
/**
128+
* getaddresses
129+
*
130+
* Returns the list of all addresses in the wallet.
131+
*
132+
* Result:
133+
* [ (json array of )
134+
* "address" (string) an address
135+
* ,...
136+
* ]
137+
*
138+
* @return Addresses of the Wallet
139+
* @throws MultichainException
140+
*/
141+
public final static List<String> getAddresses() throws MultichainException {
142+
return getAddressesStringList();
143+
}
144+
145+
/**
146+
* getaddresses ( verbose ) with verbose true
147+
*
148+
* Returns the list of all addresses in the wallet.
149+
*
150+
* Arguments:
151+
* 1. "verbose" (boolean, optional, default=false) The account name.
152+
*
153+
* Result:
154+
* [ (json array of )
155+
* "address" (string) an address
156+
* or
157+
* "address-datails" (object) address details if verbose=true
158+
* ,...
159+
* ]
160+
*
161+
* @return Addresses of the Wallet
162+
* @throws MultichainException
163+
*/
164+
public final static List<Address> getAddressesList() throws MultichainException {
165+
List<Address> addresses = new ArrayList<Address>();
166+
167+
String stringAddresses = executeGetAddresses(true);
168+
addresses = AddressFormatter.formatAddressesList(stringAddresses);
169+
170+
return addresses;
171+
}
172+
173+
/**
174+
* Returns a list of balances of all addresses in this node’s wallet
175+
*
176+
* getmultibalances ("address(es)" assets minconf includeLocked includeWatchonly)
177+
*
178+
* Returns asset balances for specified address
179+
*
180+
* Arguments:
181+
* 1. "address(es)" (string, optional) Address(es) to return balance for, comma delimited. Default - all
182+
* or
183+
* 1. "address(es)" (array, optional) A json array of addresses to return balance for
184+
* 2. "assets" (array, optional) A json array of asset identifiers to return balance for, default - all []
185+
* 3. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.
186+
* 4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')
187+
* 5. includeLocked (bool, optional, default=false) Also take locked outputs into account
188+
* Results are an Object of balance arrays with totals and details for each asset.
189+
*
190+
* @return Balances
191+
*/
192+
public static List<MultiBalance> getMultiBalances(String[] addresses) throws MultichainException {
193+
List<MultiBalance> listMultiBalance = new ArrayList<MultiBalance>();
194+
195+
String stringMultiBalance = executeGetMultiBalances(addresses);
196+
listMultiBalance = BalanceFormatter.formatMultiBalances(stringMultiBalance);
197+
198+
return listMultiBalance;
199+
}
200+
201+
/**
202+
* {@link #getMultiBalances(String[]) with only 1 address}
203+
*
204+
* @param address
205+
* @return
206+
* @throws MultichainException
207+
*/
208+
public static List<MultiBalance> getMultiBalances(String address) throws MultichainException {
209+
String[] addresses = {address};
210+
211+
return getMultiBalances(addresses);
212+
}
213+
214+
/**
215+
* {@link #getMultiBalances(String) without address}
216+
*
217+
* @return
218+
* @throws MultichainException
219+
*/
220+
public static List<MultiBalance> getMultiBalances() throws MultichainException {
221+
return getMultiBalances("");
222+
}
223+
224+
/**
225+
*
226+
* getaddressbalances "address" ( minconf includeLocked )
227+
*
228+
* Returns asset balances for specified address
229+
*
230+
* Arguments:
231+
* 1. "address" (string, required) Address to return balance for.
232+
* 2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.
233+
* 3. includeLocked (bool, optional, default=false) Also take locked outputs into account
234+
* Results are an array of Objects with totals and details for each asset.
235+
*
236+
* @param address
237+
* @return Balance of the address
238+
* @throws MultichainException
239+
*/
240+
public static List<BalanceAsset> getAddressBalances(String address) throws MultichainException {
241+
List<BalanceAsset> balance = new ArrayList<BalanceAsset>();
242+
243+
String stringBalances = executeGetAddressBalances(address);
244+
balance = BalanceFormatter.formatBalanceAssets(stringBalances);
245+
246+
return balance;
247+
}
248+
249+
250+
/**
251+
*
252+
* getnewaddress ( "account" )
253+
*
254+
* Returns a new address for receiving payments.
255+
* If 'account' is specified (recommended), it is added to the address book
256+
* so payments received with the address will be credited to 'account'.
257+
*
258+
* Arguments:
259+
* 1. "account" (string, optional) The account name for the address to be linked to. if not provided, the default account "" is used. It can also be set to the empty string "" to represent the default account. The account does not need to exist, it will be created if there is no account by the given name.
260+
*
261+
* Result:
262+
* "address" (string) The new address
263+
*
264+
* @return Address created
265+
* @throws MultichainException
266+
*/
267+
public final static Address getNewAddress() throws MultichainException {
268+
Address address = new Address();
269+
270+
String stringAddress = executeGetNewAddress();
271+
address = validateAddress(stringAddress);
272+
273+
return address;
274+
}
275+
276+
/**
277+
* Adds address to the wallet, without an associated private key, to create
278+
* a watch-only address. This is an address whose activity and balance can
279+
* be retrieved , but whose funds cannot be spent by this node
280+
*
281+
* importaddress "address" ( "label" rescan )
282+
*
283+
* Adds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend.
284+
*
285+
* Arguments:
286+
* 1. "address" (string, required) The address
287+
* 2. "label" (string, optional, default="") An optional label
288+
* 3. rescan (boolean, optional, default=true) Rescan the wallet for transactions
289+
*
290+
* Note: This call can take minutes to complete if rescan is true.
291+
*
292+
* @param address
293+
* @param label
294+
* @param rescan
295+
* If rescan is true, the entire blockchain is checked for
296+
* transactions relating to all addresses in the wallet,
297+
* including the added one
298+
* @throws MultichainException
299+
*/
300+
public static void importAddress(String address, String label, boolean rescan) throws MultichainException {
301+
/*String systemMessage = */executeImportAddress(address, label, rescan);
302+
}
303+
304+
/**
305+
* Get information about an address
306+
*
307+
* validateaddress "address"
308+
*
309+
* Return information about the given address.
310+
*
311+
* Arguments:
312+
* 1. "address" (string, required) The address to validate
313+
*
314+
* Result:
315+
* {
316+
* "isvalid" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.
317+
* "address" : "address", (string) The address validated
318+
* "ismine" : true|false, (boolean) If the address is yours or not
319+
* "isscript" : true|false, (boolean) If the key is a script
320+
* "pubkey" : "publickeyhex", (string) The hex value of the raw public key
321+
* "iscompressed" : true|false, (boolean) If the address is compressed
322+
* "account" : "account" (string) The account associated with the address, "" is the default account
323+
* }
324+
*
325+
* @param stringAddress Address String in multichain
326+
* @return Address with Information
327+
* @throws MultichainException
328+
*/
329+
public final static Address validateAddress(String stringAddress) throws MultichainException {
330+
Address address = new Address();
331+
332+
String stringAddressInfo = executeValidateAddress(stringAddress);
333+
address = AddressFormatter.formatAddress(stringAddressInfo);
334+
335+
return address;
336+
}
337+
338+
339+
}

0 commit comments

Comments
 (0)