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

Decoding Input/Output data #127

Closed
baquedano opened this issue Mar 8, 2019 · 3 comments
Closed

Decoding Input/Output data #127

baquedano opened this issue Mar 8, 2019 · 3 comments

Comments

@baquedano
Copy link

baquedano commented Mar 8, 2019

So I was trying to create a way to decode the [String:Any] values that the decode functions return into something a little easier to use by taking the values of the dictionary and casting them to the types, tho it doesn't work nicely on tuples cause they can't be dynamically created, however I stumbled upon a problem and it was that instead of getting an array of 5 values (which is the number of I have) I was getting an array with 10 values out of the dictionary by using dictionary.compactMap { $0.value }, after further inspecting I found that it happened because of this:

    /// ABIElement.swift --> ABi.Element extension --> decodeReturnData (_ data: Data) -> [String:Any]? 
    for output in function.outputs {
        let name = "\(i)"
        returnArray[name] = values[i]
        if output.name != "" {
            returnArray[output.name] = values[i]
        }
        i  = i + 1
    }

the params are getting added more than once if the output has a name, is this really necessary? why not:

  /// ABIElement.swift --> ABi.Element extension --> decodeReturnData (_ data: Data) -> [String:Any]? 
            for output in function.outputs {
                returnArray[output.name ?? "\(i)"] = values[i]
                i = i + 1
            }
@shamatar
Copy link
Contributor

Hello @baquedano

This part of design was based on the other runtime Web3 libraries. In fact Solidity developers can omit specifying output values names, so way of addressing using just an integer index is necessary as a baseline. Names are there for developers to be able to filter the keys in the dictionary and output the values using some meaningful name.

Sincerely, Alex

@BaldyAsh
Copy link
Collaborator

Hi @baquedano

If you are satisfied with the answer, I think this issue should be closed

@baquedano
Copy link
Author

@BaldyAsh Yes, close it please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants