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

walletrpc.GetTransactionResponse.GetBlockHash returns incorrect block hash #1365

Closed
barisere opened this issue Dec 28, 2018 · 2 comments
Closed

Comments

@barisere
Copy link

Here's a snippet that shows how I'm using the package.

import pb "github.com/decred/dcrwallet/rpc/walletrpc"
import "github.com/decred/dcrd/chaincfg/chainhash"

// setup connection, ...

hash, err := chainhash.NewHashFromStr(transactionHash)
// handle error
getTxRequest := &pb.GetTransactionRequest{TransactionHash: hash[:]}
getTxResponse, err := c.walletServiceClient.GetTransaction(context.Background(), getTxRequest)
// handle error
fmt.Printf("%x\n", getTxResponse.GetBlockHash())

// the following fails
blockInfo, err := c.walletServiceClient.BlockInfo(context.Background(), &pb.BlockInfoRequest{BlockHash: getTxResponse.GetBlockHash()})
// handle error

The block hash printed is a byte-reversed copy of transactionHash. It is also different from the block hash displayed on dcrdata (testnet.dcrdata.org). If I copy the block hash shown on dcrdata into the c.walletServiceClient.BlockInfo request, it works as expected. But if I use the value of block hash returned by the package, I get the following error.

rpc error: code = NotFound desc = wallet.BlockInfo: item does not exist: block header

Package version: github.com/decred/dcrwallet/rpc/walletrpc v0.2.0

@davecgh
Copy link
Member

davecgh commented Dec 28, 2018

Hashes on the wire are reversed from the way they are shown. The response is the raw bytes. Since you're just printing it with %x, you're not reversing it. Convert it to a chainhash.Hash first with:

blockHash, err := chainhash.NewHash(getTxResponse.GetBlockHash())
// handle err
fmt.Println(blockHash)

EDIT: Although that doesn't address the issue which is that it's returning the txhash as the blockhash. I confirmed it locally as well.

@jrick
Copy link
Member

jrick commented Jan 2, 2019

This is fixed as of github.com/decred/dcrwallet/wallet v1.1.2.

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

3 participants