From 557a3e9202c89878a15ffe65b284ce83d8ba438c Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 9 Oct 2017 22:44:44 -0400 Subject: [PATCH] Arrange the transactionbroadcast --- .../ValidateBitsharesSendRequest.java | 40 ++++++++++++++----- .../crystalwallet/dao/CrystalDatabase.java | 2 + .../manager/BitsharesAccountManager.java | 18 +++++---- .../crystalwallet/models/GrapheneAccount.java | 16 ++++++++ 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateBitsharesSendRequest.java b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateBitsharesSendRequest.java index 8610cbe..3b6c136 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateBitsharesSendRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateBitsharesSendRequest.java @@ -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; } diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java index 5ead245..bb4d7d2 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java @@ -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) { diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java index a2f8e7a..f5c979f 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -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 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 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 diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java index 7f8e84d..915c4b7 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java @@ -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; + } }