save transactions in db
Validate send request only one asset and amount
This commit is contained in:
parent
f80ac3b06d
commit
a0797edf6e
5 changed files with 35 additions and 42 deletions
|
@ -136,7 +136,7 @@ public abstract class GrapheneApiGenerator {
|
|||
* @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){
|
||||
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
|
||||
public void onSuccess(WitnessResponse response) {
|
||||
WitnessResponse<List<HistoricalTransfer>> resp = response;
|
||||
|
|
|
@ -19,36 +19,28 @@ public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest {
|
|||
// The destination account id
|
||||
private String mToAccount;
|
||||
// The amount of the transaction
|
||||
private long mBaseAmount;
|
||||
private long mAmount;
|
||||
// The asset id of the transaction
|
||||
private String mBaseAsset;
|
||||
// The fee amount
|
||||
private long mFeeAmount;
|
||||
// The fee asset id
|
||||
private String mFeeAsset;
|
||||
private String mAsset;
|
||||
// The memo, can be null
|
||||
private String mMemo;
|
||||
// The state of this request
|
||||
private Boolean isSend;
|
||||
|
||||
public ValidateBitsharesSendRequest(Context context, GrapheneAccount sourceAccount,
|
||||
String toAccount, long baseAmount, String baseAsset,
|
||||
long feeAmount,String feeAsset, String memo) {
|
||||
String toAccount, long amount, String asset, String memo) {
|
||||
super(CryptoCoin.BITSHARES);
|
||||
this.mContext = context;
|
||||
this.mSourceAccount = sourceAccount;
|
||||
this.mToAccount = toAccount;
|
||||
this.mBaseAmount = baseAmount;
|
||||
this.mBaseAsset = baseAsset;
|
||||
this.mFeeAmount = feeAmount;
|
||||
this.mFeeAsset = feeAsset;
|
||||
this.mAmount = amount;
|
||||
this.mAsset = asset;
|
||||
this.mMemo = memo;
|
||||
}
|
||||
|
||||
public ValidateBitsharesSendRequest(Context context, GrapheneAccount sourceAccount,
|
||||
String toAccount, long baseAmount, String baseAsset,
|
||||
long feeAmount,String feeAsset) {
|
||||
this(context, sourceAccount,toAccount,baseAmount,baseAsset,feeAmount,feeAsset,null);
|
||||
String toAccount, long amount, String asset) {
|
||||
this(context, sourceAccount,toAccount,amount,asset,null);
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
|
@ -63,21 +55,14 @@ public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest {
|
|||
return mToAccount;
|
||||
}
|
||||
|
||||
public long getBaseAmount() {
|
||||
return mBaseAmount;
|
||||
public long getAmount() {
|
||||
return mAmount;
|
||||
}
|
||||
|
||||
public String getBaseAsset() {
|
||||
return mBaseAsset;
|
||||
public String getAsset() {
|
||||
return mAsset;
|
||||
}
|
||||
|
||||
public long getFeeAmount() {
|
||||
return mFeeAmount;
|
||||
}
|
||||
|
||||
public String getFeeAsset() {
|
||||
return mFeeAsset;
|
||||
}
|
||||
|
||||
public String getMemo() {
|
||||
return mMemo;
|
||||
|
|
|
@ -223,14 +223,14 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
|||
}
|
||||
|
||||
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 toUserAccount = new UserAccount(sendRequest.getToAccount());
|
||||
TransferOperationBuilder builder = new TransferOperationBuilder()
|
||||
.setSource(fromUserAccount)
|
||||
.setDestination(toUserAccount)
|
||||
.setTransferAmount(new AssetAmount(UnsignedLong.valueOf(sendRequest.getBaseAmount()), new Asset(sendRequest.getBaseAsset())))
|
||||
.setFee(new AssetAmount(UnsignedLong.valueOf(sendRequest.getFeeAmount()), feeAsset));
|
||||
.setTransferAmount(new AssetAmount(UnsignedLong.valueOf(sendRequest.getAmount()), new Asset(sendRequest.getAsset())))
|
||||
.setFee(new AssetAmount(UnsignedLong.valueOf(0), feeAsset));
|
||||
if(sendRequest.getMemo() != null) {
|
||||
//builder.setMemo(new Memo(fromUserAccount,toUserAccount,0,sendRequest.getMemo().getBytes()));
|
||||
//TODO memo
|
||||
|
@ -315,7 +315,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
|||
int stop = start + limit;
|
||||
|
||||
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
|
||||
public void success(Object answer, int idPetition) {
|
||||
List<HistoricalTransfer> transfers = (List<HistoricalTransfer>) answer ;
|
||||
for(HistoricalTransfer transfer : transfers){
|
||||
CryptoCoinTransaction transaction = new CryptoCoinTransaction();
|
||||
for(HistoricalTransfer transfer : transfers) {
|
||||
if (transfer.getOperation() != null){
|
||||
CryptoCoinTransaction transaction = new CryptoCoinTransaction();
|
||||
transaction.setAccountId(account.getId());
|
||||
transaction.setAmount(transfer.getOperation().getAssetAmount().getAmount().longValue());
|
||||
CryptoCurrency currency = db.cryptoCurrencyDao().getByName(transfer.getOperation().getAssetAmount().getAsset().getSymbol());
|
||||
if(currency == null){
|
||||
if (currency == null) {
|
||||
System.out.println("CryptoCurrency not in database");
|
||||
//CryptoCurrency not in database
|
||||
Asset asset = transfer.getOperation().getAssetAmount().getAsset();
|
||||
|
@ -357,24 +358,28 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
|||
}else if(asset.getAssetType() == Asset.AssetType.UIA){
|
||||
assetType = BitsharesAsset.Type.UIA;
|
||||
}*/
|
||||
currency = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(), assetType);
|
||||
db.cryptoCurrencyDao().insertCryptoCurrency(currency);
|
||||
db.bitsharesAssetDao().insertBitsharesAssetInfo(new BitsharesAssetInfo((BitsharesAsset)currency));
|
||||
currency = new BitsharesAsset(asset.getSymbol(), asset.getPrecision(), asset.getObjectId(), assetType);
|
||||
long idCryptoCurrency = db.cryptoCurrencyDao().insertCryptoCurrency(currency)[0];
|
||||
BitsharesAssetInfo info = new BitsharesAssetInfo((BitsharesAsset) currency);
|
||||
info.setCryptoCurrencyId(idCryptoCurrency);
|
||||
currency.setId((int)idCryptoCurrency);
|
||||
db.bitsharesAssetDao().insertBitsharesAssetInfo(info);
|
||||
|
||||
}
|
||||
transaction.setIdCurrency(currency.getId());
|
||||
transaction.setConfirmed(true); //graphene transaction are always confirmed
|
||||
transaction.setFrom(transfer.getOperation().getFrom().getName());
|
||||
transaction.setInput(!transfer.getOperation().getFrom().getName().equals(account.getName()));
|
||||
transaction.setTo(transfer.getOperation().getTo().getName());
|
||||
transaction.setFrom(transfer.getOperation().getFrom().getObjectId());
|
||||
transaction.setInput(!transfer.getOperation().getFrom().getObjectId().equals(account.getAccountId()));
|
||||
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){
|
||||
int newStart= start + limit;
|
||||
int newStop= stop + limit;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ public class BitsharesAssetInfo {
|
|||
}
|
||||
|
||||
public BitsharesAssetInfo(BitsharesAsset asset){
|
||||
this.cryptoCurrencyId = asset.getId();
|
||||
this.bitsharesId = asset.getBitsharesId();
|
||||
this.assetType = asset.getAssetType();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package cy.agorise.crystalwallet.models;
|
|||
import android.arch.persistence.room.ColumnInfo;
|
||||
import android.arch.persistence.room.Entity;
|
||||
import android.arch.persistence.room.ForeignKey;
|
||||
import android.arch.persistence.room.Ignore;
|
||||
import android.arch.persistence.room.PrimaryKey;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.recyclerview.extensions.DiffCallback;
|
||||
|
@ -32,6 +33,7 @@ public class CryptoCoinTransaction {
|
|||
/**
|
||||
* The account associated with this transaction
|
||||
*/
|
||||
@Ignore
|
||||
protected CryptoNetAccount account;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue