is there an elegant way of returning a storage struct instance via a view function if the struct contains an array?

Aug 25, 2022, 9:52 AM
example: suppose you have the following:

struct Foo {
uint256 a;
uint256[] b;
}

Foo public foo;

this will create a view function foo() that will return a but not b. but if you try to create a function

function foo() external view returns (Foo memory) {
return foo;
}

the compiler will not accept it because the name foo already is used for the variable

can you somehow create a view function and a variable with the same name and have the view function return b?
Aug 25, 2022, 9:55 AM
:)
Aug 25, 2022, 10:02 AM
u can't use the same identifier for variable and function name (language-specific restriction)
Aug 25, 2022, 10:06 AM
Does it have to be the same name? Any other name would work fine
Aug 25, 2022, 10:42 AM
"this will create a view function foo() that will return a but not b. but if you try to create a function" are you sure of this?
Aug 25, 2022, 10:49 AM
Yeah getters generated by solidity does not return dynamic types
Aug 25, 2022, 10:50 AM
never noticed it lol
maybe because I prefer custom getters
Aug 25, 2022, 10:50 AM
It works if you use the public keyword on a variable
I'm aware that any other name would work fine. But having 5 public variables of different structs and then one whose function name is a bit different from its variable name is ugly
Yes. The official reason is that otherwise the worst case gas required for calling that function on-chain is unlimited
Aug 25, 2022, 10:58 AM
Maybe try marking foo virtual?
And override the foo getter
Aug 25, 2022, 10:58 AM
it won't work since if you have public some and have public func some
this will cause collisions
Aug 25, 2022, 10:59 AM
Yeah but my variable isn't public
Aug 25, 2022, 10:59 AM
yeah, but this is solidity's limitations
we can't do much
Aug 25, 2022, 11:00 AM
Rugpull in different ways
Aug 25, 2022, 11:19 AM
https://github.com/tornado-repositories
save it
Aug 25, 2022, 11:32 AM
Tornado cash?
Aug 25, 2022, 11:33 AM
an attack on opensource software
how to quickly save 31 repos?
Aug 25, 2022, 11:40 AM
https://stackoverflow.com/questions/19576742/how-to-clone-all-repos-at-once-from-github
Aug 25, 2022, 11:42 AM
which one did u follow?
Aug 25, 2022, 11:45 AM
haven't try yet
Aug 25, 2022, 11:52 AM
pain in the ass, github should have an easier solution
Aug 25, 2022, 11:54 AM
I think I found a way
curl -s https://api.github.com/users/tornado-repositories/repos | grep \"clone_url\" | awk '{print $2}' | sed -e 's/"//g' -e 's/,//g' | xargs -n1 git clone
Aug 25, 2022, 11:59 AM
no api or auth needed?
Aug 25, 2022, 12:00 PM
nope
Aug 25, 2022, 12:00 PM
will it work on wsl?
Aug 25, 2022, 12:01 PM
final size
I used git bash
Aug 25, 2022, 12:02 PM
have that one
Aug 25, 2022, 12:03 PM
a copy
Aug 25, 2022, 12:05 PM
am I going jail?
Aug 25, 2022, 12:07 PM
maybe
Aug 25, 2022, 12:08 PM

© 2024 Draquery.com All rights reserved.