Added support for the 'get_key_references' API call in the single-connection mode

This commit is contained in:
Nelson R. Perez 2018-10-08 19:55:49 -05:00
parent 2618a6a3a0
commit b361cf5830
5 changed files with 88 additions and 2 deletions

View file

@ -26,6 +26,7 @@ import cy.agorise.graphenej.api.calls.GetBlock;
import cy.agorise.graphenej.api.calls.GetBlockHeader; import cy.agorise.graphenej.api.calls.GetBlockHeader;
import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties; import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties;
import cy.agorise.graphenej.api.calls.GetFullAccounts; import cy.agorise.graphenej.api.calls.GetFullAccounts;
import cy.agorise.graphenej.api.calls.GetKeyReferences;
import cy.agorise.graphenej.api.calls.GetLimitOrders; import cy.agorise.graphenej.api.calls.GetLimitOrders;
import cy.agorise.graphenej.api.calls.GetMarketHistory; import cy.agorise.graphenej.api.calls.GetMarketHistory;
import cy.agorise.graphenej.api.calls.GetObjects; import cy.agorise.graphenej.api.calls.GetObjects;
@ -178,6 +179,13 @@ public class DeserializationMap {
.registerTypeAdapter(DynamicGlobalProperties.class, new DynamicGlobalProperties.DynamicGlobalPropertiesDeserializer()) .registerTypeAdapter(DynamicGlobalProperties.class, new DynamicGlobalProperties.DynamicGlobalPropertiesDeserializer())
.create(); .create();
mGsonMap.put(GetDynamicGlobalProperties.class, getDynamicGlobalPropertiesGson); mGsonMap.put(GetDynamicGlobalProperties.class, getDynamicGlobalPropertiesGson);
// GetKeyReferences
mClassMap.put(GetKeyReferences.class, List.class);
Gson getKeyReferencesGson = new GsonBuilder()
.registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer())
.create();
mGsonMap.put(GetKeyReferences.class, getKeyReferencesGson);
} }
public Class getReceivedClass(Class _class){ public Class getReceivedClass(Class _class){

View file

@ -33,6 +33,7 @@ import cy.agorise.graphenej.api.bitshares.Nodes;
import cy.agorise.graphenej.api.calls.ApiCallable; import cy.agorise.graphenej.api.calls.ApiCallable;
import cy.agorise.graphenej.api.calls.GetAccounts; import cy.agorise.graphenej.api.calls.GetAccounts;
import cy.agorise.graphenej.api.calls.GetFullAccounts; import cy.agorise.graphenej.api.calls.GetFullAccounts;
import cy.agorise.graphenej.api.calls.GetKeyReferences;
import cy.agorise.graphenej.api.calls.GetLimitOrders; import cy.agorise.graphenej.api.calls.GetLimitOrders;
import cy.agorise.graphenej.api.calls.GetMarketHistory; import cy.agorise.graphenej.api.calls.GetMarketHistory;
import cy.agorise.graphenej.api.calls.GetObjects; import cy.agorise.graphenej.api.calls.GetObjects;
@ -490,6 +491,9 @@ public class NetworkService extends Service {
} else if (requestClass == GetFullAccounts.class) { } else if (requestClass == GetFullAccounts.class) {
Type GetFullAccountsResponse = new TypeToken<JsonRpcResponse<List<FullAccountDetails>>>(){}.getType(); Type GetFullAccountsResponse = new TypeToken<JsonRpcResponse<List<FullAccountDetails>>>(){}.getType();
parsedResponse = gson.fromJson(text, GetFullAccountsResponse); parsedResponse = gson.fromJson(text, GetFullAccountsResponse);
} else if(requestClass == GetKeyReferences.class){
Type GetKeyReferencesResponse = new TypeToken<JsonRpcResponse<List<List<UserAccount>>>>(){}.getType();
parsedResponse = gson.fromJson(text, GetKeyReferencesResponse);
} else { } else {
Log.w(TAG,"Unknown request class"); Log.w(TAG,"Unknown request class");
} }

View file

@ -0,0 +1,43 @@
package cy.agorise.graphenej.api.calls;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import cy.agorise.graphenej.Address;
import cy.agorise.graphenej.RPC;
import cy.agorise.graphenej.api.ApiAccess;
import cy.agorise.graphenej.errors.MalformedAddressException;
import cy.agorise.graphenej.models.ApiCall;
/**
* Wrapper around the 'get_key_references' API call.
*/
public class GetKeyReferences implements ApiCallable {
public static final int REQUIRED_API = ApiAccess.API_NONE;
private List<Address> addresses = new ArrayList<>();
public GetKeyReferences(String addr) throws MalformedAddressException, IllegalArgumentException {
this(new Address(addr));
}
public GetKeyReferences(Address address){
addresses.add(address);
}
public GetKeyReferences(List<Address> addressList){
addresses.addAll(addressList);
}
@Override
public ApiCall toApiCall(int apiId, long sequenceId) {
ArrayList<Serializable> inner = new ArrayList<Serializable>();
for(Address addr : addresses){
inner.add(addr.toString());
}
ArrayList<Serializable> params = new ArrayList<>();
params.add(inner);
return new ApiCall(apiId, RPC.CALL_GET_KEY_REFERENCES, params, RPC.VERSION, sequenceId);
}
}

View file

@ -48,7 +48,8 @@ public class CallsActivity extends AppCompatActivity {
RPC.CALL_GET_ACCOUNT_HISTORY_BY_OPERATIONS, RPC.CALL_GET_ACCOUNT_HISTORY_BY_OPERATIONS,
RPC.CALL_GET_FULL_ACCOUNTS, RPC.CALL_GET_FULL_ACCOUNTS,
RPC.CALL_SET_SUBSCRIBE_CALLBACK, RPC.CALL_SET_SUBSCRIBE_CALLBACK,
RPC.CALL_GET_DYNAMIC_GLOBAL_PROPERTIES RPC.CALL_GET_DYNAMIC_GLOBAL_PROPERTIES,
RPC.CALL_GET_KEY_REFERENCES
}; };
@NonNull @NonNull

