GetScatter / eos-sharp

C# client library for EOS blockchains
MIT License
75 stars 48 forks source link

Unable to submit array types (Array or List) in Action #30

Closed dbendt closed 5 years ago

dbendt commented 5 years ago

It appears no array type may be used in the data member of a Api.v1.Action. Attempted to use an Array and List types and received the following exception.

Here is the full Exception dump. ` {"ClassName":"System.InvalidCastException","Message":"Specified cast is not valid.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at (wrapper castclass) System.Object.castclass_with_cache(object,intptr,intptr)\r\n at EosSharp.Core.Providers.AbiSerializationProvider.WriteAbiType (System.IO.MemoryStream ms, System.Object value, System.String type, EosSharp.Core.Api.v1.Abi abi) [0x0005a] in :0 \r\n at EosSharp.Core.Providers.AbiSerializationProvider.WriteAbiStruct (System.IO.MemoryStream ms, System.Object value, EosSharp.Core.Api.v1.AbiStruct abiStruct, EosSharp.Core.Api.v1.Abi abi) [0x000b7] in :0 \r\n at EosSharp.Core.Providers.AbiSerializationProvider.SerializeActionData (EosSharp.Core.Api.v1.Action action, EosSharp.Core.Api.v1.Abi abi) [0x00089] in :0 \r\n at EosSharp.Core.Providers.AbiSerializationProvider.WriteAction (System.IO.MemoryStream ms, EosSharp.Core.Api.v1.Action action, EosSharp.Core.Api.v1.Abi abi) [0x00064] in :0 \r\n at EosSharp.Core.Providers.AbiSerializationProvider+d15.MoveNext () [0x001c2] in :0 \r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 \r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0 \r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 \r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 \r\n at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in :0 \r\n at EosSharp.Core.EosBase+d31.MoveNext () [0x002cf] in :0 \r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 \r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0 \r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 \r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 \r\n at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in :0 \r\n at ScatterTransaction+d21.MoveNext () [0x004b2] in C:\dev\unity\turnbased\Turn Based\Assets\Scripts\Common\ScatterTransaction.cs:118 ","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2147467262,"Source":"mscorlib"} UnityEngine.Debug:Log(Object)

d__21:MoveNext() (at Assets/Scripts/Common/ScatterTransaction.cs:153) System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetException(Exception) EosSharp.Core.d__31:MoveNext() System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetException(Exception) EosSharp.Core.Providers.d__15:MoveNext() System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetResult(Abi) EosSharp.Core.Providers.d__22:MoveNext() System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetResult(GetRawAbiResponse) EosSharp.Core.Api.v1.d__14:MoveNext() System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetResult(GetRawAbiResponse) EosSharp.Unity3D.d__81:MoveNext() System.Runtime.CompilerServices.MoveNextRunner:Run() EosSharp.Unity3D.UnityWebRequestAwaiter:OnRequestCompleted(AsyncOperation) UnityEngine.AsyncOperation:InvokeCompletionEvent() ` Here is the simple EOS action I used to test: ```cpp void emptyarray( name user, vector) { print("It worked!"); } ``` Generated ABI: ```json { "name": "emptyarray", "base": "", "fields": [ { "name": "user", "type": "name" }, { "name": "array", "type": "uint64[]" } ] } ``` C# snippet ```csharp var result = await eos.CreateTransaction(new EosSharp.Core.Api.v1.Transaction() { actions = new List() { new EosSharp.Core.Api.v1.Action() { account = MYACCOUNT, authorization = new List() { new PermissionLevel() {actor = MYUSER, permission = MYAUTHORITY } }, name = "emptyarray", data = new Dictionary() { { "user", MYUSER }, { "array", new List() }, } } } }); ``` Tested this using ```cleos``` and ```eosjs``` and this works as expected.
mmcs85 commented 5 years ago

Confirmed the bug. You could get around this by using List<object> afaik. But update to eos-sharp 2.0.4 it should work

dbendt commented 5 years ago

Thanks for the quick fix. FWIW, I was able to get it work using List<object> but not List<uint>.

mmcs85 commented 5 years ago

Great that it works for you!