Merge branch 'develop' of github.com:Agorise/crystal-wallet-android into develop
This commit is contained in:
commit
af4a4aca8b
6 changed files with 115 additions and 83 deletions
|
@ -35,14 +35,18 @@ public abstract class GetEstimateFee {
|
|||
call.enqueue(new Callback<JsonObject>() {
|
||||
@Override
|
||||
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
|
||||
try {
|
||||
listener.estimateFee((double) (response.body().get("2").getAsDouble()));
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
listener.fail();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<JsonObject> call, Throwable t) {
|
||||
listener.fail();
|
||||
listener.estimateFee(-1);
|
||||
}
|
||||
});
|
||||
}catch(Exception e){
|
||||
|
|
|
@ -97,8 +97,8 @@ class InsightApiServiceGenerator {
|
|||
return chain.proceed(request);
|
||||
}
|
||||
});
|
||||
sClientBuilder.readTimeout(5, TimeUnit.MINUTES);
|
||||
sClientBuilder.connectTimeout(5, TimeUnit.MINUTES);
|
||||
sClientBuilder.readTimeout(30, TimeUnit.SECONDS);
|
||||
sClientBuilder.connectTimeout(30, TimeUnit.SECONDS);
|
||||
OkHttpClient client = sClientBuilder.build();
|
||||
Retrofit retrofit = sBuilder.client(client).build();
|
||||
return retrofit.create(serviceClass);
|
||||
|
|
|
@ -52,8 +52,8 @@ public class CrystalApplication extends Application {
|
|||
|
||||
|
||||
public static final String BITCOIN_SERVER_URLS[] ={
|
||||
"https://testnet.blockexplorer.com/",
|
||||
"https://test-insight.bitpay.com",
|
||||
//"https://testnet.blockexplorer.com/",
|
||||
//"https://insight.bitpay.com/"
|
||||
|
||||
};
|
||||
|
|
|
@ -502,6 +502,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
|
|||
throwable.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
crystalDialog.dismiss();
|
||||
Toast.makeText(getContext(), getContext().getString(R.string.unable_to_send_amount), Toast.LENGTH_LONG);
|
||||
}
|
||||
}
|
||||
|
@ -534,6 +535,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
|
|||
throwable.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
crystalDialog.dismiss();
|
||||
Toast.makeText(getContext(), getContext().getString(R.string.unable_to_send_amount), Toast.LENGTH_LONG);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,11 +241,12 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
|
|||
ccTransaction.setAccountId(address.getAccountId());
|
||||
ccTransaction.setFrom(addr);
|
||||
ccTransaction.setInput(false);
|
||||
amount -= (long) (txi.fee * Math.pow(10, cryptoCoin.getPrecision()));
|
||||
}
|
||||
|
||||
if (ccTransaction.getAccountId() == address.getAccountId()) {
|
||||
//if (ccTransaction.getAccountId() == address.getAccountId()) {
|
||||
amount -= (long) (vin.value * Math.pow(10, cryptoCoin.getPrecision()));
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
if (ccTransaction.getFrom() == null || ccTransaction.getFrom().isEmpty()) {
|
||||
|
@ -280,9 +281,9 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
|
|||
ccTransaction.setTo(addr);
|
||||
}
|
||||
|
||||
if (ccTransaction.getAccountId() == address.getAccountId()) {
|
||||
//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()) {
|
||||
|
@ -374,24 +375,37 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
|
|||
//TODO check server connection
|
||||
//TODO validate to address
|
||||
|
||||
System.out.println("GeneralAccount Manager Send request, asking fee");
|
||||
InsightApiGenerator.getEstimateFee(this.cryptoCoin,new ApiRequest(1, new ApiRequestListener() {
|
||||
@Override
|
||||
public void success(Object answer, int idPetition) {
|
||||
System.out.println("GeneralAccount Manager Send request, fee " + answer.toString());
|
||||
try {
|
||||
Transaction tx = new Transaction(cryptoCoin.getParameters());
|
||||
long currentAmount = 0;
|
||||
long fee = -1;
|
||||
long feeRate = (long) (((double) answer) * Math.pow(10, cryptoCoin.getPrecision()));
|
||||
fee = 226 * feeRate;
|
||||
|
||||
System.out.println("GeneralAccount Manager Send request getting utxos" );
|
||||
CrystalDatabase db = CrystalDatabase.getAppDatabase(request.getContext());
|
||||
db.bitcoinTransactionDao();
|
||||
|
||||
List<BitcoinTransactionGTxIO> utxos = getUtxos(request.getSourceAccount().getId(), db);
|
||||
System.out.println("GeneralAccount Manager Send request utxos found " + utxos.size() );
|
||||
for(BitcoinTransactionGTxIO utxo : utxos){
|
||||
currentAmount += utxo.getAmount();
|
||||
if(currentAmount >= request.getAmount() + fee) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentAmount < request.getAmount() + fee) {
|
||||
System.out.println("GeneralAccount Manager Send request no balance" );
|
||||
request.setStatus(BitcoinSendRequest.StatusCode.NO_BALANCE);
|
||||
return;
|
||||
}
|
||||
|
||||
AccountSeed seed = db.accountSeedDao().findById(request.getSourceAccount().getSeedId());
|
||||
DeterministicKey purposeKey = HDKeyDerivation.deriveChildKey((DeterministicKey) seed.getPrivateKey(),
|
||||
new ChildNumber(44, true));
|
||||
|
@ -460,23 +474,35 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf
|
|||
addrKey = HDKeyDerivation.deriveChildKey(externalKey, new ChildNumber((int) btAddress.getIndex(), true));
|
||||
}
|
||||
tx.addSignedInput(outPoint, script, addrKey, Transaction.SigHash.ALL, true);
|
||||
currentAmount -= utxo.getAmount();
|
||||
if(currentAmount<= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("GeneralAccount Manager Send request rawtx " +Util.bytesToHex(tx.bitcoinSerialize()) );
|
||||
InsightApiGenerator.broadcastTransaction(cryptoCoin, Util.bytesToHex(tx.bitcoinSerialize()), new ApiRequest(1, new ApiRequestListener() {
|
||||
@Override
|
||||
public void success(Object answer, int idPetition) {
|
||||
System.out.println("GeneralAccount MAnager succed send");
|
||||
request.setStatus(BitcoinSendRequest.StatusCode.SUCCEEDED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(int idPetition) {
|
||||
System.out.println("GeneralAccount MAnager succed fail");
|
||||
request.setStatus(BitcoinSendRequest.StatusCode.PETITION_FAILED);
|
||||
}
|
||||
}));
|
||||
}catch(Exception e){
|
||||
System.out.println("GeneralAccount Manager Send request error ");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(int idPetition) {
|
||||
System.out.println("GeneralAccount Manager Send request fee fail" );
|
||||
request.setStatus(BitcoinSendRequest.StatusCode.NO_FEE);
|
||||
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public class BitcoinSendRequest extends CryptoNetInfoRequest {
|
|||
|
||||
public void setStatus(StatusCode code){
|
||||
this.status = code;
|
||||
this._fireOnCarryOutEvent();
|
||||
this.validate();
|
||||
}
|
||||
|
||||
public StatusCode getStatus() {
|
||||
|
|
Loading…
Reference in a new issue