ProvableHQ / sdk

A Software Development Kit (SDK) for Zero-Knowledge Transactions
https://provable.tools
GNU General Public License v3.0
584 stars 468 forks source link

Unable to fetch the value of a mapping for a struct key (even after urlencode) #886

Closed harshnambiar closed 3 months ago

harshnambiar commented 3 months ago

I am trying to fetch a key value from the "codes" mapping of this. The key is of the type CodeBlock {creator: address, cno: u64} but I am unable to fetch the value. I am trying to use urlencode but I get the error: Invalid URL: Failed to parse string. Parsing Error: VerboseError { errors: [("CodeBlock { creator: aleo1vgdqhep7fpflj0yslgv05nflv7xdh5sexfvqpe6qav5g56x86grsr8l8m8, cno: 2 }", Nom(Tag)), ("CodeBlock { creator: aleo1vgdqhep7fpflj0yslgv05nflv7xdh5sexfvqpe6qav5g56x86grsr8l8m8, cno: 2 }", Nom(Alt))] }

The urlencode key used was: CodeBlock%20%7B%20creator%3A%20aleo1vgdqhep7fpflj0yslgv05nflv7xdh5sexfvqpe6qav5g56x86grsr8l8m8%2C%20cno%3A%202%20%7D

Using the urlencode for CodeBlock {creator: add, cno: c}, CodeBlock{ add, c}, {add, c}, {creator: add, cno: c} all produced similar error.

I am using the https://node.puzzle.online/testnet3/program/cypher_nm01.aleo/mapping/codes/CodeBlock%20%7B%20creator%3A%20aleo1vgdqhep7fpflj0yslgv05nflv7xdh5sexfvqpe6qav5g56x86grsr8l8m8%2C%20cno%3A%202%20%7D url for this. I am able to get another mapping through it so there isn't something wrong on the node.puzzle end. Should something be done differently?

d0cd commented 3 months ago

When you're using struct (passing it in as input or querying an endpoint) as input you do not need to include the name of the struct. Furthermore, you'll need to pass in valid addresses and integer literals. Note that integer literals need to have a type suffix. URLEncoding this works: { creator: aleo1vgdqhep7fpflj0yslgv05nflv7xdh5sexfvqpe6qav5g56x86grsr8l8m8, cno: 2u64 } URL: https://node.puzzle.online/testnet3/program/cypher_nm01.aleo/mapping/codes/%7B%20creator%3A%20aleo1vgdqhep7fpflj0yslgv05nflv7xdh5sexfvqpe6qav5g56x86grsr8l8m8%2C%20cno%3A%202u64%20%7D