Skip to content

Commit cb273ce

Browse files
author
Claus Nielsen
committed
Added wrappers for bitcoind methods getwork, keypoolrefill, listaccounts and listaddressgroupings.
1 parent 90ea964 commit cb273ce

22 files changed

+570
-29
lines changed

src/main/java/dk/clanie/bitcoin/client/BitcoindClient.java

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@
5252
import dk.clanie.bitcoin.client.response.GetTransactionResponse;
5353
import dk.clanie.bitcoin.client.response.GetTxOutResponse;
5454
import dk.clanie.bitcoin.client.response.GetTxOutSetInfoResponse;
55+
import dk.clanie.bitcoin.client.response.GetWorkResponse;
5556
import dk.clanie.bitcoin.client.response.IntegerResponse;
57+
import dk.clanie.bitcoin.client.response.ListAccountsResponse;
58+
import dk.clanie.bitcoin.client.response.ListAddressGroupingsResponse;
5659
import dk.clanie.bitcoin.client.response.ListReceivedByAccountResponse;
5760
import dk.clanie.bitcoin.client.response.ListReceivedByAddressResponse;
5861
import dk.clanie.bitcoin.client.response.ListUnspentResponse;
@@ -294,7 +297,7 @@ public StringResponse getAccountAddress(String account) {
294297
*/
295298
public GetAddedNodeInfoResponse getAddedNodeInfo(Boolean dns, String node) {
296299
// TODO When calling with dns=false an object is returned; when calling with dns=true an array is returned.
297-
// TODO Currently only the array case (dns=true) is handled - see https://github.com/bitcoin/bitcoin/issues/2467
300+
// TODO Currently only the array case (dns=true) is handled - see https://github.com/bitcoin/bitcoin/issues/2467
298301
// TODO If bitcoind isn't changed (bug 2467) implement special serialization of the response in _GetAddedNodeInfoResponse_dnsArgFalse.json
299302
List<Object> params = newArrayList();
300303
params.add(dns);
@@ -605,7 +608,28 @@ public GetTxOutSetInfoResponse getTxOutSetInfo() {
605608
}
606609

607610

608-
// TODO getwork [data] If [data] is not specified, returns formatted hash data to work on:
611+
/**
612+
* Returns formatted hash data to work on.
613+
*
614+
* @return {@link GetWorkResponse} - true if succesfull.
615+
*/
616+
public GetWorkResponse getWork() {
617+
return jsonRpc("getwork", EMPTY_LIST, GetWorkResponse.class);
618+
}
619+
620+
621+
/**
622+
* Tries to solve the block.
623+
*
624+
* @param data
625+
* - block data
626+
* @return {@link BooleanResponse} - true if succesfull.
627+
*/
628+
public BooleanResponse getWork(String data) {
629+
List<Object> params = newArrayList();
630+
params.add(data);
631+
return jsonRpc("getwork", params, BooleanResponse.class);
632+
}
609633

610634

611635
/**
@@ -644,9 +668,47 @@ public VoidResponse importPrivateKey(String key, String label, Boolean rescan) {
644668
}
645669

646670

647-
// TODO keypoolrefill Fills the keypool, requires wallet passphrase to be set. Y
648-
// TODO listaccounts [minconf=1] Returns Object that has account names as keys, account balances as values. N
649-
// TODO listaddressgroupings version 0.7 Returns all addresses in the wallet and info used for coincontrol. N
671+
/**
672+
* Fills the keypool.
673+
* <p>
674+
* Requires unlocked wallet.
675+
*
676+
* @return {@link VoidResponse}
677+
*/
678+
public VoidResponse keyPoolRefill() {
679+
return jsonRpc("keypoolrefill", EMPTY_LIST, VoidResponse.class);
680+
}
681+
682+
683+
/**
684+
* Returns account names and balances.
685+
*
686+
* @param minConf
687+
* - minimum number of confirmations for included transactions,
688+
* default 1.
689+
* @return {@link ListAccountsResponse}
690+
*/
691+
public ListAccountsResponse listAccounts(Integer minConf) {
692+
List<Object> params = newArrayList();
693+
params.add(firstNotNull(minConf, 1));
694+
return jsonRpc("listaccounts", params, ListAccountsResponse.class);
695+
}
696+
697+
698+
/**
699+
* Lists groups of addresses which have had their common ownership made
700+
* public by common use as inputs or as the resulting change in past
701+
* transactions.
702+
*
703+
* @return {@link ListAddressGroupingsResponse}
704+
*
705+
* @since bitcoind 0.7
706+
*/
707+
public ListAddressGroupingsResponse listAddressGroupings() {
708+
return jsonRpc("listaddressgroupings", EMPTY_LIST, ListAddressGroupingsResponse.class);
709+
}
710+
711+
650712
// TODO listlockunspent version 0.8 Returns list of temporarily unspendable outputs
651713

652714

src/main/java/dk/clanie/bitcoin/client/response/JsonObject.java renamed to src/main/java/dk/clanie/bitcoin/client/response/AnyJsonObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
* @author Claus Nielsen
2626
*/
2727
@SuppressWarnings("serial")
28-
public class JsonObject extends JsonExtra {
28+
public class AnyJsonObject extends JsonExtra {
2929

3030
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright (C) 2013, Claus Nielsen, cn@cn-consult.dk
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program; if not, write to the Free Software Foundation, Inc.,
16+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
*/
18+
package dk.clanie.bitcoin.client.response;
19+
20+
import java.math.BigDecimal;
21+
22+
import org.springframework.roo.addon.javabean.RooJavaBean;
23+
24+
import dk.clanie.core.BaseClass;
25+
26+
/**
27+
* Amount and account.
28+
*
29+
* @author Claus Nielsen
30+
*/
31+
@SuppressWarnings("serial")
32+
@RooJavaBean(settersByDefault = false)
33+
public class BalanceAndAccount extends BaseClass {
34+
35+
/**
36+
* Amount.
37+
*/
38+
private BigDecimal amount;
39+
40+
/**
41+
* Account.
42+
*/
43+
private String account;
44+
45+
/**
46+
* Full constructor.
47+
*
48+
* @param amount
49+
* - address balance
50+
* @param account
51+
* - ccount, if any (may be null)
52+
*/
53+
public BalanceAndAccount(BigDecimal amount, String account) {
54+
this.amount = amount;
55+
this.account = account;
56+
}
57+
58+
59+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
2+
// You may push code into the target .java compilation unit if you wish to edit any member(s).
3+
4+
package dk.clanie.bitcoin.client.response;
5+
6+
import dk.clanie.bitcoin.client.response.BalanceAndAccount;
7+
import java.math.BigDecimal;
8+
9+
privileged aspect BalanceAndAccount_Roo_JavaBean {
10+
11+
public BigDecimal BalanceAndAccount.getAmount() {
12+
return this.amount;
13+
}
14+
15+
public String BalanceAndAccount.getAccount() {
16+
return this.account;
17+
}
18+
19+
}

src/main/java/dk/clanie/bitcoin/client/response/GetBlockTemplateResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class GetBlockTemplateResult extends JsonExtra {
7878
*/
7979
@JsonProperty("coinbaseaux")
8080
@JsonInclude(Include.NON_EMPTY)
81-
private JsonObject coinBaseAux;
81+
private AnyJsonObject coinBaseAux;
8282

8383
/**
8484
* Information for coinbase transaction.

src/main/java/dk/clanie/bitcoin/client/response/GetBlockTemplateResult_Roo_JavaBean.aj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
package dk.clanie.bitcoin.client.response;
55

66
import dk.clanie.bitcoin.client.Transaction;
7+
import dk.clanie.bitcoin.client.response.AnyJsonObject;
78
import dk.clanie.bitcoin.client.response.GetBlockTemplateResult;
8-
import dk.clanie.bitcoin.client.response.JsonObject;
99
import java.util.Date;
1010

1111
privileged aspect GetBlockTemplateResult_Roo_JavaBean {
@@ -22,7 +22,7 @@ privileged aspect GetBlockTemplateResult_Roo_JavaBean {
2222
return this.transactions;
2323
}
2424

25-
public JsonObject GetBlockTemplateResult.getCoinBaseAux() {
25+
public AnyJsonObject GetBlockTemplateResult.getCoinBaseAux() {
2626
return this.coinBaseAux;
2727
}
2828

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (C) 2013, Claus Nielsen, cn@cn-consult.dk
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program; if not, write to the Free Software Foundation, Inc.,
16+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
*/
18+
package dk.clanie.bitcoin.client.response;
19+
20+
import org.springframework.roo.addon.javabean.RooJavaBean;
21+
22+
/**
23+
* Response object returned by BitcoindClient's getWork method.
24+
*
25+
* @author Claus Nielsen
26+
*/
27+
@SuppressWarnings("serial")
28+
@RooJavaBean(settersByDefault = false)
29+
public class GetWorkResponse extends BitcoindJsonRpcResponse<GetWorkResult> {
30+
31+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright (C) 2013, Claus Nielsen, cn@cn-consult.dk
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program; if not, write to the Free Software Foundation, Inc.,
16+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
*/
18+
package dk.clanie.bitcoin.client.response;
19+
20+
import org.springframework.roo.addon.javabean.RooJavaBean;
21+
22+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
23+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
24+
25+
import dk.clanie.bitcoin.json.JsonExtra;
26+
27+
/**
28+
* Data returned by BitcoindClient's getWork method.
29+
*
30+
* @author Claus Nielsen
31+
*/
32+
@SuppressWarnings("serial")
33+
@RooJavaBean(settersByDefault = false)
34+
@JsonPropertyOrder({
35+
"data",
36+
"target"
37+
})
38+
@JsonIgnoreProperties({"midstate", "hash1"})
39+
public class GetWorkResult extends JsonExtra {
40+
41+
/**
42+
* Block data.
43+
*/
44+
private String data;
45+
46+
/**
47+
* Little endian hash target.
48+
*/
49+
private String target;
50+
51+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
2+
// You may push code into the target .java compilation unit if you wish to edit any member(s).
3+
4+
package dk.clanie.bitcoin.client.response;
5+
6+
import dk.clanie.bitcoin.client.response.GetWorkResult;
7+
8+
privileged aspect GetWorkResult_Roo_JavaBean {
9+
10+
public String GetWorkResult.getData() {
11+
return this.data;
12+
}
13+
14+
public String GetWorkResult.getTarget() {
15+
return this.target;
16+
}
17+
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (C) 2013, Claus Nielsen, cn@cn-consult.dk
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program; if not, write to the Free Software Foundation, Inc.,
16+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
*/
18+
package dk.clanie.bitcoin.client.response;
19+
20+
/**
21+
* Response object used for BitcoindClient's listAccounts method.
22+
*
23+
* @author Claus Nielsen
24+
*/
25+
@SuppressWarnings("serial")
26+
public class ListAccountsResponse extends BitcoindJsonRpcResponse<ListAccountsResult> {
27+
28+
}

0 commit comments

Comments
 (0)