use of com.samourai.wallet.JSONRPC.JSONRPC in project samourai-wallet-android by Samourai-Wallet.
the class APIFactory method getDynamicFees.
public synchronized JSONObject getDynamicFees() {
JSONObject jsonObject = null;
try {
int sel = PrefsUtil.getInstance(context).getValue(PrefsUtil.FEE_PROVIDER_SEL, 0);
if (sel == 1) {
int[] blocks = new int[] { 2, 6, 24 };
List<SuggestedFee> suggestedFees = new ArrayList<SuggestedFee>();
JSONRPC jsonrpc = new JSONRPC(TrustedNodeUtil.getInstance().getUser(), TrustedNodeUtil.getInstance().getPassword(), TrustedNodeUtil.getInstance().getNode(), TrustedNodeUtil.getInstance().getPort());
for (int i = 0; i < blocks.length; i++) {
JSONObject feeObj = jsonrpc.getFeeEstimate(blocks[i]);
if (feeObj != null && feeObj.has("result")) {
double fee = feeObj.getDouble("result");
SuggestedFee suggestedFee = new SuggestedFee();
suggestedFee.setDefaultPerKB(BigInteger.valueOf((long) (fee * 1e8)));
suggestedFee.setStressed(false);
suggestedFee.setOK(true);
suggestedFees.add(suggestedFee);
}
}
if (suggestedFees.size() > 0) {
FeeUtil.getInstance().setEstimatedFees(suggestedFees);
}
} else {
StringBuilder url = new StringBuilder(WebUtil.BITCOIND_FEE_URL);
// Log.i("APIFactory", "Dynamic fees:" + url.toString());
String response = WebUtil.getInstance(null).getURL(url.toString());
// Log.i("APIFactory", "Dynamic fees response:" + response);
try {
jsonObject = new JSONObject(response);
parseDynamicFees_bitcoind(jsonObject);
} catch (JSONException je) {
je.printStackTrace();
jsonObject = null;
}
}
} catch (Exception e) {
jsonObject = null;
e.printStackTrace();
}
return jsonObject;
}
use of com.samourai.wallet.JSONRPC.JSONRPC in project samourai-wallet-android by Samourai-Wallet.
the class PushTx method trustedNode.
public String trustedNode(String hexString) {
try {
JSONRPC jsonrpc = new JSONRPC(TrustedNodeUtil.getInstance().getUser(), TrustedNodeUtil.getInstance().getPassword(), TrustedNodeUtil.getInstance().getNode(), TrustedNodeUtil.getInstance().getPort());
String response = jsonrpc.pushTx(hexString).toString();
return response;
} catch (Exception e) {
return null;
}
}
use of com.samourai.wallet.JSONRPC.JSONRPC in project samourai-wallet-android by Samourai-Wallet.
the class SettingsActivity2 method getTrustedNode.
private void getTrustedNode() {
final EditText edNode = new EditText(SettingsActivity2.this);
edNode.setHint(R.string.trusted_node_ip_hint);
edNode.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
edNode.setText(TrustedNodeUtil.getInstance().getNode() == null ? "" : TrustedNodeUtil.getInstance().getNode());
final EditText edPort = new EditText(SettingsActivity2.this);
edPort.setHint(R.string.trusted_node_port_hint);
edPort.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_CLASS_NUMBER);
edPort.setText(TrustedNodeUtil.getInstance().getPort() == 0 ? Integer.toString(TrustedNodeUtil.DEFAULT_PORT) : Integer.toString(TrustedNodeUtil.getInstance().getPort()));
final EditText edUser = new EditText(SettingsActivity2.this);
edUser.setHint(R.string.trusted_node_user_hint);
edUser.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
edUser.setText(TrustedNodeUtil.getInstance().getUser() == null ? "" : TrustedNodeUtil.getInstance().getUser());
final EditText edPassword = new EditText(SettingsActivity2.this);
edPassword.setHint(R.string.trusted_node_password_hint);
edPassword.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_PASSWORD);
edPassword.setSingleLine(true);
edPassword.setText(TrustedNodeUtil.getInstance().getPassword() == null ? "" : TrustedNodeUtil.getInstance().getPassword());
LinearLayout restoreLayout = new LinearLayout(SettingsActivity2.this);
restoreLayout.setOrientation(LinearLayout.VERTICAL);
restoreLayout.addView(edNode);
restoreLayout.addView(edPort);
restoreLayout.addView(edUser);
restoreLayout.addView(edPassword);
AlertDialog.Builder dlg = new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.trusted_node).setView(restoreLayout).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
final String node = edNode.getText().toString();
final String port = edPort.getText().toString().length() == 0 ? Integer.toString(TrustedNodeUtil.DEFAULT_PORT) : edPort.getText().toString();
final String user = edUser.getText().toString();
final String password = edPassword.getText().toString();
if (node != null && node.length() > 0 && port != null && port.length() > 0 && user != null && user.length() > 0 && password != null && password.length() > 0) {
TrustedNodeUtil.getInstance().setParams(user, new CharSequenceX(password), node, Integer.parseInt(port));
final Handler handler = new Handler();
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
final CheckBoxPreference cbPref8 = (CheckBoxPreference) SettingsActivity2.this.findPreference("useTrustedNode");
boolean isOK = false;
JSONRPC jsonrpc = new JSONRPC(user, new CharSequenceX(password), node, Integer.parseInt(port));
String result = jsonrpc.getNetworkInfoAsString();
Log.d("TrustedNodeUtil", "getnetworkinfo:" + result);
if (result != null) {
try {
JSONObject obj = new JSONObject(result);
if (obj != null && obj.has("version") && obj.has("subversion")) {
if (obj.getString("subversion").contains("Bitcoin XT") || obj.getString("subversion").contains("Classic") || obj.getString("subversion").contains("BitcoinUnlimited") || obj.getString("subversion").contains("SegWit2x") || obj.getString("subversion").contains("Segwit2x") || obj.getString("subversion").contains("Bitcoin ABC") || obj.getString("subversion").contains("Satoshi:1.14")) {
Toast.makeText(SettingsActivity2.this, R.string.trusted_node_breaks_consensus, Toast.LENGTH_SHORT).show();
} else if (obj.getInt("version") < 130100 || !obj.getString("subversion").contains("Satoshi")) {
isOK = true;
Toast.makeText(SettingsActivity2.this, R.string.trusted_node_not_core_131, Toast.LENGTH_SHORT).show();
} else {
isOK = true;
Toast.makeText(SettingsActivity2.this, "Trusted node running:\n" + obj.getString("subversion") + ", " + obj.getInt("version"), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(SettingsActivity2.this, R.string.trusted_node_ko, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Toast.makeText(SettingsActivity2.this, e.getMessage() + "\n" + R.string.trusted_node_error, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(SettingsActivity2.this, R.string.trusted_node_not_responding, Toast.LENGTH_SHORT).show();
}
final boolean _isOK = isOK;
handler.post(new Runnable() {
@Override
public void run() {
if (_isOK) {
cbPref8.setEnabled(true);
TrustedNodeUtil.getInstance().setValidated(true);
} else {
cbPref8.setChecked(false);
cbPref8.setEnabled(false);
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.USE_TRUSTED_NODE, false);
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.FEE_PROVIDER_SEL, 0);
TrustedNodeUtil.getInstance().setValidated(false);
}
SettingsActivity2.this.recreate();
}
});
Looper.loop();
}
}).start();
dialog.dismiss();
} else if ((node == null || node.length() == 0) && (port == null || port.length() == 0) && (user == null || user.length() == 0) && (password == null || password.length() == 0)) {
TrustedNodeUtil.getInstance().reset();
} else {
Toast.makeText(SettingsActivity2.this, R.string.trusted_node_not_valid, Toast.LENGTH_SHORT).show();
}
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
if (!isFinishing()) {
dlg.show();
}
}
Aggregations