Get Trade History
This commit is contained in:
parent
6e2b886fd2
commit
d9d01ddc37
10 changed files with 192 additions and 32 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
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class Authority implements GrapheneSerializable {
|
||||||
this.account_auths = accountAuthorities;
|
this.account_auths = accountAuthorities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PublicKey> getKeyAuths(){
|
public List<PublicKey> getKeyAuthList(){
|
||||||
ArrayList<PublicKey> keys = new ArrayList<>();
|
ArrayList<PublicKey> keys = new ArrayList<>();
|
||||||
for(PublicKey pk : key_auths.keySet()){
|
for(PublicKey pk : key_auths.keySet()){
|
||||||
keys.add(pk);
|
keys.add(pk);
|
||||||
|
@ -69,6 +69,14 @@ public class Authority implements GrapheneSerializable {
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap<PublicKey, Integer> getKeyAuths(){
|
||||||
|
return this.key_auths;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<UserAccount, Integer> getAccountAuths(){
|
||||||
|
return this.account_auths;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toJsonString() {
|
public String toJsonString() {
|
||||||
return null;
|
return null;
|
||||||
|
@ -138,6 +146,19 @@ public class Authority implements GrapheneSerializable {
|
||||||
return Bytes.toArray(byteArray);
|
return Bytes.toArray(byteArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
Authority authority = (Authority) obj;
|
||||||
|
HashMap<PublicKey, Integer> keyAuths = authority.getKeyAuths();
|
||||||
|
HashMap<UserAccount, Integer> 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.
|
* Custom deserializer used while parsing the 'get_account_by_name' API call response.
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,11 +20,18 @@ public class BrainKey {
|
||||||
// The size of the word dictionary
|
// The size of the word dictionary
|
||||||
public static final int DICT_WORD_COUNT = 49744;
|
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;
|
public static final int BRAINKEY_WORD_COUNT = 12;
|
||||||
|
|
||||||
|
/* The corresponding private key derivated from the brain key */
|
||||||
private ECKey mPrivateKey;
|
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
|
* Method that will generate a random brain key
|
||||||
*
|
*
|
||||||
|
@ -49,7 +56,6 @@ public class BrainKey {
|
||||||
stringBuilder.append(word);
|
stringBuilder.append(word);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
}
|
}
|
||||||
System.out.println("Suggestion: '"+stringBuilder.toString().trim()+"'");
|
|
||||||
return stringBuilder.toString().trim();
|
return stringBuilder.toString().trim();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -60,6 +66,8 @@ public class BrainKey {
|
||||||
* @param sequence Sequence number
|
* @param sequence Sequence number
|
||||||
*/
|
*/
|
||||||
public BrainKey(String words, int sequence) {
|
public BrainKey(String words, int sequence) {
|
||||||
|
this.mBrainKey = words;
|
||||||
|
this.sequenceNumber = sequence;
|
||||||
String encoded = String.format("%s %d", words, sequence);
|
String encoded = String.format("%s %d", words, sequence);
|
||||||
try {
|
try {
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-512");
|
MessageDigest md = MessageDigest.getInstance("SHA-512");
|
||||||
|
@ -100,4 +108,12 @@ public class BrainKey {
|
||||||
DumpedPrivateKey wif = this.mPrivateKey.decompress().getPrivateKeyEncoded(NetworkParameters.fromID(NetworkParameters.ID_MAINNET));
|
DumpedPrivateKey wif = this.mPrivateKey.decompress().getPrivateKeyEncoded(NetworkParameters.fromID(NetworkParameters.ID_MAINNET));
|
||||||
return wif.toString();
|
return wif.toString();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public String getBrainKey(){
|
||||||
|
return mBrainKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSequenceNumber(){
|
||||||
|
return sequenceNumber;
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,4 +39,15 @@ public class PublicKey implements ByteSerializable {
|
||||||
}
|
}
|
||||||
return new Address(pk).toString();
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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