mmgen-addrimport 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. mmgen-addrimport: Import addresses generated by mmgen-addrgen into an
  20. online bitcoind watching wallet.
  21. """
  22. import sys
  23. from mmgen.Opts import *
  24. from mmgen.config import *
  25. from mmgen.license import *
  26. from mmgen.utils import check_infile,parse_addrs_file,confirm_or_exit
  27. help_data = {
  28. 'prog_name': sys.argv[0].split("/")[-1],
  29. 'desc': """Import addresses generated by mmgen-addrgen into an
  30. online bitcoind watching wallet""",
  31. 'usage':"[opts] [infile]",
  32. 'options': """
  33. -h, --help Print this help message
  34. -q, --quiet Suppress warnings
  35. -v, --verbose Produce more verbose output
  36. """
  37. }
  38. short_opts = "hqv"
  39. long_opts = "help", "quiet", "verbose"
  40. opts,cmd_args = process_opts(sys.argv,help_data,"".join(short_opts),long_opts)
  41. if len(cmd_args) != 1: usage(help_data)
  42. check_infile(cmd_args[0])
  43. seed_id,addr_data = parse_addrs_file(cmd_args[0])
  44. from mmgen.tx import check_wallet_addr_label,connect_to_bitcoind
  45. for i in addr_data:
  46. i[2] = " ".join(i[2:]) if len(i) > 2 else ""
  47. check_wallet_addr_label(i[2])
  48. c = connect_to_bitcoind(http_timeout=3600)
  49. message = """
  50. Importing addresses can take a long time, up to 30 min. per address on a
  51. low-powered computer such as a netbook.
  52. """
  53. confirm_or_exit(message, "continue", expect="YES")
  54. for n,i in enumerate(addr_data):
  55. label = "%s:%s %s" % (seed_id,str(i[0]),i[2])
  56. msg("Importing %-6s %-34s (%s)" % (
  57. ("%s/%s:" % (n+1,len(addr_data))),
  58. i[1], label)
  59. )
  60. c.importaddress(i[1],label)