Merge branch 'develop' of github.com:Agorise/graphenej into develop

This commit is contained in:
Severiano Jaramillo 2018-11-06 11:37:08 -06:00
commit 76713f0623
10 changed files with 101 additions and 7 deletions

View file

@ -5,12 +5,11 @@ apply plugin: 'com.android.library'
//apply from: 'maven-push.gradle'
android {
compileSdkVersion 24
buildToolsVersion '28.0.3'
compileSdkVersion 28
defaultConfig {
minSdkVersion 14
targetSdkVersion 24
targetSdkVersion 28
versionCode 12
versionName "0.4.7-alpha3"
vectorDrawables.useSupportLibrary = true

View file

@ -191,6 +191,11 @@ public class AssetAmount implements ByteSerializable, JsonSerializable {
return jsonAmount;
}
@Override
public String toString() {
return String.format("(asset=%s, amount=%s)", asset.getObjectId(), amount.toString(10));
}
/**
* Custom serializer used to translate this object into the JSON-formatted entry we need for a transaction.
*/

View file

@ -25,7 +25,7 @@ public class RPC {
public static final String CALL_LOOKUP_ACCOUNTS = "lookup_accounts";
public static final String CALL_LIST_ASSETS = "list_assets";
public static final String CALL_GET_OBJECTS = "get_objects";
public static final String 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_GET_BLOCK_HEADER = "get_block_header";
public static final String CALL_GET_BLOCK = "get_block";

View file

@ -79,7 +79,7 @@ public class GetAccountBalances extends BaseGrapheneHandler {
}
params.add(mUserAccount.getObjectId());
params.add(assetList);
ApiCall apiCall = new ApiCall(0, RPC.GET_ACCOUNT_BALANCES, params, RPC.VERSION, requestId);
ApiCall apiCall = new ApiCall(0, RPC.CALL_GET_ACCOUNT_BALANCES, params, RPC.VERSION, requestId);
websocket.sendText(apiCall.toJsonString());
}

View file

@ -19,6 +19,7 @@ import cy.agorise.graphenej.LimitOrder;
import cy.agorise.graphenej.Memo;
import cy.agorise.graphenej.Transaction;
import cy.agorise.graphenej.UserAccount;
import cy.agorise.graphenej.api.calls.GetAccountBalances;
import cy.agorise.graphenej.api.calls.GetAccountByName;
import cy.agorise.graphenej.api.calls.GetAccountHistoryByOperations;
import cy.agorise.graphenej.api.calls.GetAccounts;
@ -185,6 +186,13 @@ public class DeserializationMap {
.registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer())
.create();
mGsonMap.put(GetKeyReferences.class, getKeyReferencesGson);
// GetAccountBalances
mClassMap.put(GetAccountBalances.class, List.class);
Gson getAccountBalancesGson = new GsonBuilder()
.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer())
.create();
mGsonMap.put(GetAccountBalances.class, getAccountBalancesGson);
}
public Class getReceivedClass(Class _class){

View file

@ -32,6 +32,7 @@ import cy.agorise.graphenej.UserAccount;
import cy.agorise.graphenej.api.ApiAccess;
import cy.agorise.graphenej.api.ConnectionStatusUpdate;
import cy.agorise.graphenej.api.calls.ApiCallable;
import cy.agorise.graphenej.api.calls.GetAccountBalances;
import cy.agorise.graphenej.api.calls.GetAccounts;
import cy.agorise.graphenej.api.calls.GetFullAccounts;
import cy.agorise.graphenej.api.calls.GetKeyReferences;
@ -567,7 +568,10 @@ public class NetworkService extends Service {
} else if(requestClass == GetKeyReferences.class){
Type GetKeyReferencesResponse = new TypeToken<JsonRpcResponse<List<List<UserAccount>>>>(){}.getType();
parsedResponse = gson.fromJson(text, GetKeyReferencesResponse);
} else {
} else if(requestClass == GetAccountBalances.class){
Type GetAccountBalancesResponse = new TypeToken<JsonRpcResponse<List<AssetAmount>>>(){}.getType();
parsedResponse = gson.fromJson(text, GetAccountBalancesResponse);
}else {
Log.w(TAG,"Unknown request class");
}
}else{

View file

@ -0,0 +1,42 @@
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.UserAccount;
import cy.agorise.graphenej.api.ApiAccess;
import cy.agorise.graphenej.models.ApiCall;
/**
* Wrapper around the 'get_account_balances' API call.
*
* @see <a href="https://goo.gl/faFdey">get_account_balances API doc</a>
*/
public class GetAccountBalances implements ApiCallable {
public static final int REQUIRED_API = ApiAccess.API_NONE;
private UserAccount mUserAccount;
private List<Asset> mAssetList;
public GetAccountBalances(UserAccount userAccount, List<Asset> assets){
mUserAccount = userAccount;
mAssetList = assets;
}
@Override
public ApiCall toApiCall(int apiId, long sequenceId) {
ArrayList<Serializable> params = new ArrayList<>();
ArrayList<Serializable> assetList = new ArrayList<>();
if(mAssetList != null){
for(Asset asset : mAssetList){
assetList.add(asset.getObjectId());
}
}
params.add(mUserAccount.getObjectId());
params.add(assetList);
return new ApiCall(apiId, RPC.CALL_GET_ACCOUNT_BALANCES, params, RPC.VERSION, sequenceId);
}
}

View file

@ -49,7 +49,8 @@ public class CallsActivity extends AppCompatActivity {
RPC.CALL_GET_FULL_ACCOUNTS,
RPC.CALL_SET_SUBSCRIBE_CALLBACK,
RPC.CALL_GET_DYNAMIC_GLOBAL_PROPERTIES,
RPC.CALL_GET_KEY_REFERENCES
RPC.CALL_GET_KEY_REFERENCES,
RPC.CALL_GET_ACCOUNT_BALANCES
};
@NonNull

View file

@ -19,10 +19,13 @@ import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cy.agorise.graphenej.Asset;
import cy.agorise.graphenej.AssetAmount;
import cy.agorise.graphenej.Memo;
import cy.agorise.graphenej.OperationType;
import cy.agorise.graphenej.RPC;
@ -30,6 +33,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.GetAccountBalances;
import cy.agorise.graphenej.api.calls.GetAccountByName;
import cy.agorise.graphenej.api.calls.GetAccountHistoryByOperations;
import cy.agorise.graphenej.api.calls.GetAccounts;
@ -144,6 +148,8 @@ public class PerformCallActivity extends ConnectedActivity {
case RPC.CALL_GET_KEY_REFERENCES:
setupGetKeyReferences();
break;
case RPC.CALL_GET_ACCOUNT_BALANCES:
setupGetAccountBalances();
default:
Log.d(TAG,"Default called");
}
@ -269,6 +275,12 @@ public class PerformCallActivity extends ConnectedActivity {
param1.setText("BTS8a7XJ94u1traaLGFHw6NgpvUaxmbG4MyCcZC1hBj9HCBuMEwXP");
}
private void setupGetAccountBalances(){
requiredInput(2);
param1.setHint(R.string.get_account_balances_arg1);
param2.setHint(R.string.get_account_balances_arg2);
}
private void requiredInput(int inputCount){
if(inputCount == 0){
mParam1View.setVisibility(View.GONE);
@ -340,6 +352,8 @@ public class PerformCallActivity extends ConnectedActivity {
case RPC.CALL_GET_KEY_REFERENCES:
getKeyReferences();
break;
case RPC.CALL_GET_ACCOUNT_BALANCES:
getAccountBalances();
default:
Log.d(TAG,"Default called");
}
@ -440,6 +454,17 @@ public class PerformCallActivity extends ConnectedActivity {
}
}
private void getAccountBalances(){
String accountId = param1.getText().toString();
UserAccount userAccount = new UserAccount(accountId);
String assets = param2.getText().toString();
String[] assetArray = assets.split(",");
List<Asset> assetList = new ArrayList<Asset>();
for(String id : assetArray) assetList.add(new Asset(id));
long id = mNetworkService.sendMessage(new GetAccountBalances(userAccount, assetList), GetAccountBalances.REQUIRED_API);
responseMap.put(id, mRPC);
}
/**
* Internal method that will decide what to do with each JSON-RPC response
*
@ -450,6 +475,12 @@ public class PerformCallActivity extends ConnectedActivity {
if(responseMap.get(id) != null){
String request = responseMap.get(id);
switch(request){
case RPC.CALL_GET_ACCOUNT_BALANCES:
List<AssetAmount> balances = (List<AssetAmount>) response.result;
StringBuilder builder = new StringBuilder();
for(AssetAmount assetAmount : balances) builder.append(assetAmount).append("\n");
mResponseView.setText(builder.toString());
break;
case RPC.CALL_GET_ACCOUNTS:
case RPC.CALL_GET_BLOCK:
case RPC.CALL_GET_BLOCK_HEADER:

View file

@ -54,4 +54,8 @@
<!-- GetFullAccounts input fields -->
<string name="get_full_accounts_arg1">Account names or ids, separated by commas</string>
<!-- GetAccountBalances -->
<string name="get_account_balances_arg1">User account</string>
<string name="get_account_balances_arg2">Comma-separated list of assets</string>
</resources>