Open Nixsm opened 6 years ago
I think this should be fine. Is there a reason why we currently use a variadic parameter instead of an array? Just convenience? @pixelmatrix
I was just trying to emulate a natural way to call these so it actually looks like a function. I totally agree that variadics are a pain to work with if you're not calling them directly though. I think it just depends what we want the default usage to be.
myDynamicContract['getBalance']?(myAddress)
or…
myDynamicContract['getBalance']?([myAddress])
// alternatively…
myDynamicContract.invokeMethod(with: 'getBalance')?(myAddress)
What I was really aiming for though was to support dynamic member subscripts once Swift 4.2 is released so we could do:
myDynamicContract.getBalance?(myAccount)
I'll implement this asap and send a PR, thanks for the response guys!
I'll leave the default subscript method and add a new invokeMethod
to the contract, so we keep the variadic interface working
Problem
Currently we have this method to invoke methods of a contract:
However, variadic functions a bit of pain to work with, in a sense that we can't send an array of parameters, we have to type each parameter separated by commas.
Possible Solution
I suggest we drop the variadic parameter and create a
subscript
method that receives an array ofABIEncodable
and then, create a normal method to be used with variadic parameters, something like this:Of course we'd need to refactor the
SolidityInvocation
implementations.Disclaimer