Skip to content

NIL parameters pass to rpc-call #3

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

Closed
evd0kim opened this issue Sep 7, 2018 · 9 comments
Closed

NIL parameters pass to rpc-call #3

evd0kim opened this issue Sep 7, 2018 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@evd0kim
Copy link

evd0kim commented Sep 7, 2018

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
Copy link
Owner

nanmu42 commented Sep 8, 2018

Could you elaborate on this?

@nanmu42
Copy link
Owner

nanmu42 commented Sep 8, 2018

I see the current version working as expected.

Is there a specific reason for this modification?

@evd0kim
Copy link
Author

evd0kim commented Sep 8, 2018

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 evd0kim changed the title Non-nil parameters pass to rpc-call NIL parameters pass to rpc-call Sep 8, 2018
@evd0kim
Copy link
Author

evd0kim commented Sep 8, 2018

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

@evd0kim
Copy link
Author

evd0kim commented Sep 8, 2018

@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
Copy link
Owner

nanmu42 commented Sep 8, 2018

Thank you for finding this bug. 🍻

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.

@nanmu42 nanmu42 added bug Something isn't working good first issue Good for newcomers labels Sep 8, 2018
@nanmu42 nanmu42 self-assigned this Sep 8, 2018
@nanmu42 nanmu42 removed the good first issue Good for newcomers label Sep 8, 2018
@evd0kim
Copy link
Author

evd0kim commented Sep 8, 2018

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
Copy link
Owner

nanmu42 commented Sep 8, 2018

You are very kind. :D

@nanmu42
Copy link
Owner

nanmu42 commented Sep 9, 2018

I am closing this.

Feel free to reopen this issue if the bug persists.

@nanmu42 nanmu42 closed this as completed Sep 9, 2018
nanmu42 pushed a commit that referenced this issue Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants