What massa.ts exposes #2125
Replies: 3 comments 5 replies
-
We will also have to add things like:
|
Beta Was this translation helpful? Give feedback.
-
Handling "Missing" Data from a Smart ContractWe want a smart contract to be able to attempt interact with data that may not exist yet without risk of the transaction failing. Some example use-cases:
Currently, calling
At its core, the problem is that currently, a smart contract has no way of checking if a key already has a value except by calling Potential Solution: Implement
|
Beta Was this translation helpful? Give feedback.
-
Provide Hashing PrimitivesWe should expose the ability to run the same hashing algorithms the execution engine runs within smart contracts. For example, if I have a string in my smart contract, and want to calculate the hash of it that will be used as a key in storage, I should have Currently, there are no easy-to-use SHA256 or base58check packages for AssemblyScript. The ones that exist are mainly assemblyscript implementations packaged to be used from javascript and do not integrate easily with the assemblyscript compiler. The main reason this is currently needed is because |
Beta Was this translation helpful? Give feedback.
-
As defined in massa.ts
data storage
TODO intro
Note that all the following functions also have an equivalent
_for
-postfixed version with "for_address" as 1st parameter: they execute the base function from the point of view of another SC defined byfor_address
.data_set
Sets an entry in the datastore of the current address.
If the entry exists, it is overwritten.
Gas cost
TODO formula (also let's define how storage costs work)
Parameters
Returns
Nothing
data_get
Gets an entry.
Gas cost
TODO formula
Parameters
Returns
The found value, or err if not found
data_contains_key
Checks if an entry exists
Gas cost
TODO formula
Parameters
Returns
True if found, False if not found
data_remove
Removes an entry.
Gas cost
TODO formula
TODO define reclaimed space
Parameters
Returns
Boolean: True if something was effectively deleted
Followup Ideas
Optional return values
Having enumerable return values (equivalent of Option or Result in rust) that can be mapped to an error throw (not well supported in AS yet) or a
null
value by massa.ts can be useful.This can be implemented for example by returning a formatted string or JSON-serialized object from the ABI and processing it in massa.ts to translate it into a
value | null
for exampleExample; in massa.ts:
Beta Was this translation helpful? Give feedback.
All reactions