Merge pull request #9 from hvarona/develop

Develop
This commit is contained in:
hvarona 2018-11-20 23:04:58 -04:00 committed by GitHub
commit 9a63c25ee4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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[] ={
"https://insight.bitpay.com/"
"https://insight.bitpay.com/",
"https://testnet.blockexplorer.com/"
};
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")
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")
LiveData<CryptoNetAccount> getByIdLiveData( long accountId);

View file

@ -13,7 +13,7 @@ import java.util.List;
*/
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)),
LITECOIN(CryptoNet.LITECOIN,"LTC",8,2,null),
DASH(CryptoNet.DASH,"DASH",8,5,null),

View file

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

View file

@ -402,7 +402,7 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
// @Override
// public void onCarryOut() {
// 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(){
@Override

View file

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

View file

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

View file

@ -9,12 +9,14 @@ import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.util.DiffUtil;
import org.bitcoinj.core.Base58;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.crypto.HDKeyDerivation;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import cy.agorise.crystalwallet.enums.SeedType;
import cy.agorise.crystalwallet.models.seed.BIP39;
@ -115,8 +117,6 @@ public class AccountSeed {
BufferedReader reader = null;
switch (type) {
case BRAINKEY:
try {
reader = new BufferedReader(new InputStreamReader(context.getAssets().open("brainkeydict.txt"), "UTF-8"));
@ -130,6 +130,7 @@ public class AccountSeed {
} catch (IOException e) {
e.printStackTrace();
}
break;
case BIP39:
try {
reader = new BufferedReader(new InputStreamReader(context.getAssets().open("bip39dict.txt"), "UTF-8"));
@ -139,6 +140,7 @@ public class AccountSeed {
} catch (IOException e) {
e.printStackTrace();
}
break;
}
return null;
}
@ -149,6 +151,15 @@ public class AccountSeed {
return new BrainKey(this.mMasterSeed,0).getPrivateKey();
case BIP39:
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;
}

View file

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

View file

@ -27,6 +27,13 @@ public class CalculateBitcoinUriRequest extends CryptoNetInfoRequest {
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) {
super(coin);
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){
try{

View file

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