NEWTON
Asked
3 months ago
105
views
1
This question has a bounty of $0.00 in testnet ETH. Answers to this question are eligible to win that bounty.
These are testnet contracts. Not real ETH.
$0.00
Hey guys,
I got this error The return type of storage variables must be a felts-only type (cannot contain pointers)
when when compiling this:
struct MultipleLinear {
number_of_features: felt,
coef_s: felt*,
intercept_: felt,
}
@storage_var
func solution_storage(address: felt) -> (solution: MultipleLinear) {
}
Apparently storage can only return felt? So what would be the solution if I want it to return an array or a struct that contains felt*?
trangnv
asked
3 months ago
1
Accepted answer
Hey,
You can only return felt, so if you want to return an array you have to use another storage_var
. For exemple if I want to return an array you may do something like this:
struct Array {
array_index: felt,
len: felt,
}
@storage_var
func get_array() -> (array: Array) {
}
@storage_var
func array(array_index: felt, index: felt) -> (value: felt) {
}
As you can see, the storage get_array()
will return a struct of type Array
which contain the array_index and len
of the array. Then use it in storage_var array()
to get the corresponding value. Since you have the len
you can create a recursion to the storage var to get all the element of the array of index array_index
.
0xC7a4...1094Da
answered
2 months ago
how to return struct
Are you able to nest mappings in Cairo like you can in Solidity?
Is there no way for me to have a struct as a `@storage_var` if it contains an array fo felts inside ?
A switch statement in Cairo lang to set two distinct values
how I could read a felt* from ap in Cairo lang?
Cairo Error: Getting Expected expression of type 'felt', got '(res : felt)'
How can I pass an array of felt to call with Nile in StarkNet?
How many time does it take for stark to eth starkgate bridge process?
When you run warp deploy or warp invoke, which account is paying for the tx fees on the Goerli testnet?
Cairo: let vs tempvar what is the difference?
Deploying kakarot evm on starkEx
How do I create AX (ArgentX) contract using starknetjs?
how I could read a felt* from ap in Cairo lang?
Does anybody have an idea what is `get_caller_address` returning on an L1 handler call?