Merge pull request #10 from hvarona/develop

Fix amount on bitcoin transactions
This commit is contained in:
hvarona 2018-11-21 19:52:44 -04:00 committed by GitHub
commit 8502272b25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 123 additions and 122 deletions

View file

@ -219,7 +219,7 @@ public abstract class BitsharesFaucetApiGenerator {
public interface IWebService { public interface IWebService {
@Headers({"Content-Type: application/json"}) @Headers({"Content-Type: application/json"})
@POST("/api/v1/accounts") @POST("/faucet/api/v1/accounts")
Call<RegisterAccountResponse> getReg(@Body Map<String, HashMap> params); Call<RegisterAccountResponse> getReg(@Body Map<String, HashMap> params);
} }

View file

@ -52,8 +52,10 @@ public class CrystalApplication extends Application {
public static final String BITCOIN_SERVER_URLS[] ={ public static final String BITCOIN_SERVER_URLS[] ={
"https://insight.bitpay.com/", "https://test-insight.bitpay.com",
"https://testnet.blockexplorer.com/" "https://testnet.blockexplorer.com/",
//"https://insight.bitpay.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

@ -327,7 +327,6 @@ public class FileBackupManager implements FileServiceRequestsListener {
public static byte[] decompress(byte[] inputBytes, int which) { public static byte[] decompress(byte[] inputBytes, int which) {
InputStream in = null; InputStream in = null;
try { try {
System.out.println("Bytes: "+Util.bytesToHex(inputBytes));
ByteArrayInputStream input = new ByteArrayInputStream(inputBytes); ByteArrayInputStream input = new ByteArrayInputStream(inputBytes);
ByteArrayOutputStream output = new ByteArrayOutputStream(16*2048); ByteArrayOutputStream output = new ByteArrayOutputStream(16*2048);
if(which == Util.XZ) { if(which == Util.XZ) {

View file

@ -171,9 +171,12 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
* @param txi * @param txi
*/ */
public void processTxi(Txi txi){ public void processTxi(Txi txi){
try {
System.out.println("GeneralAccountManager processingTxi " + txi.txid);
CrystalDatabase db = CrystalDatabase.getAppDatabase(this.context); CrystalDatabase db = CrystalDatabase.getAppDatabase(this.context);
List<BitcoinTransaction> btTransactions = db.bitcoinTransactionDao().getTransactionsByTxid(txi.txid); List<BitcoinTransaction> btTransactions = db.bitcoinTransactionDao().getTransactionsByTxid(txi.txid);
if (!btTransactions.isEmpty()) { if (!btTransactions.isEmpty()) {
System.out.println("GeneralAccountManager Transaction not null " + txi.txid);
for (BitcoinTransaction btTransaction : btTransactions) { for (BitcoinTransaction btTransaction : btTransactions) {
btTransaction.setConfirmations(txi.confirmations); btTransaction.setConfirmations(txi.confirmations);
CryptoCoinTransaction ccTransaction = db.transactionDao().getById(btTransaction.getCryptoCoinTransactionId()); CryptoCoinTransaction ccTransaction = db.transactionDao().getById(btTransaction.getCryptoCoinTransactionId());
@ -228,7 +231,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
} }
if (ccTransaction.getAccountId() == address.getAccountId()) { if (ccTransaction.getAccountId() == address.getAccountId()) {
amount -= vin.value; amount -= (long) (vin.value * Math.pow(10, cryptoCoin.getPrecision()));
} }
} }
@ -255,6 +258,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
output.setOriginalTxId(txi.txid); output.setOriginalTxId(txi.txid);
gtxios.add(output); gtxios.add(output);
BitcoinAddress address = db.bitcoinAddressDao().getdadress(addr); BitcoinAddress address = db.bitcoinAddressDao().getdadress(addr);
if (address != null) { if (address != null) {
if (ccTransaction.getAccountId() < 0) { if (ccTransaction.getAccountId() < 0) {
@ -264,7 +268,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
} }
if (ccTransaction.getAccountId() == address.getAccountId()) { if (ccTransaction.getAccountId() == address.getAccountId()) {
amount += vout.value; amount += (long) (vout.value * Math.pow(10, cryptoCoin.getPrecision()));
} }
} else { } else {
//TOOD multiple send address //TOOD multiple send address
@ -300,6 +304,9 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
updateBalance(ccTransaction, amount, db); updateBalance(ccTransaction, amount, db);
} }
} }
}catch(Exception e){
e.printStackTrace();
}
} }
private void createGeneralAccount(CreateBitcoinAccountRequest request){ private void createGeneralAccount(CreateBitcoinAccountRequest request){

View file

@ -23,7 +23,7 @@ public class BitcoinCryptoNetVerifier extends CryptoNetVerifier{
CryptoNetManager.verifiedCryptoNetURL(cryptoCoin.getCryptoNet(), url, System.currentTimeMillis() - startTime); CryptoNetManager.verifiedCryptoNetURL(cryptoCoin.getCryptoNet(), url, System.currentTimeMillis() - startTime);
}else{ }else{
System.out.println("BitcoinCryptoNetVerifier bad genesis block " + value); System.out.println("BitcoinCryptoNetVerifier bad genesis block " + value + " " + url);
} }
//TODO bad genesis block //TODO bad genesis block
}else{ }else{

View file

@ -32,7 +32,6 @@ public abstract class CryptoNetManager {
public static String getURL(CryptoNet crypto, int index){ public static String getURL(CryptoNet crypto, int index){
if(TestedURLs.containsKey(crypto) && TestedURLs.get(crypto).size()>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(); return TestedURLs.get(crypto).get(index).getUrl();
} }
System.out.println("Servers " + crypto.getLabel()+" dioesn't have testedurl"); System.out.println("Servers " + crypto.getLabel()+" dioesn't have testedurl");

View file

@ -38,7 +38,6 @@ public class GetChainId extends BaseGrapheneHandler {
@Override @Override
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception { public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
System.out.println("<<< "+frame.getPayloadText());
String response = frame.getPayloadText(); String response = frame.getPayloadText();
Type GetChainIdResponse = new TypeToken<WitnessResponse<String>>(){}.getType(); Type GetChainIdResponse = new TypeToken<WitnessResponse<String>>(){}.getType();
@ -55,7 +54,5 @@ public class GetChainId extends BaseGrapheneHandler {
@Override @Override
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception { public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception {
if(frame.isTextFrame())
System.out.println(">>> "+frame.getPayloadText());
} }
} }

View file

@ -38,7 +38,6 @@ public class GetDatabaseVersion extends BaseGrapheneHandler {
@Override @Override
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception { public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
System.out.println("<<< "+frame.getPayloadText());
String response = frame.getPayloadText(); String response = frame.getPayloadText();
Type GetChainIdResponse = new TypeToken<WitnessResponse<String>>(){}.getType(); Type GetChainIdResponse = new TypeToken<WitnessResponse<String>>(){}.getType();
@ -55,8 +54,6 @@ public class GetDatabaseVersion extends BaseGrapheneHandler {
@Override @Override
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception { public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception {
if(frame.isTextFrame())
System.out.println(">>> "+frame.getPayloadText());
} }
public class VersionResponse{ public class VersionResponse{