Added support for the 'get_assets' API call on the single-connection mode
This commit is contained in:
parent
0cba6a9f8d
commit
b54ae2cbae
7 changed files with 96 additions and 3 deletions
|
@ -24,6 +24,7 @@ public class RPC {
|
||||||
public static final String CALL_GET_ACCOUNT_HISTORY_BY_OPERATIONS = "get_account_history_by_operations";
|
public static final String CALL_GET_ACCOUNT_HISTORY_BY_OPERATIONS = "get_account_history_by_operations";
|
||||||
public static final String CALL_LOOKUP_ACCOUNTS = "lookup_accounts";
|
public static final String CALL_LOOKUP_ACCOUNTS = "lookup_accounts";
|
||||||
public static final String CALL_LIST_ASSETS = "list_assets";
|
public static final String CALL_LIST_ASSETS = "list_assets";
|
||||||
|
public static final String CALL_GET_ASSETS = "get_assets";
|
||||||
public static final String CALL_GET_OBJECTS = "get_objects";
|
public static final String CALL_GET_OBJECTS = "get_objects";
|
||||||
public static final String CALL_GET_ACCOUNT_BALANCES = "get_account_balances";
|
public static final String CALL_GET_ACCOUNT_BALANCES = "get_account_balances";
|
||||||
public static final String CALL_LOOKUP_ASSET_SYMBOLS = "lookup_asset_symbols";
|
public static final String CALL_LOOKUP_ASSET_SYMBOLS = "lookup_asset_symbols";
|
||||||
|
|
|
@ -23,6 +23,7 @@ import cy.agorise.graphenej.api.calls.GetAccountBalances;
|
||||||
import cy.agorise.graphenej.api.calls.GetAccountByName;
|
import cy.agorise.graphenej.api.calls.GetAccountByName;
|
||||||
import cy.agorise.graphenej.api.calls.GetAccountHistoryByOperations;
|
import cy.agorise.graphenej.api.calls.GetAccountHistoryByOperations;
|
||||||
import cy.agorise.graphenej.api.calls.GetAccounts;
|
import cy.agorise.graphenej.api.calls.GetAccounts;
|
||||||
|
import cy.agorise.graphenej.api.calls.GetAssets;
|
||||||
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.GetDynamicGlobalProperties;
|
import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties;
|
||||||
|
@ -193,6 +194,13 @@ public class DeserializationMap {
|
||||||
.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer())
|
.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer())
|
||||||
.create();
|
.create();
|
||||||
mGsonMap.put(GetAccountBalances.class, getAccountBalancesGson);
|
mGsonMap.put(GetAccountBalances.class, getAccountBalancesGson);
|
||||||
|
|
||||||
|
// GetAssets
|
||||||
|
mClassMap.put(GetAssets.class, List.class);
|
||||||
|
Gson getAssetsGson = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(Asset.class, new Asset.AssetDeserializer())
|
||||||
|
.create();
|
||||||
|
mGsonMap.put(GetAssets.class, getAssetsGson);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getReceivedClass(Class _class){
|
public Class getReceivedClass(Class _class){
|
||||||
|
|
|
@ -34,6 +34,7 @@ import cy.agorise.graphenej.api.ConnectionStatusUpdate;
|
||||||
import cy.agorise.graphenej.api.calls.ApiCallable;
|
import cy.agorise.graphenej.api.calls.ApiCallable;
|
||||||
import cy.agorise.graphenej.api.calls.GetAccountBalances;
|
import cy.agorise.graphenej.api.calls.GetAccountBalances;
|
||||||
import cy.agorise.graphenej.api.calls.GetAccounts;
|
import cy.agorise.graphenej.api.calls.GetAccounts;
|
||||||
|
import cy.agorise.graphenej.api.calls.GetAssets;
|
||||||
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.GetKeyReferences;
|
||||||
import cy.agorise.graphenej.api.calls.GetLimitOrders;
|
import cy.agorise.graphenej.api.calls.GetLimitOrders;
|
||||||
|
@ -580,6 +581,9 @@ public class NetworkService extends Service {
|
||||||
} else if(requestClass == GetAccountBalances.class){
|
} else if(requestClass == GetAccountBalances.class){
|
||||||
Type GetAccountBalancesResponse = new TypeToken<JsonRpcResponse<List<AssetAmount>>>(){}.getType();
|
Type GetAccountBalancesResponse = new TypeToken<JsonRpcResponse<List<AssetAmount>>>(){}.getType();
|
||||||
parsedResponse = gson.fromJson(text, GetAccountBalancesResponse);
|
parsedResponse = gson.fromJson(text, GetAccountBalancesResponse);
|
||||||
|
} else if(requestClass == GetAssets.class){
|
||||||
|
Type GetAssetsResponse = new TypeToken<JsonRpcResponse<List<Asset>>>(){}.getType();
|
||||||
|
parsedResponse = gson.fromJson(text, GetAssetsResponse);
|
||||||
}else {
|
}else {
|
||||||
Log.w(TAG,"Unknown request class");
|
Log.w(TAG,"Unknown request class");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
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 GetAssets implements ApiCallable {
|
||||||
|
public static final int REQUIRED_API = ApiAccess.API_NONE;
|
||||||
|
|
||||||
|
private List<Asset> assetList = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that will receive a List of Asset instances.
|
||||||
|
*
|
||||||
|
* @param assets List of Asset instances.
|
||||||
|
*/
|
||||||
|
public GetAssets(List<Asset> assets){
|
||||||
|
assetList.addAll(assets);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that will accept a string containing the asset id.
|
||||||
|
*
|
||||||
|
* @param id String containing the asset id of the desired asset.
|
||||||
|
*/
|
||||||
|
public GetAssets(String id){
|
||||||
|
assetList.add(new Asset(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that accepts an {@link Asset} object instance.
|
||||||
|
*
|
||||||
|
* @param asset Asset class instance.
|
||||||
|
*/
|
||||||
|
public GetAssets(Asset asset){
|
||||||
|
assetList.add(asset);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiCall toApiCall(int apiId, long sequenceId) {
|
||||||
|
ArrayList<Serializable> params = new ArrayList<>();
|
||||||
|
ArrayList<Serializable> assetIds = new ArrayList<>();
|
||||||
|
for(Asset asset : assetList){
|
||||||
|
assetIds.add(asset.getObjectId());
|
||||||
|
}
|
||||||
|
params.add(assetIds);
|
||||||
|
return new ApiCall(apiId, RPC.CALL_GET_ASSETS, params, RPC.VERSION, sequenceId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -70,6 +70,7 @@ public class CallsActivity extends AppCompatActivity {
|
||||||
RPC.CALL_GET_REQUIRED_FEES,
|
RPC.CALL_GET_REQUIRED_FEES,
|
||||||
RPC.CALL_LOOKUP_ASSET_SYMBOLS,
|
RPC.CALL_LOOKUP_ASSET_SYMBOLS,
|
||||||
RPC.CALL_LIST_ASSETS,
|
RPC.CALL_LIST_ASSETS,
|
||||||
|
RPC.CALL_GET_ASSETS,
|
||||||
RPC.CALL_GET_ACCOUNT_BY_NAME,
|
RPC.CALL_GET_ACCOUNT_BY_NAME,
|
||||||
RPC.CALL_GET_LIMIT_ORDERS,
|
RPC.CALL_GET_LIMIT_ORDERS,
|
||||||
RPC.CALL_GET_ACCOUNT_HISTORY_BY_OPERATIONS,
|
RPC.CALL_GET_ACCOUNT_HISTORY_BY_OPERATIONS,
|
||||||
|
|
|
@ -45,6 +45,7 @@ import cy.agorise.graphenej.api.calls.GetAccountBalances;
|
||||||
import cy.agorise.graphenej.api.calls.GetAccountByName;
|
import cy.agorise.graphenej.api.calls.GetAccountByName;
|
||||||
import cy.agorise.graphenej.api.calls.GetAccountHistoryByOperations;
|
import cy.agorise.graphenej.api.calls.GetAccountHistoryByOperations;
|
||||||
import cy.agorise.graphenej.api.calls.GetAccounts;
|
import cy.agorise.graphenej.api.calls.GetAccounts;
|
||||||
|
import cy.agorise.graphenej.api.calls.GetAssets;
|
||||||
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;
|
||||||
|
@ -143,6 +144,9 @@ public class PerformCallActivity extends ConnectedActivity {
|
||||||
case RPC.CALL_LIST_ASSETS:
|
case RPC.CALL_LIST_ASSETS:
|
||||||
setupListAssets();
|
setupListAssets();
|
||||||
break;
|
break;
|
||||||
|
case RPC.CALL_GET_ASSETS:
|
||||||
|
setupGetAssets();
|
||||||
|
break;
|
||||||
case RPC.CALL_GET_ACCOUNT_BY_NAME:
|
case RPC.CALL_GET_ACCOUNT_BY_NAME:
|
||||||
setupAccountByName();
|
setupAccountByName();
|
||||||
break;
|
break;
|
||||||
|
@ -240,12 +244,16 @@ public class PerformCallActivity extends ConnectedActivity {
|
||||||
|
|
||||||
private void setupListAssets(){
|
private void setupListAssets(){
|
||||||
requiredInput(2);
|
requiredInput(2);
|
||||||
Resources resources = getResources();
|
mParam1View.setHint(getString(R.string.list_assets_arg1));
|
||||||
mParam1View.setHint(resources.getString(R.string.list_assets_arg1));
|
mParam2View.setHint(getString(R.string.list_assets_arg2));
|
||||||
mParam2View.setHint(resources.getString(R.string.list_assets_arg2));
|
|
||||||
param2.setInputType(InputType.TYPE_CLASS_NUMBER);
|
param2.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupGetAssets(){
|
||||||
|
requiredInput(1);
|
||||||
|
mParam1View.setHint(getString(R.string.get_assets_arg));
|
||||||
|
}
|
||||||
|
|
||||||
private void setupAccountByName(){
|
private void setupAccountByName(){
|
||||||
requiredInput(1);
|
requiredInput(1);
|
||||||
Resources resources = getResources();
|
Resources resources = getResources();
|
||||||
|
@ -361,6 +369,9 @@ public class PerformCallActivity extends ConnectedActivity {
|
||||||
case RPC.CALL_LIST_ASSETS:
|
case RPC.CALL_LIST_ASSETS:
|
||||||
sendListAssets();
|
sendListAssets();
|
||||||
break;
|
break;
|
||||||
|
case RPC.CALL_GET_ASSETS:
|
||||||
|
sendGetAssets();
|
||||||
|
break;
|
||||||
case RPC.CALL_GET_ACCOUNT_BY_NAME:
|
case RPC.CALL_GET_ACCOUNT_BY_NAME:
|
||||||
getAccountByName();
|
getAccountByName();
|
||||||
break;
|
break;
|
||||||
|
@ -436,6 +447,16 @@ public class PerformCallActivity extends ConnectedActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendGetAssets(){
|
||||||
|
String assetIds = param1.getText().toString();
|
||||||
|
ArrayList<Asset> assetList = new ArrayList<>();
|
||||||
|
for(String id :assetIds.split(",")){
|
||||||
|
assetList.add(new Asset(id));
|
||||||
|
}
|
||||||
|
long id = mNetworkService.sendMessage(new GetAssets(assetList), GetAssets.REQUIRED_API);
|
||||||
|
responseMap.put(id, mRPC);
|
||||||
|
}
|
||||||
|
|
||||||
private void getAccountByName(){
|
private void getAccountByName(){
|
||||||
String accountName = param1.getText().toString();
|
String accountName = param1.getText().toString();
|
||||||
long id = mNetworkService.sendMessage(new GetAccountByName(accountName), GetAccountByName.REQUIRED_API);
|
long id = mNetworkService.sendMessage(new GetAccountByName(accountName), GetAccountByName.REQUIRED_API);
|
||||||
|
@ -552,6 +573,7 @@ public class PerformCallActivity extends ConnectedActivity {
|
||||||
case RPC.CALL_GET_REQUIRED_FEES:
|
case RPC.CALL_GET_REQUIRED_FEES:
|
||||||
case RPC.CALL_LOOKUP_ASSET_SYMBOLS:
|
case RPC.CALL_LOOKUP_ASSET_SYMBOLS:
|
||||||
case RPC.CALL_LIST_ASSETS:
|
case RPC.CALL_LIST_ASSETS:
|
||||||
|
case RPC.CALL_GET_ASSETS:
|
||||||
case RPC.CALL_GET_ACCOUNT_BY_NAME:
|
case RPC.CALL_GET_ACCOUNT_BY_NAME:
|
||||||
case RPC.CALL_GET_LIMIT_ORDERS:
|
case RPC.CALL_GET_LIMIT_ORDERS:
|
||||||
case RPC.CALL_GET_ACCOUNT_HISTORY_BY_OPERATIONS:
|
case RPC.CALL_GET_ACCOUNT_HISTORY_BY_OPERATIONS:
|
||||||
|
|
|
@ -41,6 +41,9 @@
|
||||||
<string name="list_assets_arg1">Lower bound of symbol names to retrieve</string>
|
<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>
|
<string name="list_assets_arg2">Maximum number of assets to fetch (must not exceed 100)</string>
|
||||||
|
|
||||||
|
<!-- Get assets input fields -->
|
||||||
|
<string name="get_assets_arg">List of asset ids separated by commas</string>
|
||||||
|
|
||||||
<!-- Get account by name fields -->
|
<!-- Get account by name fields -->
|
||||||
<string name="get_accounts_by_name_arg1">Account name</string>
|
<string name="get_accounts_by_name_arg1">Account name</string>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue