esaulpaugh / headlong

High-performance Contract ABI and RLP for Ethereum

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

ShoaibKakal opened this issue · comments

       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

       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

Thank you @leiiiooo 😍