From 8ff53de0ae07fd288f3111581f8a83c18f1fefdc Mon Sep 17 00:00:00 2001 From: hvarona Date: Sat, 10 Nov 2018 23:21:49 -0400 Subject: [PATCH 01/11] Added BitcoinUriRequest --- .../manager/GeneralAccountManager.java | 91 ++++++++++++++----- .../manager/SteemAccountManager.java | 4 +- .../CalculateBitcoinUriRequest.java | 69 ++++++++++++++ 3 files changed, 141 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CalculateBitcoinUriRequest.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java index 9b49076..acf34f2 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java @@ -38,6 +38,7 @@ 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.CalculateBitcoinUriRequest; import cy.agorise.crystalwallet.requestmanagers.CreateBitcoinAccountRequest; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequest; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestsListener; @@ -153,6 +154,8 @@ 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{ System.out.println("Invalid " +this.cryptoCoin.getLabel() + " request "); } @@ -461,28 +464,74 @@ 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(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.getLabel()+":"); + + CrystalDatabase db = CrystalDatabase.getAppDatabase(request.getContext()); + long index = db.bitcoinAddressDao().getLastExternalAddress(request.getAccount().getId()); + BitcoinAddress address = db.bitcoinAddressDao().getExternalByIndex(index); + if(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()); + } + + request.setUri(uri.toString()); + request.validate(); } private List getUtxos(long accountId, CrystalDatabase db){ diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java index 997b1ce..ecef586 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java @@ -215,7 +215,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()); @@ -242,7 +242,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()); diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CalculateBitcoinUriRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CalculateBitcoinUriRequest.java new file mode 100644 index 0000000..7388e78 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CalculateBitcoinUriRequest.java @@ -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(); + } + } + +} From 6e81192b37d0d06f100daa14bded60fb04507076 Mon Sep 17 00:00:00 2001 From: hvarona Date: Sun, 11 Nov 2018 21:59:28 -0400 Subject: [PATCH 02/11] Added steem url and verifier Added bip21 implementation with lowercase --- .../application/CrystalApplication.java | 13 +++++++++ .../manager/GeneralAccountManager.java | 2 +- .../manager/SteemAccountManager.java | 28 ------------------- .../network/CryptoNetVerifier.java | 2 ++ 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java index 67fc2b4..9e78385 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java +++ b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java @@ -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); diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java index acf34f2..fd56ef0 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java @@ -495,7 +495,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf } private void calculateUri(CalculateBitcoinUriRequest request) { - StringBuilder uri = new StringBuilder(this.cryptoCoin.getLabel()+":"); + StringBuilder uri = new StringBuilder(this.cryptoCoin.getLabel().toLowerCase()+":"); CrystalDatabase db = CrystalDatabase.getAppDatabase(request.getContext()); long index = db.bitcoinAddressDao().getLastExternalAddress(request.getAccount().getId()); diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java index ecef586..677352b 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java @@ -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; @@ -185,8 +184,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 { @@ -699,31 +696,6 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR } } - /** - * 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 "); - } - } - /** * Class to retrieve the account id or the account name, if one of those is missing */ diff --git a/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetVerifier.java b/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetVerifier.java index c0e38ee..7ded8ca 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetVerifier.java +++ b/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetVerifier.java @@ -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; } From 9c6db3a6ea30b5d72444363e9b70d11216b61ce7 Mon Sep 17 00:00:00 2001 From: hvarona Date: Sun, 11 Nov 2018 22:26:34 -0400 Subject: [PATCH 03/11] fix calculate uri --- .../cy/agorise/crystalwallet/manager/GeneralAccountManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java index fd56ef0..3b5a5c8 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java @@ -500,7 +500,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf CrystalDatabase db = CrystalDatabase.getAppDatabase(request.getContext()); long index = db.bitcoinAddressDao().getLastExternalAddress(request.getAccount().getId()); BitcoinAddress address = db.bitcoinAddressDao().getExternalByIndex(index); - if(db.bitcoinTransactionDao().getGtxIOByAddress(address.getAddress()).size()<=0){ + if(address != null && db.bitcoinTransactionDao().getGtxIOByAddress(address.getAddress()).size()<=0){ uri.append(address.getAddress()); }else { index++; From 14a405f67c07df5a53e54c101f4b9560edf998c9 Mon Sep 17 00:00:00 2001 From: hvarona Date: Sun, 11 Nov 2018 23:06:09 -0400 Subject: [PATCH 04/11] change grapheneapigenerator to be used with steem --- .../apigenerator/GrapheneApiGenerator.java | 40 +++++------ .../manager/BitsharesAccountManager.java | 20 +++--- .../manager/GeneralAccountManager.java | 2 +- .../manager/SteemAccountManager.java | 71 ++++--------------- 4 files changed, 44 insertions(+), 89 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java index 4383d8e..9c32893 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -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 assetNames, final ApiRequest request){ + public static void getAssetByName(ArrayList 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 assetIds, final ApiRequest request){ + public static void getAssetById(ArrayList assetIds, CryptoNet cryptoNet, final ApiRequest request){ ArrayList 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 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 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 names = new ArrayList<>(); names.add(baseAssetName); - GrapheneApiGenerator.getAssetByName(names,getAssetRequest); + GrapheneApiGenerator.getAssetByName(names,CryptoNet.BITSHARES,getAssetRequest); }else { BitsharesAsset baseAsset = new BitsharesAsset(baseCurrency); 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 ba6ada9..55cf375 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -306,7 +306,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 +314,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 +384,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 +394,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 +449,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI validateRequest.setAccountExists(false); } }); - GrapheneApiGenerator.getAccountIdByName(validateRequest.getAccountName(),checkAccountName); + GrapheneApiGenerator.getAccountIdByName(validateRequest.getAccountName(),CryptoNet.BITSHARES,checkAccountName); } /** @@ -647,7 +647,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 +659,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 +670,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI ApiRequest assetRequest = new ApiRequest(0, nameListener); ArrayList assetNames = new ArrayList<>(); assetNames.add(assetName); - GrapheneApiGenerator.getAssetByName(assetNames, assetRequest); + GrapheneApiGenerator.getAssetByName(assetNames, CryptoNet.BITSHARES,assetRequest); } @@ -783,7 +783,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI }); ArrayList 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 +812,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()))); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java index 3b5a5c8..d7df4fc 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java @@ -465,7 +465,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf CrystalDatabase db = CrystalDatabase.getAppDatabase(request.getContext()); long index = db.bitcoinAddressDao().getLastExternalAddress(request.getAccount().getId()); BitcoinAddress address = db.bitcoinAddressDao().getExternalByIndex(index); - if(db.bitcoinTransactionDao().getGtxIOByAddress(address.getAddress()).size()<=0){ + if(address != null && db.bitcoinTransactionDao().getGtxIOByAddress(address.getAddress()).size()<=0){ request.setAddress(address.getAddress()); request.setStatus(NextBitcoinAccountAddressRequest.StatusCode.SUCCEEDED); }else { diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java index 677352b..63d4173 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java @@ -223,47 +223,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.STEEM); - 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); } /** @@ -284,21 +249,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()) { @@ -309,7 +266,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()); @@ -331,7 +288,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 @@ -341,7 +298,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR } }); - GrapheneApiGenerator.getAccountIdByName(importRequest.getAccountName(),checkAccountName); + GrapheneApiGenerator.getAccountIdByName(importRequest.getAccountName(),CryptoNet.STEEM,checkAccountName); } /** @@ -366,7 +323,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR validateRequest.setAccountExists(false); } }); - GrapheneApiGenerator.getAccountIdByName(validateRequest.getAccountName(),checkAccountName); + GrapheneApiGenerator.getAccountIdByName(validateRequest.getAccountName(),CryptoNet.STEEM,checkAccountName); } /** @@ -376,7 +333,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 @@ -475,7 +432,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 @@ -527,7 +484,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); } /** @@ -539,7 +496,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); } @@ -550,7 +507,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR ApiRequest assetRequest = new ApiRequest(0, nameListener); ArrayList assetNames = new ArrayList<>(); assetNames.add(assetName); - GrapheneApiGenerator.getAssetByName(assetNames, assetRequest); + GrapheneApiGenerator.getAssetByName(assetNames, CryptoNet.STEEM, assetRequest); } @@ -663,7 +620,7 @@ public class SteemAccountManager implements CryptoAccountManager, CryptoNetInfoR }); ArrayList 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); @@ -692,7 +649,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()))); + GrapheneApiGenerator.getBlockHeaderTime(transfer.getBlockNum(), CryptoNet.STEEM,new ApiRequest(0, new GetTransactionDate(transaction, db.transactionDao()))); } } From 0126d6d114a3839b6935ed194967702d3dc19bfa Mon Sep 17 00:00:00 2001 From: hvarona Date: Mon, 12 Nov 2018 22:11:14 -0400 Subject: [PATCH 05/11] Fix import graphene accounts --- .../crystalwallet/manager/BitsharesAccountManager.java | 6 ++++-- .../agorise/crystalwallet/manager/SteemAccountManager.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) 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 55cf375..62ff8ec 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -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); } diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java index 63d4173..8c66c29 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/SteemAccountManager.java @@ -99,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); } @@ -111,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); } From 719d6769fca6659dbcd5b20297305026e7ae57a4 Mon Sep 17 00:00:00 2001 From: hvarona Date: Mon, 12 Nov 2018 22:40:44 -0400 Subject: [PATCH 06/11] Change bitcoin address model keys --- .../crystalwallet/manager/GeneralAccountManager.java | 6 ++++-- .../cy/agorise/crystalwallet/models/BitcoinAddress.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java index d7df4fc..08c2e90 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java @@ -98,7 +98,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); @@ -495,7 +495,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf } private void calculateUri(CalculateBitcoinUriRequest request) { - StringBuilder uri = new StringBuilder(this.cryptoCoin.getLabel().toLowerCase()+":"); + StringBuilder uri = new StringBuilder(this.cryptoCoin.name().toLowerCase()+":"); CrystalDatabase db = CrystalDatabase.getAppDatabase(request.getContext()); long index = db.bitcoinAddressDao().getLastExternalAddress(request.getAccount().getId()); @@ -530,6 +530,8 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf uri.append(request.getAmount()); } + System.out.println("GeneralAccountMAnager uri calculated : " + uri.toString()); + request.setUri(uri.toString()); request.validate(); } diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/BitcoinAddress.java b/app/src/main/java/cy/agorise/crystalwallet/models/BitcoinAddress.java index ac076f7..f8ca2bd 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/BitcoinAddress.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/BitcoinAddress.java @@ -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, From 193f42673959633cbd2b84f96b62a27a3e1e0a3c Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Tue, 13 Nov 2018 21:38:05 -0400 Subject: [PATCH 07/11] - Added a bitcoin parse request to read bitcoin alike URIs - Now the receive fragment generates bitcoin alike URIs - Added commented code to read QR code URIs in the send fragment --- .../fragments/ReceiveTransactionFragment.java | 127 +++++++++++++----- .../fragments/SendTransactionFragment.java | 23 ++++ .../BitcoinUriParseRequest.java | 76 +++++++++++ 3 files changed, 191 insertions(+), 35 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/requestmanagers/BitcoinUriParseRequest.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java index dbf3848..bc94748 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java @@ -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(){ + this.qrCodeTask = new AsyncTask() { - @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() { + + @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 { diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java index e3490f4..d60a221 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -803,8 +803,31 @@ 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 + /*BitcoinUriParseRequest bitcoinUriParseRequest = new BitcoinUriParseRequest(result.getText()); + + bitcoinUriParseRequest.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + if (bitcoinUriParseRequest.getAddress() != null) { + try { + crystalDialog.dismiss(); + thisFragment.dismiss(); + //thisFragment.finalize(); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + } else { + Toast.makeText(getContext(), "Not a valid QR info", Toast.LENGTH_LONG); + } + } + }); + + CryptoNetInfoRequests.getInstance().addRequest(bitcoinUriParseRequest);*/ } } \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/BitcoinUriParseRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/BitcoinUriParseRequest.java new file mode 100644 index 0000000..ad2a5b9 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/BitcoinUriParseRequest.java @@ -0,0 +1,76 @@ +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 address; + private Double amount; + private String memo; + + private StatusCode status = StatusCode.NOT_STARTED; + + public BitcoinUriParseRequest(String uri) { + super(CryptoCoin.BITCOIN); + this.address = ""; + this.amount = -1.0; + this.memo = ""; + } + + 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; + } +} From 91ef2d0e9aa3be2ed182128bd5e7ce1d3bf3e15f Mon Sep 17 00:00:00 2001 From: hvarona Date: Tue, 13 Nov 2018 22:02:22 -0400 Subject: [PATCH 08/11] Added parseUri to BitocinManager --- .../manager/GeneralAccountManager.java | 64 ++++++++++++++++++- .../BitcoinUriParseRequest.java | 13 +++- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java index 08c2e90..6b437c1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java @@ -38,6 +38,7 @@ 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; @@ -156,12 +157,13 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf 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 "); } } - } /** @@ -536,6 +538,66 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf 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 getUtxos(long accountId, CrystalDatabase db){ List answer = new ArrayList<>(); List bTGTxI = new ArrayList<>(); diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/BitcoinUriParseRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/BitcoinUriParseRequest.java index ad2a5b9..1c2e7be 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/BitcoinUriParseRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/BitcoinUriParseRequest.java @@ -22,17 +22,22 @@ public class BitcoinUriParseRequest extends CryptoNetInfoRequest { NOT_VALID } + private String uri; + private String address; private Double amount; private String memo; + + private StatusCode status = StatusCode.NOT_STARTED; - public BitcoinUriParseRequest(String uri) { - super(CryptoCoin.BITCOIN); + public BitcoinUriParseRequest(String uri, CryptoCoin cryptoCoin) { + super(cryptoCoin); this.address = ""; this.amount = -1.0; this.memo = ""; + this.uri = uri; } public String getAddress() { @@ -73,4 +78,8 @@ public class BitcoinUriParseRequest extends CryptoNetInfoRequest { public StatusCode getStatus() { return status; } + + public String getUri() { + return uri; + } } From a11f74f6a5dd2f55ad40b9091904f2ce8ae00357 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Tue, 13 Nov 2018 22:30:51 -0400 Subject: [PATCH 09/11] - Now the send fragment reads bitcoin alike URI --- .../fragments/SendTransactionFragment.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java index d60a221..be671e9 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -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; @@ -809,18 +810,21 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat } //Is not a bitshares QR - /*BitcoinUriParseRequest bitcoinUriParseRequest = new BitcoinUriParseRequest(result.getText()); + 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) { - try { - crystalDialog.dismiss(); - thisFragment.dismiss(); - //thisFragment.finalize(); - } catch (Throwable throwable) { - throwable.printStackTrace(); + 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); @@ -828,6 +832,6 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat } }); - CryptoNetInfoRequests.getInstance().addRequest(bitcoinUriParseRequest);*/ + CryptoNetInfoRequests.getInstance().addRequest(bitcoinUriParseRequest); } } \ No newline at end of file From b6cddedbd4e0d16bed3253bd4c9586822e9ea6c8 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Tue, 13 Nov 2018 22:46:50 -0400 Subject: [PATCH 10/11] - Fixed tables creation --- .../java/cy/agorise/crystalwallet/dao/CrystalDatabase.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 8ee1f5d..1b224ec 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java @@ -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)"); } }; From 683883ca0ea0e29555168aecffe763e6b9ef32bd Mon Sep 17 00:00:00 2001 From: hvarona Date: Wed, 14 Nov 2018 22:49:47 -0400 Subject: [PATCH 11/11] Fix account seed names --- .../crystalwallet/manager/BitsharesAccountManager.java | 5 +++++ 1 file changed, 5 insertions(+) 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 62ff8ec..b26b661 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -198,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); }