Skip to content

Commit 7f78de5

Browse files
author
[a561842] Hubert Marteau
committed
Adding CreateKeyPairs
1 parent 6bdeafb commit 7f78de5

File tree

7 files changed

+381
-165
lines changed

7 files changed

+381
-165
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.2-SNAPSHOT</version>
6+
<version>0.4.3-SNAPSHOT</version>
77

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

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

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,69 @@
1313
import multichain.command.builders.QueryBuilderAddress;
1414
import multichain.object.Address;
1515
import multichain.object.BalanceAsset;
16+
import multichain.object.KeyPairs;
1617
import multichain.object.MultiBalance;
1718
import multichain.object.formatters.AddressFormatter;
1819
import multichain.object.formatters.BalanceFormatter;
1920

2021
/**
2122
* @author Ub - H. MARTEAU
22-
* @version 4.2
23+
* @version 4.3
2324
*/
2425
public class AddressCommand extends QueryBuilderAddress {
2526

2627
public AddressCommand(String ip, String port, String login, String password) {
2728
initialize(ip, port, login, password);
2829
}
2930

31+
/**
32+
* Creates public/private key pairs. These key pairs are not stored in the
33+
* wallet.
34+
*
35+
* Arguments: 1. count (number, optional, default=1) Number of pairs to
36+
* create.
37+
*
38+
* Result: [ (json array of ) { "address" : "address", (string)
39+
* Pay-to-pubkeyhash address "pubkey" : "pubkey", (string) Public key
40+
* (hexadecimal) "privkey" : "privatekey", (string) Private key,
41+
* base58-encoded as required for signrawtransaction } ]
42+
*
43+
* @param numberOfPairs
44+
* @return
45+
* @throws MultichainException
46+
*/
47+
public List<KeyPairs> createKeyPairs() throws MultichainException {
48+
return createKeyPairs(1);
49+
}
50+
51+
/**
52+
* Creates public/private key pairs. These key pairs are not stored in the
53+
* wallet.
54+
*
55+
* Arguments: 1. count (number, optional, default=1) Number of pairs to
56+
* create.
57+
*
58+
* Result: [ (json array of ) { "address" : "address", (string)
59+
* Pay-to-pubkeyhash address "pubkey" : "pubkey", (string) Public key
60+
* (hexadecimal) "privkey" : "privatekey", (string) Private key,
61+
* base58-encoded as required for signrawtransaction } ]
62+
*
63+
* @param numberOfPairs
64+
* @return
65+
* @throws MultichainException
66+
*/
67+
public List<KeyPairs> createKeyPairs(int numberOfPairs) throws MultichainException {
68+
List<KeyPairs> listKeyPairs = new ArrayList<KeyPairs>();
69+
Object objectKeyPairs = executeCreateKeyPairs(numberOfPairs);
70+
71+
if (verifyInstance(objectKeyPairs, ArrayList.class)
72+
&& verifyInstanceofList((ArrayList<Object>) objectKeyPairs, KeyPairs.class)) {
73+
listKeyPairs = AddressFormatter.formatKeyPairsList((ArrayList<Object>) objectKeyPairs);
74+
}
75+
76+
return listKeyPairs;
77+
}
78+
3079
/**
3180
* addmultisigaddress nrequired ["key",...] ( "account" )
3281
*

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,31 @@
1212

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

19+
/**
20+
* Creates public/private key pairs. These key pairs are not stored in the
21+
* wallet.
22+
*
23+
* Arguments: 1. count (number, optional, default=1) Number of pairs to
24+
* create.
25+
*
26+
* Result: [ (json array of ) { "address" : "address", (string)
27+
* Pay-to-pubkeyhash address "pubkey" : "pubkey", (string) Public key
28+
* (hexadecimal) "privkey" : "privatekey", (string) Private key,
29+
* base58-encoded as required for signrawtransaction } ]
30+
*
31+
* @param numberOfPairs
32+
* @return
33+
* @throws MultichainException
34+
*/
35+
protected Object executeCreateKeyPairs(int numberOfPairs) throws MultichainException {
36+
MultichainTestParameter.valueIsPositive("number of pairs", numberOfPairs);
37+
return execute(CommandEnum.CREATEKEYPAIRS, numberOfPairs);
38+
}
39+
1940
/**
2041
* addmultisigaddress nrequired ["key",...] ( "account" )
2142
*
@@ -37,8 +58,8 @@ public class QueryBuilderAddress extends QueryBuilderCommon {
3758
* @return the P2SH address
3859
* @throws MultichainException
3960
*/
40-
protected Object executeAddMultiSigAddress(int numberOfSigRequired, String[] publicKeys)
41-
throws MultichainException {
61+
protected Object executeAddMultiSigAddress( int numberOfSigRequired,
62+
String[] publicKeys) throws MultichainException {
4263
MultichainTestParameter.valueIsPositive("number of signature required", numberOfSigRequired);
4364
MultichainTestParameter.isNotNullOrEmpty("publicKeys", publicKeys);
4465
MultichainTestParameter.arrayNotContainNullOrEmptyValues("publicKeys", publicKeys);

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

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
import java.util.Map;
1717
import java.util.UUID;
1818

19-
import multichain.command.MultichainException;
20-
import multichain.object.MultiChainRPCAnswer;
21-
import multichain.object.formatters.GsonFormatters;
22-
2319
import org.apache.http.HttpEntity;
2420
import org.apache.http.HttpResponse;
2521
import org.apache.http.auth.AuthScope;
@@ -37,107 +33,111 @@
3733
import com.google.gson.GsonBuilder;
3834
import com.google.gson.internal.LinkedTreeMap;
3935

36+
import multichain.command.MultichainException;
37+
import multichain.object.MultiChainRPCAnswer;
38+
import multichain.object.formatters.GsonFormatters;
39+
4040
/**
4141
* @author Ub - H. MARTEAU & Jagrut KOSTI
42-
* @version 3.1
42+
* @version 4.3
4343
*/
4444
abstract class QueryBuilderCommon extends GsonFormatters {
4545

4646
private CloseableHttpClient httpclient = null;
4747
private HttpPost httppost = null;
4848

49-
protected enum CommandEnum
50-
{
51-
ADDMULTISIGADDRESS,
52-
ADDNODE,
53-
APPENDRAWCHANGE,
54-
APPENDRAWEXCHANGE,
55-
APPENDROWMETADA,
56-
CLEARMEMPOOL,
57-
COMBINEUNPSENT,
58-
CREATE,
59-
CREATEFROM,
60-
CREATEMULTISIG,
61-
CREATERAWEXCHANGE,
62-
CREATERAWSENDFROM,
63-
CREATERAWTRANSACTION,
64-
DECODERAWEXCHANGE,
65-
DECODERAWTRANSACTION,
66-
DISABLERAWTRANSACTION,
67-
DUMPPRIVKEY,
68-
GETADDRESSBALANCES,
69-
GETADDRESSES,
70-
GETADDRESSTRANSACTION,
71-
GETASSETBALANCES,
72-
GETBESTBLOCKHASH,
73-
GETBLOCK,
74-
GETBLOCKCHAINPARAMS,
75-
GETBLOCKCOUNT,
76-
GETBLOCKHASH,
77-
GETINFO,
78-
GETMULTIBALANCES,
79-
GETNEWADDRESS,
80-
GETRAWCHANGEADDRESS,
81-
GETPEERINFO,
82-
GETRAWTRANSACTION,
83-
GETSTREAMITEM,
84-
GETTOTALBALANCES,
85-
GETTRANSACTION,
86-
GETTXOUT,
87-
GETTXOUTDATA,
88-
GETUNCONFIRMEDBALANCE,
89-
GETWALLETTRANSACTION,
90-
GRANT,
91-
GRANTFROM,
92-
GRANTWITHMETADATA,
93-
GRANTWITHMETADATAFROM,
94-
HELP,
95-
IMPORTADDRESS,
96-
IMPORTPRIVKEY,
97-
ISSUE,
98-
ISSUEFROM,
99-
ISSUEMORE,
100-
ISSUEMOREFROM,
101-
LISTADDRESSTRANSACTIONS,
102-
LISTASSETS,
103-
LISTLOCKUNPSENT,
104-
LISTPERMISSIONS,
105-
LISTSTREAMITEMS,
106-
LISTSTREAMKEYITEMS,
107-
LISTSTREAMKEYS,
108-
LISTSTREAMPUBLISHERS,
109-
LISTSTREAMPUBLISHERITEMS,
110-
LISTSTREAMS,
111-
LISTUNSPENT,
112-
LISTWALLETTRANSACTIONS,
113-
LOCKUNSPENT,
114-
PAUSE,
115-
PING,
116-
PREPARELOCKUNSPENT,
117-
PREPARELOCKUNSPENTFROM,
118-
PUBLISH,
119-
PUBLISHFROM,
120-
RESUME,
121-
REVOKE,
122-
REVOKEFROM,
123-
SENDASSETFROM,
124-
SENDASSETTOADDRESS,
125-
SENDFROM,
126-
SENDFROMADDRESS,
127-
SENDRAWTRANSACTION,
128-
SENDTOADDRESS,
129-
SENDWITHMETADATA,
130-
SENDWITHMETADATAFROM,
131-
SETLASTBLOCK,
132-
SIGNMESSAGE,
133-
SIGNRAWTRANSACTION,
134-
STOP,
135-
SUBSCRIBE,
136-
UNSUBSCRIBE,
137-
VALIDATEADDRESS,
138-
VERIFYMESSAGE,
139-
SENDWITHDATA,
140-
SENDWITHDATAFROM
49+
protected enum CommandEnum {
50+
ADDMULTISIGADDRESS,
51+
ADDNODE,
52+
APPENDRAWCHANGE,
53+
APPENDRAWEXCHANGE,
54+
APPENDROWMETADA,
55+
CLEARMEMPOOL,
56+
COMBINEUNPSENT,
57+
CREATE,
58+
CREATEFROM,
59+
CREATEKEYPAIRS,
60+
CREATEMULTISIG,
61+
CREATERAWEXCHANGE,
62+
CREATERAWSENDFROM,
63+
CREATERAWTRANSACTION,
64+
DECODERAWEXCHANGE,
65+
DECODERAWTRANSACTION,
66+
DISABLERAWTRANSACTION,
67+
DUMPPRIVKEY,
68+
GETADDRESSBALANCES,
69+
GETADDRESSES,
70+
GETADDRESSTRANSACTION,
71+
GETASSETBALANCES,
72+
GETBESTBLOCKHASH,
73+
GETBLOCK,
74+
GETBLOCKCHAINPARAMS,
75+
GETBLOCKCOUNT,
76+
GETBLOCKHASH,
77+
GETINFO,
78+
GETMULTIBALANCES,
79+
GETNEWADDRESS,
80+
GETRAWCHANGEADDRESS,
81+
GETPEERINFO,
82+
GETRAWTRANSACTION,
83+
GETSTREAMITEM,
84+
GETTOTALBALANCES,
85+
GETTRANSACTION,
86+
GETTXOUT,
87+
GETTXOUTDATA,
88+
GETUNCONFIRMEDBALANCE,
89+
GETWALLETTRANSACTION,
90+
GRANT,
91+
GRANTFROM,
92+
GRANTWITHMETADATA,
93+
GRANTWITHMETADATAFROM,
94+
HELP,
95+
IMPORTADDRESS,
96+
IMPORTPRIVKEY,
97+
ISSUE,
98+
ISSUEFROM,
99+
ISSUEMORE,
100+
ISSUEMOREFROM,
101+
LISTADDRESSTRANSACTIONS,
102+
LISTASSETS,
103+
LISTLOCKUNPSENT,
104+
LISTPERMISSIONS,
105+
LISTSTREAMITEMS,
106+
LISTSTREAMKEYITEMS,
107+
LISTSTREAMKEYS,
108+
LISTSTREAMPUBLISHERS,
109+
LISTSTREAMPUBLISHERITEMS,
110+
LISTSTREAMS,
111+
LISTUNSPENT,
112+
LISTWALLETTRANSACTIONS,
113+
LOCKUNSPENT,
114+
PAUSE,
115+
PING,
116+
PREPARELOCKUNSPENT,
117+
PREPARELOCKUNSPENTFROM,
118+
PUBLISH,
119+
PUBLISHFROM,
120+
RESUME,
121+
REVOKE,
122+
REVOKEFROM,
123+
SENDASSETFROM,
124+
SENDASSETTOADDRESS,
125+
SENDFROM,
126+
SENDFROMADDRESS,
127+
SENDRAWTRANSACTION,
128+
SENDTOADDRESS,
129+
SENDWITHMETADATA,
130+
SENDWITHMETADATAFROM,
131+
SETLASTBLOCK,
132+
SIGNMESSAGE,
133+
SIGNRAWTRANSACTION,
134+
STOP,
135+
SUBSCRIBE,
136+
UNSUBSCRIBE,
137+
VALIDATEADDRESS,
138+
VERIFYMESSAGE,
139+
SENDWITHDATA,
140+
SENDWITHDATAFROM
141141
}
142142

143143
protected void initialize(String ip, String port, String login, String password) {
@@ -158,7 +158,7 @@ protected void initialize(String ip, String port, String login, String password)
158158
*
159159
* @return
160160
*
161-
* example :
161+
* example :
162162
* MultichainQueryBuidlder.executeProcess(MultichainCommand
163163
* .SENDTOADDRESS,"1EyXuq2JVrj4E3CpM9iNGNSqBpZ2iTPdwGKgvf
164164
* {\"rdcoin\":0.01}"

0 commit comments

Comments
 (0)