Merge pull request #8 from hvarona/develop

Develop
This commit is contained in:
hvarona 2018-11-17 13:17:47 -04:00 committed by GitHub
commit 6e4b66a5e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 486 additions and 181 deletions

View file

@ -1,7 +1,6 @@
package cy.agorise.crystalwallet.apigenerator;
import android.content.Context;
import android.util.Log;
import java.io.Serializable;
import java.util.ArrayList;
@ -9,7 +8,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import cy.agorise.crystalwallet.application.constant.BitsharesConstant;
import cy.agorise.crystalwallet.dao.BitsharesAssetDao;
import cy.agorise.crystalwallet.dao.CryptoCoinBalanceDao;
import cy.agorise.crystalwallet.dao.CryptoCurrencyDao;
@ -107,7 +105,7 @@ public abstract class GrapheneApiGenerator {
* @param accountId The accountId to retrieve
* @param request The Api request object, to answer this petition
*/
public static void getAccountById(String accountId, final ApiRequest request){
public static void getAccountById(String accountId, CryptoNet cryptoNet, final ApiRequest request){
WebSocketThread thread = new WebSocketThread(new GetAccounts(accountId,
new WitnessResponseListener() {
@Override
@ -128,7 +126,7 @@ public abstract class GrapheneApiGenerator {
public void onError(BaseResponse.Error error) {
request.getListener().fail(request.getId());
}
}),CryptoNetManager.getURL(CryptoNet.BITSHARES));
}),CryptoNetManager.getURL(cryptoNet));
thread.start();
}
@ -138,7 +136,7 @@ public abstract class GrapheneApiGenerator {
* @param address The address to retrieve
* @param request The Api request object, to answer this petition
*/
public static void getAccountByOwnerOrActiveAddress(Address address, final ApiRequest request){
public static void getAccountByOwnerOrActiveAddress(Address address, CryptoNet cryptoNet, final ApiRequest request){
WebSocketThread thread = new WebSocketThread(new GetKeyReferences(address, true,
new WitnessResponseListener() {
@Override
@ -168,7 +166,7 @@ public abstract class GrapheneApiGenerator {
public void onError(BaseResponse.Error error) {
request.getListener().fail(request.getId());
}
}),CryptoNetManager.getURL(CryptoNet.BITSHARES));
}),CryptoNetManager.getURL(cryptoNet));
thread.start();
}
@ -205,7 +203,7 @@ public abstract class GrapheneApiGenerator {
* @param accountName The account Name to find
* @param request The Api request object, to answer this petition
*/
public static void getAccountByName(String accountName, final ApiRequest request){
public static void getAccountByName(String accountName, CryptoNet cryptoNet,final ApiRequest request){
WebSocketThread thread = new WebSocketThread(new GetAccountByName(accountName,
new WitnessResponseListener() {
@Override
@ -222,7 +220,7 @@ public abstract class GrapheneApiGenerator {
public void onError(BaseResponse.Error error) {
request.getListener().fail(request.getId());
}
}),CryptoNetManager.getURL(CryptoNet.BITSHARES));
}),CryptoNetManager.getURL(cryptoNet));
thread.start();
}
@ -232,7 +230,7 @@ public abstract class GrapheneApiGenerator {
* @param accountName The account Name to find
* @param request The Api request object, to answer this petition
*/
public static void getAccountIdByName(String accountName, final ApiRequest request){
public static void getAccountIdByName(String accountName, CryptoNet cryptoNet, final ApiRequest request){
WebSocketThread thread = new WebSocketThread(new GetAccountByName(accountName,
new WitnessResponseListener() {
@Override
@ -249,7 +247,7 @@ public abstract class GrapheneApiGenerator {
public void onError(BaseResponse.Error error) {
request.getListener().fail(request.getId());
}
}),CryptoNetManager.getURL(CryptoNet.BITSHARES));
}),CryptoNetManager.getURL(cryptoNet));
thread.start();
}
@ -283,7 +281,7 @@ public abstract class GrapheneApiGenerator {
* @param assetNames The list of the names of the assets to be retrieve
* @param request the api request object, to answer this petition
*/
public static void getAssetByName(ArrayList<String> assetNames, final ApiRequest request){
public static void getAssetByName(ArrayList<String> assetNames, CryptoNet cryptoNet,final ApiRequest request){
WebSocketThread thread = new WebSocketThread(new LookupAssetSymbols(assetNames,true,
new WitnessResponseListener() {
@ -318,7 +316,7 @@ public abstract class GrapheneApiGenerator {
public void onError(BaseResponse.Error error) {
request.getListener().fail(request.getId());
}
}),CryptoNetManager.getURL(CryptoNet.BITSHARES));
}),CryptoNetManager.getURL(cryptoNet));
thread.start();
}
@ -327,7 +325,7 @@ public abstract class GrapheneApiGenerator {
* @param assetIds The list of the ids to retrieve
* @param request the api request object, to answer this petition
*/
public static void getAssetById(ArrayList<String> assetIds, final ApiRequest request){
public static void getAssetById(ArrayList<String> assetIds, CryptoNet cryptoNet, final ApiRequest request){
ArrayList<Asset> assets = new ArrayList<>();
for(String assetId : assetIds){
Asset asset = new Asset(assetId);
@ -366,7 +364,7 @@ public abstract class GrapheneApiGenerator {
public void onError(BaseResponse.Error error) {
request.getListener().fail(request.getId());
}
}),CryptoNetManager.getURL(CryptoNet.BITSHARES));
}),CryptoNetManager.getURL(cryptoNet));
thread.start();
}
@ -438,7 +436,7 @@ public abstract class GrapheneApiGenerator {
});
ArrayList<String> assets = new ArrayList<>();
assets.add(tOperation.getAssetAmount().getAsset().getObjectId());
GrapheneApiGenerator.getAssetById(assets,assetRequest);
GrapheneApiGenerator.getAssetById(assets,CryptoNet.BITSHARES,assetRequest);
}else{
saveTransaction(transaction,cryptoCurrencyDao.getById(info.getCryptoCurrencyId()),accountBitsharesId,tOperation,context);
}
@ -531,7 +529,7 @@ public abstract class GrapheneApiGenerator {
});
ArrayList<String> assets = new ArrayList<>();
assets.add(tOperation.getAssetAmount().getAsset().getObjectId());
GrapheneApiGenerator.getAssetById(assets,assetRequest);
GrapheneApiGenerator.getAssetById(assets,CryptoNet.STEEM,assetRequest);
}else{
saveTransaction(transaction,cryptoCurrencyDao.getById(info.getCryptoCurrencyId()),accountSteemId,tOperation,context);
}
@ -594,7 +592,7 @@ public abstract class GrapheneApiGenerator {
* @param context The android context of this application
*/
public static void getAccountBalance(final long accountId, final String accountGrapheneId,
CryptoNet cryptoNet, final Context context){
final CryptoNet cryptoNet, final Context context){
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
final CryptoCoinBalanceDao balanceDao = db.cryptoCoinBalanceDao();
@ -640,7 +638,7 @@ public abstract class GrapheneApiGenerator {
public void fail(int idPetition) {
}
});
getAssetById(idAssets,getAssetRequest);
getAssetById(idAssets,cryptoNet,getAssetRequest);
}else {
@ -666,7 +664,7 @@ public abstract class GrapheneApiGenerator {
* @param blockHeader The block header to retrieve the date time
* @param request the api request object, to answer this petition
*/
public static void getBlockHeaderTime(long blockHeader, final ApiRequest request){
public static void getBlockHeaderTime(long blockHeader, CryptoNet cryptoNet,final ApiRequest request){
WebSocketThread thread = new WebSocketThread(new GetBlockHeader(blockHeader, new WitnessResponseListener() {
@Override
public void onSuccess(WitnessResponse response) {
@ -681,7 +679,7 @@ public abstract class GrapheneApiGenerator {
public void onError(BaseResponse.Error error) {
request.getListener().fail(request.getId());
}
}),CryptoNetManager.getURL(CryptoNet.BITSHARES));
}),CryptoNetManager.getURL(cryptoNet));
thread.start();
}
@ -784,7 +782,7 @@ public abstract class GrapheneApiGenerator {
});
ArrayList<String> names = new ArrayList<>();
names.add(baseAssetName);
GrapheneApiGenerator.getAssetByName(names,getAssetRequest);
GrapheneApiGenerator.getAssetByName(names,CryptoNet.BITSHARES,getAssetRequest);
}else {
BitsharesAsset baseAsset = new BitsharesAsset(baseCurrency);

View file

@ -57,6 +57,17 @@ public class CrystalApplication extends Application {
public static final CryptoCurrency BITCOIN_CURRENCY = new CryptoCurrency("BTC",CryptoNet.BITCOIN,8);
public static String STEEM_URL[] =
{
"https://api.steemit.com",
"https://api.steemitdev.com",
"https://api.steemitstage.com",
"https://api.steem.house",
"https://appbasetest.timcliff.com",
};
@Override
public void onCreate() {
super.onCreate();
@ -108,6 +119,8 @@ public class CrystalApplication extends Application {
db.cryptoCurrencyDao().insertCryptoCurrency(BITCOIN_CURRENCY);
}
CryptoNetManager.addCryptoNetURL(CryptoNet.STEEM,STEEM_URL);
GeneralSetting generalSettingPreferredLanguage = db.generalSettingDao().getSettingByName(GeneralSetting.SETTING_NAME_PREFERRED_LANGUAGE);

View file

@ -118,6 +118,9 @@ public abstract class CrystalDatabase extends RoomDatabase {
+"io_index INTEGER NOT NULL,"
+"address TEXT,"
+"is_output INTEGER NOT NULL,"
+"amount INTEGER NOT NULL,"
+"script_hex TEXT,"
+"original_txid TEXT,"
+"PRIMARY KEY (bitcoin_transaction_id, io_index, is_output),"
+"FOREIGN KEY (bitcoin_transaction_id) REFERENCES bitcoin_transaction(crypto_coin_transaction_id) ON DELETE CASCADE)");
}
@ -131,7 +134,7 @@ public abstract class CrystalDatabase extends RoomDatabase {
+"address_index INTEGER NOT NULL,"
+"is_change INTEGER NOT NULL,"
+"address TEXT NOT NULL,"
+"PRIMARY KEY (account_id, address_index),"
+"PRIMARY KEY (account_id, address_index, is_change),"
+"FOREIGN KEY (account_id) REFERENCES crypto_net_account(id) ON DELETE CASCADE)");
}
};

