diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java index 4b1973e..d3ed6e6 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java @@ -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){ diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java index f9dadf9..45d9504 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java @@ -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>(){}.getType(); parsedResponse = gson.fromJson(text, GetBlockHeaderResponse); + } else if(responsePayloadClass == AccountProperties.class){ + Type GetAccountByNameResponse = new TypeToken>(){}.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 diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetAccountByName.java b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetAccountByName.java new file mode 100644 index 0000000..3aeff26 --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetAccountByName.java @@ -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 accountParams = new ArrayList<>(); + accountParams.add(this.accountName); + return new ApiCall(apiId, RPC.CALL_GET_ACCOUNT_BY_NAME, accountParams, RPC.VERSION, sequenceId); + } +} diff --git a/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java b/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java index 9375949..2faa8bb 100644 --- a/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java +++ b/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java @@ -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 diff --git a/sample/src/main/java/cy/agorise/labs/sample/PerformCallActivity.java b/sample/src/main/java/cy/agorise/labs/sample/PerformCallActivity.java index bb8a7b2..f8a8927 100644 --- a/sample/src/main/java/cy/agorise/labs/sample/PerformCallActivity.java +++ b/sample/src/main/java/cy/agorise/labs/sample/PerformCallActivity.java @@ -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()); diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index d5f9db1..112c1f6 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -37,4 +37,7 @@ Lower bound of symbol names to retrieve Maximum number of assets to fetch (must not exceed 100) + + + Account name