wallet/balance is Non-Negative
We're done with our rules. Now we need to add smart functions to our collection and predicate specs from simplest to most complicated.
The simplest smart function we need to add is
nonNegative?. This function will make sure that our
wallet/balance is non-negative.
The below transaction creates a new function,
nonNegative?, and adds it to the
wallet/balance predicate. It is missing the smart function code - that part will be up to you!
"_id": ["_predicate/name", "crypto/balance"],
"specDoc": "Balance cannot be negative."
"code": "SMART FUNCTION CODE HERE"
You will need the following Universal SmartFunctions to write the
nonNegative? smart function. Below is a subset of the universal smart functions that are available in Fluree. More information about each function can be found in the Universal SmartFunctions section.
You will need one (or several) of these smart function to write,
You will also need one context-specific function
(?o), which gets the object (value) of the predicate,
wallet/balance that is being edited. For example, if the
wallet/balance is 100,
(+ 1 (?o)) will return 101.
Write a Smart Function!
Using the smart functions listed above, can you figure out how to create a smart function that checks whether the wallet/balance is greater than zero?