[Qt] Prevent balloon-spam after rescan

Rebased-from: acd432b5b38464ef3ecb87f80b1bbebe9d7c2022
https://github.com/bitcoin/bitcoin/pull/4530
[Qt] Fix Transaction details shows wrong To:

Rebased-from: b90711cabffa8bf83ddee98cfc179c0aef5732ef
bitcoin-cli, rpcclient: prefer EXIT_FAILURE cstdlib constant

A more complex construction via abs() yields the same end result.

Rebased-From: 34ff109
Rebased-By: Wladimir J. van der Laan <laanwj@gmail.com>

Rebased-from: 0cafb630254c6459ea02f6fc47e1c37bb81a1238
RPC client: Simplify command line string-to-JSON-value conversion code

By default, all command line parameters are converted into JSON string
values.  There is no need to manually specify the incoming type.

A binary decision "parse as string or JSON?" is all that's necessary.

Convert to a simple class, initialized at runtime startup, which offers
a quick lookup to answer "parse as JSON?" conversion question.

Future parameter conversions need only to indicate the method name
and zero-based index of the parameter needing JSON parsing.

Conflicts:
	src/rpcclient.cpp

Rebased-from: e35b37b1b8252c3d3f66001ba1efccd263307add
Allow -onlynet=onion to be used

Just an alias for onlynet=tor, but matches the new name
of the proxy option -onion= better.

Conflicts:
	src/init.cpp

Rebased-from: 60dc8e4208058814494b301c355a5996af9517a9
https://github.com/bitcoin/bitcoin/pull/4605
Add IsReachable(net) function

Allows other parts of the program to query for reachable
status of a network. Similar to IsLimited(net).

Rebased-from: c91a9471be7a96311a7e1452a3624aa557bc185d
https://github.com/bitcoin/bitcoin/pull/4605
Add GetNetworkName function

Returns the network name for an Network enum.

Rebased-from: 075cf49e593025030c8b3572e606960f15de424e
https://github.com/bitcoin/bitcoin/pull/4605
Add detailed network info to getnetworkinfo RPC

This commit adds per-network information to the
getnetworkinfo RPC call:

- Is the network limited?
- Is the network reachable
- Which proxy is used for this network, if any

Inspired by #2575.

Conflicts:
	src/init.cpp
	src/rpcnet.cpp

Rebased-from: aa8279513b5d206c172d3da3d5e3034c61d47b39
https://github.com/bitcoin/bitcoin/pull/4605
Add support for watch-only addresses

Changes:
* Add Add/Have WatchOnly methods to CKeyStore, and implementations
  in CBasicKeyStore.
* Add similar methods to CWallet, and support entries for it in
  CWalletDB.
* Make IsMine in script/wallet return a new enum 'isminetype',
  rather than a boolean. This allows distinguishing between
  spendable and unspendable coins.
* Add a field fSpendable to COutput (GetAvailableCoins' return type).
* Mark watchonly coins in listunspent as 'watchonly': true.
* Add 'watchonly' to validateaddress, suppressing script/pubkey/...
  in this case.

Based on a patch by Eric Lombrozo.

Conflicts:
	src/qt/walletmodel.cpp
	src/rpcserver.cpp
	src/wallet.cpp

Conflicts:
	src/script.h

Rebased-from: c8988460a2865b99ee96da6799d37ac6ccb79d4d
https://github.com/bitcoin/bitcoin/pull/4045
qt: Hide unspendable outputs in coin control

Rebased-from: 2935b211033610d7ef0deef9bf1b344a5bac029f
https://github.com/bitcoin/bitcoin/pull/4045
Watchonly balances are shown separately in gui.

Rebased-from: ffd40da361639faeef405c7e4a504a340d77aa5b
https://github.com/bitcoin/bitcoin/pull/4045
Watchonly transactions are marked in transaction history

Rebased-from: d2692f61164730322547871f2124de06ade0436b
https://github.com/bitcoin/bitcoin/pull/4045
Added argument to getbalance to include watchonly addresses and fixed errors in balance calculation.

Conflicts:
	src/wallet.h

Rebased-from: d4640d7d8c3ba373195d33ab75db9c8cb43f8806
https://github.com/bitcoin/bitcoin/pull/4045
Added argument to listaccounts to include watchonly addresses

Rebased-from: 83f3543f20348aa718620314e7deb37bd0f71b90
https://github.com/bitcoin/bitcoin/pull/4045
Showing 'involvesWatchonly' property for transactions returned by 'listtransactions' and 'listsinceblock'.
It is only appended when the transaction involves a watchonly address.

Rebased-from: 952877e01c1045298fd51d1152d96c304d4cf2a4
https://github.com/bitcoin/bitcoin/pull/4045
Added argument to listtransactions and listsinceblock to include watchonly addresses

Rebased-from: d7d5d23b77e204eccd4bf8a5608c1a499d5fc42f
https://github.com/bitcoin/bitcoin/pull/4045
fixed tiny glitch and improved readability like laanwj suggested

Rebased-from: a5c6c5d6df887764ac07664aae842234c19bbf8d
https://github.com/bitcoin/bitcoin/pull/4045
added includeWatchonly argument to 'gettransaction' because it affects balance calculation

Rebased-from: f87ba3df64bb5825f7e2f6a33c93cf5738682019
https://github.com/bitcoin/bitcoin/pull/4045
added includedWatchonly argument to listreceivedbyaddress/...account

Rebased-from: 0fa2f8899adf8f9f0ead29ba5d708ead6c5d4eaf
https://github.com/bitcoin/bitcoin/pull/4045
Use script matching rather than destination matching for watch-only.

This changes the keystore data format, wallet format and IsMine logic
to detect watch-only outputs based on direct script matching rather
than first trying to convert outputs to destinations (addresses).

The reason is that we don't know how the software that has the spending
keys works. It may support the same types of scripts as us, but that is
not guaranteed. Furthermore, it removes the ambiguity between addresses
used as identifiers for output scripts or identifiers for public keys.

One practical implication is that adding a normal pay-to-pubkey-hash
address via importaddress will not cause payments to the corresponding
full public key to be detected as IsMine. If that is wanted, add those
scripts directly (importaddress now also accepts any hex-encoded script).

Conflicts:
	src/wallet.cpp

Rebased-from: d5087d1ba08142bdf135333a0da08ef0f5fc7ef0
https://github.com/bitcoin/bitcoin/pull/4045