web3swift icon indicating copy to clipboard operation
web3swift copied to clipboard

Fix for EIP681: parsing of arrays and encoding of EIP681Code into URL

Open JeneaVranceanu opened this issue 3 years ago • 0 comments
trafficstars

Authors: @JeneaVranceanu, @a-tkchnk


The problem

Having EIP681 link like this one:

ethereum:0x9aBbDB06A61cC686BD635484439549D45c2449cc@2828/functionName123?string[]=[123,2,5000,wwweer2-=!]

during parsing will result in loss of query parameters and function name and the result would be the following link:

ethereum:0x9aBbDB06A61cC686BD635484439549D45c2449cc@2828

What is introduced in this PR?

  1. EIP681 parsing of arrays in query parameters. Tuples are not yet handled.
  2. Encoding of EIP681Code.parameters parameters usable in URL.
  3. Added func makeEIP681Link(urlEncoded: Bool) -> String? to create EIP681 link from EIP681Code. EIP681Code structure is used to create an EIP681 URL in a String representation with an option to URL encode the EIP681 link before it's returned so it's an actually valid URL.
  4. Fixed old test cases for EIP681 and added new ones.

Previously, both array and tuple types weren't supported during parsing. Support for array parsing/decoding was added. Covered with multiple test cases. Support for tuples will come soon.

Also, support for creating a URL (a String is actually returned) back from EIP681Code instance was added. So now we can create EIP681Code by hand, by assigning values to its properties and call func makeEIP681Link() to get back a valid URL. There is still some work to do to support value, gas and other such parameters in encoding. This PR is the first in the sequence of improvements.

JeneaVranceanu avatar Aug 11 '22 10:08 JeneaVranceanu