Bigchaindb: Invalid transaction (TransactionNotInValidBlock)

Created on 9 Mar 2017  ·  4Comments  ·  Source: bigchaindb/bigchaindb

Following the example code

from bigchaindb_driver import BigchainDB
from bigchaindb_driver.crypto import generate_keypair
bdb = BigchainDB('http://0.0.0.0:32769')


bicycle = {
  'data': {
    'bicycle': {
      'serial_number': 'abcd1234',
      'manufacturer': 'bkfab',
    },
  },
}

metadata = {'planet': 'earth'}

alice, bob = generate_keypair(), generate_keypair()


prepared_creation_tx = bdb.transactions.prepare(
       operation='CREATE',
       signers=alice.public_key,
       asset=bicycle,
       metadata=metadata,
   )




fulfilled_creation_tx = bdb.transactions.fulfill(prepared_creation_tx, private_keys=alice.private_key)

txid = fulfilled_creation_tx['id']

sent_creation_tx = bdb.transactions.send(fulfilled_creation_tx)

# print(bdb.transactions.status(txid))

"""""
while bdb.transactions.status(txid).get('status') != 'valid':
         if bdb.transactions.status(txid).get('status') == 'valid':
             break
print(bdb.transactions.status(txid))
"""""

creation_tx = bdb.transactions.retrieve(txid)

#print(creation_tx)

# 轉移交易
asset_id = creation_tx['id']

transfer_asset = {
    'id': asset_id,
}

output_index = 0

output = creation_tx['outputs'][output_index]

transfer_input = {
       'fulfillment': output['condition']['details'],
       'fulfills': {
            'output': output_index,
            'txid': creation_tx['id'],
        },
        'owners_before': output['public_keys'],
}


prepared_transfer_tx = bdb.transactions.prepare(
      operation='TRANSFER',
      asset=transfer_asset,
      inputs=transfer_input,
      recipients=bob.public_key,
) 

fulfilled_transfer_tx = bdb.transactions.fulfill(
      prepared_transfer_tx,
      private_keys=alice.private_key,
)

sent_transfer_tx = bdb.transactions.send(fulfilled_transfer_tx)

console

Traceback (most recent call last):
  File "test.py", line 82, in <module>
    sent_transfer_tx = bdb.transactions.send(fulfilled_transfer_tx)
  File "/usr/local/lib/python3.6/site-packages/bigchaindb_driver/driver.py", line 305, in send
    method='POST', path=self.path, json=transaction, headers=headers)
  File "/usr/local/lib/python3.6/site-packages/bigchaindb_driver/transport.py", line 58, in forward_request
    headers=headers,
  File "/usr/local/lib/python3.6/site-packages/bigchaindb_driver/connection.py", line 57, in request
    raise exc_cls(response.status_code, text, json)
bigchaindb_driver.exceptions.BadRequest: (400, '{\n  "message": "Invalid transaction (TransactionNotInValidBlock): input `eed100811514b93d8da5f055e08cdfcb475241e668f8eea9a1d332503d239afd` does not exist in a valid block", \n  "status": 400\n}\n', {'message': 'Invalid transaction (TransactionNotInValidBlock): input `eed100811514b93d8da5f055e08cdfcb475241e668f8eea9a1d332503d239afd` does not exist in a valid block', 'status': 400})
BUG

Most helpful comment

You get an error because you are trying to transfer a transaction that has not been validated yet, hence it does not exist in a valid block.

Try to replace

"""""
while bdb.transactions.status(txid).get('status') != 'valid':
         if bdb.transactions.status(txid).get('status') == 'valid':
             break
print(bdb.transactions.status(txid))
"""""

with

import time
for attempt in range(10):
    if bdb.transactions.status(txid).get('status') == 'valid':
        break
    time.sleep(0.5)

In this way you wait for the transaction to be validated and put in a valid block.

All 4 comments

You get an error because you are trying to transfer a transaction that has not been validated yet, hence it does not exist in a valid block.

Try to replace

"""""
while bdb.transactions.status(txid).get('status') != 'valid':
         if bdb.transactions.status(txid).get('status') == 'valid':
             break
print(bdb.transactions.status(txid))
"""""

with

import time
for attempt in range(10):
    if bdb.transactions.status(txid).get('status') == 'valid':
        break
    time.sleep(0.5)

