convex.asset.box.cvx Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of convex-core Show documentation
Show all versions of convex-core Show documentation
Convex core libraries and common utilities
The newest version!
'asset.box
(call *registry*
(register {:description ["A box acts as a holder of arbitrary assets, bundling them together."
"Assets are described in `convex.asset` and created using accounts such as `convex.fungible`."
"The owner of the box has exclusive rights to put assets in or take assets out."
"The box itself is an asset with the designator `[box-actor id]`."
"This library uses `asset.box.actor` as default actor. An alternative implementation can be provided if required."]
:name "Asset box API."}))
;;;;;;;;;; Setup
(import asset.box.actor :as box.actor)
(import convex.asset :as asset-lib)
;;;;;;;;;; Public API
(defn burn
^{:doc {:description "Destroys a set of box ids which must be owned and empty."
:signature [{:params [set-box-ids]}
{:params [actor set-box-ids]}]}}
([set-box-ids]
(burn box.actor
set-box-ids))
([actor set-box-ids]
(call actor
(burn set-box-ids))))
(defn create
^{:doc {:description "Creates a new box and returns its id."
:signature [{:params []}
{:params [actor]}]}}
([]
(create box.actor))
([actor]
(call actor
(create))))
(defn insert
^{:doc {:description "Inserts an asset into a box."
:signature [{:params [box asset]}]}}
([box asset]
(asset-lib/transfer box asset)))
(defn remove
^{:doc {:description "Removes an asset from the given box."
:signature [{:params [box-id]}
{:params [actor box-id asset]}]}}
([box asset]
(call box (remove asset))))