esaulpaugh / headlong

High-performance Contract ABI and RLP for Ethereum
Apache License 2.0
79 stars 20 forks source link

Function.formatCall() is not returning the right string. #45

Closed ShoaibKakal closed 2 years ago

ShoaibKakal commented 2 years ago
       val args = Tuple.of("My new Name")
        val function = com.esaulpaugh.headlong.abi.Function("setName(string)")
        val encodedFunction = function.encodeCall(args)
        val arr: ByteArray = encodedFunction.array()
        val formattedEncoding =
            com.esaulpaugh.headlong.abi.Function.formatCall(arr, 0, arr.size)
      print(formattedEncoding)

Actual Result: ID c47f0027 0 0000000000000000000000000000000000000000000000000000000000000020 1 000000000000000000000000000000000000000000000000000000000000000b 2 4d79206e6577204e616d65000000000000000000000000000000000000000000

Expected Result: c47f00270000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b4d79206e6577204e616d65000000000000000000000000000000000000000000

I want the above code to return the expected result but it returns the above actual result. Please have a look @esaulpaugh

leiiiooo commented 2 years ago
       val args = Tuple.of("My new Name")
        val function = com.esaulpaugh.headlong.abi.Function("setName(string)")
        val encodedFunction = function.encodeCall(args)
        val arr: ByteArray = encodedFunction.array()
        val formattedEncoding =
            com.esaulpaugh.headlong.abi.Function.formatCall(arr, 0, arr.size)
      print(formattedEncoding)

Actual Result: ID c47f0027 0 0000000000000000000000000000000000000000000000000000000000000020 1 000000000000000000000000000000000000000000000000000000000000000b 2 4d79206e6577204e616d65000000000000000000000000000000000000000000

Expected Result: c47f00270000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b4d79206e6577204e616d65000000000000000000000000000000000000000000

I want the above code to return the expected result but it returns the above actual result. Please have a look @esaulpaugh

You should use FastHex.encodeToString

ShoaibKakal commented 2 years ago

Thank you @leiiiooo 😍