Merge branch 'develop' of github.com:Agorise/crystal-wallet-android into develop

feat_androidx_migration
Severiano Jaramillo 2018-11-20 21:28:08 -06:00
commit db4827456f
12 changed files with 60 additions and 19 deletions

View File

@ -52,7 +52,8 @@ public class CrystalApplication extends Application {
public static final String BITCOIN_SERVER_URLS[] ={ public static final String BITCOIN_SERVER_URLS[] ={
"https://insight.bitpay.com/" "https://insight.bitpay.com/",
"https://testnet.blockexplorer.com/"
}; };
public static final CryptoCurrency BITCOIN_CURRENCY = new CryptoCurrency("BTC",CryptoNet.BITCOIN,8); public static final CryptoCurrency BITCOIN_CURRENCY = new CryptoCurrency("BTC",CryptoNet.BITCOIN,8);

View File

@ -29,6 +29,9 @@ public interface CryptoNetAccountDao {
@Query("SELECT cna.* FROM crypto_net_account cna WHERE seed_id = :seedId") @Query("SELECT cna.* FROM crypto_net_account cna WHERE seed_id = :seedId")
List<CryptoNetAccount> getAllCryptoNetAccountBySeed( long seedId); List<CryptoNetAccount> getAllCryptoNetAccountBySeed( long seedId);
@Query("SELECT cna.* FROM crypto_net_account cna WHERE crypto_net == 'BITCOIN'")
LiveData<List<CryptoNetAccount>> getAllBitcoins();
@Query("SELECT * FROM crypto_net_account WHERE id = :accountId") @Query("SELECT * FROM crypto_net_account WHERE id = :accountId")
LiveData<CryptoNetAccount> getByIdLiveData( long accountId); LiveData<CryptoNetAccount> getByIdLiveData( long accountId);

View File

@ -13,7 +13,7 @@ import java.util.List;
*/ */
public enum CryptoCoin implements Serializable { public enum CryptoCoin implements Serializable {
BITCOIN(CryptoNet.BITCOIN,"BTC",8,0,NetworkParameters.fromID(NetworkParameters.ID_MAINNET)), BITCOIN(CryptoNet.BITCOIN,"BTC",8,0,NetworkParameters.fromID(NetworkParameters.ID_TESTNET)),
BITCOIN_TEST(CryptoNet.BITCOIN_TEST,"BTC",8,1,NetworkParameters.fromID(NetworkParameters.ID_TESTNET)), BITCOIN_TEST(CryptoNet.BITCOIN_TEST,"BTC",8,1,NetworkParameters.fromID(NetworkParameters.ID_TESTNET)),
LITECOIN(CryptoNet.LITECOIN,"LTC",8,2,null), LITECOIN(CryptoNet.LITECOIN,"LTC",8,2,null),
DASH(CryptoNet.DASH,"DASH",8,5,null), DASH(CryptoNet.DASH,"DASH",8,5,null),

View File

@ -6,5 +6,6 @@ package cy.agorise.crystalwallet.enums;
public enum SeedType { public enum SeedType {
BIP39, BIP39,
BRAINKEY BRAINKEY,
WIF
} }

View File

@ -402,7 +402,7 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
// @Override // @Override
// public void onCarryOut() { // public void onCarryOut() {
// if (addressRequest.getStatus() == NextBitcoinAccountAddressRequest.StatusCode.SUCCEEDED){ // if (addressRequest.getStatus() == NextBitcoinAccountAddressRequest.StatusCode.SUCCEEDED){
final CalculateBitcoinUriRequest uriRequest = new CalculateBitcoinUriRequest(cryptoCoin, cryptoNetAccount, getContext()); final CalculateBitcoinUriRequest uriRequest = new CalculateBitcoinUriRequest(cryptoCoin, cryptoNetAccount, getContext(), amount);
uriRequest.setListener(new CryptoNetInfoRequestListener(){ uriRequest.setListener(new CryptoNetInfoRequestListener(){
@Override @Override

View File

@ -804,8 +804,8 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
} }
//Is not a bitshares QR //Is not a bitshares QR
CryptoCoin cryptoCoin = CryptoCoin.getByCryptoNet(this.cryptoNetAccount.getCryptoNet()).get(0); //CryptoCoin cryptoCoin = CryptoCoin.getByCryptoNet(this.cryptoNetAccount.getCryptoNet()).get(0);
final BitcoinUriParseRequest bitcoinUriParseRequest = new BitcoinUriParseRequest(result.getText(), cryptoCoin); final BitcoinUriParseRequest bitcoinUriParseRequest = new BitcoinUriParseRequest(result.getText(), CryptoCoin.BITCOIN);
bitcoinUriParseRequest.setListener(new CryptoNetInfoRequestListener() { bitcoinUriParseRequest.setListener(new CryptoNetInfoRequestListener() {
@Override @Override

View File

@ -527,9 +527,9 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
uri.append(address.getAddress()); uri.append(address.getAddress());
} }
if(request.getCurrency()!= null){ if(request.getAmount() > 0 ){
uri.append("?amount="); uri.append("?amount=");
uri.append(request.getAmount()); uri.append(Double.toString(request.getAmount()));
} }
System.out.println("GeneralAccountMAnager uri calculated : " + uri.toString()); System.out.println("GeneralAccountMAnager uri calculated : " + uri.toString());
@ -542,14 +542,15 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
String uri = request.getUri(); String uri = request.getUri();
if(uri.indexOf(":")>0){ if(uri.indexOf(":")>0){
String cryptoNet = uri.substring(0,uri.indexOf(":")); String cryptoNet = uri.substring(0,uri.indexOf(":"));
if(cryptoNet.equalsIgnoreCase(this.cryptoCoin.getLabel())){ if(cryptoNet.equalsIgnoreCase(this.cryptoCoin.name().toLowerCase())){
try{ try{
Address address = Address.fromBase58(this.cryptoCoin.getParameters(), request.getAddress()); int parameterIndex =uri.indexOf("?");
Address address = Address.fromBase58(this.cryptoCoin.getParameters(), uri.substring(uri.indexOf(":")+1,parameterIndex>0?parameterIndex:uri.length()));
request.setAddress(address.toString()); request.setAddress(address.toString());
request.setStatus(BitcoinUriParseRequest.StatusCode.VALID); request.setStatus(BitcoinUriParseRequest.StatusCode.VALID);
if(uri.indexOf("?")>0){ if(parameterIndex>0){
try { try {
String[] parameters = uri.substring(uri.indexOf("?") + 1).split("&"); String[] parameters = uri.substring(parameterIndex + 1).split("&");
for (String parameter : parameters) { for (String parameter : parameters) {
int idx = parameter.indexOf("="); int idx = parameter.indexOf("=");
if (idx > 0 && parameter.substring(0, idx).equalsIgnoreCase("amount")) { if (idx > 0 && parameter.substring(0, idx).equalsIgnoreCase("amount")) {
@ -566,13 +567,14 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
request.setStatus(BitcoinUriParseRequest.StatusCode.NOT_VALID); request.setStatus(BitcoinUriParseRequest.StatusCode.NOT_VALID);
} }
}else{ }else{
if(uri.indexOf("?")>0){ int parameterIndex =uri.indexOf("?");
if(parameterIndex>0){
try{ try{
Address address = Address.fromBase58(this.cryptoCoin.getParameters(), request.getAddress()); Address address = Address.fromBase58(this.cryptoCoin.getParameters(), uri.substring(uri.indexOf(":")+1,parameterIndex>0?parameterIndex:uri.length()));
request.setAddress(address.toString()); request.setAddress(address.toString());
request.setStatus(BitcoinUriParseRequest.StatusCode.VALID); request.setStatus(BitcoinUriParseRequest.StatusCode.VALID);
try{ try{
String[] parameters = uri.substring(uri.indexOf("?")+1).split("&"); String[] parameters = uri.substring(parameterIndex+1).split("&");
for(String parameter : parameters){ for(String parameter : parameters){
int idx = parameter.indexOf("="); int idx = parameter.indexOf("=");
if(idx > 0 && parameter.substring(0,idx).equalsIgnoreCase("amount")){ if(idx > 0 && parameter.substring(0,idx).equalsIgnoreCase("amount")){
@ -586,7 +588,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
} }
}else{ }else{
try{ try{
Address address = Address.fromBase58(this.cryptoCoin.getParameters(), request.getAddress()); Address address = Address.fromBase58(this.cryptoCoin.getParameters(), uri);
request.setAddress(address.toString()); request.setAddress(address.toString());
request.setStatus(BitcoinUriParseRequest.StatusCode.VALID); request.setStatus(BitcoinUriParseRequest.StatusCode.VALID);

View File

@ -9,12 +9,14 @@ import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.util.DiffUtil; import android.support.v7.util.DiffUtil;
import org.bitcoinj.core.Base58;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import org.bitcoinj.crypto.HDKeyDerivation; import org.bitcoinj.crypto.HDKeyDerivation;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.Arrays;
import cy.agorise.crystalwallet.enums.SeedType; import cy.agorise.crystalwallet.enums.SeedType;
import cy.agorise.crystalwallet.models.seed.BIP39; import cy.agorise.crystalwallet.models.seed.BIP39;
@ -115,8 +117,6 @@ public class AccountSeed {
BufferedReader reader = null; BufferedReader reader = null;
switch (type) { switch (type) {
case BRAINKEY: case BRAINKEY:
try { try {
reader = new BufferedReader(new InputStreamReader(context.getAssets().open("brainkeydict.txt"), "UTF-8")); reader = new BufferedReader(new InputStreamReader(context.getAssets().open("brainkeydict.txt"), "UTF-8"));
@ -130,6 +130,7 @@ public class AccountSeed {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
break;
case BIP39: case BIP39:
try { try {
reader = new BufferedReader(new InputStreamReader(context.getAssets().open("bip39dict.txt"), "UTF-8")); reader = new BufferedReader(new InputStreamReader(context.getAssets().open("bip39dict.txt"), "UTF-8"));
@ -139,6 +140,7 @@ public class AccountSeed {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
break;
} }
return null; return null;
} }
@ -149,6 +151,15 @@ public class AccountSeed {
return new BrainKey(this.mMasterSeed,0).getPrivateKey(); return new BrainKey(this.mMasterSeed,0).getPrivateKey();
case BIP39: case BIP39:
return HDKeyDerivation.createMasterPrivateKey(new BIP39(mId, mMasterSeed).getSeed()); return HDKeyDerivation.createMasterPrivateKey(new BIP39(mId, mMasterSeed).getSeed());
case WIF:
byte[] decoded = Base58.decode(this.mMasterSeed);
byte[] privKey = Arrays.copyOfRange(decoded, 1, decoded.length - 4);
byte[] checksum = Arrays.copyOfRange(decoded, decoded.length - 4, decoded.length);
//TODO calculate chekcsum
while(privKey.length>32){
privKey = Arrays.copyOfRange(privKey,0,privKey.length-1);
}
return ECKey.fromPrivate(privKey);
} }
return null; return null;
} }

View File

@ -22,6 +22,8 @@ public class BitcoinCryptoNetVerifier extends CryptoNetVerifier{
if(value.equals(cryptoCoin.getParameters().getGenesisBlock().getHashAsString())){ if(value.equals(cryptoCoin.getParameters().getGenesisBlock().getHashAsString())){
CryptoNetManager.verifiedCryptoNetURL(cryptoCoin.getCryptoNet(), url, System.currentTimeMillis() - startTime); CryptoNetManager.verifiedCryptoNetURL(cryptoCoin.getCryptoNet(), url, System.currentTimeMillis() - startTime);
}else{
System.out.println("BitcoinCryptoNetVerifier bad genesis block " + value);
} }
//TODO bad genesis block //TODO bad genesis block
}else{ }else{

View File

@ -27,6 +27,13 @@ public class CalculateBitcoinUriRequest extends CryptoNetInfoRequest {
this.context = context; this.context = context;
} }
public CalculateBitcoinUriRequest(CryptoCoin coin, CryptoNetAccount account, Context context, double amount) {
super(coin);
this.account = account;
this.context = context;
this.amount = amount;
}
public CalculateBitcoinUriRequest(CryptoCoin coin, CryptoNetAccount account, CryptoCurrency currency, double amount, Context context) { public CalculateBitcoinUriRequest(CryptoCoin coin, CryptoNetAccount account, CryptoCurrency currency, double amount, Context context) {
super(coin); super(coin);
this.account = account; this.account = account;

View File

@ -170,7 +170,15 @@ public class CrystalWalletService extends LifecycleService {
} }
}); });
final LiveData<List<CryptoNetAccount>> cryptoNetAccountList = db.cryptoNetAccountDao().getAllBitcoins();
cryptoNetAccountList.observe(this, new Observer<List<CryptoNetAccount>>() {
@Override
public void onChanged(@Nullable List<CryptoNetAccount> cryptoNetAccounts) {
for(CryptoNetAccount nextCryptoNetAccount : cryptoNetAccounts) {
generalAccountManager.loadAccountFromDB(nextCryptoNetAccount,thisService);
}
}
});
/*while(this.keepLoadingAccountTransactions){ /*while(this.keepLoadingAccountTransactions){
try{ try{

View File

@ -2,6 +2,7 @@ package cy.agorise.crystalwallet.views;
import android.arch.lifecycle.ViewModelProviders; import android.arch.lifecycle.ViewModelProviders;
import android.content.Context; import android.content.Context;
import android.support.annotation.Nullable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -30,6 +31,11 @@ public class CryptoNetAccountAdapter extends ArrayAdapter<CryptoNetAccount> {
this.data = objects; this.data = objects;
} }
@Override
public CryptoNetAccount getItem(int position) {
return data.get(position);
}
@Override @Override
public View getDropDownView(int position, View convertView, ViewGroup parent) { public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getView(position, convertView, parent); return getView(position, convertView, parent);