Closed ChristopherA closed 7 years ago
I recently updated the txref code to confirm with the BIP. Testnet must use txtest as human readable part and we have higher bounds for max height and pos (this why it's two bytes longer).
I think my implementation (use newest master either libbtc or the txref repo) is correct.
The testnet support was just added, the last time I reviewed @shannona txid2bench32 it was using mainnet logic for testnet (my reference implementation was not ready for testnet during the time @shannona had copied it over). See the BIP for testnet: https://github.com/bitcoin/bips/pull/555
So your newest txref code might be all that's needed? I'll give it a shot.
@shannona: I think so. You will need some adoption on the caller side. Make sure you have large enough buffers.
Right. Got it. Will take a look in the morn. Thank you!
I've updated to the newest version of txref_code.c (and .h), with the testnet support, and now I get similar, but maddeningly different results. It's maddening because as far as I can tell I'm providing the same input. The blockheight and index check out:
./txid2bech32 f8cdaff3ebd9e862ed5885f8975489090595abe1470397f79780ead1c7528107
Txid: f8cdaff3ebd9e862ed5885f8975489090595abe1470397f79780ead1c7528107
Height: 1152194
Position: 1
Network: testnet3
HRP: txtest
Magic:
Non-Standard: 1
Txref: txtest1-xxyv-xzxz-qqmq-tyke
Versus:
./bitcoin-txref -t 1152194 1
Height: 1152194
Position: 1
Network: testnet3
HRP: txtest
Magic:
Non-Standard: 1
Txref: txtest1-xyv2-xzyq-qqm5-tyke
This is my invocation for the testnet case:
success = btc_txref_encode(encoded_txref, TXREF_BECH32_HRP_TESTNET, TXREF_MAGIC_BTC_TESTNET, blockheight, blockindex, 1);
The updated files are here. Any idea what mistake I'm making?
Unshockingly, the correct reference decodes, and mine does not at all:
$ ./bitcoin-txref txtest1-xyv2-xzyq-qqm5-tyke
Height: 1152194
Position: 1
Magic: 6
Notice: different network
$ ./bitcoin-txref txtest1-xxyv-xzxz-qqmq-tyke
Error decoding transaction reference.
@shannona, FYI when I run my playground tool with txid f8cdaff3ebd9e862ed5885f8975489090595abe1470397f79780ead1c7528107
, I get tx1-xyv2-xxqq-fpmp-u0
.
I haven't attempted to run the c code yet, and I should output more details (intermediate steps like block height and index). I'll probably get to that tomorrow.
Which doesn't match Jonas' results. In fact, it's apparently not the correct style for a testnet txref, which should start with 'txtest1'. I suspect you're having the same problem I did, which is using the version of his tools prior to three days ago, before he introduced testnet support. (But as you can see, even with the code I updated today, I still can't quite get my results to match his.)
@jonasschnelli if you had any insight into why I can't quite get the right answer (see the 3rd and 4th answers above), it'd be quite welcome.
@shannona —
When I
bitcoin-cli gettransaction
for testnet transactionf8cdaff3ebd9e862ed5885f8975489090595abe1470397f79780ead1c7528107
I get a named JSON value"blockindex": 1,
You can see the transaction here: https://live.blockcypher.com/btc-testnet/tx/f8cdaff3ebd9e862ed5885f8975489090595abe1470397f79780ead1c7528107/
You can see the block the transaction is in here: https://live.blockcypher.com/btc-testnet/block/00000000b3487880b2814da8c0a6b545453d88945dc29a7b700f653cd7e9cdc7/
Note that it is block 1152194 and it is the 2nd transaction (index 1 as index 0 is the coin base reward)
When I use the txid2bech32 tool, I get:
When I use the latest rev of https://github.com/libbtc/libbtc, and correct the txref to the latest format for testnet, (c/tx1/testtx/) and run it against that tool (which does not talk to bitcoind), I get:
Note this is not the height nor index above:
If do use the libbtc tool to do the reverse, given height and index:
Clearly something is wrong. It is slightly possible that there is a bug in @jonasschnelli code in libbtc as it was just added a few days ago, but I wouldn't think so given the testing code he uses.
cc: @kimdhamilton