diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java index 7ce7f5e..5b2b6d2 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java @@ -219,7 +219,7 @@ public abstract class BitsharesFaucetApiGenerator { public interface IWebService { @Headers({"Content-Type: application/json"}) - @POST("/api/v1/accounts") + @POST("/faucet/api/v1/accounts") Call getReg(@Body Map params); } 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 5240ea1..f0c3f29 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java +++ b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java @@ -52,8 +52,10 @@ public class CrystalApplication extends Application { public static final String BITCOIN_SERVER_URLS[] ={ - "https://insight.bitpay.com/", - "https://testnet.blockexplorer.com/" + "https://test-insight.bitpay.com", + "https://testnet.blockexplorer.com/", + //"https://insight.bitpay.com/" + }; public static final CryptoCurrency BITCOIN_CURRENCY = new CryptoCurrency("BTC",CryptoNet.BITCOIN,8); diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/FileBackupManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/FileBackupManager.java index b0944dd..106a310 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/FileBackupManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/FileBackupManager.java @@ -327,7 +327,6 @@ public class FileBackupManager implements FileServiceRequestsListener { public static byte[] decompress(byte[] inputBytes, int which) { InputStream in = null; try { - System.out.println("Bytes: "+Util.bytesToHex(inputBytes)); ByteArrayInputStream input = new ByteArrayInputStream(inputBytes); ByteArrayOutputStream output = new ByteArrayOutputStream(16*2048); if(which == Util.XZ) { 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 6af2174..4065186 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java @@ -171,134 +171,141 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf * @param txi */ public void processTxi(Txi txi){ - CrystalDatabase db = CrystalDatabase.getAppDatabase(this.context); - List btTransactions = db.bitcoinTransactionDao().getTransactionsByTxid(txi.txid); - if(!btTransactions.isEmpty()){ - for(BitcoinTransaction btTransaction : btTransactions) { - btTransaction.setConfirmations(txi.confirmations); - CryptoCoinTransaction ccTransaction = db.transactionDao().getById(btTransaction.getCryptoCoinTransactionId()); - if (!ccTransaction.isConfirmed() && btTransaction.getConfirmations() >= cryptoCoin.getCryptoNet().getConfirmationsNeeded()) { - ccTransaction.setConfirmed(true); - db.transactionDao().insertTransaction(ccTransaction); - updateBalance(ccTransaction,(ccTransaction.getInput()?1:-1)*ccTransaction.getAmount(),db); - } + try { + System.out.println("GeneralAccountManager processingTxi " + txi.txid); + CrystalDatabase db = CrystalDatabase.getAppDatabase(this.context); + List btTransactions = db.bitcoinTransactionDao().getTransactionsByTxid(txi.txid); + if (!btTransactions.isEmpty()) { + System.out.println("GeneralAccountManager Transaction not null " + txi.txid); + for (BitcoinTransaction btTransaction : btTransactions) { + btTransaction.setConfirmations(txi.confirmations); + CryptoCoinTransaction ccTransaction = db.transactionDao().getById(btTransaction.getCryptoCoinTransactionId()); + if (!ccTransaction.isConfirmed() && btTransaction.getConfirmations() >= cryptoCoin.getCryptoNet().getConfirmationsNeeded()) { + ccTransaction.setConfirmed(true); + db.transactionDao().insertTransaction(ccTransaction); + updateBalance(ccTransaction, (ccTransaction.getInput() ? 1 : -1) * ccTransaction.getAmount(), db); + } - db.bitcoinTransactionDao().insertBitcoinTransaction(btTransaction); - } - }else { + db.bitcoinTransactionDao().insertBitcoinTransaction(btTransaction); + } + } else { /*List ccTransactions = new ArrayList(); btTransactions = new ArrayList();*/ //TODO transactions involving multiples accounts - CryptoCoinTransaction ccTransaction = new CryptoCoinTransaction(); - BitcoinTransaction btTransaction = new BitcoinTransaction(); - btTransaction.setTxId(txi.txid); - btTransaction.setBlock(txi.blockheight); - btTransaction.setFee((long) (txi.fee * Math.pow(10, cryptoCoin.getPrecision()))); - btTransaction.setConfirmations(txi.confirmations); - ccTransaction.setDate(new Date(txi.time * 1000)); - if(txi.txlock || txi.confirmations >= cryptoCoin.getCryptoNet().getConfirmationsNeeded()) { - ccTransaction.setConfirmed(true); - }else{ - ccTransaction.setConfirmed(false); - } - - ccTransaction.setInput(false); - - long amount = 0; - - - //transaction.setAccount(this.mAccount); - //transaction.setType(cryptoCoin); - List gtxios = new ArrayList(); - for (Vin vin : txi.vin) { - BitcoinTransactionGTxIO input = new BitcoinTransactionGTxIO(); - String addr = vin.addr; - input.setAddress(addr); - input.setIndex(vin.n); - input.setOutput(true); - input.setAmount((long) (vin.value * Math.pow(10, cryptoCoin.getPrecision()))); - input.setOriginalTxId(vin.txid); - input.setScriptHex(vin.scriptSig.hex); - - BitcoinAddress address = db.bitcoinAddressDao().getdadress(addr); - if(address != null){ - if(ccTransaction.getAccountId() < 0){ - ccTransaction.setAccountId(address.getAccountId()); - ccTransaction.setFrom(addr); - ccTransaction.setInput(false); - } - - if(ccTransaction.getAccountId()== address.getAccountId()){ - amount -= vin.value; - } - } - - if(ccTransaction.getFrom() == null || ccTransaction.getFrom().isEmpty()){ - ccTransaction.setFrom(addr); - } - - gtxios.add(input); - - - } - - for (Vout vout : txi.vout) { - if (vout.scriptPubKey.addresses == null || vout.scriptPubKey.addresses.length <= 0) { - + CryptoCoinTransaction ccTransaction = new CryptoCoinTransaction(); + BitcoinTransaction btTransaction = new BitcoinTransaction(); + btTransaction.setTxId(txi.txid); + btTransaction.setBlock(txi.blockheight); + btTransaction.setFee((long) (txi.fee * Math.pow(10, cryptoCoin.getPrecision()))); + btTransaction.setConfirmations(txi.confirmations); + ccTransaction.setDate(new Date(txi.time * 1000)); + if (txi.txlock || txi.confirmations >= cryptoCoin.getCryptoNet().getConfirmationsNeeded()) { + ccTransaction.setConfirmed(true); } else { - BitcoinTransactionGTxIO output = new BitcoinTransactionGTxIO(); - String addr = vout.scriptPubKey.addresses[0]; - output.setAddress(addr); - output.setIndex(vout.n); - output.setOutput(false); - output.setAmount((long) (vout.value * Math.pow(10, cryptoCoin.getPrecision()))); - output.setScriptHex(vout.scriptPubKey.hex); - output.setOriginalTxId(txi.txid); + ccTransaction.setConfirmed(false); + } + + ccTransaction.setInput(false); + + long amount = 0; + + + //transaction.setAccount(this.mAccount); + //transaction.setType(cryptoCoin); + List gtxios = new ArrayList(); + for (Vin vin : txi.vin) { + BitcoinTransactionGTxIO input = new BitcoinTransactionGTxIO(); + String addr = vin.addr; + input.setAddress(addr); + input.setIndex(vin.n); + input.setOutput(true); + input.setAmount((long) (vin.value * Math.pow(10, cryptoCoin.getPrecision()))); + input.setOriginalTxId(vin.txid); + input.setScriptHex(vin.scriptSig.hex); - gtxios.add(output); BitcoinAddress address = db.bitcoinAddressDao().getdadress(addr); - if(address != null){ - if(ccTransaction.getAccountId() < 0){ + if (address != null) { + if (ccTransaction.getAccountId() < 0) { ccTransaction.setAccountId(address.getAccountId()); - ccTransaction.setInput(true); - ccTransaction.setTo(addr); + ccTransaction.setFrom(addr); + ccTransaction.setInput(false); } - if(ccTransaction.getAccountId()== address.getAccountId()){ - amount += vout.value; + if (ccTransaction.getAccountId() == address.getAccountId()) { + amount -= (long) (vin.value * Math.pow(10, cryptoCoin.getPrecision())); } - }else{ - //TOOD multiple send address - if(ccTransaction.getTo() == null || ccTransaction.getTo().isEmpty()){ - ccTransaction.setTo(addr); + } + + if (ccTransaction.getFrom() == null || ccTransaction.getFrom().isEmpty()) { + ccTransaction.setFrom(addr); + } + + gtxios.add(input); + + + } + + for (Vout vout : txi.vout) { + if (vout.scriptPubKey.addresses == null || vout.scriptPubKey.addresses.length <= 0) { + + } else { + BitcoinTransactionGTxIO output = new BitcoinTransactionGTxIO(); + String addr = vout.scriptPubKey.addresses[0]; + output.setAddress(addr); + output.setIndex(vout.n); + output.setOutput(false); + output.setAmount((long) (vout.value * Math.pow(10, cryptoCoin.getPrecision()))); + output.setScriptHex(vout.scriptPubKey.hex); + output.setOriginalTxId(txi.txid); + + gtxios.add(output); + + BitcoinAddress address = db.bitcoinAddressDao().getdadress(addr); + if (address != null) { + if (ccTransaction.getAccountId() < 0) { + ccTransaction.setAccountId(address.getAccountId()); + ccTransaction.setInput(true); + ccTransaction.setTo(addr); + } + + if (ccTransaction.getAccountId() == address.getAccountId()) { + amount += (long) (vout.value * Math.pow(10, cryptoCoin.getPrecision())); + } + } else { + //TOOD multiple send address + if (ccTransaction.getTo() == null || ccTransaction.getTo().isEmpty()) { + ccTransaction.setTo(addr); + } } } } - } - ccTransaction.setAmount(amount); - CryptoCurrency currency = db.cryptoCurrencyDao().getByNameAndCryptoNet(this.cryptoCoin.name(), this.cryptoCoin.getCryptoNet().name()); - if (currency == null) { - currency = new CryptoCurrency(); - currency.setCryptoNet(this.cryptoCoin.getCryptoNet()); - currency.setName(this.cryptoCoin.name()); - currency.setPrecision(this.cryptoCoin.getPrecision()); - long idCurrency = db.cryptoCurrencyDao().insertCryptoCurrency(currency)[0]; - currency.setId(idCurrency); - } + ccTransaction.setAmount(amount); + CryptoCurrency currency = db.cryptoCurrencyDao().getByNameAndCryptoNet(this.cryptoCoin.name(), this.cryptoCoin.getCryptoNet().name()); + if (currency == null) { + currency = new CryptoCurrency(); + currency.setCryptoNet(this.cryptoCoin.getCryptoNet()); + currency.setName(this.cryptoCoin.name()); + currency.setPrecision(this.cryptoCoin.getPrecision()); + long idCurrency = db.cryptoCurrencyDao().insertCryptoCurrency(currency)[0]; + currency.setId(idCurrency); + } - ccTransaction.setIdCurrency((int)currency.getId()); + ccTransaction.setIdCurrency((int) currency.getId()); - long ccId = db.transactionDao().insertTransaction(ccTransaction)[0]; - btTransaction.setCryptoCoinTransactionId(ccId); - long btId = db.bitcoinTransactionDao().insertBitcoinTransaction(btTransaction)[0]; - for(BitcoinTransactionGTxIO gtxio : gtxios){ - gtxio.setBitcoinTransactionId(btId); - db.bitcoinTransactionDao().insertBitcoinTransactionGTxIO(gtxio); - } + long ccId = db.transactionDao().insertTransaction(ccTransaction)[0]; + btTransaction.setCryptoCoinTransactionId(ccId); + long btId = db.bitcoinTransactionDao().insertBitcoinTransaction(btTransaction)[0]; + for (BitcoinTransactionGTxIO gtxio : gtxios) { + gtxio.setBitcoinTransactionId(btId); + db.bitcoinTransactionDao().insertBitcoinTransactionGTxIO(gtxio); + } - if(ccTransaction.isConfirmed()) { - updateBalance(ccTransaction,amount,db); + if (ccTransaction.isConfirmed()) { + updateBalance(ccTransaction, amount, db); + } } + }catch(Exception e){ + e.printStackTrace(); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/network/BitcoinCryptoNetVerifier.java b/app/src/main/java/cy/agorise/crystalwallet/network/BitcoinCryptoNetVerifier.java index d38bcfb..9ebd52a 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/network/BitcoinCryptoNetVerifier.java +++ b/app/src/main/java/cy/agorise/crystalwallet/network/BitcoinCryptoNetVerifier.java @@ -23,7 +23,7 @@ public class BitcoinCryptoNetVerifier extends CryptoNetVerifier{ CryptoNetManager.verifiedCryptoNetURL(cryptoCoin.getCryptoNet(), url, System.currentTimeMillis() - startTime); }else{ - System.out.println("BitcoinCryptoNetVerifier bad genesis block " + value); + System.out.println("BitcoinCryptoNetVerifier bad genesis block " + value + " " + url); } //TODO bad genesis block }else{ diff --git a/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetManager.java b/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetManager.java index 24bf672..544d1fb 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetManager.java @@ -32,7 +32,6 @@ public abstract class CryptoNetManager { public static String getURL(CryptoNet crypto, int index){ if(TestedURLs.containsKey(crypto) && TestedURLs.get(crypto).size()>index){ - System.out.println("Servers url list " + Arrays.toString(TestedURLs.get(crypto).toArray())); return TestedURLs.get(crypto).get(index).getUrl(); } System.out.println("Servers " + crypto.getLabel()+" dioesn't have testedurl"); diff --git a/app/src/main/java/cy/agorise/crystalwallet/network/GetChainId.java b/app/src/main/java/cy/agorise/crystalwallet/network/GetChainId.java index 2863514..044c05b 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/network/GetChainId.java +++ b/app/src/main/java/cy/agorise/crystalwallet/network/GetChainId.java @@ -38,7 +38,6 @@ public class GetChainId extends BaseGrapheneHandler { @Override public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception { - System.out.println("<<< "+frame.getPayloadText()); String response = frame.getPayloadText(); Type GetChainIdResponse = new TypeToken>(){}.getType(); @@ -55,7 +54,5 @@ public class GetChainId extends BaseGrapheneHandler { @Override public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception { - if(frame.isTextFrame()) - System.out.println(">>> "+frame.getPayloadText()); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/network/GetDatabaseVersion.java b/app/src/main/java/cy/agorise/crystalwallet/network/GetDatabaseVersion.java index 6625030..8146e36 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/network/GetDatabaseVersion.java +++ b/app/src/main/java/cy/agorise/crystalwallet/network/GetDatabaseVersion.java @@ -38,7 +38,6 @@ public class GetDatabaseVersion extends BaseGrapheneHandler { @Override public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception { - System.out.println("<<< "+frame.getPayloadText()); String response = frame.getPayloadText(); Type GetChainIdResponse = new TypeToken>(){}.getType(); @@ -55,8 +54,6 @@ public class GetDatabaseVersion extends BaseGrapheneHandler { @Override public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception { - if(frame.isTextFrame()) - System.out.println(">>> "+frame.getPayloadText()); } public class VersionResponse{