This commit is contained in:
Javier Varona 2017-10-09 22:46:09 -04:00
commit 9670d23dc1
4 changed files with 57 additions and 19 deletions

View file

@ -1,27 +1,41 @@
package cy.agorise.crystalwallet.cryptonetinforequests;
import android.content.Context;
import cy.agorise.crystalwallet.enums.CryptoCoin;
import cy.agorise.crystalwallet.models.GrapheneAccount;
/**
* Class used to make a send amount request.
*
* Created by henry on 8/10/2017.
*/
public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest {
private String mSourceAccount;
// The app context
private Context mContext;
// The source account used to transfer fund from
private GrapheneAccount mSourceAccount;
// The destination account id
private String mToAccount;
// The amount of the transaction
private long mBaseAmount;
// The asset id of the transaction
private String mBaseAsset;
// The fee amount
private long mFeeAmount;
// The fee asset id
private String mFeeAsset;
// The memo, can be null
private String mMemo;
// The state of this request
private Boolean isSend;
public ValidateBitsharesSendRequest(String sourceAccount, String toAccount,
long baseAmount, String baseAsset, long feeAmount,
String feeAsset, String memo) {
public ValidateBitsharesSendRequest(Context context, GrapheneAccount sourceAccount,
String toAccount, long baseAmount, String baseAsset,
long feeAmount,String feeAsset, String memo) {
super(CryptoCoin.BITSHARES);
this.mContext = context;
this.mSourceAccount = sourceAccount;
this.mToAccount = toAccount;
this.mBaseAmount = baseAmount;
@ -31,13 +45,17 @@ public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest {
this.mMemo = memo;
}
public ValidateBitsharesSendRequest(String sourceAccount, String toAccount,
long baseAmount, String baseAsset, long feeAmount,
String feeAsset) {
this(sourceAccount,toAccount,baseAmount,baseAsset,feeAmount,feeAsset,null);
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);
}
public String getSourceAccount() {
public Context getContext() {
return mContext;
}
public GrapheneAccount getSourceAccount() {
return mSourceAccount;
}

View file

@ -41,6 +41,8 @@ public abstract class CrystalDatabase extends RoomDatabase {
return instance;
}
/*static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {

View file

@ -1,5 +1,7 @@
package cy.agorise.crystalwallet.manager;
import android.arch.lifecycle.LiveData;
import com.google.common.primitives.UnsignedLong;
import org.bitcoinj.core.ECKey;
@ -14,18 +16,18 @@ import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestsListe
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest;
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest;
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAccountRequest;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.graphenej.Address;
import cy.agorise.graphenej.Asset;
import cy.agorise.graphenej.AssetAmount;
import cy.agorise.graphenej.BaseOperation;
import cy.agorise.graphenej.BlockData;
import cy.agorise.graphenej.BrainKey;
import cy.agorise.graphenej.PublicKey;
import cy.agorise.graphenej.Transaction;
import cy.agorise.graphenej.UserAccount;
import cy.agorise.graphenej.models.AccountProperties;
import cy.agorise.graphenej.operations.TransferOperation;
import cy.agorise.graphenej.operations.TransferOperationBuilder;
/**
@ -117,7 +119,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
private void validateSendRequest(final ValidateBitsharesSendRequest sendRequest){
Asset feeAsset = new Asset(sendRequest.getFeeAsset());
TransferOperationBuilder builder = new TransferOperationBuilder()
.setSource(new UserAccount(sendRequest.getSourceAccount()))
.setSource(new UserAccount(sendRequest.getSourceAccount().getAccountId()))
.setDestination(new UserAccount(sendRequest.getToAccount()))
.setTransferAmount(new AssetAmount(UnsignedLong.valueOf(sendRequest.getBaseAmount()), new Asset(sendRequest.getBaseAsset())))
.setFee(new AssetAmount(UnsignedLong.valueOf(sendRequest.getFeeAmount()), feeAsset));
@ -125,11 +127,11 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
ArrayList<BaseOperation> operationList = new ArrayList();
operationList.add(builder.build());
//TODO blockdata
BlockData blockData = null;
//TODO privateKey
ECKey privateKey = null;
Transaction transaction = new Transaction(privateKey, blockData, operationList);
//TODO get privateKey with seed model
LiveData<AccountSeed> seed = CrystalDatabase.getAppDatabase(sendRequest.getContext()).accountSeedDao().findById(sendRequest.getSourceAccount().getSeedId());
ECKey privateKey = new BrainKey(seed.getValue().getMasterSeed(),0).getPrivateKey();
Transaction transaction = new Transaction(privateKey, null, operationList);
ApiRequest transactionRequest = new ApiRequest(0, new ApiRequestListener() {
@Override

View file

@ -7,5 +7,21 @@ package cy.agorise.crystalwallet.models;
public class GrapheneAccount extends CryptoNetAccount {
protected String name;
protected String accountId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAccountId() {
return accountId;
}
public void setAccountId(String accountId) {
this.accountId = accountId;
}
}