Public and private volumes
You pick public or private when you create a volume, and can’t change it. Either way, a volume pays for its own storage from money you put in it. Your keys and your data says who can see what.
1. Create a volume and add a file
First connect your wallet to storage, once. It asks for a passphrase to protect the storage key it creates:Output
Output
volume create creates the volume and pays for its first stretch of storage from your wallet, and put <volume> <local file> <path in the volume> uploads a file. cowboy cbfs cat handbook faq/refunds.md prints one file back.
When the volume needs more storage, cowboy cbfs volume deposit handbook --amount 1 adds 1 CBY.
Leave out --public to create a private volume. An actor can use your private volume only after you allow it:
Output
2. Read it from an off-chain function
An off-chain function is your own Python, run in a container, andcowboy.toml declares the volumes it gets. Runner jobs can take volumes too, with volumes= (reference), but this page uses a function.
Output
cowboy.toml with the following, using your wallet’s address as owner:
name and owner say which volume: the volume called handbook that this address owns. A volume declared this way is mounted read-only. files lists the files cowboy run downloads for a local run, and doesn’t limit what the deployed function can read.
Write the function in offchain/handbook.py:
/mnt/volumes. A local run sets COWBOY_VOLUME_ROOT to a folder of its own instead.
Export the function in offchain/__init__.py:
actors/reader/main.py with the actor that calls it:
Output
cowboy check also prints how one call is priced. The actor’s balance pays for each call.
3. Test it
Test the function with a folder standing in for the volume, inoffchain/tests/test_handbook.py:
Output
Output
CBOR reading is the handler’s answer. Without --stub, cowboy run downloads the file from the real volume, so it needs a network.