View file

@ -29,6 +29,7 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
@ -38,6 +39,10 @@ import com.google.zxing.common.BitMatrix;
import butterknife.OnClick;
import cy.agorise.crystalwallet.enums.CryptoCoin;
import cy.agorise.crystalwallet.enums.CryptoNet;
import cy.agorise.crystalwallet.requestmanagers.CalculateBitcoinUriRequest;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests;
import cy.agorise.crystalwallet.requestmanagers.NextBitcoinAccountAddressRequest;
import cy.agorise.crystalwallet.util.CircularImageView;
import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel;
import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter;
@ -341,52 +346,104 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
CryptoNetAccount toAccountSelected = (CryptoNetAccount) spTo.getSelectedItem();
/*
* this is only for graphene accounts.
*
**/
GrapheneAccount grapheneAccountSelected = new GrapheneAccount(toAccountSelected);
grapheneAccountSelected.loadInfo(db.grapheneAccountInfoDao().getByAccountId(toAccountSelected.getId()));
if (this.cryptoNetAccount.getCryptoNet() == CryptoNet.BITSHARES) {
/*
* this is only for graphene accounts.
*
**/
GrapheneAccount grapheneAccountSelected = new GrapheneAccount(toAccountSelected);
grapheneAccountSelected.loadInfo(db.grapheneAccountInfoDao().getByAccountId(toAccountSelected.getId()));
this.invoiceItems.clear();
this.invoiceItems.add(
new LineItem("transfer", 1, amount)
);
this.invoiceItems.clear();
this.invoiceItems.add(
new LineItem("transfer", 1, amount)
);
LineItem items[] = new LineItem[this.invoiceItems.size()];
items = this.invoiceItems.toArray(items);
this.invoice.setLineItems(items);
this.invoice.setTo(grapheneAccountSelected.getName());
this.invoice.setCurrency(this.cryptoCurrency.getName());
LineItem items[] = new LineItem[this.invoiceItems.size()];
items = this.invoiceItems.toArray(items);
this.invoice.setLineItems(items);
this.invoice.setTo(grapheneAccountSelected.getName());
this.invoice.setCurrency(this.cryptoCurrency.getName());
if (this.qrCodeTask != null){
this.qrCodeTask.cancel(true);
}
if (this.qrCodeTask != null) {
this.qrCodeTask.cancel(true);
}
this.qrCodeTask = new AsyncTask<Object, Void, Void>(){
this.qrCodeTask = new AsyncTask<Object, Void, Void>() {
@Override
protected Void doInBackground(Object... voids) {
try {
final Bitmap bitmap = textToImageEncode(Invoice.toQrCode(invoice));
@Override
protected Void doInBackground(Object... voids) {
try {
final Bitmap bitmap = textToImageEncode(Invoice.toQrCode(invoice));
if (!this.isCancelled()) {
ReceiveTransactionFragment.this.getActivity().runOnUiThread(new Runnable() {
if (!this.isCancelled()) {
ReceiveTransactionFragment.this.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
ivQrCode.setImageBitmap(bitmap);
}
});
}
} catch (WriterException e) {
Log.e("ReceiveFragment", "Error creating QrCode");
}
return null;
}
};
this.qrCodeTask.execute(null, null, null);
} else {
final CryptoCoin cryptoCoin = CryptoCoin.getByCryptoNet(this.cryptoNetAccount.getCryptoNet()).get(0);
//final NextBitcoinAccountAddressRequest addressRequest = new NextBitcoinAccountAddressRequest(this.cryptoNetAccount, cryptoCoin, getContext());
//addressRequest.setListener(new CryptoNetInfoRequestListener() {
// @Override
// public void onCarryOut() {
// if (addressRequest.getStatus() == NextBitcoinAccountAddressRequest.StatusCode.SUCCEEDED){
final CalculateBitcoinUriRequest uriRequest = new CalculateBitcoinUriRequest(cryptoCoin, cryptoNetAccount, getContext());
uriRequest.setListener(new CryptoNetInfoRequestListener(){
@Override
public void run() {
ivQrCode.setImageBitmap(bitmap);
public void onCarryOut(){
if (uriRequest.getUri() != null){
qrCodeTask = new AsyncTask<Object, Void, Void>() {
@Override
protected Void doInBackground(Object... voids) {
try {
final Bitmap bitmap = textToImageEncode(uriRequest.getUri());
if (!this.isCancelled()) {
ReceiveTransactionFragment.this.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
ivQrCode.setImageBitmap(bitmap);
}
});
}
} catch (WriterException e) {
Log.e("ReceiveFragment", "Error creating QrCode");
}
return null;
}
};
qrCodeTask.execute(null, null, null);
} else {
Log.e("ReceiveFragment", "Error obtaining the uri");
}
}
});
}
} catch (WriterException e) {
Log.e("ReceiveFragment", "Error creating QrCode");
}
return null;
}
};
this.qrCodeTask.execute(null,null,null);
CryptoNetInfoRequests.getInstance().addRequest(uriRequest);
// } else {
// Toast.makeText(getContext(),"Error creating address",Toast.LENGTH_SHORT);
// }
// }
//});
}
}
Bitmap textToImageEncode(String Value) throws WriterException {

View file

@ -68,6 +68,7 @@ import cy.agorise.crystalwallet.enums.CryptoCoin;
import cy.agorise.crystalwallet.enums.CryptoNet;
import cy.agorise.crystalwallet.interfaces.OnResponse;
import cy.agorise.crystalwallet.requestmanagers.BitcoinSendRequest;
import cy.agorise.crystalwallet.requestmanagers.BitcoinUriParseRequest;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequest;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests;
@ -803,8 +804,34 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH));
etAmount.setText(df.format(amount));
Log.i("SendFragment", result.getText());
return;
}catch(Exception e){
e.printStackTrace();
}
//Is not a bitshares QR
CryptoCoin cryptoCoin = CryptoCoin.getByCryptoNet(this.cryptoNetAccount.getCryptoNet()).get(0);
final BitcoinUriParseRequest bitcoinUriParseRequest = new BitcoinUriParseRequest(result.getText(), cryptoCoin);
bitcoinUriParseRequest.setListener(new CryptoNetInfoRequestListener() {
@Override
public void onCarryOut() {
if (bitcoinUriParseRequest.getAddress() != null) {
if (!bitcoinUriParseRequest.getAddress().equals("")) {
etTo.setText(bitcoinUriParseRequest.getAddress());
}
if (bitcoinUriParseRequest.getAmount() > 0) {
etAmount.setText(bitcoinUriParseRequest.getAmount().toString());
}
if (!bitcoinUriParseRequest.getMemo().equals("")) {
etMemo.setText(bitcoinUriParseRequest.getMemo());
}
} else {
Toast.makeText(getContext(), "Not a valid QR info", Toast.LENGTH_LONG);
}
}
});
CryptoNetInfoRequests.getInstance().addRequest(bitcoinUriParseRequest);
}
}

