From f93f91fc1f76154d80d74f4cc6e40ce5f5eed19b Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Sun, 18 Dec 2016 17:15:41 -0500 Subject: [PATCH 1/4] Improving the BrainKey class --- .../bitsharesmunich/graphenej/BrainKey.java | 22 ++++++++++++++++--- ...tAccountNameById.java => GetAccounts.java} | 0 2 files changed, 19 insertions(+), 3 deletions(-) rename src/main/java/de/bitsharesmunich/graphenej/api/{GetAccountNameById.java => GetAccounts.java} (100%) diff --git a/src/main/java/de/bitsharesmunich/graphenej/BrainKey.java b/src/main/java/de/bitsharesmunich/graphenej/BrainKey.java index c8f966a..4fcfdae 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/BrainKey.java +++ b/src/main/java/de/bitsharesmunich/graphenej/BrainKey.java @@ -20,11 +20,18 @@ public class BrainKey { // The size of the word dictionary public static final int DICT_WORD_COUNT = 49744; - // The required number of words + /* The required number of words */ public static final int BRAINKEY_WORD_COUNT = 12; + /* The corresponding private key derivated from the brain key */ private ECKey mPrivateKey; + /* The actual words from this brain key + the sequence number */ + private String mBrainKey; + + /* The sequence number */ + private int sequenceNumber; + /** * Method that will generate a random brain key * @@ -49,7 +56,6 @@ public class BrainKey { stringBuilder.append(word); stringBuilder.append(" "); } - System.out.println("Suggestion: '"+stringBuilder.toString().trim()+"'"); return stringBuilder.toString().trim(); } /** @@ -60,6 +66,8 @@ public class BrainKey { * @param sequence Sequence number */ public BrainKey(String words, int sequence) { + this.mBrainKey = words; + this.sequenceNumber = sequence; String encoded = String.format("%s %d", words, sequence); try { MessageDigest md = MessageDigest.getInstance("SHA-512"); @@ -100,4 +108,12 @@ public class BrainKey { DumpedPrivateKey wif = this.mPrivateKey.decompress().getPrivateKeyEncoded(NetworkParameters.fromID(NetworkParameters.ID_MAINNET)); return wif.toString(); } -} + + public String getBrainKey(){ + return mBrainKey; + } + + public int getSequenceNumber(){ + return sequenceNumber; + } +} \ No newline at end of file diff --git a/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountNameById.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java similarity index 100% rename from src/main/java/de/bitsharesmunich/graphenej/api/GetAccountNameById.java rename to src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java From 5fa4d8667f912aff327480b22e677597acedda91 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Sun, 18 Dec 2016 17:18:41 -0500 Subject: [PATCH 2/4] Implementing the equals and hashcode methods for the Authority class --- .../bitsharesmunich/graphenej/Authority.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/bitsharesmunich/graphenej/Authority.java b/src/main/java/de/bitsharesmunich/graphenej/Authority.java index da01e83..54279f5 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/Authority.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Authority.java @@ -61,7 +61,7 @@ public class Authority implements GrapheneSerializable { this.account_auths = accountAuthorities; } - public List getKeyAuths(){ + public List getKeyAuthList(){ ArrayList keys = new ArrayList<>(); for(PublicKey pk : key_auths.keySet()){ keys.add(pk); @@ -69,6 +69,14 @@ public class Authority implements GrapheneSerializable { return keys; } + public HashMap getKeyAuths(){ + return this.key_auths; + } + + public HashMap getAccountAuths(){ + return this.account_auths; + } + @Override public String toJsonString() { return null; @@ -138,6 +146,19 @@ public class Authority implements GrapheneSerializable { return Bytes.toArray(byteArray); } + @Override + public boolean equals(Object obj) { + Authority authority = (Authority) obj; + 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)); + return this.key_auths.equals(keyAuths) && + this.account_auths.equals(accountAuths) && + this.weight_threshold == authority.weight_threshold; + } + /** * Custom deserializer used while parsing the 'get_account_by_name' API call response. * From 4e2601e80f2da5a6633f15bd8fb0eff475761939 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Sun, 18 Dec 2016 17:20:05 -0500 Subject: [PATCH 3/4] Implementing equals and hashcode in PublicKey class --- .../java/de/bitsharesmunich/graphenej/PublicKey.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java b/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java index ea6bb9f..b331c3d 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java +++ b/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java @@ -39,4 +39,15 @@ public class PublicKey implements ByteSerializable { } return new Address(pk).toString(); } + + @Override + public int hashCode() { + return publicKey.hashCode(); + } + + @Override + public boolean equals(Object obj) { + PublicKey other = (PublicKey) obj; + return this.publicKey.equals(other.getKey()); + } } \ No newline at end of file From dcd8717bd090458eaa11742d7029c750cd4544e1 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Sun, 18 Dec 2016 17:21:30 -0500 Subject: [PATCH 4/4] Renaming 'GetAccountNameById' to 'GetAccounts' to better reflect the underlying API call used --- .gitignore | 2 + .../de/bitsharesmunich/graphenej/RPC.java | 2 +- .../de/bitsharesmunich/graphenej/Test.java | 40 ++++++------ .../graphenej/api/GetAccountByName.java | 12 +++- .../graphenej/api/GetAccounts.java | 18 +++--- .../graphenej/AuthorityTest.java | 61 +++++++++++++++++++ .../graphenej/PublicKeyTest.java | 33 ++++++++++ 7 files changed, 140 insertions(+), 28 deletions(-) create mode 100644 src/test/java/de/bitsharesmunich/graphenej/AuthorityTest.java create mode 100644 src/test/java/de/bitsharesmunich/graphenej/PublicKeyTest.java diff --git a/.gitignore b/.gitignore index 8afe977..44eaed5 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,5 @@ atlassian-ide-plugin.xml /*.log src/main/java/com/luminiasoft/bitshares/mycelium/* + +bts_bilthon_20161218.bin diff --git a/src/main/java/de/bitsharesmunich/graphenej/RPC.java b/src/main/java/de/bitsharesmunich/graphenej/RPC.java index e2b80ed..f45cd21 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/RPC.java +++ b/src/main/java/de/bitsharesmunich/graphenej/RPC.java @@ -10,10 +10,10 @@ public class RPC { public static final String CALL_HISTORY = "history"; 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_ACCOUNTS = "get_accounts"; 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_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_RELATIVE_ACCOUNT_HISTORY = "get_relative_account_history"; public static final String CALL_LOOKUP_ACCOUNTS = "lookup_accounts"; diff --git a/src/main/java/de/bitsharesmunich/graphenej/Test.java b/src/main/java/de/bitsharesmunich/graphenej/Test.java index 6e471a7..a6df16f 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/Test.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Test.java @@ -21,6 +21,9 @@ import org.spongycastle.crypto.digests.RIPEMD160Digest; import javax.net.ssl.SSLContext; import java.io.*; import java.lang.reflect.Type; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.security.NoSuchAlgorithmException; import java.util.*; import java.util.logging.Level; @@ -87,7 +90,7 @@ public class Test { WebSocket mWebSocket = factory.createSocket(OPENLEDGER_WITNESS_URL); ArrayList userAccounts = new ArrayList(); userAccounts.add(new UserAccount(accountId)); - mWebSocket.addListener(new GetAccountNameById(userAccounts, null)); + mWebSocket.addListener(new GetAccounts(userAccounts, null)); mWebSocket.connect(); } catch (IOException e) { System.out.println("IOException. Msg: " + e.getMessage()); @@ -381,13 +384,8 @@ public class Test { @Override public void onSuccess(WitnessResponse response) { System.out.println("onSuccess"); - WitnessResponse accountProperties = response; - System.out.println("account id: "+accountProperties.result.id); - Authority authority = accountProperties.result.active; - System.out.println("number of keys: "+authority.getKeyAuths().size()); - for(PublicKey publicKey : authority.getKeyAuths()){ - System.out.println("public key: "+publicKey.getAddress()); - } + AccountProperties accountProperties = (AccountProperties) response.result; + System.out.println("Owner and active authorities are the same: "+accountProperties.active.equals(accountProperties.owner)); } @Override @@ -461,7 +459,8 @@ public class Test { brainKey = new BrainKey(suggestion, 0); } else { System.out.println("Using brain key: " + Main.BILTHON_83_BRAIN_KEY); - brainKey = new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0); +// brainKey = new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0); + brainKey = new BrainKey("AMIDIC SKELIC CARLOAD CAPSULE FACY WONNED STICH BULBULE MESOLE SEMEED STRAVE PREBORN", 0); } ECKey key = brainKey.getPrivateKey(); System.out.println("Private key..................: " + Util.bytesToHex(key.getSecretBytes())); @@ -567,7 +566,7 @@ public class Test { WebSocket mWebSocket = factory.createSocket(BLOCK_PAY_FR); ArrayList userAccounts = new ArrayList<>(); userAccounts.add(new UserAccount("1.2.138632")); - mWebSocket.addListener(new GetAccountNameById(userAccounts, listener)); + mWebSocket.addListener(new GetAccounts(userAccounts, listener)); mWebSocket.connect(); } catch (IOException e) { System.out.println("IOException. Msg: " + e.getMessage()); @@ -628,10 +627,16 @@ public class Test { } public void testImportBinFile() { - byte inputBytes[] = new byte[]{(byte) 2, (byte) 175, (byte) 24, (byte) 227, (byte) 182, (byte) 11, (byte) 113, (byte) 151, (byte) 112, (byte) 157, (byte) 137, (byte) 157, (byte) 244, (byte) 237, (byte) 228, (byte) 92, (byte) 34, (byte) 138, (byte) 171, (byte) 248, (byte) 24, (byte) 161, (byte) 171, (byte) 75, (byte) 2, (byte) 183, (byte) 47, (byte) 213, (byte) 50, (byte) 109, (byte) 220, (byte) 6, (byte) 124, (byte) 108, (byte) 32, (byte) 164, (byte) 204, (byte) 234, (byte) 10, (byte) 12, (byte) 154, (byte) 225, (byte) 11, (byte) 178, (byte) 238, (byte) 9, (byte) 122, (byte) 244, (byte) 175, (byte) 185, (byte) 143, (byte) 27, (byte) 134, (byte) 192, (byte) 37, (byte) 239, (byte) 148, (byte) 253, (byte) 124, (byte) 68, (byte) 6, (byte) 211, (byte) 20, (byte) 224, (byte) 50, (byte) 31, (byte) 208, (byte) 87, (byte) 115, (byte) 115, (byte) 11, (byte) 81, (byte) 182, (byte) 223, (byte) 230, (byte) 102, (byte) 230, (byte) 245, (byte) 182, (byte) 77, (byte) 157, (byte) 182, (byte) 79, (byte) 247, (byte) 134, (byte) 178, (byte) 87, (byte) 93, (byte) 146, (byte) 89, (byte) 167, (byte) 191, (byte) 34, (byte) 17, (byte) 117, (byte) 173, (byte) 59, (byte) 142, (byte) 54, (byte) 120, (byte) 237, (byte) 124, (byte) 217, (byte) 252, (byte) 112, (byte) 97, (byte) 153, (byte) 124, (byte) 144, (byte) 80, (byte) 33, (byte) 130, (byte) 15, (byte) 18, (byte) 157, (byte) 98, (byte) 130, (byte) 80, (byte) 206, (byte) 27, (byte) 8, (byte) 142, (byte) 245, (byte) 22, (byte) 244, (byte) 219, (byte) 38, (byte) 228, (byte) 173, (byte) 147, (byte) 42, (byte) 100, (byte) 99, (byte) 108, (byte) 146, (byte) 110, (byte) 100, (byte) 215, (byte) 183, (byte) 20, (byte) 112, (byte) 93, (byte) 195, (byte) 12, (byte) 174, (byte) 130, (byte) 35, (byte) 71, (byte) 172, (byte) 237, (byte) 112, (byte) 197, (byte) 250, (byte) 67, (byte) 36, (byte) 185, (byte) 117, (byte) 211, (byte) 147, (byte) 21, (byte) 251, (byte) 214, (byte) 178, (byte) 152, (byte) 25, (byte) 107, (byte) 206, (byte) 184, (byte) 113, (byte) 67, (byte) 169, (byte) 55, (byte) 95, (byte) 249, (byte) 193, (byte) 215, (byte) 20, (byte) 124, (byte) 62, (byte) 179, (byte) 125, (byte) 2, (byte) 96, (byte) 46, (byte) 137, (byte) 133, (byte) 46, (byte) 37, (byte) 138, (byte) 19, (byte) 215, (byte) 2, (byte) 189, (byte) 91, (byte) 61, (byte) 119, (byte) 150, (byte) 6, (byte) 188, (byte) 220, (byte) 232, (byte) 12, (byte) 108, (byte) 128, (byte) 92, (byte) 172, (byte) 119, (byte) 138, (byte) 215, (byte) 90, (byte) 8, (byte) 56, (byte) 126, (byte) 145, (byte) 133, (byte) 193, (byte) 47, (byte) 147, (byte) 106, (byte) 219, (byte) 58, (byte) 227, (byte) 20, (byte) 60, (byte) 147, (byte) 38, (byte) 218, (byte) 17, (byte) 130, (byte) 196, (byte) 134, (byte) 105, (byte) 94, (byte) 235, (byte) 26, (byte) 245, (byte) 119, (byte) 153, (byte) 11, (byte) 29, (byte) 33, (byte) 230, (byte) 151, (byte) 149, (byte) 63, (byte) 91, (byte) 170, (byte) 75, (byte) 43, (byte) 223, (byte) 192, (byte) 104, (byte) 161, (byte) 58, (byte) 135, (byte) 226, (byte) 175, (byte) 171, (byte) 202, (byte) 113, (byte) 142, (byte) 40, (byte) 139, (byte) 240, (byte) 10, (byte) 54, (byte) 213, (byte) 55, (byte) 235, (byte) 175, (byte) 211, (byte) 193, (byte) 151, (byte) 43, (byte) 233, (byte) 81, (byte) 250, (byte) 245, (byte) 120, (byte) 211, (byte) 107, (byte) 73, (byte) 75, (byte) 74, (byte) 98, (byte) 10, (byte) 208, (byte) 68, (byte) 185, (byte) 183, (byte) 251, (byte) 193, (byte) 65, (byte) 125, (byte) 65, (byte) 52, (byte) 154, (byte) 115, (byte) 118, (byte) 217, (byte) 254, (byte) 140, (byte) 116, (byte) 124, (byte) 158, (byte) 70, (byte) 94, (byte) 28, (byte) 132, (byte) 231, (byte) 142, (byte) 209, (byte) 163, (byte) 182, (byte) 227, (byte) 129, (byte) 243, (byte) 130, (byte) 28, (byte) 238, (byte) 35, (byte) 235, (byte) 120, (byte) 199, (byte) 26, (byte) 209, (byte) 58, (byte) 181, (byte) 124, (byte) 44, (byte) 38, (byte) 132, (byte) 54, (byte) 168, (byte) 31, (byte) 150, (byte) 191, (byte) 140, (byte) 101, (byte) 141, (byte) 104, (byte) 74, (byte) 29, (byte) 76, (byte) 254, (byte) 67, (byte) 43, (byte) 123, (byte) 67, (byte) 208, (byte) 132, (byte) 61, (byte) 36, (byte) 167, (byte) 195, (byte) 231, (byte) 234, (byte) 136, (byte) 55, (byte) 97, (byte) 205, (byte) 242, (byte) 182, (byte) 237, (byte) 179, (byte) 13, (byte) 24, (byte) 249, (byte) 53, (byte) 151, (byte) 66, (byte) 252, (byte) 254, (byte) 173, (byte) 91, (byte) 52, (byte) 70, (byte) 239, (byte) 235, (byte) 94, (byte) 18, (byte) 115, (byte) 143, (byte) 134, (byte) 206, (byte) 244, (byte) 77, (byte) 247, (byte) 201, (byte) 61, (byte) 115, (byte) 78, (byte) 186, (byte) 199, (byte) 89, (byte) 144, (byte) 69, (byte) 231, (byte) 174, (byte) 2, (byte) 167, (byte) 157, (byte) 148, (byte) 88, (byte) 150, (byte) 171, (byte) 50, (byte) 82, (byte) 230, (byte) 211, (byte) 14, (byte) 55, (byte) 165, (byte) 103, (byte) 67, (byte) 172, (byte) 148, (byte) 252, (byte) 10, (byte) 104, (byte) 24, (byte) 179, (byte) 152, (byte) 156, (byte) 169, (byte) 228, (byte) 123, (byte) 205, (byte) 247, (byte) 10, (byte) 127, (byte) 106, (byte) 100, (byte) 10, (byte) 187, (byte) 81, (byte) 0, (byte) 55, (byte) 177, (byte) 60, (byte) 139, (byte) 41, (byte) 62, (byte) 163, (byte) 83, (byte) 242, (byte) 1, (byte) 122, (byte) 247, (byte) 181, (byte) 102, (byte) 218, (byte) 205, (byte) 70, (byte) 235, (byte) 147, (byte) 195, (byte) 107, (byte) 248, (byte) 139, (byte) 169, (byte) 203, (byte) 174, (byte) 22, (byte) 126, (byte) 65, (byte) 123, (byte) 14, (byte) 33, (byte) 131, (byte) 49, (byte) 6, (byte) 187, (byte) 156, (byte) 50, (byte) 92, (byte) 145, (byte) 74, (byte) 90, (byte) 132, (byte) 151, (byte) 105, (byte) 187, (byte) 195, (byte) 56, (byte) 45, (byte) 134, (byte) 204, (byte) 7, (byte) 130, (byte) 153, (byte) 209, (byte) 87, (byte) 231, (byte) 78, (byte) 90, (byte) 168, (byte) 93, (byte) 200, (byte) 149, (byte) 204, (byte) 128, (byte) 85, (byte) 17, (byte) 17, (byte) 219, (byte) 161, (byte) 167, (byte) 73, (byte) 218, (byte) 116, (byte) 233, (byte) 202, (byte) 19, (byte) 110, (byte) 95, (byte) 115, (byte) 233, (byte) 137, (byte) 85, (byte) 112, (byte) 70, (byte) 226, (byte) 217, (byte) 126, (byte) 70, (byte) 214, (byte) 47, (byte) 133, (byte) 129, (byte) 78, (byte) 127, (byte) 81, (byte) 192, (byte) 48, (byte) 91, (byte) 224, (byte) 124, (byte) 13, (byte) 176, (byte) 131, (byte) 53, (byte) 192, (byte) 92, (byte) 113, (byte) 235, (byte) 86, (byte) 38, (byte) 178, (byte) 133, (byte) 204, (byte) 110, (byte) 195, (byte) 230, (byte) 140, (byte) 213, (byte) 208, (byte) 188, (byte) 185, (byte) 37, (byte) 103, (byte) 177, (byte) 181, (byte) 120, (byte) 78, (byte) 192, (byte) 30, (byte) 224, (byte) 250, (byte) 2, (byte) 66, (byte) 76, (byte) 162, (byte) 87, (byte) 8, (byte) 131, (byte) 54, (byte) 247, (byte) 91, (byte) 9, (byte) 236, (byte) 18, (byte) 53, (byte) 11, (byte) 141, (byte) 144, (byte) 193, (byte) 139, (byte) 168, (byte) 170, (byte) 223, (byte) 190, (byte) 90, (byte) 23, (byte) 29, (byte) 177, (byte) 79, (byte) 38, (byte) 232, (byte) 148, (byte) 80, (byte) 211, (byte) 207, (byte) 201, (byte) 129, (byte) 2, (byte) 228, (byte) 86, (byte) 144, (byte) 32, (byte) 27, (byte) 235, (byte) 105, (byte) 136, (byte) 217, (byte) 195, (byte) 234, (byte) 243, (byte) 198, (byte) 87, (byte) 186, (byte) 31, (byte) 21, (byte) 144, (byte) 200, (byte) 27, (byte) 34, (byte) 82, (byte) 220, (byte) 37, (byte) 67, (byte) 44, (byte) 140, (byte) 233, (byte) 144, (byte) 218, (byte) 185, (byte) 46, (byte) 151, (byte) 96, (byte) 91}; - - System.out.println(FileBin.getBrainkeyFromByte(inputBytes, "123456")); + try { + String current = new File(".").getCanonicalPath(); + File file = new File(current + "/src/main/java/de/bitsharesmunich/graphenej/bts_bilthon_20161218.bin"); + Path path = Paths.get(file.getAbsolutePath()); + byte[] data = Files.readAllBytes(path); + System.out.println(FileBin.getBrainkeyFromByte(data, "123456")); + } catch (IOException e) { + System.out.println("IOException while trying to open bin file. Msg: "+e.getMessage()); + } } public void testAccountUpdateSerialization() { @@ -676,14 +681,14 @@ public class Test { } }; - String newAddress = "BTS5EHEfnQ4CgvTzNqE5TwWUGSLg3urcLVXrvQ2W7apxEqjczk4Ev"; + String newAddress = "BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYhnY"; try { Address address = new Address(newAddress); HashMap authMap = new HashMap<>(); authMap.put(address.getPublicKey(), 1); Authority authority = new Authority(1, authMap, null); AccountOptions options = new AccountOptions(address.getPublicKey()); - BrainKey brainKey = new BrainKey(Main.BILTHON_83_ORIGINAL_BRAIN_KEY, 0); + BrainKey brainKey = new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0); Transaction transaction = new AccountUpdateTransactionBuilder(brainKey.getPrivateKey()) .setAccont(new UserAccount("1.2.138632")) // .setOwner(authority) @@ -896,12 +901,13 @@ public class Test { WebSocket mWebSocket = factory.createSocket(BLOCK_PAY_DE); - mWebSocket.addListener(new GetLimitOrders("1.3.0", "1.3.562", 100, new WitnessResponseListener() { + mWebSocket.addListener(new GetLimitOrders("1.3.562", "1.3.0", 100, new WitnessResponseListener() { @Override public void onSuccess(WitnessResponse response) { List orders = (List) response.result; for(LimitOrder order : orders){ - double price = (((double) order.sell_price.base.getAmount().longValue()) / ((double) order.sell_price.quote.getAmount().longValue())) / 10; + System.out.println(String.format("OBITS: %d, BTS: %d", order.sell_price.base.getAmount().longValue(), order.sell_price.quote.getAmount().longValue())); + double price = (((double) order.sell_price.quote.getAmount().longValue()) / ((double) order.sell_price.base.getAmount().longValue())); System.out.println(String.format("Selling %s for %s at %f %s/%s, expiration: %s", order.sell_price.base.getAsset().getObjectId(), order.sell_price.quote.getAsset().getObjectId(), diff --git a/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java index 8a804de..bb5117a 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java @@ -39,12 +39,14 @@ public class GetAccountByName extends WebSocketAdapter { public void onConnected(WebSocket websocket, Map> headers) throws Exception { ArrayList accountParams = new ArrayList<>(); 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()); } @Override public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception { + if(frame.isTextFrame()) + System.out.println("<<< "+frame.getPayloadText()); String response = frame.getPayloadText(); GsonBuilder builder = new GsonBuilder(); @@ -62,6 +64,14 @@ public class GetAccountByName extends WebSocketAdapter { websocket.disconnect(); } + @Override + public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception { + if(frame.isTextFrame()){ + System.out.println(">>> "+frame.getPayloadText()); + } + } + + @Override public void onError(WebSocket websocket, WebSocketException cause) throws Exception { mListener.onError(new BaseResponse.Error(cause.getMessage())); diff --git a/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java index 2068010..70b9f76 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java @@ -29,35 +29,35 @@ import java.util.Map; * * @author henry */ -public class GetAccountNameById extends WebSocketAdapter { +public class GetAccounts extends WebSocketAdapter { private String accountId; private List userAccounts; private WitnessResponseListener mListener; - public GetAccountNameById(String accountId, WitnessResponseListener listener){ + public GetAccounts(String accountId, WitnessResponseListener listener){ this.accountId = accountId; this.mListener = listener; } - public GetAccountNameById(List accounts, WitnessResponseListener listener){ + public GetAccounts(List accounts, WitnessResponseListener listener){ this.userAccounts = accounts; this.mListener = listener; } @Override public void onConnected(WebSocket websocket, Map> headers) throws Exception { - ArrayList accountParams = new ArrayList(); - ArrayList paramAddress = new ArrayList(); + ArrayList params = new ArrayList(); + ArrayList accountIds = new ArrayList(); if(accountId == null){ for(UserAccount account : userAccounts) { - paramAddress.add(account.getObjectId()); + accountIds.add(account.getObjectId()); } }else{ - paramAddress.add(accountId); + accountIds.add(accountId); } - accountParams.add(paramAddress); - ApiCall getAccountByAddress = new ApiCall(0, RPC.CALL_GET_ACCOUNTS, accountParams, RPC.VERSION, 1); + params.add(accountIds); + ApiCall getAccountByAddress = new ApiCall(0, RPC.CALL_GET_ACCOUNTS, params, RPC.VERSION, 1); websocket.sendText(getAccountByAddress.toJsonString()); } diff --git a/src/test/java/de/bitsharesmunich/graphenej/AuthorityTest.java b/src/test/java/de/bitsharesmunich/graphenej/AuthorityTest.java new file mode 100644 index 0000000..cc9846d --- /dev/null +++ b/src/test/java/de/bitsharesmunich/graphenej/AuthorityTest.java @@ -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 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 keyMap1 = new HashMap<>(); + HashMap 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(){ + } +} \ No newline at end of file diff --git a/src/test/java/de/bitsharesmunich/graphenej/PublicKeyTest.java b/src/test/java/de/bitsharesmunich/graphenej/PublicKeyTest.java new file mode 100644 index 0000000..fe6307a --- /dev/null +++ b/src/test/java/de/bitsharesmunich/graphenej/PublicKeyTest.java @@ -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 { + + } + +} \ No newline at end of file