Introducing support for the LookupAssetSymbol api call wrapper in the single connection mode

This commit is contained in:
Nelson R. Perez 2018-06-16 14:54:17 -05:00
parent 918d27b5cd
commit 05699df638
4 changed files with 79 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import cy.agorise.graphenej.AccountOptions; import cy.agorise.graphenej.AccountOptions;
import cy.agorise.graphenej.Asset;
import cy.agorise.graphenej.AssetAmount; import cy.agorise.graphenej.AssetAmount;
import cy.agorise.graphenej.AssetOptions; import cy.agorise.graphenej.AssetOptions;
import cy.agorise.graphenej.Authority; 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.GetMarketHistory;
import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory; import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory;
import cy.agorise.graphenej.api.calls.GetRequiredFees; 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.Block;
import cy.agorise.graphenej.models.BlockHeader; import cy.agorise.graphenej.models.BlockHeader;
import cy.agorise.graphenej.models.BucketObject; import cy.agorise.graphenej.models.BucketObject;
@ -92,6 +94,13 @@ public class DeserializationMap {
.registerTypeAdapter(BucketObject.class, new BucketObject.BucketDeserializer()) .registerTypeAdapter(BucketObject.class, new BucketObject.BucketDeserializer())
.create(); .create();
mGsonMap.put(GetMarketHistory.class, getMarketHistoryGson); 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){ public Class getReceivedClass(Class _class){

View file

@ -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<Asset> mAssetList;
public LookupAssetSymbols(List<Asset> assetList){
this.mAssetList = assetList;
}
public LookupAssetSymbols(Asset asset){
mAssetList = new ArrayList<Asset>();
mAssetList.add(asset);
}
@Override
public ApiCall toApiCall(int apiId, long sequenceId) {
ArrayList<Serializable> params = new ArrayList<>();
ArrayList<String> 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);
}
}

View file

@ -20,6 +20,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.Asset;
import cy.agorise.graphenej.UserAccount; import cy.agorise.graphenej.UserAccount;
import cy.agorise.graphenej.api.ConnectionStatusUpdate; import cy.agorise.graphenej.api.ConnectionStatusUpdate;
import cy.agorise.graphenej.api.android.DeserializationMap; 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.GetBlock;
import cy.agorise.graphenej.api.calls.GetBlockHeader; import cy.agorise.graphenej.api.calls.GetBlockHeader;
import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory; import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory;
import cy.agorise.graphenej.api.calls.LookupAssetSymbols;
import cy.agorise.graphenej.models.JsonRpcResponse; import cy.agorise.graphenej.models.JsonRpcResponse;
import cy.agorise.graphenej.objects.Memo; import cy.agorise.graphenej.objects.Memo;
import cy.agorise.graphenej.operations.TransferOperation; import cy.agorise.graphenej.operations.TransferOperation;
@ -57,6 +59,9 @@ public class MainActivity extends AppCompatActivity {
@BindView(R.id.argument_get_relative_account_history) @BindView(R.id.argument_get_relative_account_history)
EditText mArgumentGetRelativeAccountHistory; EditText mArgumentGetRelativeAccountHistory;
@BindView(R.id.argument_lookup_asset_symbol)
EditText mLookupAssetSymbol;
// In case we want to interact directly with the service // In case we want to interact directly with the service
private NetworkService mService; private NetworkService mService;
@ -74,6 +79,7 @@ public class MainActivity extends AppCompatActivity {
private final int GET_BLOCK_RESPONSE = 1; private final int GET_BLOCK_RESPONSE = 1;
private final int GET_BLOCK_HEADER_RESPONSE = 2; private final int GET_BLOCK_HEADER_RESPONSE = 2;
private final int GET_RELATIVE_ACCOUNT_HISTORY_RESPONSE = 3; private final int GET_RELATIVE_ACCOUNT_HISTORY_RESPONSE = 3;
private final int LOOKUP_ASSET_SYMBOL = 4;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -126,6 +132,9 @@ public class MainActivity extends AppCompatActivity {
case GET_BLOCK_HEADER_RESPONSE: case GET_BLOCK_HEADER_RESPONSE:
mResponse.setText(mResponse.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n"); mResponse.setText(mResponse.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n");
break; break;
case LOOKUP_ASSET_SYMBOL:
mResponse.setText(mResponse.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n");
break;
default: default:
Log.w(TAG,"Case not handled"); Log.w(TAG,"Case not handled");
} }
@ -184,6 +193,14 @@ public class MainActivity extends AppCompatActivity {
responseMap.put(id, GET_RELATIVE_ACCOUNT_HISTORY_RESPONSE); 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) @OnClick(R.id.next_activity)
public void onNextActivity(View v){ public void onNextActivity(View v){
Intent intent = new Intent(this, SecondActivity.class); Intent intent = new Intent(this, SecondActivity.class);

View file

@ -94,6 +94,22 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="1.2.138632"/> android:text="1.2.138632"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/call_lookup_asset_symbol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lookup asset symbol"/>
<EditText
android:id="@+id/argument_lookup_asset_symbol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.3.0"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
<Button <Button