Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryFailed #200

Open
matisalimbene opened this issue Jan 13, 2025 · 3 comments
Open

QueryFailed #200

matisalimbene opened this issue Jan 13, 2025 · 3 comments

Comments

@matisalimbene
Copy link

I'm trying to execute a Query using FindTransactionByHash, but I get QueryFailed (code 500) as a response.

I'm on Iroha version: v2.0.0-pre-rc.20 with the following library versions:

    "@iroha2/client": "^7.0.0",
    "@iroha2/crypto-core": "^1.1.1",
    "@iroha2/crypto-target-bundler": "^1.1.1",
    "@iroha2/crypto-target-node": "^1.1.1",
    "@iroha2/crypto-target-web": "^1.1.1",
    "@iroha2/data-model": "^7.0.0",

So for instance, If I use hash value 846F5E5498B4FA615B8137C16CD55707DDE349FE79C7A49B07A838F9A, the code below is how I prepare and execute the query:

const getTXbyHash = async (hash) => {
  logger.info(`[srv] getTXbyHash ... : ${hash}`);

  const { QueryBox, Expression, Value, HashValue } = datamodel;

  // Convert the string to a Buffer
  const buffer = Buffer.from(hash, 'utf8');

  // Create a 32-byte array
  const arrayU8L32 = new Uint8Array(32);

  // Copy the buffer into the 32-byte array
  arrayU8L32.set(buffer.slice(0, 32), 0);

  const query = QueryBox('FindTransactionByHash', {
    hash: Expression(
      'Raw',
      Value('Hash', HashValue('Transaction', arrayU8L32))
    ),
  });

  const { pre, client } = clientFactory();

  try {
    const result = await client.requestWithQueryBox(pre, query);
    const { tag, content } = result;
    if (tag !== 'Ok') return { error: content.enum.tag };

    return {
      data: result,
    };
  } catch (error) {
    logger.error(error);
    return { error: error.message };
  }
};
@0x009922
Copy link
Contributor

QueryFailed is the value of content.enum.tag you are returning as an error. However, there is more information about what exactly failed in content.enum.value.

@matisalimbene
Copy link
Author

Hey @0x009922, thanks for your help so far!! I do appreciate it.

Just so that is documented, bellow is a sample response for this Query, even tho I'm certain that the Hash I use does exist.

{
    "data": {
        "tag": "Err",
        "content": {
            "enum": {
                "tag": "QueryFailed",
                "content": {
                    "enum": {
                        "tag": "Find",
                        "content": {
                            "enum": {
                                "tag": "Transaction",
                                "content": {
                                    "0": 107,
                                    "1": 77,
                                    "2": 52,
                                    "3": 228,
                                    "4": 68,
                                    "5": 72,
                                    "6": 175,
                                    "7": 190,
                                    "8": 15,
                                    "9": 149,
                                    "10": 233,
                                    "11": 158,
                                    "12": 114,
                                    "13": 117,
                                    "14": 13,
                                    "15": 47,
                                    "16": 54,
                                    "17": 195,
                                    "18": 172,
                                    "19": 142,
                                    "20": 240,
                                    "21": 163,
                                    "22": 146,
                                    "23": 239,
                                    "24": 148,
                                    "25": 26,
                                    "26": 78,
                                    "27": 0,
                                    "28": 179,
                                    "29": 57,
                                    "30": 97,
                                    "31": 151
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

I switched logging to DEBUG and saw this:

025-01-15T13:28:06.011852Z DEBUG request{method=POST path=/query version=HTTP/1.1 remote.addr=181.85.41.212:23104}: iroha_core::smartcontracts::isi::query: Executing query=Find transaction with `fc76fa0f0388e0dcb9ecc0cc0bb2f7a07963acb4ec3dea7af6e3ebbf0ee9dcc1` hash
2025-01-15T13:28:06.013073Z  WARN request{method=POST path=/query version=HTTP/1.1 remote.addr=181.85.41.212:23104}: warp::filters::trace: unable to serve request (client error) status=404 error=None

The hash is on lower caps, so would always fail. Unless it is just being shown lowercaps in logging, but it's correct when executing the search. (The hash on the log is from a different test I did, it doesn't correspond to the bytes on the response sample above)

Where you able to use FindTransactionByHash with v2.0.0-pre-rc.20 and SDK 7.0 ?

@0x009922
Copy link
Contributor

The hash is on lower caps, so would always fail. Unless it is just being shown lowercaps in logging, but it's correct when executing the search. (The hash on the log is from a different test I did, it doesn't correspond to the bytes on the response sample above)

Iroha is ignorant to the hash case and processes it as a sequence of bytes.

Where you able to use FindTransactionByHash with v2.0.0-pre-rc.20 and SDK 7.0 ?

I am now having difficulties with this too. Investigating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants