nanmu42 / etherscan-api

:guitar: Golang client for Ethereum Etherscan API (and its families like BscScan) / Golang 以太坊 Etherscan API库(也支持同一家族的BscScan)
MIT License
240 stars 107 forks source link

NIL parameters pass to rpc-call #3

Closed evd0kim closed 6 years ago

evd0kim commented 6 years ago

They are not pass, if the code in helper.go change to:

// compose adds input to param, whose key is tag
// if input is nil, compose is a no-op.
func compose(param map[string]interface{}, tag string, input interface{}) {
    if  reflect.ValueOf(input).IsNil() {
        return
    }
    param[tag] = input
}
nanmu42 commented 6 years ago

Could you elaborate on this?

nanmu42 commented 6 years ago

I see the current version working as expected.

Is there a specific reason for this modification?

evd0kim commented 6 years ago

Hey, Maybe I'm an inexperienced coder in Golang and did something wrong but

ERC20TxList, err := client.ERC20Transfers( nil, &watchAddress, nil, nil, 0, 0)

Didn't work. The reason was this piece pass nil further:

    if input == nil {
        return
    }

The problem initially happened with startBlock/endBlock since you commented about them that they could be equal to nil or something and I later found in etherscan.io documentation about it. I only found a way after that because I was too lazy to write a code which figures out contract addresses.

evd0kim commented 6 years ago

I'm very sorry, the header of an issue could misguide you.

evd0kim commented 6 years ago

@nanmu42 I see a link to Golang FAQ. I investigated Golang types a little bit and realized that the problem is in non-nil type value. Do you know another solution to this without reflect?

nanmu42 commented 6 years ago

Thank you for finding this bug. :beers:

The problem should be solved in v1.0.2. You may close this issue after confirming it is working.

Yes, there is another way, but less DRY -- check for nil in every function like ERC20Transfers(), so long as it is not passed in an interface, if a == nil should still work as expected.

evd0kim commented 6 years ago

That's another way I thought about.

I tried to figure out how to make it work without changing your code at all but it seems there is no way because the compiler doesn't allow to pass nil type as *string argument.

Thank you for your work anyway. Nice, clean, small project.

nanmu42 commented 6 years ago

You are very kind. :D

nanmu42 commented 6 years ago

I am closing this.

Feel free to reopen this issue if the bug persists.