ofek/bit

Multisig error

dDoom opened this issue · 3 comments

dDoom commented

What's wrong with that? The code below gives out an error Traceback (most recent call last): File "/home/tony/Documents/DLF/Dev/1.py", line 15, in <module> NetworkAPI.broadcast_tx_testnet(tx_2) File "/home/tony/.local/lib/python3.7/site-packages/bit/network/services.py", line 533, in broadcast_tx_testnet raise ConnectionError('Transaction broadcast failed, or ' ConnectionError: Transaction broadcast failed, or Unspents were already used

Balance = 0.04 BTC

from bit import MultiSigTestnet, PrivateKeyTestnet, wif_to_key
from bit.network import NetworkAPI

key1 = wif_to_key(WIF1)
key2 = wif_to_key(WIF2)

multisig1 = MultiSigTestnet(key1, {key1.public_key, key2.public_key}, 2)
multisig2 = MultiSigTestnet(key2, {key1.public_key, key2.public_key}, 2)
tx_1 = multisig1.create_transaction([('2Mxpa7jzh37ZuXKVxqnS5RLD7XCdGFrDFy1', 100000, 'satoshi')], fee=30)
tx_2 = multisig2.sign_transaction(tx_1) 
print(tx_1, tx_2)
NetworkAPI.broadcast_tx_testnet(tx_2)



I have tried to recreate your error using the two WIFs from WALLET_FORMAT_TEST_1 and WALLET_FORMAT_TEST_2 found in tests/samples.py.

However, I was able to create the transaction and broadcast it using your code from unspents sent to the multisigs Segwit address (see transaction: https://blockstream.info/testnet/tx/bd11bd58603101ec5a8fa0a65299962410a376dc66ddad047abb1d774e66e3ad).

But can you post the hex value of your tx_2? Then it will be easier to further investigate what is wrong.

dDoom commented
tx_2 = '010000000481abe4f55b10488990b84bb7389510a05852990d4227955af0c03b7ae6d27f6800000000910047304402204e4f876cba0fe41b8e5021c14b75859ce4515a5612dbe4b753d3e3daf42fe020022041e1efe63fff851300a4e3e24d11d9192caa19f42724a7e2cec5eb4aa67372c201475221025337858e577d37d2e358e94d1b411fba08bae0d68e1564991e463a04c8ccc6a12102b2f408c02a83b8b415399e86b1ab4d2c38a4319e25de6ccff118caa6e7a2875552aeffffffff55a3c35dd3b0827b938f8ff4682fa0caf8adb00fb3e6bd89ce493e47f8aa891d010000009100473044022028f9ec3e12bee073e1e2682ed9b0c143115b706c5747479de4451a05ddac478f022029c94666c9e8da17aa3a7c55a488968c3386e0997bb45a05df650932df20238c01475221025337858e577d37d2e358e94d1b411fba08bae0d68e1564991e463a04c8ccc6a12102b2f408c02a83b8b415399e86b1ab4d2c38a4319e25de6ccff118caa6e7a2875552aeffffffff40580f3ac8c5012688d089a04c337ecdafe13a7397e5f775d51dbdcd495e59fa00000000910047304402207d1c22717e49b838e16134a961bd5970f352d1b65d737e5abb6b04dad9b838a102205e6a0a1147c33cc775f3f975cfd68e11c171f9ff83ec767808e6a37e3e2cec5101475221025337858e577d37d2e358e94d1b411fba08bae0d68e1564991e463a04c8ccc6a12102b2f408c02a83b8b415399e86b1ab4d2c38a4319e25de6ccff118caa6e7a2875552aeffffffff86b0585b244547da7495f9ba5eef8cfee2b7e71afc343ed680473fe2c17278b401000000db004830450221008a32d69b06b09b9cf8422f110b132d40c07d75bcaee109bfdb361d717f58e4a402207451160ec3a85e7aa35f8dfb4084adaa5edc4e748de9cc38acf30347fce3670801483045022100815758bea2215d317111ceb9ac4bc8646fa6ca40039fa973cd1046ae23b4f3a102204997bfe659382172c17c237554d54b56b124bb71e0d012cc05f16c4a75244beb01475221025337858e577d37d2e358e94d1b411fba08bae0d68e1564991e463a04c8ccc6a12102b2f408c02a83b8b415399e86b1ab4d2c38a4319e25de6ccff118caa6e7a2875552aeffffffff02a08601000000000017a9143d27287d061f4ba9a8018527d4330f6158d6e0198704a83a000000000017a9140daf58f95803f99fba8993461407b1f15ec3cc588700000000'

WIF1 = 'cQsNkUkWmhkzB2vwVkpccK7YBEsAquLdqJyEjB5QQdFpgVLGNuG7'
WIF2 = 'cUqMP1g55H2SyUw1D1o1Es5fQqZkgeZTHpK7o5UW5De2cBQSSXW6'

Thanks for submitting your issue with all the info! I found the bug, which occurs when using multiple inputs for the same multisig contract such as in your example. I will push a fix ASAP!