From 05699df6382838dae1b33c3579e4e159c1ddb0d9 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Sat, 16 Jun 2018 14:54:17 -0500 Subject: [PATCH] Introducing support for the LookupAssetSymbol api call wrapper in the single connection mode --- .../api/android/DeserializationMap.java | 9 +++++ .../api/calls/LookupAssetSymbols.java | 37 +++++++++++++++++++ .../cy/agorise/labs/sample/MainActivity.java | 17 +++++++++ sample/src/main/res/layout/activity_main.xml | 16 ++++++++ 4 files changed, 79 insertions(+) create mode 100644 graphenej/src/main/java/cy/agorise/graphenej/api/calls/LookupAssetSymbols.java 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 7ac69a3..f3726df 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 @@ -9,6 +9,7 @@ import java.util.HashMap; import java.util.List; import cy.agorise.graphenej.AccountOptions; +import cy.agorise.graphenej.Asset; import cy.agorise.graphenej.AssetAmount; import cy.agorise.graphenej.AssetOptions; import cy.agorise.graphenej.Authority; @@ -19,6 +20,7 @@ import cy.agorise.graphenej.api.calls.GetBlockHeader; import cy.agorise.graphenej.api.calls.GetMarketHistory; import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory; import cy.agorise.graphenej.api.calls.GetRequiredFees; +import cy.agorise.graphenej.api.calls.LookupAssetSymbols; import cy.agorise.graphenej.models.Block; import cy.agorise.graphenej.models.BlockHeader; import cy.agorise.graphenej.models.BucketObject; @@ -92,6 +94,13 @@ public class DeserializationMap { .registerTypeAdapter(BucketObject.class, new BucketObject.BucketDeserializer()) .create(); mGsonMap.put(GetMarketHistory.class, getMarketHistoryGson); + + // LookupAssetSymbols + mClassMap.put(LookupAssetSymbols.class, List.class); + Gson lookupAssetSymbolGson = new GsonBuilder() + .registerTypeAdapter(Asset.class, new Asset.AssetDeserializer()) + .create(); + mGsonMap.put(LookupAssetSymbols.class, lookupAssetSymbolGson); } public Class getReceivedClass(Class _class){ diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/calls/LookupAssetSymbols.java b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/LookupAssetSymbols.java new file mode 100644 index 0000000..3114ff0 --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/LookupAssetSymbols.java @@ -0,0 +1,37 @@ +package cy.agorise.graphenej.api.calls; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.api.ApiAccess; +import cy.agorise.graphenej.models.ApiCall; + +public class LookupAssetSymbols implements ApiCallable { + public static final int REQUIRED_API = ApiAccess.API_NONE; + + private List mAssetList; + + public LookupAssetSymbols(List assetList){ + this.mAssetList = assetList; + } + + public LookupAssetSymbols(Asset asset){ + mAssetList = new ArrayList(); + mAssetList.add(asset); + } + + @Override + public ApiCall toApiCall(int apiId, long sequenceId) { + ArrayList params = new ArrayList<>(); + ArrayList subArray = new ArrayList<>(); + for(int i = 0; i < mAssetList.size(); i++){ + Asset asset = mAssetList.get(i); + subArray.add(asset.getObjectId()); + params.add(subArray); + } + return new ApiCall(apiId, RPC.CALL_LOOKUP_ASSET_SYMBOLS, params, RPC.VERSION, sequenceId); + } +} diff --git a/sample/src/main/java/cy/agorise/labs/sample/MainActivity.java b/sample/src/main/java/cy/agorise/labs/sample/MainActivity.java index a8ee0fc..bee0297 100644 --- a/sample/src/main/java/cy/agorise/labs/sample/MainActivity.java +++ b/sample/src/main/java/cy/agorise/labs/sample/MainActivity.java @@ -20,6 +20,7 @@ import java.util.HashMap; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; +import cy.agorise.graphenej.Asset; import cy.agorise.graphenej.UserAccount; import cy.agorise.graphenej.api.ConnectionStatusUpdate; import cy.agorise.graphenej.api.android.DeserializationMap; @@ -29,6 +30,7 @@ import cy.agorise.graphenej.api.calls.GetAccounts; import cy.agorise.graphenej.api.calls.GetBlock; import cy.agorise.graphenej.api.calls.GetBlockHeader; import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory; +import cy.agorise.graphenej.api.calls.LookupAssetSymbols; import cy.agorise.graphenej.models.JsonRpcResponse; import cy.agorise.graphenej.objects.Memo; import cy.agorise.graphenej.operations.TransferOperation; @@ -57,6 +59,9 @@ public class MainActivity extends AppCompatActivity { @BindView(R.id.argument_get_relative_account_history) EditText mArgumentGetRelativeAccountHistory; + @BindView(R.id.argument_lookup_asset_symbol) + EditText mLookupAssetSymbol; + // In case we want to interact directly with the service private NetworkService mService; @@ -74,6 +79,7 @@ public class MainActivity extends AppCompatActivity { private final int GET_BLOCK_RESPONSE = 1; private final int GET_BLOCK_HEADER_RESPONSE = 2; private final int GET_RELATIVE_ACCOUNT_HISTORY_RESPONSE = 3; + private final int LOOKUP_ASSET_SYMBOL = 4; @Override protected void onCreate(Bundle savedInstanceState) { @@ -126,6 +132,9 @@ public class MainActivity extends AppCompatActivity { case GET_BLOCK_HEADER_RESPONSE: mResponse.setText(mResponse.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n"); break; + case LOOKUP_ASSET_SYMBOL: + mResponse.setText(mResponse.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n"); + break; default: Log.w(TAG,"Case not handled"); } @@ -184,6 +193,14 @@ public class MainActivity extends AppCompatActivity { responseMap.put(id, GET_RELATIVE_ACCOUNT_HISTORY_RESPONSE); } + @OnClick(R.id.call_lookup_asset_symbol) + public void onLookupAssetSymbol(View v){ + String assetId = mLookupAssetSymbol.getText().toString(); + Asset asset = new Asset(assetId); + long id = mService.sendMessage(new LookupAssetSymbols(asset), LookupAssetSymbols.REQUIRED_API); + responseMap.put(id, LOOKUP_ASSET_SYMBOL); + } + @OnClick(R.id.next_activity) public void onNextActivity(View v){ Intent intent = new Intent(this, SecondActivity.class); diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 3dc31e8..a646fd1 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -94,6 +94,22 @@ android:layout_height="wrap_content" android:text="1.2.138632"/> + +