View file

@ -146,7 +146,8 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
GrapheneAccount fetch = (GrapheneAccount) answer;
grapheneAccount.setName(fetch.getName());
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount);
long idAccount = db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount)[0];
grapheneAccount.setId(idAccount);
db.grapheneAccountInfoDao().insertGrapheneAccountInfo(new GrapheneAccountInfo(grapheneAccount));
subscribeBitsharesAccount(grapheneAccount.getId(),grapheneAccount.getAccountId(),context);
}
@ -158,7 +159,8 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
});
}else {
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount);
long idAccount = db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount)[0];
grapheneAccount.setId(idAccount);
db.grapheneAccountInfoDao().insertGrapheneAccountInfo(new GrapheneAccountInfo(grapheneAccount));
subscribeBitsharesAccount(grapheneAccount.getId(), grapheneAccount.getAccountId(), context);
}
@ -196,6 +198,11 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
info.setName(fetch.getName());
grapheneAccount.setName(fetch.getName());
db.grapheneAccountInfoDao().insertGrapheneAccountInfo(info);
AccountSeed seed = db.accountSeedDao().findById(grapheneAccount.getSeedId());
if(seed.getName() == null || seed.getName().isEmpty()){
seed.setName(grapheneAccount.getName());
db.accountSeedDao().insertAccountSeed(seed);
}
subscribeBitsharesAccount(grapheneAccount.getId(),grapheneAccount.getAccountId(),context);
}
@ -306,7 +313,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.BAD_SEED);
}
});
GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(new Address(ECKey.fromPublicOnly(bip39.getBitsharesActiveKey(0).getPubKey())),getAccountNamesBP39);
GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(new Address(ECKey.fromPublicOnly(bip39.getBitsharesActiveKey(0).getPubKey())),CryptoNet.BITSHARES,getAccountNamesBP39);
}
});
@ -314,7 +321,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
BrainKey bk = new BrainKey(importRequest.getMnemonic(), 0);
GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(bk.getPublicAddress("BTS"),getAccountNamesBK);
GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(bk.getPublicAddress("BTS"),CryptoNet.BITSHARES,getAccountNamesBK);
}
@ -384,7 +391,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
importRequest.setStatus(ValidateImportBitsharesAccountRequest.StatusCode.NO_ACCOUNT_DATA);
}
});
GrapheneApiGenerator.getAccountById((String)answer,getAccountInfo);
GrapheneApiGenerator.getAccountById((String)answer,CryptoNet.BITSHARES,getAccountInfo);
}
@Override
@ -394,7 +401,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
}
});
GrapheneApiGenerator.getAccountIdByName(importRequest.getAccountName(),checkAccountName);
GrapheneApiGenerator.getAccountIdByName(importRequest.getAccountName(),CryptoNet.BITSHARES,checkAccountName);
}
private void validateCreateAccount(final ValidateCreateBitsharesAccountRequest createRequest){
@ -449,7 +456,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
validateRequest.setAccountExists(false);
}
});
GrapheneApiGenerator.getAccountIdByName(validateRequest.getAccountName(),checkAccountName);
GrapheneApiGenerator.getAccountIdByName(validateRequest.getAccountName(),CryptoNet.BITSHARES,checkAccountName);
}
/**
@ -647,7 +654,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
AccountIdOrNameListener listener = new AccountIdOrNameListener(request);
ApiRequest accountRequest = new ApiRequest(0, listener);
GrapheneApiGenerator.getAccountById(grapheneId,accountRequest);
GrapheneApiGenerator.getAccountById(grapheneId,CryptoNet.BITSHARES,accountRequest);
}
/**
@ -659,7 +666,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
AccountIdOrNameListener listener = new AccountIdOrNameListener(request);
ApiRequest accountRequest = new ApiRequest(0, listener);
GrapheneApiGenerator.getAccountByName(grapheneName,accountRequest);
GrapheneApiGenerator.getAccountByName(grapheneName,CryptoNet.BITSHARES,accountRequest);
}
@ -670,7 +677,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
ApiRequest assetRequest = new ApiRequest(0, nameListener);
ArrayList<String> assetNames = new ArrayList<>();
assetNames.add(assetName);
GrapheneApiGenerator.getAssetByName(assetNames, assetRequest);
GrapheneApiGenerator.getAssetByName(assetNames, CryptoNet.BITSHARES,assetRequest);
}
@ -783,7 +790,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
});
ArrayList<String> assets = new ArrayList<>();
assets.add(transfer.getOperation().getAssetAmount().getAsset().getObjectId());
GrapheneApiGenerator.getAssetById(assets,assetRequest);
GrapheneApiGenerator.getAssetById(assets,CryptoNet.BITSHARES,assetRequest);
}else{
saveTransaction(transaction,info,transfer);
@ -812,7 +819,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
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(),CryptoNet.BITSHARES, new ApiRequest(0, new GetTransactionDate(transaction, db.transactionDao())));
}
}

View file

@ -38,6 +38,8 @@ import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCurrency;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.requestmanagers.BitcoinSendRequest;
import cy.agorise.crystalwallet.requestmanagers.BitcoinUriParseRequest;
import cy.agorise.crystalwallet.requestmanagers.CalculateBitcoinUriRequest;
import cy.agorise.crystalwallet.requestmanagers.CreateBitcoinAccountRequest;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequest;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestsListener;
@ -97,7 +99,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
CryptoCoinBalance balance = new CryptoCoinBalance();
balance.setBalance(0);
balance.setCryptoCurrencyId(db.cryptoCurrencyDao().getByName(cryptoCoin.name(),cryptoCoin.name()).getId());
balance.setCryptoCurrencyId(db.cryptoCurrencyDao().getByName(cryptoCoin.getLabel(),cryptoCoin.name()).getId());
balance.setAccountId(account.getId());
db.cryptoCoinBalanceDao().insertCryptoCoinBalance(balance);
@ -153,12 +155,15 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
this.getNextAddress((NextBitcoinAccountAddressRequest) request);
}else if(request instanceof ValidateBitcoinAddressRequest){
this.validateAddress((ValidateBitcoinAddressRequest) request);
}else if(request instanceof CalculateBitcoinUriRequest){
this.calculateUri((CalculateBitcoinUriRequest) request);
}else if(request instanceof BitcoinUriParseRequest){
this.parseUri((BitcoinUriParseRequest) request);
}else{
System.out.println("Invalid " +this.cryptoCoin.getLabel() + " request ");
}
}
}
/**
@ -461,28 +466,136 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
private void getNextAddress(NextBitcoinAccountAddressRequest request){
CrystalDatabase db = CrystalDatabase.getAppDatabase(request.getContext());
long index = db.bitcoinAddressDao().getLastExternalAddress(request.getAccount().getId());
index++;
AccountSeed seed = db.accountSeedDao().findById(request.getAccount().getSeedId());
DeterministicKey purposeKey = HDKeyDerivation.deriveChildKey((DeterministicKey) seed.getPrivateKey(),
new ChildNumber(44, true));
DeterministicKey coinKey = HDKeyDerivation.deriveChildKey(purposeKey,
new ChildNumber(cryptoCoin.getCoinNumber(), true));
DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(coinKey,
new ChildNumber(request.getAccount().getAccountIndex(), true));
DeterministicKey externalKey = HDKeyDerivation.deriveChildKey(accountKey,
new ChildNumber(0, false));
ECKey addrKey = HDKeyDerivation.deriveChildKey(externalKey, new ChildNumber((int) index, true));
BitcoinAddress address = new BitcoinAddress();
address.setChange(false);
address.setAccountId(request.getAccount().getId());
address.setIndex(index);
String addressString =addrKey.toAddress(this.cryptoCoin.getParameters()).toString();
address.setAddress(addressString);
db.bitcoinAddressDao().insertBitcoinAddresses(address);
InsightApiGenerator.getTransactionFromAddress(this.cryptoCoin,addressString,true, null);
BitcoinAddress address = db.bitcoinAddressDao().getExternalByIndex(index);
if(address != null && db.bitcoinTransactionDao().getGtxIOByAddress(address.getAddress()).size()<=0){
request.setAddress(address.getAddress());
request.setStatus(NextBitcoinAccountAddressRequest.StatusCode.SUCCEEDED);
}else {
index++;
AccountSeed seed = db.accountSeedDao().findById(request.getAccount().getSeedId());
DeterministicKey purposeKey = HDKeyDerivation.deriveChildKey((DeterministicKey) seed.getPrivateKey(),
new ChildNumber(44, true));
DeterministicKey coinKey = HDKeyDerivation.deriveChildKey(purposeKey,
new ChildNumber(cryptoCoin.getCoinNumber(), true));
DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(coinKey,
new ChildNumber(request.getAccount().getAccountIndex(), true));
DeterministicKey externalKey = HDKeyDerivation.deriveChildKey(accountKey,
new ChildNumber(0, false));
ECKey addrKey = HDKeyDerivation.deriveChildKey(externalKey, new ChildNumber((int) index, true));
address = new BitcoinAddress();
address.setChange(false);
address.setAccountId(request.getAccount().getId());
address.setIndex(index);
String addressString = addrKey.toAddress(this.cryptoCoin.getParameters()).toString();
address.setAddress(addressString);
db.bitcoinAddressDao().insertBitcoinAddresses(address);
InsightApiGenerator.getTransactionFromAddress(this.cryptoCoin, addressString, true, null);
request.setAddress(addressString);
request.setStatus(NextBitcoinAccountAddressRequest.StatusCode.SUCCEEDED);
request.setAddress(addressString);
request.setStatus(NextBitcoinAccountAddressRequest.StatusCode.SUCCEEDED);
}
}
private void calculateUri(CalculateBitcoinUriRequest request) {
StringBuilder uri = new StringBuilder(this.cryptoCoin.name().toLowerCase()+":");
CrystalDatabase db = CrystalDatabase.getAppDatabase(request.getContext());
long index = db.bitcoinAddressDao().getLastExternalAddress(request.getAccount().getId());
BitcoinAddress address = db.bitcoinAddressDao().getExternalByIndex(index);
if(address != null && db.bitcoinTransactionDao().getGtxIOByAddress(address.getAddress()).size()<=0){
uri.append(address.getAddress());
}else {
index++;
AccountSeed seed = db.accountSeedDao().findById(request.getAccount().getSeedId());
DeterministicKey purposeKey = HDKeyDerivation.deriveChildKey((DeterministicKey) seed.getPrivateKey(),
new ChildNumber(44, true));
DeterministicKey coinKey = HDKeyDerivation.deriveChildKey(purposeKey,
new ChildNumber(cryptoCoin.getCoinNumber(), true));
DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(coinKey,
new ChildNumber(request.getAccount().getAccountIndex(), true));
DeterministicKey externalKey = HDKeyDerivation.deriveChildKey(accountKey,
new ChildNumber(0, false));
ECKey addrKey = HDKeyDerivation.deriveChildKey(externalKey, new ChildNumber((int) index, true));
address = new BitcoinAddress();
address.setChange(false);
address.setAccountId(request.getAccount().getId());
address.setIndex(index);
String addressString = addrKey.toAddress(this.cryptoCoin.getParameters()).toString();
address.setAddress(addressString);
db.bitcoinAddressDao().insertBitcoinAddresses(address);
InsightApiGenerator.getTransactionFromAddress(this.cryptoCoin, addressString, true, null);
uri.append(address.getAddress());
}
if(request.getCurrency()!= null){
uri.append("?amount=");
uri.append(request.getAmount());
}
System.out.println("GeneralAccountMAnager uri calculated : " + uri.toString());
request.setUri(uri.toString());
request.validate();
}
private void parseUri(BitcoinUriParseRequest request){
String uri = request.getUri();
if(uri.indexOf(":")>0){
String cryptoNet = uri.substring(0,uri.indexOf(":"));
if(cryptoNet.equalsIgnoreCase(this.cryptoCoin.getLabel())){
try{
Address address = Address.fromBase58(this.cryptoCoin.getParameters(), request.getAddress());
request.setAddress(address.toString());
request.setStatus(BitcoinUriParseRequest.StatusCode.VALID);
if(uri.indexOf("?")>0){
try {
String[] parameters = uri.substring(uri.indexOf("?") + 1).split("&");
for (String parameter : parameters) {
int idx = parameter.indexOf("=");
if (idx > 0 && parameter.substring(0, idx).equalsIgnoreCase("amount")) {
request.setAmount(Double.parseDouble(parameter.substring(idx + 1)));
}
}
}catch(Exception ignored){}
}
}catch(AddressFormatException ex){
request.setStatus(BitcoinUriParseRequest.StatusCode.NOT_VALID);
}
}else{
request.setStatus(BitcoinUriParseRequest.StatusCode.NOT_VALID);
}
}else{
if(uri.indexOf("?")>0){
try{
Address address = Address.fromBase58(this.cryptoCoin.getParameters(), request.getAddress());
request.setAddress(address.toString());
request.setStatus(BitcoinUriParseRequest.StatusCode.VALID);
try{
String[] parameters = uri.substring(uri.indexOf("?")+1).split("&");
for(String parameter : parameters){
int idx = parameter.indexOf("=");
if(idx > 0 && parameter.substring(0,idx).equalsIgnoreCase("amount")){
request.setAmount(Double.parseDouble(parameter.substring(idx+1)));
}
}
}catch(Exception ignored){}
}catch(AddressFormatException ex){
request.setStatus(BitcoinUriParseRequest.StatusCode.NOT_VALID);
}
}else{
try{
Address address = Address.fromBase58(this.cryptoCoin.getParameters(), request.getAddress());
request.setAddress(address.toString());
request.setStatus(BitcoinUriParseRequest.StatusCode.VALID);
}catch(AddressFormatException ex){
request.setStatus(BitcoinUriParseRequest.StatusCode.NOT_VALID);
}
}
}
request.validate();
}
private List<BitcoinTransactionGTxIO> getUtxos(long accountId, CrystalDatabase db){

View file

@ -33,7 +33,6 @@ import cy.agorise.crystalwallet.models.GrapheneAccount;
import cy.agorise.crystalwallet.models.GrapheneAccountInfo;
import cy.agorise.crystalwallet.models.seed.BIP39;
import cy.agorise.crystalwallet.network.CryptoNetManager;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetEquivalentRequest;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequest;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestsListener;
import cy.agorise.crystalwallet.requestmanagers.GetBitsharesAccountNameCacheRequest;
@ -100,7 +99,8 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
GrapheneAccount fetch = (GrapheneAccount) answer;
grapheneAccount.setName(fetch.getName());
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount);
long idAccount = db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount)[0];
grapheneAccount.setId(idAccount);
db.grapheneAccountInfoDao().insertGrapheneAccountInfo(new GrapheneAccountInfo(grapheneAccount));
subscribeSteemAccount(grapheneAccount.getId(),grapheneAccount.getAccountId(),context);
}
@ -112,7 +112,8 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
});
}else {
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount);
long idAccount = db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount)[0];
grapheneAccount.setId(idAccount);
db.grapheneAccountInfoDao().insertGrapheneAccountInfo(new GrapheneAccountInfo(grapheneAccount));
subscribeSteemAccount(grapheneAccount.getId(), grapheneAccount.getAccountId(), context);
}
@ -185,8 +186,6 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
this.validateExistAcccount((ValidateExistBitsharesAccountRequest) request);
} else if (request instanceof ValidateBitsharesSendRequest) {
this.validateSendRequest((ValidateBitsharesSendRequest) request);
} else if (request instanceof CryptoNetEquivalentRequest) {
this.getEquivalentValue((CryptoNetEquivalentRequest) request);
} else if (request instanceof GetBitsharesAccountNameCacheRequest) {
this.getBitsharesAccountNameCacheRequest((GetBitsharesAccountNameCacheRequest) request);
} else {
@ -215,7 +214,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
long idSeed = accountSeedDao.insertAccountSeed(seed);
if (idSeed >= 0) {
GrapheneAccount account = new GrapheneAccount();
account.setCryptoNet(CryptoNet.BITSHARES);
account.setCryptoNet(CryptoNet.STEEM);
account.setAccountIndex(0);
account.setSeedId(idSeed);
account.setAccountId(userAccount.getObjectId());
@ -226,47 +225,12 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
@Override
public void fail(int idPetition) {
BIP39 bip39 = new BIP39(-1, importRequest.getMnemonic());
ApiRequest getAccountNamesBP39 = new ApiRequest(0, new ApiRequestListener() {
@Override
public void success(Object answer, int idPetition) {
if(answer != null && importRequest.getStatus().equals(ImportBitsharesAccountRequest.StatusCode.NOT_STARTED)) {
UserAccount userAccount = (UserAccount) answer;
importRequest.setSeedType(SeedType.BIP39);
importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.SUCCEEDED);
AccountSeed seed = new AccountSeed();
seed.setName(userAccount.getName());
seed.setType(importRequest.getSeedType());
seed.setMasterSeed(importRequest.getMnemonic());
long idSeed = accountSeedDao.insertAccountSeed(seed);
if (idSeed >= 0) {
GrapheneAccount account = new GrapheneAccount();
account.setCryptoNet(CryptoNet.BITSHARES);
account.setAccountIndex(0);
account.setSeedId(idSeed);
account.setAccountId(userAccount.getObjectId());
importAccountFromSeed(account, importRequest.getContext());
}
}
}
@Override
public void fail(int idPetition) {
importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.BAD_SEED);
}
});
GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(new Address(ECKey.fromPublicOnly(bip39.getBitsharesActiveKey(0).getPubKey())),getAccountNamesBP39);
importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.BAD_SEED);
}
});
BrainKey bk = new BrainKey(importRequest.getMnemonic(), 0);
GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(bk.getPublicAddress("BTS"),getAccountNamesBK);
GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(bk.getPublicAddress("STM"),CryptoNet.STEEM,getAccountNamesBK);
}
/**
@ -287,21 +251,13 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
AccountProperties prop = (AccountProperties) answer;
BrainKey bk = new BrainKey(importRequest.getMnemonic(), 0);
for(PublicKey activeKey : prop.owner.getKeyAuthList()){
if((new Address(activeKey.getKey(),"BTS")).toString().equals(bk.getPublicAddress("BTS").toString())){
if((new Address(activeKey.getKey(),"STM")).toString().equals(bk.getPublicAddress("STM").toString())){
importRequest.setSeedType(SeedType.BRAINKEY);
importRequest.setStatus(ValidateImportBitsharesAccountRequest.StatusCode.SUCCEEDED);
break;
}
}
BIP39 bip39 = new BIP39(-1, importRequest.getMnemonic());
for(PublicKey activeKey : prop.active.getKeyAuthList()){
if((new Address(activeKey.getKey(),"BTS")).toString().equals(new Address(ECKey.fromPublicOnly(bip39.getBitsharesActiveKey(0).getPubKey())).toString())){
importRequest.setSeedType(SeedType.BIP39);
importRequest.setStatus(ValidateImportBitsharesAccountRequest.StatusCode.SUCCEEDED);
break;
}
}
if ((importRequest.getStatus() == ValidateImportBitsharesAccountRequest.StatusCode.SUCCEEDED)){
if (importRequest.addAccountIfValid()) {
@ -312,7 +268,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
long idSeed = accountSeedDao.insertAccountSeed(seed);
if (idSeed >= 0) {
GrapheneAccount account = new GrapheneAccount();
account.setCryptoNet(CryptoNet.BITSHARES);
account.setCryptoNet(CryptoNet.STEEM);
account.setAccountIndex(0);
account.setSeedId(idSeed);
account.setName(importRequest.getAccountName());
@ -334,7 +290,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
importRequest.setStatus(ValidateImportBitsharesAccountRequest.StatusCode.NO_ACCOUNT_DATA);
}
});
GrapheneApiGenerator.getAccountById((String)answer,getAccountInfo);
GrapheneApiGenerator.getAccountById((String)answer,CryptoNet.STEEM,getAccountInfo);
}
@Override
@ -344,7 +300,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
}
});
GrapheneApiGenerator.getAccountIdByName(importRequest.getAccountName(),checkAccountName);
GrapheneApiGenerator.getAccountIdByName(importRequest.getAccountName(),CryptoNet.STEEM,checkAccountName);
}
/**
@ -369,7 +325,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
validateRequest.setAccountExists(false);
}
});
GrapheneApiGenerator.getAccountIdByName(validateRequest.getAccountName(),checkAccountName);
GrapheneApiGenerator.getAccountIdByName(validateRequest.getAccountName(),CryptoNet.STEEM,checkAccountName);
}
/**
@ -379,7 +335,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
//TODO check internet, server connection
//TODO feeAsset
CrystalDatabase db = CrystalDatabase.getAppDatabase(sendRequest.getContext());
CryptoCurrency currency = db.cryptoCurrencyDao().getByNameAndCryptoNet(sendRequest.getAsset(), CryptoNet.BITSHARES.name());
CryptoCurrency currency = db.cryptoCurrencyDao().getByNameAndCryptoNet(sendRequest.getAsset(), CryptoNet.STEEM.name());
if (currency == null){
getAssetInfoByName(sendRequest.getAsset(), new ManagerRequest() {
@Override
@ -478,7 +434,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
ECKey privateKey = sendRequest.getSourceAccount().getActiveKey(sendRequest.getContext());
Transaction transaction = new Transaction(privateKey, null, operationList);
transaction.setChainId(CryptoNetManager.getChaindId(CryptoNet.BITSHARES));
transaction.setChainId(CryptoNetManager.getChaindId(CryptoNet.STEEM));
ApiRequest transactionRequest = new ApiRequest(0, new ApiRequestListener() {
@Override
@ -530,7 +486,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
AccountIdOrNameListener listener = new AccountIdOrNameListener(request);
ApiRequest accountRequest = new ApiRequest(0, listener);
GrapheneApiGenerator.getAccountById(grapheneId,accountRequest);
GrapheneApiGenerator.getAccountById(grapheneId,CryptoNet.STEEM,accountRequest);
}
/**
@ -542,7 +498,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
AccountIdOrNameListener listener = new AccountIdOrNameListener(request);
ApiRequest accountRequest = new ApiRequest(0, listener);
GrapheneApiGenerator.getAccountByName(grapheneName,accountRequest);
GrapheneApiGenerator.getAccountByName(grapheneName,CryptoNet.STEEM,accountRequest);
}
@ -553,7 +509,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
ApiRequest assetRequest = new ApiRequest(0, nameListener);
ArrayList<String> assetNames = new ArrayList<>();
assetNames.add(assetName);
GrapheneApiGenerator.getAssetByName(assetNames, assetRequest);
GrapheneApiGenerator.getAssetByName(assetNames, CryptoNet.STEEM, assetRequest);
}
@ -666,7 +622,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
});
ArrayList<String> assets = new ArrayList<>();
assets.add(transfer.getOperation().getAssetAmount().getAsset().getObjectId());
GrapheneApiGenerator.getAssetById(assets,assetRequest);
GrapheneApiGenerator.getAssetById(assets,CryptoNet.STEEM,assetRequest);
}else{
saveTransaction(transaction,info,transfer);
@ -695,32 +651,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR
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())));
}
}
/**
* Gets the current change from two assets
*/
private void getEquivalentValue(final CryptoNetEquivalentRequest request){
if(request.getFromCurrency() instanceof BitsharesAsset && request.getToCurrency() instanceof BitsharesAsset) {
BitsharesAsset fromAsset = (BitsharesAsset) request.getFromCurrency();
BitsharesAsset toAsset = (BitsharesAsset) request.getToCurrency();
ApiRequest getEquivalentRequest = new ApiRequest(0, new ApiRequestListener() {
@Override
public void success(Object answer, int idPetition) {
request.setPrice((Long)answer);
}
@Override
public void fail(int idPetition) {
//TODO error
}
});
GrapheneApiGenerator.getEquivalentValue(fromAsset.getBitsharesId(),toAsset.getBitsharesId(), getEquivalentRequest);
}else{
//TODO error
System.out.println("Equivalent Value error ");
GrapheneApiGenerator.getBlockHeaderTime(transfer.getBlockNum(), CryptoNet.STEEM,new ApiRequest(0, new GetTransactionDate(transaction, db.transactionDao())));
}
}

