Renaming 'GetAccountNameById' to 'GetAccounts' to better reflect the underlying API call used
This commit is contained in:
parent
4e2601e80f
commit
dcd8717bd0
7 changed files with 140 additions and 28 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -77,3 +77,5 @@ atlassian-ide-plugin.xml
|
||||||
/*.log
|
/*.log
|
||||||
|
|
||||||
src/main/java/com/luminiasoft/bitshares/mycelium/*
|
src/main/java/com/luminiasoft/bitshares/mycelium/*
|
||||||
|
|
||||||
|
bts_bilthon_20161218.bin
|
||||||
|
|
|
@ -10,10 +10,10 @@ public class RPC {
|
||||||
public static final String CALL_HISTORY = "history";
|
public static final String CALL_HISTORY = "history";
|
||||||
public static final String CALL_DATABASE = "database";
|
public static final String CALL_DATABASE = "database";
|
||||||
public static final String CALL_GET_ACCOUNT_BY_NAME = "get_account_by_name";
|
public static final String CALL_GET_ACCOUNT_BY_NAME = "get_account_by_name";
|
||||||
|
public static final String CALL_GET_ACCOUNTS = "get_accounts";
|
||||||
public static final String CALL_GET_DYNAMIC_GLOBAL_PROPERTIES = "get_dynamic_global_properties";
|
public static final String CALL_GET_DYNAMIC_GLOBAL_PROPERTIES = "get_dynamic_global_properties";
|
||||||
public static final String CALL_BROADCAST_TRANSACTION = "broadcast_transaction";
|
public static final String CALL_BROADCAST_TRANSACTION = "broadcast_transaction";
|
||||||
public static final String CALL_GET_REQUIRED_FEES = "get_required_fees";
|
public static final String CALL_GET_REQUIRED_FEES = "get_required_fees";
|
||||||
public static final String CALL_GET_ACCOUNTS = "get_accounts";
|
|
||||||
public static final String CALL_GET_KEY_REFERENCES = "get_key_references";
|
public static final String CALL_GET_KEY_REFERENCES = "get_key_references";
|
||||||
public static final String CALL_GET_RELATIVE_ACCOUNT_HISTORY = "get_relative_account_history";
|
public static final String CALL_GET_RELATIVE_ACCOUNT_HISTORY = "get_relative_account_history";
|
||||||
public static final String CALL_LOOKUP_ACCOUNTS = "lookup_accounts";
|
public static final String CALL_LOOKUP_ACCOUNTS = "lookup_accounts";
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -39,12 +39,14 @@ public class GetAccountByName extends WebSocketAdapter {
|
||||||
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
||||||
ArrayList<Serializable> accountParams = new ArrayList<>();
|
ArrayList<Serializable> accountParams = new ArrayList<>();
|
||||||
accountParams.add(this.accountName);
|
accountParams.add(this.accountName);
|
||||||
ApiCall getAccountByName = new ApiCall(0, RPC.CALL_GET_ACCOUNT_BY_NAME, accountParams, "2.0", 1);
|
ApiCall getAccountByName = new ApiCall(0, RPC.CALL_GET_ACCOUNT_BY_NAME, accountParams, RPC.VERSION, 1);
|
||||||
websocket.sendText(getAccountByName.toJsonString());
|
websocket.sendText(getAccountByName.toJsonString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
||||||
|
if(frame.isTextFrame())
|
||||||
|
System.out.println("<<< "+frame.getPayloadText());
|
||||||
String response = frame.getPayloadText();
|
String response = frame.getPayloadText();
|
||||||
GsonBuilder builder = new GsonBuilder();
|
GsonBuilder builder = new GsonBuilder();
|
||||||
|
|
||||||
|
@ -62,6 +64,14 @@ public class GetAccountByName extends WebSocketAdapter {
|
||||||
websocket.disconnect();
|
websocket.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
||||||
|
if(frame.isTextFrame()){
|
||||||
|
System.out.println(">>> "+frame.getPayloadText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
|
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
|
||||||
mListener.onError(new BaseResponse.Error(cause.getMessage()));
|
mListener.onError(new BaseResponse.Error(cause.getMessage()));
|
||||||
|
|
|
@ -29,35 +29,35 @@ import java.util.Map;
|
||||||
*
|
*
|
||||||
* @author henry
|
* @author henry
|
||||||
*/
|
*/
|
||||||
public class GetAccountNameById extends WebSocketAdapter {
|
public class GetAccounts extends WebSocketAdapter {
|
||||||
|
|
||||||
private String accountId;
|
private String accountId;
|
||||||
private List<UserAccount> userAccounts;
|
private List<UserAccount> userAccounts;
|
||||||
private WitnessResponseListener mListener;
|
private WitnessResponseListener mListener;
|
||||||
|
|
||||||
public GetAccountNameById(String accountId, WitnessResponseListener listener){
|
public GetAccounts(String accountId, WitnessResponseListener listener){
|
||||||
this.accountId = accountId;
|
this.accountId = accountId;
|
||||||
this.mListener = listener;
|
this.mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetAccountNameById(List<UserAccount> accounts, WitnessResponseListener listener){
|
public GetAccounts(List<UserAccount> accounts, WitnessResponseListener listener){
|
||||||
this.userAccounts = accounts;
|
this.userAccounts = accounts;
|
||||||
this.mListener = listener;
|
this.mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
||||||
ArrayList<Serializable> accountParams = new ArrayList();
|
ArrayList<Serializable> params = new ArrayList();
|
||||||
ArrayList<Serializable> paramAddress = new ArrayList();
|
ArrayList<Serializable> accountIds = new ArrayList();
|
||||||
if(accountId == null){
|
if(accountId == null){
|
||||||
for(UserAccount account : userAccounts) {
|
for(UserAccount account : userAccounts) {
|
||||||
paramAddress.add(account.getObjectId());
|
accountIds.add(account.getObjectId());
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
paramAddress.add(accountId);
|
accountIds.add(accountId);
|
||||||
}
|
}
|
||||||
accountParams.add(paramAddress);
|
params.add(accountIds);
|
||||||
ApiCall getAccountByAddress = new ApiCall(0, RPC.CALL_GET_ACCOUNTS, accountParams, RPC.VERSION, 1);
|
ApiCall getAccountByAddress = new ApiCall(0, RPC.CALL_GET_ACCOUNTS, params, RPC.VERSION, 1);
|
||||||
websocket.sendText(getAccountByAddress.toJsonString());
|
websocket.sendText(getAccountByAddress.toJsonString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package de.bitsharesmunich.graphenej;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.InputMismatchException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nelson on 12/16/16.
|
||||||
|
*/
|
||||||
|
public class AuthorityTest {
|
||||||
|
private Authority authority;
|
||||||
|
private Authority sameAuthority;
|
||||||
|
private Authority differentAuthority;
|
||||||
|
private Authority keyAuthority1;
|
||||||
|
private Authority keyAuthority2;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
authority = new Authority();
|
||||||
|
sameAuthority = new Authority();
|
||||||
|
HashMap<UserAccount, Integer> accountAuthorityMap = new HashMap<>();
|
||||||
|
UserAccount userAccount = new UserAccount("1.2.20000");
|
||||||
|
accountAuthorityMap.put(userAccount, 1);
|
||||||
|
differentAuthority = new Authority(1, null, accountAuthorityMap);
|
||||||
|
|
||||||
|
Address address1 = new Address("BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYhnY");
|
||||||
|
Address address2 = new Address("BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYhnY");
|
||||||
|
PublicKey publicKey = address1.getPublicKey();
|
||||||
|
PublicKey samePublicKey = address2.getPublicKey();
|
||||||
|
HashMap<PublicKey, Integer> keyMap1 = new HashMap<>();
|
||||||
|
HashMap<PublicKey, Integer> keyMap2 = new HashMap<>();
|
||||||
|
keyMap1.put(publicKey, 1);
|
||||||
|
keyMap2.put(samePublicKey, 1);
|
||||||
|
keyAuthority1 = new Authority(1, keyMap1, null);
|
||||||
|
keyAuthority2 = new Authority(1, keyMap2, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.junit.Test
|
||||||
|
public void toBytes() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equals() throws Exception {
|
||||||
|
assertEquals("Equal authorities", authority, sameAuthority);
|
||||||
|
assertEquals("Different authorities ", authority, differentAuthority);
|
||||||
|
assertEquals("Two public keys with the same public key should be equal", keyAuthority1, keyAuthority2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown(){
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package de.bitsharesmunich.graphenej;
|
||||||
|
|
||||||
|
import org.bitcoinj.core.*;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nelson on 12/16/16.
|
||||||
|
*/
|
||||||
|
public class PublicKeyTest {
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
@org.junit.Test
|
||||||
|
public void equals() throws Exception {
|
||||||
|
Address address1 = new Address("BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYhnY");
|
||||||
|
Address address2 = new Address("BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYhnY");
|
||||||
|
Address address3 = new Address("BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYp00");
|
||||||
|
PublicKey pk1 = address1.getPublicKey();
|
||||||
|
PublicKey pk2 = address2.getPublicKey();
|
||||||
|
PublicKey pk3 = address3.getPublicKey();
|
||||||
|
assertEquals("Public keys must be equal", pk1, pk2);
|
||||||
|
assertNotEquals("Public keys must not be equal", pk1, pk3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue