bitcoind-walletunlock.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. bitcoind-walletunlock.py: Unlock a Bitcoin wallet securely
  20. """
  21. import sys
  22. from mmgen.Opts import *
  23. from mmgen.tx import *
  24. from mmgen.util import msg, my_getpass, my_raw_input
  25. prog_name = sys.argv[0].split("/")[-1]
  26. help_data = {
  27. 'prog_name': prog_name,
  28. 'desc': "Unlock a Bitcoin wallet securely",
  29. 'usage': "[opts]",
  30. 'options': """
  31. -h, --help Print this help message
  32. -e, --echo-passphrase Print passphrase to screen when typing it
  33. """
  34. }
  35. short_opts = "he"
  36. long_opts = "help","echo_passphrase"
  37. opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
  38. c = connect_to_bitcoind()
  39. prompt = "Enter passphrase: "
  40. if 'echo_passphrase' in opts:
  41. password = my_raw_input(prompt)
  42. else:
  43. password = my_getpass(prompt)
  44. from bitcoinrpc import exceptions
  45. try:
  46. c.walletpassphrase(password, 9999)
  47. except exceptions.WalletWrongEncState:
  48. msg("Wallet is unencrypted")
  49. except exceptions.WalletPassphraseIncorrect:
  50. msg("Passphrase incorrect")
  51. except exceptions.WalletAlreadyUnlocked:
  52. msg("WARNING: Wallet already unlocked!")