near-runtime-ts
near-runtime-ts copied to clipboard
collections.Map should be able to store and return arbitrary data
Observe the following model:
export class Tiger {
name: string;
}
If I want to store multiple lists of tigers
in a persistent way, it makes sense to use a persistent map:
const tigers = collections.Map<string, Tiger[]>("t")
I'm assuming that I'll store a list of tigers for a user. This is a simplified version:
export function saveTheTigers(tigs:Tiger[]):string {
let tigerOwner = context.sender;
tigers.set(tigerOwner, tigs);
return "Tigers saved successfully";
}
export function getTheTigers(name:string):Tiger[] {
let tigerOwner = context.sender;
let tigs = tigers.get(counter);
return tigs;
}
Expected behavior: Returns list of tigers on the frontend
Observed behavior:
This is because a reference to the array is returned, rather than the array itself. We should support the return of an array to the frontend client.
Wrap tigers into a TigerList object and problem solved. It's an AssemblyScript issue, since it doesn't expose arrays basic types at the pre-compile time, so we can't build serializer and deserializer in assemblyscript without hacking the compiler.
Wrap tigers into a TigerList object and problem solved. It's an AssemblyScript issue, since it doesn't expose arrays basic types at the pre-compile time, so we can't build serializer and deserializer in assemblyscript without hacking the compiler.
This is pretty rough. This must be true for any arbitrary data we'd like to store then?