mmgen-addrimport 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 connect_to_bitcoind
  45. c = connect_to_bitcoind(mmgen=True)
  46. message = """
  47. Importing addresses can take a long time, up to 30 min. per address on a
  48. low-powered computer such as a netbook.
  49. """
  50. confirm_or_exit(message, "continue", expect="YES")
  51. for n,i in enumerate(addr_data):
  52. comment = " " + " ".join(i[2:]) if len(i) > 2 else ""
  53. label = "%s:%s%s" % (seed_id,str(i[0]),comment)
  54. msg("Importing %-6s %-34s (%s)" % (
  55. ("%s/%s:" % (n+1,len(addr_data))),
  56. i[1], label)
  57. )
  58. c.importaddress(i[1],label)