Added support for the get_account_by_name API call wrapper in the single connection mode

This commit is contained in:
Nelson R. Perez 2018-08-08 18:53:57 -05:00
parent 4d7f2a28a5
commit de3dc2b120
6 changed files with 63 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import cy.agorise.graphenej.AssetAmount;
import cy.agorise.graphenej.AssetOptions;
import cy.agorise.graphenej.Authority;
import cy.agorise.graphenej.Transaction;
import cy.agorise.graphenej.api.calls.GetAccountByName;
import cy.agorise.graphenej.api.calls.GetAccounts;
import cy.agorise.graphenej.api.calls.GetBlock;
import cy.agorise.graphenej.api.calls.GetBlockHeader;
@ -23,6 +24,7 @@ import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory;
import cy.agorise.graphenej.api.calls.GetRequiredFees;
import cy.agorise.graphenej.api.calls.ListAssets;
import cy.agorise.graphenej.api.calls.LookupAssetSymbols;
import cy.agorise.graphenej.models.AccountProperties;
import cy.agorise.graphenej.models.Block;
import cy.agorise.graphenej.models.BlockHeader;
import cy.agorise.graphenej.models.BucketObject;
@ -117,6 +119,14 @@ public class DeserializationMap {
.registerTypeAdapter(Asset.class, new Asset.AssetDeserializer())
.create();
mGsonMap.put(ListAssets.class, listAssetsGson);
// GetAccountByName
mClassMap.put(GetAccountByName.class, AccountProperties.class);
Gson getAccountByNameGson = new GsonBuilder()
.registerTypeAdapter(Authority.class, new Authority.AuthorityDeserializer())
.registerTypeAdapter(AccountOptions.class, new AccountOptions.AccountOptionsDeserializer())
.create();
mGsonMap.put(GetAccountByName.class, getAccountByNameGson);
}
public Class getReceivedClass(Class _class){

View file

@ -304,6 +304,9 @@ public class NetworkService extends Service {
// If the response payload is a BlockHeader instance, we proceed to de-serialize it
Type GetBlockHeaderResponse = new TypeToken<JsonRpcResponse<BlockHeader>>(){}.getType();
parsedResponse = gson.fromJson(text, GetBlockHeaderResponse);
} else if(responsePayloadClass == AccountProperties.class){
Type GetAccountByNameResponse = new TypeToken<JsonRpcResponse<AccountProperties>>(){}.getType();
parsedResponse = gson.fromJson(text, GetAccountByNameResponse);
} else if(responsePayloadClass == List.class){
// If the response payload is a List, further inquiry is required in order to
// determine a list of what is expected here

View file

@ -0,0 +1,25 @@
package cy.agorise.graphenej.api.calls;
import java.io.Serializable;
import java.util.ArrayList;
import cy.agorise.graphenej.RPC;
import cy.agorise.graphenej.api.ApiAccess;
import cy.agorise.graphenej.models.ApiCall;
public class GetAccountByName implements ApiCallable {
public static final int REQUIRED_API = ApiAccess.API_NONE;
private String accountName;
public GetAccountByName(String name){
this.accountName = name;
}
@Override
public ApiCall toApiCall(int apiId, long sequenceId) {
ArrayList<Serializable> accountParams = new ArrayList<>();
accountParams.add(this.accountName);
return new ApiCall(apiId, RPC.CALL_GET_ACCOUNT_BY_NAME, accountParams, RPC.VERSION, sequenceId);
}
}

View file

@ -43,7 +43,8 @@ public class CallsActivity extends AppCompatActivity {
RPC.CALL_GET_RELATIVE_ACCOUNT_HISTORY,
RPC.CALL_GET_REQUIRED_FEES,
RPC.CALL_LOOKUP_ASSET_SYMBOLS,
RPC.CALL_LIST_ASSETS
RPC.CALL_LIST_ASSETS,
RPC.CALL_GET_ACCOUNT_BY_NAME
};
@NonNull

View file

@ -27,6 +27,7 @@ import cy.agorise.graphenej.UserAccount;
import cy.agorise.graphenej.api.ConnectionStatusUpdate;
import cy.agorise.graphenej.api.android.DeserializationMap;
import cy.agorise.graphenej.api.android.RxBus;
import cy.agorise.graphenej.api.calls.GetAccountByName;
import cy.agorise.graphenej.api.calls.GetAccounts;
import cy.agorise.graphenej.api.calls.GetBlock;
import cy.agorise.graphenej.api.calls.GetObjects;
@ -119,6 +120,8 @@ public class PerformCallActivity extends ConnectedActivity {
break;
case RPC.CALL_LIST_ASSETS:
setupListAssets();
case RPC.CALL_GET_ACCOUNT_BY_NAME:
setupAccountByName();
default:
Log.d(TAG,"Default called");
}
@ -195,6 +198,13 @@ public class PerformCallActivity extends ConnectedActivity {
param2.setInputType(InputType.TYPE_CLASS_NUMBER);
}
private void setupAccountByName(){
requiredInput(1);
Resources resources = getResources();
mParam1View.setHint(resources.getString(R.string.get_accounts_by_name_arg1));
param1.setInputType(InputType.TYPE_CLASS_TEXT);
}
private void requiredInput(int inputCount){
if(inputCount == 1){
mParam1View.setVisibility(View.VISIBLE);
@ -242,6 +252,8 @@ public class PerformCallActivity extends ConnectedActivity {
break;
case RPC.CALL_LIST_ASSETS:
sendListAssets();
case RPC.CALL_GET_ACCOUNT_BY_NAME:
getAccountByName();
default:
Log.d(TAG,"Default called");
}
@ -284,6 +296,12 @@ public class PerformCallActivity extends ConnectedActivity {
}
}
private void getAccountByName(){
String accountName = param1.getText().toString();
long id = mNetworkService.sendMessage(new GetAccountByName(accountName), GetAccountByName.REQUIRED_API);
responseMap.put(id, mRPC);
}
/**
* Internal method that will decide what to do with each JSON-RPC response
*
@ -321,6 +339,8 @@ public class PerformCallActivity extends ConnectedActivity {
case RPC.CALL_LIST_ASSETS:
mResponseView.setText(mResponseView.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n");
break;
case RPC.CALL_GET_ACCOUNT_BY_NAME:
mResponseView.setText(mResponseView.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n");
default:
Log.w(TAG,"Case not handled");
mResponseView.setText(mResponseView.getText() + response.result.toString());

View file

@ -37,4 +37,7 @@
<!-- List assets input fields -->
<string name="list_assets_arg1">Lower bound of symbol names to retrieve</string>
<string name="list_assets_arg2">Maximum number of assets to fetch (must not exceed 100)</string>
<!-- Get account by name fields -->
<string name="get_accounts_by_name_arg1">Account name</string>
</resources>