View file

@ -23,6 +23,7 @@ import java.util.HashMap;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import cy.agorise.graphenej.Memo;
import cy.agorise.graphenej.OperationType; import cy.agorise.graphenej.OperationType;
import cy.agorise.graphenej.RPC; import cy.agorise.graphenej.RPC;
import cy.agorise.graphenej.UserAccount; import cy.agorise.graphenej.UserAccount;
@ -35,11 +36,12 @@ import cy.agorise.graphenej.api.calls.GetAccounts;
import cy.agorise.graphenej.api.calls.GetBlock; import cy.agorise.graphenej.api.calls.GetBlock;
import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties; import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties;
import cy.agorise.graphenej.api.calls.GetFullAccounts; import cy.agorise.graphenej.api.calls.GetFullAccounts;
import cy.agorise.graphenej.api.calls.GetKeyReferences;
import cy.agorise.graphenej.api.calls.GetLimitOrders; import cy.agorise.graphenej.api.calls.GetLimitOrders;
import cy.agorise.graphenej.api.calls.GetObjects; import cy.agorise.graphenej.api.calls.GetObjects;
import cy.agorise.graphenej.api.calls.ListAssets; import cy.agorise.graphenej.api.calls.ListAssets;
import cy.agorise.graphenej.errors.MalformedAddressException;
import cy.agorise.graphenej.models.JsonRpcResponse; import cy.agorise.graphenej.models.JsonRpcResponse;
import cy.agorise.graphenej.Memo;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer; import io.reactivex.functions.Consumer;
@ -138,6 +140,10 @@ public class PerformCallActivity extends ConnectedActivity {
break; break;
case RPC.CALL_GET_DYNAMIC_GLOBAL_PROPERTIES: case RPC.CALL_GET_DYNAMIC_GLOBAL_PROPERTIES:
setupGetDynamicGlobalProperties(); setupGetDynamicGlobalProperties();
break;
case RPC.CALL_GET_KEY_REFERENCES:
setupGetKeyReferences();
break;
default: default:
Log.d(TAG,"Default called"); Log.d(TAG,"Default called");
} }
@ -257,6 +263,12 @@ public class PerformCallActivity extends ConnectedActivity {
requiredInput(0); requiredInput(0);
} }
private void setupGetKeyReferences(){
requiredInput(1);
// Test address
param1.setText("BTS8a7XJ94u1traaLGFHw6NgpvUaxmbG4MyCcZC1hBj9HCBuMEwXP");
}
private void requiredInput(int inputCount){ private void requiredInput(int inputCount){
if(inputCount == 0){ if(inputCount == 0){
mParam1View.setVisibility(View.GONE); mParam1View.setVisibility(View.GONE);
@ -324,6 +336,10 @@ public class PerformCallActivity extends ConnectedActivity {
break; break;
case RPC.CALL_GET_DYNAMIC_GLOBAL_PROPERTIES: case RPC.CALL_GET_DYNAMIC_GLOBAL_PROPERTIES:
getDynamicGlobalProperties(); getDynamicGlobalProperties();
break;
case RPC.CALL_GET_KEY_REFERENCES:
getKeyReferences();
break;
default: default:
Log.d(TAG,"Default called"); Log.d(TAG,"Default called");
} }
@ -411,6 +427,19 @@ public class PerformCallActivity extends ConnectedActivity {
responseMap.put(id, mRPC); responseMap.put(id, mRPC);
} }
private void getKeyReferences(){
String address = param1.getText().toString();
long id = 0;
try {
id = mNetworkService.sendMessage(new GetKeyReferences(address), GetKeyReferences.REQUIRED_API);
responseMap.put(id, mRPC);
} catch (MalformedAddressException | IllegalArgumentException e) {
Log.e(TAG,"MalformedAddressException. Msg: "+e.getMessage());
Toast.makeText(this, "Malformed address exception", Toast.LENGTH_SHORT).show();
param1.setText("");
}
}
/** /**
* Internal method that will decide what to do with each JSON-RPC response * Internal method that will decide what to do with each JSON-RPC response
* *
@ -435,6 +464,7 @@ public class PerformCallActivity extends ConnectedActivity {
case RPC.CALL_GET_ACCOUNT_HISTORY_BY_OPERATIONS: case RPC.CALL_GET_ACCOUNT_HISTORY_BY_OPERATIONS:
case RPC.CALL_GET_FULL_ACCOUNTS: case RPC.CALL_GET_FULL_ACCOUNTS:
case RPC.CALL_GET_DYNAMIC_GLOBAL_PROPERTIES: case RPC.CALL_GET_DYNAMIC_GLOBAL_PROPERTIES:
case RPC.CALL_GET_KEY_REFERENCES:
mResponseView.setText(mResponseView.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n"); mResponseView.setText(mResponseView.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n");
break; break;
default: default: