save transactions in db

Validate send request only one asset and amount
master
henry 2017-10-25 22:46:42 -04:00
parent f80ac3b06d
commit a0797edf6e
5 changed files with 35 additions and 42 deletions

View File

@ -136,7 +136,7 @@ public abstract class GrapheneApiGenerator {
* @param request The Api request object, to answer this petition * @param request The Api request object, to answer this petition
*/ */
public static void getAccountTransaction(String accountGrapheneId, int start, int stop, int limit, final ApiRequest request){ public static void getAccountTransaction(String accountGrapheneId, int start, int stop, int limit, final ApiRequest request){
WebSocketThread thread = new WebSocketThread(new GetRelativeAccountHistory(new UserAccount(accountGrapheneId), stop, limit, start, new WitnessResponseListener() { WebSocketThread thread = new WebSocketThread(new GetRelativeAccountHistory(new UserAccount(accountGrapheneId), start, limit, stop, new WitnessResponseListener() {
@Override @Override
public void onSuccess(WitnessResponse response) { public void onSuccess(WitnessResponse response) {
WitnessResponse<List<HistoricalTransfer>> resp = response; WitnessResponse<List<HistoricalTransfer>> resp = response;

View File

@ -19,36 +19,28 @@ public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest {
// The destination account id // The destination account id
private String mToAccount; private String mToAccount;
// The amount of the transaction // The amount of the transaction
private long mBaseAmount; private long mAmount;
// The asset id of the transaction // The asset id of the transaction
private String mBaseAsset; private String mAsset;
// The fee amount
private long mFeeAmount;
// The fee asset id
private String mFeeAsset;
// The memo, can be null // The memo, can be null
private String mMemo; private String mMemo;
// The state of this request // The state of this request
private Boolean isSend; private Boolean isSend;
public ValidateBitsharesSendRequest(Context context, GrapheneAccount sourceAccount, public ValidateBitsharesSendRequest(Context context, GrapheneAccount sourceAccount,
String toAccount, long baseAmount, String baseAsset, String toAccount, long amount, String asset, String memo) {
long feeAmount,String feeAsset, String memo) {
super(CryptoCoin.BITSHARES); super(CryptoCoin.BITSHARES);
this.mContext = context; this.mContext = context;
this.mSourceAccount = sourceAccount; this.mSourceAccount = sourceAccount;
this.mToAccount = toAccount; this.mToAccount = toAccount;
this.mBaseAmount = baseAmount; this.mAmount = amount;
this.mBaseAsset = baseAsset; this.mAsset = asset;
this.mFeeAmount = feeAmount;
this.mFeeAsset = feeAsset;
this.mMemo = memo; this.mMemo = memo;
} }
public ValidateBitsharesSendRequest(Context context, GrapheneAccount sourceAccount, public ValidateBitsharesSendRequest(Context context, GrapheneAccount sourceAccount,
String toAccount, long baseAmount, String baseAsset, String toAccount, long amount, String asset) {
long feeAmount,String feeAsset) { this(context, sourceAccount,toAccount,amount,asset,null);
this(context, sourceAccount,toAccount,baseAmount,baseAsset,feeAmount,feeAsset,null);
} }
public Context getContext() { public Context getContext() {
@ -63,21 +55,14 @@ public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest {
return mToAccount; return mToAccount;
} }
public long getBaseAmount() { public long getAmount() {
return mBaseAmount; return mAmount;
} }
public String getBaseAsset() { public String getAsset() {
return mBaseAsset; return mAsset;
} }
public long getFeeAmount() {
return mFeeAmount;
}
public String getFeeAsset() {
return mFeeAsset;
}
public String getMemo() { public String getMemo() {
return mMemo; return mMemo;

View File

@ -223,14 +223,14 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
} }
private void validateSendRequest(final ValidateBitsharesSendRequest sendRequest){ private void validateSendRequest(final ValidateBitsharesSendRequest sendRequest){
Asset feeAsset = new Asset(sendRequest.getFeeAsset()); Asset feeAsset = new Asset(sendRequest.getAsset());
UserAccount fromUserAccount =new UserAccount(sendRequest.getSourceAccount().getAccountId()); UserAccount fromUserAccount =new UserAccount(sendRequest.getSourceAccount().getAccountId());
UserAccount toUserAccount = new UserAccount(sendRequest.getToAccount()); UserAccount toUserAccount = new UserAccount(sendRequest.getToAccount());
TransferOperationBuilder builder = new TransferOperationBuilder() TransferOperationBuilder builder = new TransferOperationBuilder()
.setSource(fromUserAccount) .setSource(fromUserAccount)
.setDestination(toUserAccount) .setDestination(toUserAccount)
.setTransferAmount(new AssetAmount(UnsignedLong.valueOf(sendRequest.getBaseAmount()), new Asset(sendRequest.getBaseAsset()))) .setTransferAmount(new AssetAmount(UnsignedLong.valueOf(sendRequest.getAmount()), new Asset(sendRequest.getAsset())))
.setFee(new AssetAmount(UnsignedLong.valueOf(sendRequest.getFeeAmount()), feeAsset)); .setFee(new AssetAmount(UnsignedLong.valueOf(0), feeAsset));
if(sendRequest.getMemo() != null) { if(sendRequest.getMemo() != null) {
//builder.setMemo(new Memo(fromUserAccount,toUserAccount,0,sendRequest.getMemo().getBytes())); //builder.setMemo(new Memo(fromUserAccount,toUserAccount,0,sendRequest.getMemo().getBytes()));
//TODO memo //TODO memo
@ -315,7 +315,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
int stop = start + limit; int stop = start + limit;
ApiRequest transactionRequest = new ApiRequest(0, new TransactionRequestListener(start, stop, limit, grapheneAccount, db)); ApiRequest transactionRequest = new ApiRequest(0, new TransactionRequestListener(start, stop, limit, grapheneAccount, db));
GrapheneApiGenerator.getAccountTransaction(grapheneAccount.getName(), start, stop, limit, transactionRequest); GrapheneApiGenerator.getAccountTransaction(grapheneAccount.getAccountId(), start, stop, limit, transactionRequest);
} }
} }
@ -338,12 +338,13 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
@Override @Override
public void success(Object answer, int idPetition) { public void success(Object answer, int idPetition) {
List<HistoricalTransfer> transfers = (List<HistoricalTransfer>) answer ; List<HistoricalTransfer> transfers = (List<HistoricalTransfer>) answer ;
for(HistoricalTransfer transfer : transfers){ for(HistoricalTransfer transfer : transfers) {
CryptoCoinTransaction transaction = new CryptoCoinTransaction(); if (transfer.getOperation() != null){
CryptoCoinTransaction transaction = new CryptoCoinTransaction();
transaction.setAccountId(account.getId()); transaction.setAccountId(account.getId());
transaction.setAmount(transfer.getOperation().getAssetAmount().getAmount().longValue()); transaction.setAmount(transfer.getOperation().getAssetAmount().getAmount().longValue());
CryptoCurrency currency = db.cryptoCurrencyDao().getByName(transfer.getOperation().getAssetAmount().getAsset().getSymbol()); CryptoCurrency currency = db.cryptoCurrencyDao().getByName(transfer.getOperation().getAssetAmount().getAsset().getSymbol());
if(currency == null){ if (currency == null) {
System.out.println("CryptoCurrency not in database"); System.out.println("CryptoCurrency not in database");
//CryptoCurrency not in database //CryptoCurrency not in database
Asset asset = transfer.getOperation().getAssetAmount().getAsset(); Asset asset = transfer.getOperation().getAssetAmount().getAsset();
@ -357,24 +358,28 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
}else if(asset.getAssetType() == Asset.AssetType.UIA){ }else if(asset.getAssetType() == Asset.AssetType.UIA){
assetType = BitsharesAsset.Type.UIA; assetType = BitsharesAsset.Type.UIA;
}*/ }*/
currency = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(), assetType); currency = new BitsharesAsset(asset.getSymbol(), asset.getPrecision(), asset.getObjectId(), assetType);
db.cryptoCurrencyDao().insertCryptoCurrency(currency); long idCryptoCurrency = db.cryptoCurrencyDao().insertCryptoCurrency(currency)[0];
db.bitsharesAssetDao().insertBitsharesAssetInfo(new BitsharesAssetInfo((BitsharesAsset)currency)); BitsharesAssetInfo info = new BitsharesAssetInfo((BitsharesAsset) currency);
info.setCryptoCurrencyId(idCryptoCurrency);
currency.setId((int)idCryptoCurrency);
db.bitsharesAssetDao().insertBitsharesAssetInfo(info);
} }
transaction.setIdCurrency(currency.getId()); transaction.setIdCurrency(currency.getId());
transaction.setConfirmed(true); //graphene transaction are always confirmed transaction.setConfirmed(true); //graphene transaction are always confirmed
transaction.setFrom(transfer.getOperation().getFrom().getName()); transaction.setFrom(transfer.getOperation().getFrom().getObjectId());
transaction.setInput(!transfer.getOperation().getFrom().getName().equals(account.getName())); transaction.setInput(!transfer.getOperation().getFrom().getObjectId().equals(account.getAccountId()));
transaction.setTo(transfer.getOperation().getTo().getName()); transaction.setTo(transfer.getOperation().getTo().getObjectId());
GrapheneApiGenerator.getBlockHeaderTime(transfer.getBlockNum(),new ApiRequest(0,new GetTransactionDate(transaction,db.transactionDao()))); GrapheneApiGenerator.getBlockHeaderTime(transfer.getBlockNum(), new ApiRequest(0, new GetTransactionDate(transaction, db.transactionDao())));
}
} }
if(transfers.size()>= limit){ if(transfers.size()>= limit){
int newStart= start + limit; int newStart= start + limit;
int newStop= stop + limit; int newStop= stop + limit;
ApiRequest transactionRequest = new ApiRequest(newStart/limit, new TransactionRequestListener(newStart,newStop,limit,account,db)); ApiRequest transactionRequest = new ApiRequest(newStart/limit, new TransactionRequestListener(newStart,newStop,limit,account,db));
GrapheneApiGenerator.getAccountTransaction(account.getName(),newStart,newStop,limit,transactionRequest); GrapheneApiGenerator.getAccountTransaction(account.getAccountId(),newStart,newStop,limit,transactionRequest);
} }
} }

View File

@ -37,6 +37,7 @@ public class BitsharesAssetInfo {
} }
public BitsharesAssetInfo(BitsharesAsset asset){ public BitsharesAssetInfo(BitsharesAsset asset){
this.cryptoCurrencyId = asset.getId();
this.bitsharesId = asset.getBitsharesId(); this.bitsharesId = asset.getBitsharesId();
this.assetType = asset.getAssetType(); this.assetType = asset.getAssetType();
} }

View File

@ -3,6 +3,7 @@ package cy.agorise.crystalwallet.models;
import android.arch.persistence.room.ColumnInfo; import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity; import android.arch.persistence.room.Entity;
import android.arch.persistence.room.ForeignKey; import android.arch.persistence.room.ForeignKey;
import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.PrimaryKey; import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.recyclerview.extensions.DiffCallback; import android.support.v7.recyclerview.extensions.DiffCallback;
@ -32,6 +33,7 @@ public class CryptoCoinTransaction {
/** /**
* The account associated with this transaction * The account associated with this transaction
*/ */
@Ignore
protected CryptoNetAccount account; protected CryptoNetAccount account;
/** /**