generic m of n multisig
This commit is contained in:
@@ -366,15 +366,17 @@ class BIP32_Account(Account):
|
||||
|
||||
|
||||
|
||||
class BIP32_Account_2of2(BIP32_Account):
|
||||
class Multisig_Account(BIP32_Account):
|
||||
|
||||
def __init__(self, v):
|
||||
BIP32_Account.__init__(self, v)
|
||||
self.xpub2 = v['xpub2']
|
||||
self.m = v.get('m', 2)
|
||||
Account.__init__(self, v)
|
||||
self.xpub_list = v['xpubs']
|
||||
|
||||
def dump(self):
|
||||
d = BIP32_Account.dump(self)
|
||||
d['xpub2'] = self.xpub2
|
||||
d = Account.dump(self)
|
||||
d['xpubs'] = self.xpub_list
|
||||
d['m'] = self.m
|
||||
return d
|
||||
|
||||
def get_pubkeys(self, for_change, n):
|
||||
@@ -385,10 +387,10 @@ class BIP32_Account_2of2(BIP32_Account):
|
||||
|
||||
def redeem_script(self, for_change, n):
|
||||
pubkeys = self.get_pubkeys(for_change, n)
|
||||
return Transaction.multisig_script(sorted(pubkeys), 2)
|
||||
return Transaction.multisig_script(sorted(pubkeys), self.m)
|
||||
|
||||
def pubkeys_to_address(self, pubkeys):
|
||||
redeem_script = Transaction.multisig_script(sorted(pubkeys), 2)
|
||||
redeem_script = Transaction.multisig_script(sorted(pubkeys), self.m)
|
||||
address = hash_160_to_bc_address(hash_160(redeem_script.decode('hex')), 5)
|
||||
return address
|
||||
|
||||
@@ -396,25 +398,9 @@ class BIP32_Account_2of2(BIP32_Account):
|
||||
return self.pubkeys_to_address(self.get_pubkeys(for_change, n))
|
||||
|
||||
def get_master_pubkeys(self):
|
||||
return [self.xpub, self.xpub2]
|
||||
return self.xpub_list
|
||||
|
||||
def get_type(self):
|
||||
return _('Multisig 2 of 2')
|
||||
return _('Multisig %d of %d'%(self.m, len(self.xpub_list)))
|
||||
|
||||
|
||||
class BIP32_Account_2of3(BIP32_Account_2of2):
|
||||
|
||||
def __init__(self, v):
|
||||
BIP32_Account_2of2.__init__(self, v)
|
||||
self.xpub3 = v['xpub3']
|
||||
|
||||
def dump(self):
|
||||
d = BIP32_Account_2of2.dump(self)
|
||||
d['xpub3'] = self.xpub3
|
||||
return d
|
||||
|
||||
def get_master_pubkeys(self):
|
||||
return [self.xpub, self.xpub2, self.xpub3]
|
||||
|
||||
def get_type(self):
|
||||
return _('Multisig 2 of 3')
|
||||
|
||||
Reference in New Issue
Block a user