Skip to content

Commit

Permalink
Merge pull request hyperledger-web3j#407 from p-s-dev/master
Browse files Browse the repository at this point in the history
add rpc:parity_listAccounts which "Returns all addresses if Fat DB is…
  • Loading branch information
conor10 authored Apr 3, 2018
2 parents cceab3b + b9a5540 commit dbc75e0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class JsonRpc2_0Parity extends JsonRpc2_0Admin implements Parity {
public JsonRpc2_0Parity(Web3jService web3jService) {
super(web3jService);
}

@Override
public Request<?, ParityAllAccountsInfo> parityAllAccountsInfo() {
return new Request<>(
Expand Down Expand Up @@ -144,6 +144,24 @@ public Request<?, BooleanResponse> parityKillAccount(String accountId, String pa
BooleanResponse.class);
}

@Override
public Request<?, ParityAddressesResponse> parityListAccounts(
BigInteger quantity, String accountId, DefaultBlockParameter blockParameter) {
if (blockParameter == null) {
return new Request<>(
"parity_listAccounts",
Arrays.asList(quantity, accountId),
web3jService,
ParityAddressesResponse.class);
} else {
return new Request<>(
"parity_listAccounts",
Arrays.asList(quantity, accountId, blockParameter),
web3jService,
ParityAddressesResponse.class);
}
}

@Override
public Request<?, ParityAddressesResponse> parityListGethAccounts() {
return new Request<>(
Expand Down
9 changes: 7 additions & 2 deletions parity/src/main/java/org/web3j/protocol/parity/Parity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.web3j.protocol.parity;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -10,6 +11,7 @@
import org.web3j.protocol.admin.methods.response.BooleanResponse;
import org.web3j.protocol.admin.methods.response.NewAccountIdentifier;
import org.web3j.protocol.admin.methods.response.PersonalSign;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.parity.methods.request.Derivation;
import org.web3j.protocol.parity.methods.response.ParityAddressesResponse;
Expand All @@ -26,7 +28,7 @@ public interface Parity extends Admin, Trace {
static Parity build(Web3jService web3jService) {
return new JsonRpc2_0Parity(web3jService);
}

Request<?, ParityAllAccountsInfo> parityAllAccountsInfo();

Request<?, BooleanResponse> parityChangePassword(
Expand All @@ -51,7 +53,10 @@ Request<?, ParityDeriveAddress> parityDeriveAddressIndex(
Request<?, ParityAddressesResponse> parityImportGethAccounts(ArrayList<String> gethAddresses);

Request<?, BooleanResponse> parityKillAccount(String accountId, String password);


Request<?, ParityAddressesResponse> parityListAccounts(
BigInteger quantity, String accountId, DefaultBlockParameter blockParameter);

Request<?, ParityAddressesResponse> parityListGethAccounts();

Request<?, ParityListRecentDapps> parityListRecentDapps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.web3j.protocol.core.Response;

/**
* parity_listAccounts
* parity_getGetDappAddresses
* parity_getGetNewDappsAddresses
* parity_importGethAccounts
Expand Down
50 changes: 48 additions & 2 deletions parity/src/test/java/org/web3j/protocol/parity/RequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

import org.web3j.crypto.WalletFile;
import org.web3j.protocol.RequestTester;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.DefaultBlockParameterNumber;
import org.web3j.protocol.core.methods.request.Transaction;
import org.web3j.protocol.http.HttpService;
import org.web3j.protocol.parity.methods.request.Derivation;
Expand All @@ -27,7 +29,7 @@ public class RequestTest extends RequestTester {
protected void initWeb3Client(HttpService httpService) {
web3j = Parity.build(httpService);
}

@Test
public void testParityAllAccountsInfo() throws Exception {
web3j.parityAllAccountsInfo().send();
Expand Down Expand Up @@ -133,7 +135,51 @@ public void testParityKillAccount() throws Exception {
+ "\"params\":[\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\"hunter2\"],\"id\":1}");
//CHECKSTYLE:ON
}


@Test
public void testParityListAccountsNoAccountOffsetNoBlockTag() throws Exception {
BigInteger maxQuantityReturned = BigInteger.valueOf(100);
web3j.parityListAccounts(maxQuantityReturned, null, null).send();

verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"parity_listAccounts\","
+ "\"params\":[100,null],\"id\":1}");
}

@Test
public void testParityListAccountsNoAccountOffsetWithBlockTag() throws Exception {
BigInteger maxQuantityReturned = BigInteger.valueOf(100);
DefaultBlockParameter blockParameter = new DefaultBlockParameterNumber(BigInteger.ONE);
web3j.parityListAccounts(maxQuantityReturned, null, blockParameter).send();

verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"parity_listAccounts\","
+ "\"params\":[100,null,\"0x1\"],\"id\":1}");
}

@Test
public void testParityListAccountsWithAccountOffsetWithBlockTag() throws Exception {
BigInteger maxQuantityReturned = BigInteger.valueOf(100);
DefaultBlockParameter blockParameter = DefaultBlockParameterName.LATEST;
web3j.parityListAccounts(maxQuantityReturned,
"0x407d73d8a49eeb85d32cf465507dd71d507100c1", blockParameter).send();

//CHECKSTYLE:OFF
verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"parity_listAccounts\","
+ "\"params\":[100,\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\"latest\"],\"id\":1}");
//CHECKSTYLE:ON
}

@Test
public void testParityListAccountsWithAccountOffsetNoBlockTag() throws Exception {
BigInteger maxQuantityReturned = BigInteger.valueOf(100);
web3j.parityListAccounts(maxQuantityReturned,
"0x407d73d8a49eeb85d32cf465507dd71d507100c1", null).send();

//CHECKSTYLE:OFF
verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"parity_listAccounts\","
+ "\"params\":[100,\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\"],\"id\":1}");
//CHECKSTYLE:ON
}

public void testParityListGethAccounts() throws Exception {
web3j.parityListGethAccounts().send();

Expand Down

0 comments on commit dbc75e0

Please sign in to comment.