Stacks.js: Update needed to CLI output for transactions to fix 2 issues

Created on 8 Sep 2020  路  6Comments  路  Source: blockstack/stacks.js

Describe the bug
Currently we have 2 issues the TXID is missing the first 2 characters
The link to explorer is not pointing to the current version of the explorer

This is what we get

{
txid: 'a5659553e404089f861efba24394268a1bfefbe2d44a1301d45e2505a8ce6c79',
transaction: 'https://testnet-explorer.now.sh/txid/0xa5659553e404089f861efba24394268a1bfefbe2d44a1301d45e2505a8ce6c79'
}

This is what we should get

{
txid: '0xa5659553e404089f861efba24394268a1bfefbe2d44a1301d45e2505a8ce6c79',
transaction: 'https://testnet-explorer.blockstack.org/txid/0xa5659553e404089f861efba24394268a1bfefbe2d44a1301d45e2505a8ce6c79'
}

To Reproduce
Steps to reproduce the behavior:

  1. Go to the CLI
  2. Send a a token send transaction
  3. look at the output and you will see the 2 issues above

Expected behavior
{
txid: '0xa5659553e404089f861efba24394268a1bfefbe2d44a1301d45e2505a8ce6c79',
transaction: 'https://testnet-explorer.blockstack.org/txid/0xa5659553e404089f861efba24394268a1bfefbe2d44a1301d45e2505a8ce6c79'
}

Screenshots
If applicable, add screenshots to help explain your problem.

Terminal Log
If applicable, add console log to help explain your problem.
Screen Shot 2020-09-08 at 11 05 47 AM

Most helpful comment

My preference is towards an explicit 0x for all hex strings, based on the principle of least surprise. If you come across something displaying 447814 in the context of a block or transaction, what does it signify?

An integer block height? A truncated hash string?

If we always indicate hex with the prefix then we don't need special rules like "if the string is 64 chars or contains a-fA-F then omit 0x...".

The explicit rule is also handy when dealing with >32bit integers in JSON. Because these values have to be serialized as a string, API payloads are less surprising when using a field like {"amount": "0x447814"} vs {"amount": "447814"}. The former is more likely to be used correctly with something like BigInt(amount), while the latter is likely to be used in an error-prone parseInt(amount).

All 6 comments

The 0x prefix in the TXID is just to indicate that the string is hexadecimal. I don't think we have agreement to make the prefix format standard. For example, Bitcoin does not prefix TXIDs with 0x. The prefix is added to the explorer URL though because that's what it expects.

Regarding explorer URL, we can update that. My understanding was that https://testnet-explorer.now.sh is the most up-to-date build. If that's not the case please provide the correct URL.

@yknl feels like having a consistent txid format would be beneficial. what do you think about that? should we spend some time agree on the format in all of our projects (part of eng best practices)?

The Explorer URL for production is https://testnet-explorer.blockstack.org/

Yes we should be consistent. My vote is for not including the 0x though. @zone117x @aulneau @hstove should chime in if they feel otherwise.

My preference is towards an explicit 0x for all hex strings, based on the principle of least surprise. If you come across something displaying 447814 in the context of a block or transaction, what does it signify?

An integer block height? A truncated hash string?

If we always indicate hex with the prefix then we don't need special rules like "if the string is 64 chars or contains a-fA-F then omit 0x...".

The explicit rule is also handy when dealing with >32bit integers in JSON. Because these values have to be serialized as a string, API payloads are less surprising when using a field like {"amount": "0x447814"} vs {"amount": "447814"}. The former is more likely to be used correctly with something like BigInt(amount), while the latter is likely to be used in an error-prone parseInt(amount).

Moving this issue to the stack.js monorepo since the CLI has already been migrated and changes will be made in the new repo.

it looks like what is outstanding here is the URL to the explorer (currently printing: https://testnet-explorer.now.sh/txid/). @yknl is that correct? could we pick this issue up and fix in this sprint?

Was this page helpful?
0 / 5 - 0 ratings