planetarium / lib9c-wasm

The experimental project to port Lib9c into JavaScript environment through WASM. Build your Nine Chronicles network transaction in your local at once.
https://planetarium.github.io/lib9c-wasm/
GNU General Public License v3.0
5 stars 2 forks source link

BuildAction generates invalid code on latest lib9c / libplanet #23

Closed Akamig closed 1 year ago

Akamig commented 1 year ago

In latest state of #22, mainly BuildAction() in generate.ts generates invalid type declaration like following exemplar code

// Right function form
// Based on submodule lib9c@e1deaed, libplanet@e0592da
export function buy12(plainValue: {purchaseInfos: {orderId: Guid;tradableId: Guid;agentAddress: Address;avatarAddress: Address;type: "Food" | "FullCostume" | "HairCostume" | "EarCostume" | "EyeCostume" | "TailCostume" | "Weapon" | "Armor" | "Belt" | "Necklace" | "Ring" | "EquipmentMaterial" | "FoodMaterial" | "MonsterPart" | "NormalMaterial" | "Hourglass" | "ApStone" | "Chest" | "Title";itemPrice: {currency: Currency;sign: number;majorUnit: string;minorUnit: string;};}[];buyerAvatarAddress: Address;}): Uint8Array {
    return buildActionWrapper("buy12", plainValue as any);
}

// Wrong function form, based on PR #22, 95bec13
//                                | invalid type appears here  |
export function buy12(plainValue: {errors: {: Guid;: number;}[], purchaseInfos: {orderId: Guid;tradableId: Guid;agentAddress: Address;avatarAddress: Address;type: "Food" | "FullCostume" | "HairCostume" | "EarCostume" | "EyeCostume" | "TailCostume" | "Weapon" | "Armor" | "Belt" | "Necklace" | "Ring" | "EquipmentMaterial" | "FoodMaterial" | "MonsterPart" | "NormalMaterial" | "Hourglass" | "ApStone" | "Chest" | "Title";itemPrice: {currency: Currency;sign: number;majorUnit: string;minorUnit: string;};}[], buyerAvatarAddress: Address}): Uint8Array {
    return buildActionWrapper("buy12", plainValue as any);
}

not only this, if we try to run BuildAction anyways after deleting these invalid codes, it doesn't run with following message.

Error: System.Collections.Generic.KeyNotFoundException: Arg_KeyNotFound
   at System.Text.Json.JsonElement.GetProperty(String )
   at Lib9c.Wasm.JsonUtils.<>c__DisplayClass1_0.<ConvertJsonElementTo>b__0(ParameterInfo parameter)
   at System.Linq.Enumerable.SelectArrayIterator`2[[System.Reflection.ParameterInfo, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1[[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].AddRange(IEnumerable`1 )
   at System.Collections.Generic.EnumerableHelpers.ToArray[Object](IEnumerable`1 )
   at System.Linq.Enumerable.ToArray[Object](IEnumerable`1 )
   at Lib9c.Wasm.JsonUtils.ConvertJsonElementTo(JsonElement element, Type targetType)
   at Lib9c.Wasm.Program.BuildAction(String actionTypeString, JsonElement dictionary)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object , BindingFlags , Binder , Object[] , CultureInfo )
--- End of stack trace from previous location ---
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson)
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime jsRuntime, DotNetInvocationInfo& invocationInfo, String argsJson)
   at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson)
    at Object._convert_exception_for_method_call (webpack://dotnet/./native/dotnet.js:4704:31)
    at Object._handle_exception_for_call (webpack://dotnet/./native/dotnet.js:4737:36)
    at invokeDotNet (https://mono-wasm.invalid/managed__Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet:20:21)
    at Object.invokeDotNetFromJS (webpack://dotnet/./src/interop.ts:102:12)
    at invokePossibleInstanceMethod (webpack://dotnet/./src/dotnet-js-interop.ts:228:43)
    at fn (webpack://dotnet/./src/dotnet-js-interop.ts:116:16)
    at Object.invoke (webpack://dotnet/./src/interop.ts:33:16)
    at Object.exports.Lib9c.Wasm.buildAction (/Users/akamig/code/work/lib9c-wasm/generated/dotnet.js:12:80)
    at buildActionWrapper (/Users/akamig/code/work/lib9c-wasm/generated/actions.ts:4:30)
    at stake (/Users/akamig/code/work/lib9c-wasm/generated/actions.ts:484:12)

it seems affected by current change on Action data structure implementation changes, such as 'ActionTypeAttribute` replaced with IValue instead of string on libplanet PR #3111 further investigation seems needed, but until this solved, we can't use latest version of lib9c/libplanet to release lib9c-wasm.

Akamig commented 1 year ago

Fixed on https://github.com/planetarium/lib9c-wasm/commit/97ce7c442c623ccfdafb3e2128fa7f475961720d,

CLOSING