Has anyone seen this error:
Illegal service definition: services can only contain functions
We are calling a simple query:
public query func topAxons() : async [T.AxonPublic] {
let filtered = Array.mapFilter<T.AxonFull, T.AxonPublic>(Array.freeze(axons), func(axon) {
switch (axon.visibility, axon.neurons) {
case (#Public, ?{response={full_neurons}}) {
?getAxonPublic(axon)
};
case _ { null }
}
});
Array.sort<T.AxonPublic>(filtered, func (a, b) {
if (b.totalStake > a.totalStake) { #greater } else { #less }
});
};
// Return Axon with own balance
func getAxonPublic(axon: T.AxonFull): T.AxonPublic {
{
id = axon.id;
proxy = axon.proxy;
name = axon.name;
visibility = axon.visibility;
supply = axon.supply;
policy = axon.policy;
balance = Option.get(axon.ledger.get(Principal.fromActor(this)), 0);
totalStake = axon.totalStake;
tokenHolders = axon.ledger.size();
}
};
1 Like
It looks like that originates here:
https://github.com/dfinity/agent-js/blob/98657575b3a9ee26ee445a722b710978204c54c1/packages/candid/src/idl.ts#L1787
You should be able to set a breakpoint and see what type
is.
The generated bindings might give some clues as well.
I’m running into this with Azle right now, trying to implement the service Candid type. Did anyone figure out the problem?
Looks like call raw is not serializing for me? Same error as above
the error is thrown because 14n for call raw returns undefined.
'call_raw' : IDL.Func(
[IDL.Principal, IDL.Text, IDL.Vec(IDL.Nat8), IDL.Nat],
[Result__1_1],
[],
),
type Proxy =
service {
call_raw: (principal, text, blob, nat) -> (Result__1_1);
list_neurons: () -> (ListNeuronsResponse);
manage_neuron: (ManageNeuron) -> (ManageNeuronResponse);
mint_burn_batch: (vec MintBurnBatchCommand) -> (vec TransferResult);
recycle_cycles: (principal, nat) -> (nat);
};
Pinging @kpeacock here…what is going on with this…if you need a sample project it is GitHub - icdevs/axon: DAO in a box. @alejandrade is this just on loading a page…or when trying to call a particular function? Just creating the actor?
When i call the function create. the response throws the issues
Does create succeed? It is just the response that causes the error?
Yes the call succeed it’s just the deserialization.
What is the expected result type, and does Rust (dfx) deserialize it correctly?
type Proxy =
service {
call_raw: (principal, text, blob, nat) -> (Result__1_1);
list_neurons: () -> (ListNeuronsResponse);
manage_neuron: (ManageNeuron) -> (ManageNeuronResponse);
mint_burn_batch: (vec MintBurnBatchCommand) -> (vec TransferResult);
recycle_cycles: (principal, nat) -> (nat);
};
Is the type I’m expecting. I’m calling from the js agent in the front end.
So the decelration for it is
export interface Proxy {
'call_raw' : ActorMethod<
[Principal, string, Uint8Array | number[], bigint],
Result__1_1
>,
'list_neurons' : ActorMethod<[], ListNeuronsResponse>,
'manage_neuron' : ActorMethod<[ManageNeuron], ManageNeuronResponse>,
'mint_burn_batch' : ActorMethod<
[Array<MintBurnBatchCommand>],
Array<TransferResult>
>,
'recycle_cycles' : ActorMethod<[Principal, bigint], bigint>,
}
Interesting, this could take some time to unpack. A minimal reproducing example would be helpful
I’m pretty sure deploying the front an d back end and trying to launch an axon here will work.
1 Like
I don’t know if it will serve as a clue to reach a solution, but here I got the same error when trying to instantiate an actor class (and I suppose that with this I would be creating a canister for that actor) from another canister through a public function (mkActor ()).
1 Like
Bump because this has been blocking me for a long time now.
Thanks for the example. I can reproduce locally. Will take a deeper look.
2 Likes
I think I found the problem, will make a fix in agent-js tomorrow. Sorry about the delay.
1 Like