qt: get required locks upfront in polling functions

This avoids the GUI from getting stuck on
periodical polls if the core is holding the locks for a longer time -
for example, during a wallet rescan.

Conflicts:
	src/qt/transactiontablemodel.cpp
	src/qt/walletmodel.cpp
askpassphrasedialog: clear pass fields on accept
fix memory leak
AvailableCoins: acquire cs_main mutex

It's required when called from WalletModel
refactor coin selection for staking
update readme-qt.rst
fix relock on sending coins when "for staking only" is activated

Sets the checkbox in the askpassphrase dialog to the previous value of
fWalletUnlockStakingOnly resolving the issue that the wallet gets locked
after sending coins when "for staking only" is activated.
Allocate receive buffers in on the fly
remove unused CNode::Cleanup()

Conflicts:
	src/net.cpp
Internal RNG for approximateBestSubset to prevent degenerate behavior.

This fixes test_bitcoin failures on openbsd reported by dhill on IRC.

  On some systems rand() is a simple LCG over 2^31 and so it produces
an even-odd sequence.  ApproximateBestSubset was only using the least
significant bit and so every run of the iterative solver would be the
same for some inputs, resulting in some pretty dumb decisions.

Using something other than the least significant bit would paper over
the issue but who knows what other way a system's rand() might get us
here.  Instead we use an internal RNG with a period of something like
2^60 which is well behaved.  This also makes it possible to make the
selection deterministic for the tests, if we wanted to implement that.
Remove -detachdb and stop's detach argument.

As the only BDB database left is the wallet, and it is always
detached.

Also remove IsChainFile() predicate and related chainfile-specific
logic.

Conflicts:
	src/bitcoinrpc.cpp
	src/db.cpp
	src/qt/bitcoinstrings.cpp
Treat non-final transactions as non-standard

At least one service that accepted zero-confirmation transactions
was vulnerable because an attacker could send a transaction
with a lock time far in the future, and then have plenty of time in
which to get a double-spend mined (perhaps from a miner who wasn't
on the network when the first transaction was broadcast).

That is a variation on the "Finney attack". We still don't
recommend anybody accept 0-confirmation transactions as final
payment for anything. This change keeps non-final transactions
from appearing in the wallet, and, assuming most of the network
accepts this change, will prevent them from being relayed until
they are final.
Comments for constants

Conflicts:
	src/main.h
Make transactions larger than 100K non-standard

Extremely large transactions with lots of inputs can cost the network
almost as much to process as they cost the sender in fees.

We would never create transactions larger than 100K big; this change
makes transactions larger than 100K non-standard, so they are not
relayed/mined by default. This is most important for miners that might
create blocks larger than 250K big, who could be vulnerable to a
make-your-blocks-so-expensive-to-verify-they-get-orphaned attack.
move IsStandard and IsFinal out of CTransaction
refactor acception to mempool
Display tx nLockTime correctly when set to block #

Previously when a transaction was set to lock at a specific block the
calculation was reversed, returning a negative number. This broke the UI
and caused it to display %n in place of the actual number.

In addition the previous calculation would display "Open for 0 blocks"
when the block height was such that the next block created would
finalize the transaction. Inserted the word "more" and changed the
calculation so that the last message would be "Open for 1 more block" to
better match user expectations.

Conflicts:
	src/qt/transactionrecord.h
Fix off-by-one errors in use of IsFinalTx()

Previously CreateNewBlock() didn't take into account the fact that
IsFinalTx() without any arguments tests if the transaction is considered
final in the *current* block, when both those functions really needed to
know if the transaction would be final in the *next* block.

Additionally the UI had a similar misunderstanding.

Also adds some basic tests to check that CreateNewBlock() is in fact
mining nLockTime-using transactions correctly.

Thanks to Wladimir J. van der Laan for rebase.

Conflicts:
	src/main.cpp
	src/miner.cpp
	src/qt/transactiondesc.cpp
	src/qt/transactionrecord.cpp
	src/test/miner_tests.cpp
don't relay tx with future timestamp
schedule hardfork