chainside / btcpy

A Python3 SegWit-compliant library which provides tools to handle Bitcoin data structures in a simple fashion.
https://www.chainside.net
GNU Lesser General Public License v3.0
271 stars 74 forks source link

Different address from which I need #40

Closed impowski closed 6 years ago

impowski commented 6 years ago

Here is the address which I need 2N2qWuN9rpfw4DvPqjJ3SD1adNnmZdeM5NU (testnet)

Here is what I do to get it:

def p2sh_address(pub_key_1, pub_key_2):
    pub_key_hash_1 = pub_key_1.hash()
    pub_key_hash_2 = pub_key_2.hash()

    multisig_script = MultisigScript(2, pub_key_1, pub_key_2, 2)
    return (multisig_script, P2shAddress.from_script(multisig_script))

Here is the redeem script hex which I got: 5221020d2036fea368d0400acabe96e975b6f4e24c6f40f2e45db4264c2f117702c1e72102d0b84f4a3d4890b2fdde4dc74db4328fb3504e0247187d8286311c75b3b6bdeb52ae It's the same as on the block.io

Here is the address which I got from from_script: 2N7tpkpBJPmv2BD37eTXDUJJzhpXEoyyNU9

Am I doing something wrong or it should be like that?

impowski commented 6 years ago

So I figured this:

def p2sh_address(pub_key_1, pub_key_2):
    pub_key_hash_1 = pub_key_1.hash()
    pub_key_hash_2 = pub_key_2.hash()

    multisig_script = MultisigScript(2, pub_key_1, pub_key_2, 2)
    multisig_script_hash = multisig_script.p2wsh_hash()
    p2wsh_script = P2wshV0Script(multisig_script_hash)
    p2sh_address = P2shScript(p2wsh_script).address()
    return (multisig_script, p2sh_address)

And I got this address (exactly which I needed): 2N2qWuN9rpfw4DvPqjJ3SD1adNnmZdeM5NU