Open boid-com opened 7 months ago
Well, an action is not meant to return a value. The following link may help improve your understanding of writing contracts in AssemblyScript https://learnforpractice.github.io/ascdk-book
action return values is a feature now supported by antelope in the c++ CDT, I thought this feature was available? https://github.com/pinax-network/action-return-value
Use setActionReturnValue
to set the return value of an action.
@learnforpractice can you explain how to use setActionReturnValue
or show an example? I'm confused about the actual usage.
import {
Name,
check,
Encoder,
setActionReturnValue,
Contract,
printString,
} from "asm-chain";
@packer
class MyData {
constructor(
public name: string
){}
}
@contract
class MyContract extends Contract{
@action("test")
test(): void {
let data = new MyData("Hello,World");
setActionReturnValue(Encoder.pack(data));
}
}
I'm getting this error from the Encoder.pack() Argument of type 'MyData' is not assignable to parameter of type 'Packer'. Type 'MyData' is missing the following properties from type 'Packer': pack, unpack, getSizets(2345)
Part of the code is generated by the compiler, so ignore such warnings if the code can be compiled.
Is it possible to improve that? it's not very clear as a developer.
Yes, you can implement pack
, unpack
, and getSize
manually. Also, You can take the generated code at target directory as a reference.
I'm getting compile errors when trying to return a class structure from an action result. I get similar errors if it's just a packer class (not a table) and I also get an error if I try to return a class that does not derive from packer. Returning basic types like boolean seems to work.