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"],
"spec": ["_fn$nonNegative?"],
"specDoc": "Balance cannot be negative."
},
{
"_id": "_fn$nonNegative?",
"name": "nonNegative?",
"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, nonNegative
.
Function | Arguments | Example |
---|---|---|
inc | n optional | (inc) |
dec | n optional | (dec) |
== | arg1 arg2 ... | (== 1 1 1 1) |
+ | arg1 arg2 ... | (+ 1 2 3) |
- | arg1 arg2 ... | (- 10 9 3) |
* | arg1 arg2 ... | (* 90 10 2) |
/ | arg1 arg2 ... | (/ 36 3 4) |
> | arg1 arg2 ... | (> 90 10 2) |
< | arg1 arg2 ... | (< 90 10 2) |
>= | arg1 arg2 ... | (>= 90 90 10 2) |
< | arg1 arg2 ... | (< 2 10 90) |
<= | arg1 arg2 ... | (<= 2 10 90 90) |
max | arg1 arg2 ... | (max 1 2 3) |
min | arg1 arg2 ... | (min 1 2 3) |
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?