In this way you wait for the transaction to be validated and put in a valid block.

Hey @EasonWang01, can I close the issue if my solution works for you? Thanks!

ok,thanks

hello,i get a error when i try to trying to Multi-Signing.this is code

const txJSON = JSON.stringify({
    "Flags": 0,
    "TransactionType": "SignerListSet",
    "Account": "rBtLATdq2RgjSFJc9LXV9bU7d92uuxYKzD",
    "Fee": "12",
    "SignerQuorum": 2,
    "SignerEntries": [
        {
            "SignerEntry": {
                "Account": "rnYqQXFjeWwqpJs4Qbh4DKLsSnzYQMTL7C",
                "SignerWeight": 1
            }
        },
        {
            "SignerEntry": {
                "Account": "rwrSzrApQGfVWPvsjekGBcsrMV4AUVdEBn",
                "SignerWeight": 1
            }
        },

    ]
})

const RippleAPI = require('ripple-lib').RippleAPI;
const api = new RippleAPI({
    server: 'wss://s.altnet.rippletest.net:51233' // Public rippled server hosted by Ripple, Inc.
});


var signer1 = "rBtLATdq2RgjSFJc9LXV9bU7d92uuxYKzD" //签名地址

var signer2 = "rwrSzrApQGfVWPvsjekGBcsrMV4AUVdEBn" //另一个签名地址。

var signer3 = "rnYqQXFjeWwqpJs4Qbh4DKLsSnzYQMTL7C" //另一个签名地址。

const secret1 = 'shErGbboJ52Ahc7kPRjcU1w7mFuFz';
const secret2 = 'sshrVaGcJefMLJsAY1VrcvGk3znfM';
const secret3 = 'sh2XvANZWR3cA7sjzvkrFxNSfYxJL';


var signed1 = api.sign(txJSON, secret1, {signAs: signer1});

var signed2 = api.sign(txJSON, secret2, {signAs: signer2});

var signed3 = api.sign(txJSON, secret3, {signAs: signer3});

var transactions = [signed1["signedTransaction"], signed2["signedTransaction"], signed3["signedTransaction"]]
var tx = api.combine(transactions);
api.connect().then(() => {
    console.log(tx.signedTransaction)
    api.submit(tx.signedTransaction).then((state) => {
        console.log(state)
    }).catch((error) => {
        console.log(error)
    });
});

this is error.

[RippledError(invalidTransaction, { error: 'invalidTransaction',
  error_exception: 'transaction not valid',
  id: 2,
  request:
   { command: 'submit',
     id: 2,
     tx_blob: '12000C220000000020230000000268400000000000000C7300811477671DB7F353DD3135007A5D2B44EB84400BEE90F3E010732103BDB30ACA71E1C7F1CB62BF53F600830A057606893A66A34F7D29DA2D2D9E70CB744730450221009E4F9BF55A1D71CA9237B7BFA2DD246108D0ECD654528B23D2CF6926E6CC548702203F0C88E74BBAF2DE5F0F23C228571EA41C588C0BA25BD2808EBCD97CE3184C6D811431E5CE14DFDEA55D429788C1A53B4D7A7050AD6FE1E0107321036D59CBB61CDDBB32399255E4A03B7E3A8285F6F7B2A9AE116A65E35E74559899744630440220360103FC25D587C88F7ED12008D3EA7133247345E1E4A43C315FEB049CA0070302204F2B91FF34FBFA3B280CB7D1A1518C55607554A91B9306BCD70F5B91F2B425E4811462CED2545CB1C22A233D1BC10DF36532A970A58CE1E0107321020B0B41B6E9DC179EF8C4F67CBC6F5312F5DB72C4320F4F43118EB62345E4E7AE74473045022100FA0C84B049AE66DD84A9BBE5256B17D16E440BD2B51925E3F207A4AC8D9602A0022026B21BCE3889905D2A5C34679FF9CD6DD359D0BD6DCECF411CB493688956C282811477671DB7F353DD3135007A5D2B44EB84400BEE90E1F1F4EB130001811431E5CE14DFDEA55D429788C1A53B4D7A7050AD6FE1EB130001811462CED2545CB1C22A233D1BC10DF36532A970A58CE1F1' },
  status: 'error',
  type: 'response' })]
Was this page helpful?
0 / 5 - 0 ratings