Bitshares manager use the new bitshares account cache
This commit is contained in:
parent
39a8a1e446
commit
d0df53d8e2
2 changed files with 69 additions and 36 deletions
|
@ -24,6 +24,9 @@ public interface BitsharesAccountNameCacheDao {
|
|||
@Query("SELECT * FROM bitshares_account_name_cache WHERE account_id = :account_id")
|
||||
BitsharesAccountNameCache getByAccountId(String account_id);
|
||||
|
||||
@Query("SELECT * FROM bitshares_account_name_cache WHERE account_name = :name")
|
||||
BitsharesAccountNameCache getByAccountName(String account_name);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public long[] insertBitsharesAccountNameCache(BitsharesAccountNameCache... accountsNames);
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package cy.agorise.crystalwallet.manager;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
|
||||
|
@ -18,9 +17,9 @@ import cy.agorise.crystalwallet.apigenerator.ApiRequest;
|
|||
import cy.agorise.crystalwallet.apigenerator.ApiRequestListener;
|
||||
import cy.agorise.crystalwallet.apigenerator.BitsharesFaucetApiGenerator;
|
||||
import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator;
|
||||
import cy.agorise.crystalwallet.apigenerator.grapheneoperation.AccountUpgradeOperation;
|
||||
import cy.agorise.crystalwallet.apigenerator.grapheneoperation.AccountUpgradeOperationBuilder;
|
||||
import cy.agorise.crystalwallet.application.constant.BitsharesConstant;
|
||||
import cy.agorise.crystalwallet.models.BitsharesAccountNameCache;
|
||||
import cy.agorise.crystalwallet.models.seed.BIP39;
|
||||
import cy.agorise.crystalwallet.requestmanagers.CryptoNetEquivalentRequest;
|
||||
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequest;
|
||||
|
@ -389,17 +388,56 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast a send asset request, the idAsset is already fetched
|
||||
* @param sendRequest The petition for transfer
|
||||
* @param idAsset The Bitshares Asset's id
|
||||
*/
|
||||
private void validateSendRequest(final ValidateBitsharesSendRequest sendRequest , final String idAsset){
|
||||
final Asset feeAsset = new Asset(idAsset);
|
||||
final UserAccount fromUserAccount =new UserAccount(sendRequest.getSourceAccount().getAccountId());
|
||||
|
||||
//TODO cached to accounts
|
||||
final CrystalDatabase db = CrystalDatabase.getAppDatabase(sendRequest.getContext());
|
||||
BitsharesAccountNameCache cacheAccount = db.bitsharesAccountNameCacheDao().getByAccountName(sendRequest.getToAccount());
|
||||
if(cacheAccount == null) {
|
||||
this.getAccountInfoByName(sendRequest.getToAccount(), new ManagerRequest() {
|
||||
|
||||
@Override
|
||||
public void success(Object answer) {
|
||||
GrapheneAccount toUserGrapheneAccount = (GrapheneAccount) answer;
|
||||
UserAccount toUserAccount = new UserAccount(toUserGrapheneAccount.getAccountId());
|
||||
try {
|
||||
BitsharesAccountNameCache cacheAccount = new BitsharesAccountNameCache();
|
||||
cacheAccount.setName(sendRequest.getToAccount());
|
||||
cacheAccount.setAccountId(toUserAccount.getObjectId());
|
||||
db.bitsharesAccountNameCacheDao().insertBitsharesAccountNameCache(cacheAccount);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
validateSendRequest(sendRequest,fromUserAccount,toUserAccount,feeAsset,idAsset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail() {
|
||||
sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.NO_TO_USER_INFO);
|
||||
}
|
||||
});
|
||||
}else {
|
||||
UserAccount toUserAccount = new UserAccount(cacheAccount.getAccountId());
|
||||
this.validateSendRequest(sendRequest,fromUserAccount,toUserAccount,feeAsset,idAsset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast a transaction request
|
||||
* @param sendRequest The petition for transfer operation
|
||||
* @param fromUserAccount The source account
|
||||
* @param toUserAccount The receiver account
|
||||
* @param feeAsset The Fee Asset
|
||||
* @param idAsset The id of the asset to be used on the operation
|
||||
*/
|
||||
private void validateSendRequest(final ValidateBitsharesSendRequest sendRequest, UserAccount fromUserAccount,
|
||||
UserAccount toUserAccount, Asset feeAsset, String idAsset){
|
||||
TransferOperationBuilder builder = new TransferOperationBuilder()
|
||||
.setSource(fromUserAccount)
|
||||
.setDestination(toUserAccount)
|
||||
|
@ -433,14 +471,6 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
|||
GrapheneApiGenerator.broadcastTransaction(transaction, feeAsset, transactionRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail() {
|
||||
sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.NO_TO_USER_INFO);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast a transaction request
|
||||
*/
|
||||
|
@ -667,7 +697,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
|||
GrapheneApiGenerator.getEquivalentValue(fromAsset.getBitsharesId(),toAsset.getBitsharesId(), getEquivalentRequest);
|
||||
}else{
|
||||
//TODO error
|
||||
System.out.println("Equivalen Value error ");
|
||||
System.out.println("Equivalent Value error ");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue