diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Authority.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/Authority.java
index 54279f5..2224225 100644
--- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Authority.java
+++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/Authority.java
@@ -1,15 +1,25 @@
package de.bitsharesmunich.graphenej;
import com.google.common.primitives.Bytes;
-import com.google.gson.*;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
import de.bitsharesmunich.graphenej.errors.MalformedAddressException;
import de.bitsharesmunich.graphenej.interfaces.GrapheneSerializable;
-import java.lang.reflect.Type;
-import java.util.*;
-
/**
- * Created by nelson on 11/30/16.
+ * Class used to represent the weighted set of keys and accounts that must approve operations.
+ *
+ * {@see Authority}
*/
public class Authority implements GrapheneSerializable {
public static final String KEY_ACCOUNT_AUTHS = "account_auths";
@@ -18,14 +28,14 @@ public class Authority implements GrapheneSerializable {
public static final String KEY_EXTENSIONS = "extensions";
private long weight_threshold;
- private HashMap account_auths;
- private HashMap key_auths;
+ private HashMap account_auths;
+ private HashMap key_auths;
private Extensions extensions;
public Authority(){
this.weight_threshold = 1;
- this.account_auths = new HashMap();
- this.key_auths = new HashMap();
+ this.account_auths = new HashMap();
+ this.key_auths = new HashMap();
extensions = new Extensions();
}
@@ -36,7 +46,7 @@ public class Authority implements GrapheneSerializable {
* @param accountAuths: Map of account to weights relationships. Can be null.
* @throws MalformedAddressException
*/
- public Authority(long weight_threshold, HashMap keyAuths, HashMap accountAuths) {
+ public Authority(long weight_threshold, HashMap keyAuths, HashMap accountAuths) {
this();
this.weight_threshold = weight_threshold;
if(keyAuths != null)
@@ -49,7 +59,7 @@ public class Authority implements GrapheneSerializable {
this.account_auths = new HashMap<>();
}
- public void setKeyAuthorities(HashMap keyAuths){
+ public void setKeyAuthorities(HashMap keyAuths){
if(keyAuths != null){
for(Address address : keyAuths.keySet()){
key_auths.put(address.getPublicKey(), keyAuths.get(address));
@@ -57,10 +67,13 @@ public class Authority implements GrapheneSerializable {
}
}
- public void setAccountAuthorities(HashMap accountAuthorities){
+ public void setAccountAuthorities(HashMap accountAuthorities){
this.account_auths = accountAuthorities;
}
+ /**
+ * @return: Returns a list of public keys linked to this authority
+ */
public List getKeyAuthList(){
ArrayList keys = new ArrayList<>();
for(PublicKey pk : key_auths.keySet()){
@@ -69,11 +82,22 @@ public class Authority implements GrapheneSerializable {
return keys;
}
- public HashMap getKeyAuths(){
+ /**
+ * @return: Returns a list of accounts linked to this authority
+ */
+ public List getAccountAuthList(){
+ ArrayList accounts = new ArrayList<>();
+ for(UserAccount account : account_auths.keySet()){
+ accounts.add(account);
+ }
+ return accounts;
+ }
+
+ public HashMap getKeyAuths(){
return this.key_auths;
}
- public HashMap getAccountAuths(){
+ public HashMap getAccountAuths(){
return this.account_auths;
}
@@ -149,8 +173,8 @@ public class Authority implements GrapheneSerializable {
@Override
public boolean equals(Object obj) {
Authority authority = (Authority) obj;
- HashMap keyAuths = authority.getKeyAuths();
- HashMap accountAuths = authority.getAccountAuths();
+ HashMap keyAuths = authority.getKeyAuths();
+ HashMap accountAuths = authority.getAccountAuths();
System.out.println("key auths match: "+this.key_auths.equals(keyAuths));
System.out.println("account auths match: "+this.account_auths.equals(accountAuths));
System.out.println("weight threshold matches: "+(this.weight_threshold == authority.weight_threshold));
@@ -179,12 +203,12 @@ public class Authority implements GrapheneSerializable {
long weightThreshold = baseObject.get(KEY_WEIGHT_THRESHOLD).getAsLong();
JsonArray keyAuthArray = baseObject.getAsJsonArray(KEY_KEY_AUTHS);
JsonArray accountAuthArray = baseObject.getAsJsonArray(KEY_ACCOUNT_AUTHS);
- HashMap keyAuthMap = new HashMap<>();
- HashMap accountAuthMap = new HashMap<>();
+ HashMap keyAuthMap = new HashMap<>();
+ HashMap accountAuthMap = new HashMap<>();
for(int i = 0; i < keyAuthArray.size(); i++){
JsonArray subArray = keyAuthArray.get(i).getAsJsonArray();
String addr = subArray.get(0).getAsString();
- int weight = subArray.get(1).getAsInt();
+ long weight = subArray.get(1).getAsLong();
try {
keyAuthMap.put(new Address(addr).getPublicKey(), weight);
} catch (MalformedAddressException e) {
@@ -192,7 +216,11 @@ public class Authority implements GrapheneSerializable {
}
}
for(int i = 0; i < accountAuthArray.size(); i++){
- //TODO: Implement this
+ JsonArray subArray = accountAuthArray.get(i).getAsJsonArray();
+ String userId = subArray.get(0).getAsString();
+ long weight = subArray.get(1).getAsLong();
+ UserAccount userAccount = new UserAccount(userId);
+ accountAuthMap.put(userAccount, weight);
}
return new Authority(weightThreshold, keyAuthMap, accountAuthMap);
}
diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/AuthorityTest.java b/graphenej/src/test/java/de/bitsharesmunich/graphenej/AuthorityTest.java
index cc9846d..eb34c17 100644
--- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/AuthorityTest.java
+++ b/graphenej/src/test/java/de/bitsharesmunich/graphenej/AuthorityTest.java
@@ -1,15 +1,12 @@
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.
@@ -25,19 +22,19 @@ public class AuthorityTest {
public void setUp() throws Exception {
authority = new Authority();
sameAuthority = new Authority();
- HashMap accountAuthorityMap = new HashMap<>();
+ HashMap accountAuthorityMap = new HashMap<>();
UserAccount userAccount = new UserAccount("1.2.20000");
- accountAuthorityMap.put(userAccount, 1);
+ accountAuthorityMap.put(userAccount, 1l);
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 keyMap1 = new HashMap<>();
- HashMap keyMap2 = new HashMap<>();
- keyMap1.put(publicKey, 1);
- keyMap2.put(samePublicKey, 1);
+ HashMap keyMap1 = new HashMap<>();
+ HashMap keyMap2 = new HashMap<>();
+ keyMap1.put(publicKey, 1l);
+ keyMap2.put(samePublicKey, 1l);
keyAuthority1 = new Authority(1, keyMap1, null);
keyAuthority2 = new Authority(1, keyMap2, null);
diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetObjectsTest.java b/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetObjectsTest.java
index 3db0618..2e36a17 100644
--- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetObjectsTest.java
+++ b/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetObjectsTest.java
@@ -25,6 +25,7 @@ import de.bitsharesmunich.graphenej.models.WitnessResponse;
public class GetObjectsTest extends BaseApiTest{
private final Asset asset = new Asset("1.3.0", "BTS", 5);
private final UserAccount account = new UserAccount("1.2.116354");
+ private final UserAccount bilthon_25 = new UserAccount("1.2.151069");
private final String bitAssetId = "2.4.13";
@Test
@@ -68,7 +69,7 @@ public class GetObjectsTest extends BaseApiTest{
public void testGetAccount(){
try{
ArrayList ids = new ArrayList<>();
- ids.add(account.getObjectId());
+ ids.add(bilthon_25.getObjectId());
mWebSocket.addListener(new GetObjects(ids, new WitnessResponseListener() {
@Override
@@ -76,10 +77,11 @@ public class GetObjectsTest extends BaseApiTest{
System.out.println("onSuccess");
List result = (List) response.result;
UserAccount userAccount = (UserAccount) result.get(0);
- System.out.println("Account name: "+userAccount.getName());
- System.out.println("json string: "+userAccount.toJsonString());
- System.out.println("owner: "+userAccount.getOwner().getKeyAuthList().get(0).getAddress());
- System.out.println("active: "+userAccount.getActive().getKeyAuthList().get(0).getAddress());
+ System.out.println("Account name.....: "+userAccount.getName());
+ System.out.println("json string......: "+userAccount.toJsonString());
+ System.out.println("owner............: "+userAccount.getOwner().getKeyAuthList().get(0).getAddress());
+ System.out.println("active key.......: "+userAccount.getActive().getKeyAuthList().get(0).getAddress());
+ System.out.println("active account...: "+userAccount.getActive().getAccountAuthList().get(0).getObjectId());
System.out.println("memo: "+userAccount.getOptions().getMemoKey().getAddress());
synchronized (GetObjectsTest.this){
GetObjectsTest.this.notifyAll();
diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperationTest.java b/graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperationTest.java
index 529470f..61ff0d1 100644
--- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperationTest.java
+++ b/graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperationTest.java
@@ -39,8 +39,8 @@ public class AccountUpdateOperationTest {
@Before
public void setup(){
try{
- HashMap keyAuth = new HashMap<>();
- keyAuth.put(new Address(ADDRESS), 1);
+ HashMap keyAuth = new HashMap<>();
+ keyAuth.put(new Address(ADDRESS), 1l);
active = new Authority();
active.setKeyAuthorities(keyAuth);