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

View file

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

View file

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

View file

@ -7,5 +7,21 @@ package cy.agorise.crystalwallet.models;
public class GrapheneAccount extends CryptoNetAccount { public class GrapheneAccount extends CryptoNetAccount {
protected String name; 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;
}
} }