Created
October 13, 2012 00:26
-
-
Save gavinandresen/3882537 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Synchronize multisig addresses between two running bitcoinds | |
# | |
# Example usage: | |
# multisigsync.py --connect1=http://abc:123@127.0.0.1:9000 --connect2=http://abc:123@127.0.0.1:9001 2MsrtHjVXGdT7RuTEiUWzec87Cik1rPpmyD | |
# | |
# Connects to both bitcoinds, figures out which one knows all the public keys for | |
# the mulitisig address, then tells the other about the address. | |
# | |
from jsonrpc import ServiceProxy | |
def main(): | |
import sys | |
import optparse | |
parser = optparse.OptionParser(usage="%prog [options] address [address...]") | |
parser.add_option("--connect1", dest="connect1", default=None, | |
help="URL for HTTP-JSON-RPC connection to first bitcoin (e.g. http://user:pass@127.0.0.1:8332)") | |
parser.add_option("--connect22", dest="connect2", default=None, | |
help="URL for connection to second bitcoin") | |
(options, args) = parser.parse_args() | |
if options.connect1 is None or options.connect2 is None: | |
parser.print_help() | |
sys.exit(1) | |
bitcoind = [] | |
bitcoind.append(ServiceProxy(options.connect1)) | |
bitcoind.append(ServiceProxy(options.connect2)) | |
for address in args: | |
source = 0 | |
dest = 1 | |
r = bitcoind[source].validateaddress(address) | |
if not r["ismine"]: | |
(source,dest) = (dest,source) | |
r = bitcoind[source].validateaddress(address) | |
if "script" not in r or r["script"] != "multisig": | |
print("Skipping %s (not a multisig address)"%address) | |
continue | |
pubkeys = [] | |
for a in r["addresses"]: | |
r2 = bitcoind[source].validateaddress(a) | |
pubkeys.append(r2["pubkey"]) | |
dest_address = bitcoind[dest].addmultisigaddress(r["sigsrequired"], pubkeys) | |
if dest_address != address: | |
print("Odd result: %s != %s"%(dest_address, address)) | |
else: | |
print("Synced %s"%address) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment