Closed liutaihua closed 6 years ago
c.sign not signal
@qari signall --- i use for Sign all inputs to a transaction using a private key
@qari signall --- i use for Sign all inputs to a transaction using a private key
Please show your code all I cant see your outs
@qari signall --- i use for Sign all inputs to a transaction using a private key where c.mktx(inputs,outs) ?
my code:
c = Bitcoin(testnet=False)
addr = c.privtop2w(priv) # my addr is: 3HBGRggBpPaeWepZoKmfoHHF1U7GXcrvit
inputs = c.unspent(addr)
if len(inputs) == 0:
raise NotEnoughBalance
unspent_amount = sum([i['value'] for i in inputs])
fee = 54400
outs = [{'value': value, 'address': to_addr}, {'value': unspent_amount - value - fee, 'address': '3R19nu8MXnhvfJoCcVJKxe2THk4ZGX59YV'}]
tx = c.mktx(inputs, outs)
tx_seri = c.signall(tx, priv)
res = c.pushtx(tx_seri)
print(res.text)
return res
my code:
c = Bitcoin(testnet=False) addr = c.privtop2w(priv) # my addr is: 3HBGRggBpPaeWepZoKmfoHHF1U7GXcrvit inputs = c.unspent(addr) if len(inputs) == 0: raise NotEnoughBalance unspent_amount = sum([i['value'] for i in inputs]) fee = 54400 outs = [{'value': value, 'address': to_addr}, {'value': unspent_amount - value - fee, 'address': '3R19nu8MXnhvfJoCcVJKxe2THk4ZGX59YV'}] tx = c.mktx(inputs, outs) tx_seri = c.signall(tx, priv) res = c.pushtx(tx_seri) print(res.text) return res
I'm not sure that after tx_seri = c.signall(tx, priv) you have tx = serialize()
@qari take a look the signall source code is:
def signall(self, txobj, priv):
"""
Sign all inputs to a transaction using a private key
"""
if not isinstance(txobj, dict):
txobj = deserialize(txobj)
if isinstance(priv, dict):
for e, i in enumerate(txobj["ins"]):
k = priv["%s:%d" % (i["outpoint"]["hash"], i["outpoint"]["index"])]
txobj = self.sign(txobj, e, k)
else:
for i in range(len(txobj["ins"])):
txobj = self.sign(txobj, i, priv)
return serialize(txobj) ## already do serialize in signal method, so it should not to call serialize again
change to:
tx = c.mktx(inputs, outs)
tx1 = c.sign(tx, 0, priv) # the inputs only have single element, should be do sign once enough
tx_seri = serialize(tx1)
res = c.pushtx(tx_seri)
occur same error
I can't see problem when I change privtop2w to privtoaddr
privtop2w only for segwit address
I notice privtoaddr and privtop2w too! But if use privtoaddr will got addr that not equals my address
actually address: 3HBGRggBpPaeWepZoKmfoHHF1U7GXcrvit
c.privtoaddr(priv) # got addr: 19pBvhXHWyqT8dudRds4SJAU6c321stoHB
and it use privtoaddr in the source code. I cant understand.
my address-private_key are generate by bitcoin-cli command
Early I use c.privtoaddr(priv) but now use only SEED priv = electrum_privkey(seed, N, 0) and each wallet different for each users
thanks. I already fix this.
c.unspent(addr) got only single output res:
and init outs:
and c.signall(tx, priv) got hex string: 01000000011360e2c843711e0ac39ddde480115f367f607fea7e82a579aaedfc036c51da2b000000008b483045022100ff521bbeabdd99a39c8d57409cb41c62b2cb3e688300575d534aaa5e3731f92f0220495b622ab5f74f3ba2c0e4f02965e118ded621d932156625ec9b77e29508270f01410498d50701f190c02ac432c1c6e3e868b70bd7fe49890ffcb3f1e870310d229fa4c8413baf30b8804915ba84b24b02b2e5c346af04bce50ffb0da75f6c4aab5cfeffffffff02a08601000000000017a9140649b58a4f377d75a45b4eb0321a7a4dca5ad68d87d0230c000000000017a914a9e1a3c3ed078b33214b3df052b458b7830538938700000000
I try to decoderawtransaction the hex string from c.signall(tx, priv) returns:
got this:
Is there any problem with the above transaction info??? please help!