View file

@ -12,7 +12,7 @@ import android.support.annotation.NonNull;
*/
@Entity(
tableName="bitcoin_address",
primaryKeys = {"account_id","address_index"},
primaryKeys = {"account_id","address_index","is_change"},
foreignKeys = {
@ForeignKey(
entity = CryptoNetAccount.class,

View file

@ -18,6 +18,8 @@ public abstract class CryptoNetVerifier {
return new BitsharesCryptoNetVerifier();
}else if(cryptoNet.getLabel().equals(CryptoNet.BITCOIN.getLabel())){
return new BitcoinCryptoNetVerifier(CryptoCoin.BITCOIN);
}else if(cryptoNet.getLabel().equals(CryptoNet.STEEM.getLabel())){
return new SteemCryptoNetVerifier();
}
return null;
}

View file

@ -0,0 +1,85 @@
package cy.agorise.crystalwallet.requestmanagers;
import android.content.Context;
import cy.agorise.crystalwallet.enums.CryptoCoin;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.models.GrapheneAccount;
/**
* Class used to make a bitcoin uri parse request.
*
* Created by henry on 11/13/2018.
*/
public class BitcoinUriParseRequest extends CryptoNetInfoRequest {
/**
* The status code of this request
*/
public enum StatusCode{
NOT_STARTED,
VALID,
NOT_VALID
}
private String uri;
private String address;
private Double amount;
private String memo;
private StatusCode status = StatusCode.NOT_STARTED;
public BitcoinUriParseRequest(String uri, CryptoCoin cryptoCoin) {
super(cryptoCoin);
this.address = "";
this.amount = -1.0;
this.memo = "";
this.uri = uri;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
public String getMemo() {
return memo;
}
public void setMemo(String memo) {
this.memo = memo;
}
public void validate(){
if ((this.status != StatusCode.NOT_STARTED)){
this._fireOnCarryOutEvent();
}
}
public void setStatus(StatusCode code){
this.status = code;
this._fireOnCarryOutEvent();
}
public StatusCode getStatus() {
return status;
}
public String getUri() {
return uri;
}
}

View file

@ -0,0 +1,69 @@
package cy.agorise.crystalwallet.requestmanagers;
import android.content.Context;
import cy.agorise.crystalwallet.enums.CryptoCoin;
import cy.agorise.crystalwallet.models.CryptoCurrency;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
/**
* This class validates that an account name exist, this can be used to verified the existing accounts
* or to verified if the name is available to create an Account
*
* Created by henry on 8/10/2017.
*/
public class CalculateBitcoinUriRequest extends CryptoNetInfoRequest {
private CryptoNetAccount account;
private CryptoCurrency currency;
private double amount;
private Context context;
private String uri;
public CalculateBitcoinUriRequest(CryptoCoin coin, CryptoNetAccount account, Context context) {
super(coin);
this.account = account;
this.context = context;
}
public CalculateBitcoinUriRequest(CryptoCoin coin, CryptoNetAccount account, CryptoCurrency currency, double amount, Context context) {
super(coin);
this.account = account;
this.currency = currency;
this.amount = amount;
this.context = context;
}
public CryptoNetAccount getAccount() {
return account;
}
public CryptoCurrency getCurrency() {
return currency;
}
public double getAmount() {
return amount;
}
public Context getContext() {
return context;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
this.validate();
}
public void validate(){
if ((this.uri != null)){
this._fireOnCarryOutEvent();
}
}
}