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

Invalid memory address or nil pointer dereference on weird TxOut #5

Closed
tsileo opened this issue Dec 17, 2013 · 4 comments
Closed

Invalid memory address or nil pointer dereference on weird TxOut #5

tsileo opened this issue Dec 17, 2013 · 4 comments

Comments

@tsileo
Copy link

tsileo commented Dec 17, 2013

Hi,

I'm trying to parse the blockchain using gocoin, but I got a panic: runtime error: invalid memory address or nil pointer dereference when I try to decode address for weird TxOut.

Here is my code (https://gist.github.com/tsileo/8008319), and here is the exception I'm getting:

2013/12/17 17:56:54 128233
2013/12/17 17:56:54 128234
2013/12/17 17:56:54 128235
2013/12/17 17:56:54 128236
2013/12/17 17:56:54 128237
2013/12/17 17:56:54 128238
2013/12/17 17:56:54 128239
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x50 pc=0x44796a]

goroutine 1 [running]:
github.com/piotrnar/gocoin/btc.(*BtcAddr).String(0x0, 0x1a, 0x1a)
    /work/opensource/blockchain_playground_golang/src/github.com/piotrnar/gocoin/btc/addr.go:134 +0x2a
main.main()
    /work/opensource/blockchain_playground_golang/dat2.go:75 +0x250e

goroutine 2 [syscall]:
exit status 2

It happens on weird TxOut, when it can't decode/compute address, I found some explanations here and here.

I see it at block:

Even blockchain.info can't handle these TxOuts, I think it's missing some error checking, maybe it should return nil ?

I just started learning Go, so let me know if I missed something,

Thanks!

@piotrnar
Copy link
Owner

I think it is because you do this:

txo_addr = btc.NewAddrFromPkScript(txo.Pk_script, false).String()

btc.NewAddrFromPkScript() returns "nil" in certain cases and you unconditional call of the method String() there is causing the panic.

@tsileo
Copy link
Author

tsileo commented Dec 17, 2013

My bad! You're right, thanks a lot!!!

@tsileo tsileo closed this as completed Dec 17, 2013
@piotrnar
Copy link
Owner

Sure, no problem. Glad I could help.

@tsileo
Copy link
Author

tsileo commented Dec 17, 2013

I just wanted to let you know I've written an article about parsing block chain raw blocks using Gocoin: http://thomassileo.com/blog/2013/12/17/parsing-the-bitcoin-block-chain-with-go-language-using-gocoin/.

Let me know if you have any feedback,

Thanks!

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