@@ -58,8 +58,10 @@ private String getRpcUrl() throws IOException {
5858 String password = p .getProperty ("rpcpassword" );
5959 final String testnet = p .getProperty ("testnet" );
6060 final String nonMainnet = testnet == null || !testnet .equals ("1" ) ? p .getProperty ("regtest" ) : testnet ;
61+
6162 final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences (this );
6263 final String useDistribution = prefs .getString ("usedistribution" , "core" );
64+
6365 if (user == null || password == null ) {
6466 final String cookie = String .format ("%s/%s" , p .getProperty ("datadir" ), ".cookie" );
6567 final String cookieTestnet = String .format ("%s/%s" , p .getProperty ("datadir" ), "testnet3/.cookie" );
@@ -68,12 +70,12 @@ private String getRpcUrl() throws IOException {
6870 final String daemon = "liquid" .equals (useDistribution ) ? cookieLiquid : cookie ;
6971
7072 final String fCookie = nonMainnet == null || !nonMainnet .equals ("1" ) ? daemon : cookieTestnet ;
71- final File file = new File (fCookie );
73+ final File cookieFile = new File (fCookie );
7274
7375 final StringBuilder text = new StringBuilder ();
7476
7577 try {
76- final BufferedReader br = new BufferedReader (new FileReader (file ));
78+ final BufferedReader br = new BufferedReader (new FileReader (cookieFile ));
7779 String line ;
7880
7981 while ((line = br .readLine ()) != null ) {
@@ -100,7 +102,7 @@ private BitcoindRpcClient getRpc() throws IOException {
100102 return new BitcoinJSONRPCClient (getRpcUrl ());
101103 }
102104
103- private void broadcastPeerlist () throws IOException {
105+ private void broadcastPeerList () throws IOException {
104106 final BitcoindRpcClient bitcoin = getRpc ();
105107
106108 final Intent broadcastIntent = new Intent ();
@@ -119,15 +121,17 @@ private void broadcastPeerlist() throws IOException {
119121
120122 }
121123
122- private void broadcastNetwork () throws IOException {
124+ private void broadcastNetwork () throws IOException , BitcoinRPCException {
125+ Log .d (TAG , "broadcastNetwork" );
123126 final BitcoindRpcClient bitcoin = getRpc ();
124127 final Intent broadcastIntent = new Intent ();
125128 broadcastIntent .setAction (MainActivity .RPCResponseReceiver .ACTION_RESP );
126129 broadcastIntent .addCategory (Intent .CATEGORY_DEFAULT );
127130 broadcastIntent .putExtra (PARAM_OUT_MSG , "localonion" );
131+
128132 final BitcoindRpcClient .NetworkInfo info = bitcoin .getNetworkInfo ();
129- for (final Object addrs : info .localAddresses ()) {
130- final Map data = (Map ) addrs ;
133+ for (final Object address : info .localAddresses ()) {
134+ final Map data = (Map ) address ;
131135 final String host = (String ) data .get ("address" );
132136 if (host != null && host .endsWith (".onion" )) {
133137 final Long port = (Long ) data .get ("port" );
@@ -139,14 +143,15 @@ private void broadcastNetwork() throws IOException {
139143 break ;
140144 }
141145 }
146+
142147 final BitcoindRpcClient .BlockChainInfo blockChainInfo = bitcoin .getBlockChainInfo ();
143148 broadcastIntent .putExtra ("sync" , blockChainInfo .verificationProgress ().multiply (BigDecimal .valueOf (100 )).intValue ());
144149 broadcastIntent .putExtra ("blocks" , blockChainInfo .blocks ());
145150 sendBroadcast (broadcastIntent );
146151 }
147152
148153 private void broadcastError (final Exception e ) {
149- Log .e (TAG , e .getClass ().getName ());
154+ Log .e (TAG , "broadcastError - " + e .getClass ().getName ());
150155 final Intent broadcastIntent = new Intent ();
151156 broadcastIntent .setAction (MainActivity .RPCResponseReceiver .ACTION_RESP );
152157 broadcastIntent .addCategory (Intent .CATEGORY_DEFAULT );
@@ -169,7 +174,7 @@ protected void onHandleIntent(final Intent intent) {
169174 conn .authenticate (IOUtils .toByteArray (new FileInputStream (cookie_path )));
170175 conn .shutdownTor ("HALT" );
171176 } catch (final IOException e ) {
172- e . printStackTrace ( );
177+ Log . w ( TAG , "Error stopping TOR" , e );
173178 }
174179
175180 while (true ) {
@@ -231,7 +236,7 @@ protected void onHandleIntent(final Intent intent) {
231236
232237 if (request != null )
233238 if (request .equals ("peerlist" )) {
234- broadcastPeerlist ();
239+ broadcastPeerList ();
235240 return ;
236241 } else if (request .equals ("localonion" )) {
237242 broadcastNetwork ();
@@ -250,17 +255,22 @@ protected void onHandleIntent(final Intent intent) {
250255 sendBroadcast (broadcastIntent );
251256
252257 } catch (final BitcoinRPCException | IOException i ) {
253- Log .i (TAG , "EXE" , i );
254-
255- if (i instanceof BitcoinRPCException && (((BitcoinRPCException ) i ).getResponseCode () == 500 )) {
256- final Intent broadcastIntent = new Intent ();
257- broadcastIntent .setAction (MainActivity .RPCResponseReceiver .ACTION_RESP );
258- broadcastIntent .addCategory (Intent .CATEGORY_DEFAULT );
259- broadcastIntent .putExtra (PARAM_OUT_MSG , "OK" );
260- sendBroadcast (broadcastIntent );
261- return ;
258+ if (i instanceof BitcoinRPCException ) {
259+ final BitcoinRPCException bitcoinRPCException = (BitcoinRPCException ) i ;
260+ if (bitcoinRPCException .getResponseCode () == 500 ) {
261+ Log .d (TAG , "BitcoinRPCException - Internal Server Error" );
262+ final Intent broadcastIntent = new Intent ();
263+ broadcastIntent .setAction (MainActivity .RPCResponseReceiver .ACTION_RESP );
264+ broadcastIntent .addCategory (Intent .CATEGORY_DEFAULT );
265+ broadcastIntent .putExtra (PARAM_OUT_MSG , "OK" );
266+ sendBroadcast (broadcastIntent );
267+ return ;
268+ } else {
269+ Log .e (TAG , "BitcoinRPCException" , i );
270+ }
271+ } else {
272+ Log .e (TAG , "IOException" , i );
262273 }
263-
264274 broadcastError (i );
265275 }
266276 }
0 commit comments