primal100 / pybitcointools

Simple, common-sense Bitcoin-themed Python ECC library
Other
335 stars 151 forks source link

occur error Error #-26: 64: bad-txns-nonstandard-inputs, code=-26 #27

Closed liutaihua closed 6 years ago

liutaihua commented 6 years ago

c.unspent(addr) got only single output res:

 [{'output': '2bda516c03fcedaa79a5827eea7f607f365f1180e4dd9dc30a1e7143c8e26013:0', 'value': 950000}]

and init outs:

 [{'value': 100000, 'address': '32GGH6W8uK9WFnQwirkLM3zqSbvZV47suY'}, {'value': 795600, 'address': '3R19nu8MXnhvfJoCcVJKxe2THk4ZGX59YV'}]

and c.signall(tx, priv) got hex string: 01000000011360e2c843711e0ac39ddde480115f367f607fea7e82a579aaedfc036c51da2b000000008b483045022100ff521bbeabdd99a39c8d57409cb41c62b2cb3e688300575d534aaa5e3731f92f0220495b622ab5f74f3ba2c0e4f02965e118ded621d932156625ec9b77e29508270f01410498d50701f190c02ac432c1c6e3e868b70bd7fe49890ffcb3f1e870310d229fa4c8413baf30b8804915ba84b24b02b2e5c346af04bce50ffb0da75f6c4aab5cfeffffffff02a08601000000000017a9140649b58a4f377d75a45b4eb0321a7a4dca5ad68d87d0230c000000000017a914a9e1a3c3ed078b33214b3df052b458b7830538938700000000

c.pushtx(tx_seri)  occur error info: Validation Error: BitcoindException(super=com.neemre.btcdcli4j.core.BitcoindException: Error #-26: 64: bad-txns-nonstandard-inputs, code=-26  

I try to decoderawtransaction the hex string from c.signall(tx, priv) returns:

bitcoin-cli decoderawtransaction 01000000011360e2c843711e0ac39ddde480115f367f607fea7e82a579aaedfc036c51da2b000000008b483045022100c3752d4803644e1dfa3bb3773fb8defcab3a502b3fd91eed56b12c5c9089b38302203d49118f0c3d8a898b410f54155e8e73d6bdd0f9ad15084e9011ab3569a8aea901410498d50701f190c02ac432c1c6e3e868b70bd7fe49890ffcb3f1e870310d229fa4c8413baf30b8804915ba84b24b02b2e5c346af04bce50ffb0da75f6c4aab5cfeffffffff02d0230c000000000017a9140649b58a4f377d75a45b4eb0321a7a4dca5ad68d87a08601000000000017a914ffb8f2c954e1a7e6600578a6c7e30163f937cd038700000000  

got this:

{
  "txid": "e74e65b24779973e67baa6183c7dd6a5082d46a971d6a1a4ca21cbb164be3947",
  "hash": "e74e65b24779973e67baa6183c7dd6a5082d46a971d6a1a4ca21cbb164be3947",
  "version": 1,
  "size": 254,
  "vsize": 254,
  "locktime": 0,
  "vin": [
    {
      "txid": "2bda516c03fcedaa79a5827eea7f607f365f1180e4dd9dc30a1e7143c8e26013",
      "vout": 0,
      "scriptSig": {
        "asm": "3045022100ff521bbeabdd99a39c8d57409cb41c62b2cb3e688300575d534aaa5e3731f92f0220495b622ab5f74f3ba2c0e4f02965e118ded621d932156625ec9b77e29508270f[ALL] 0498d50701f190c02ac432c1c6e3e868b70bd7fe49890ffcb3f1e870310d229fa4c8413baf30b8804915ba84b24b02b2e5c346af04bce50ffb0da75f6c4aab5cfe",
        "hex": "483045022100ff521bbeabdd99a39c8d57409cb41c62b2cb3e688300575d534aaa5e3731f92f0220495b622ab5f74f3ba2c0e4f02965e118ded621d932156625ec9b77e29508270f01410498d50701f190c02ac432c1c6e3e868b70bd7fe49890ffcb3f1e870310d229fa4c8413baf30b8804915ba84b24b02b2e5c346af04bce50ffb0da75f6c4aab5cfe"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00100000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 0649b58a4f377d75a45b4eb0321a7a4dca5ad68d OP_EQUAL",
        "hex": "a9140649b58a4f377d75a45b4eb0321a7a4dca5ad68d87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "32GGH6W8uK9WFnQwirkLM3zqSbvZV47suY"
        ]
      }
    },
    {
      "value": 0.00795600,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_HASH160 a9e1a3c3ed078b33214b3df052b458b783053893 OP_EQUAL",
        "hex": "a914a9e1a3c3ed078b33214b3df052b458b78305389387",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "3HBGRggBpPaeWepZoKmfoHHF1U7GXcrvit"
        ]
      }
    }
  ]
}

Is there any problem with the above transaction info??? please help!

maxclax commented 6 years ago

c.sign not signal

liutaihua commented 6 years ago

@qari signall --- i use for Sign all inputs to a transaction using a private key

maxclax commented 6 years ago

@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

maxclax commented 6 years ago

@qari signall --- i use for Sign all inputs to a transaction using a private key where c.mktx(inputs,outs) ?

liutaihua commented 6 years ago

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
maxclax commented 6 years ago

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()

liutaihua commented 6 years ago

@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
liutaihua commented 6 years ago

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

maxclax commented 6 years ago

I can't see problem when I change privtop2w to privtoaddr

maxclax commented 6 years ago

privtop2w only for segwit address

liutaihua commented 6 years ago

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.

liutaihua commented 6 years ago

my address-private_key are generate by bitcoin-cli command

maxclax commented 6 years ago

Early I use c.privtoaddr(priv) but now use only SEED priv = electrum_privkey(seed, N, 0) and each wallet different for each users

liutaihua commented 6 years ago

thanks. I already fix this.