Spore DOB-0
The Spore Protocol stores value in Cells, while the Spore DOB Protocol Family built on this by interpreting and combining these Cells. The family includes protocols like DOB/0, DOB/1 or DOB/2. Spore DOB-0 is the first implementation, specifing the configuration method and interface format for decoders and providing a universal decoder to simplify development.
How Spore DOB-0 Works
Spore DOB-0 functions as follows:
- Decoding: Decodes DNA bytes using a parsing pattern, identifying traits based on specified offsets.
- Mapping: Maps each byte to a trait in a predefined pool, contributing to the DOB's unique characteristics.
- Combining: Compiles the selected traits into a structured representation, encapsulating the DOB's defined attributes and values.
DNA
DNA is the unique data owned by each DOB, defined during minting. It can be in UTF-8 encoded JSON format or raw bytes.
bytifyRawString(JSON.stringify("df4ffcb5e7a283ea7e6f09a504d0e256"));
// or
bytifyRawString(JSON.stringify(["df4ffcb5e7a283ea7e6f09a504d0e256"]));
// or
bytifyRawString(JSON.stringify({ dna: "df4ffcb5e7a283ea7e6f09a504d0e256" }))[
// or
(0, 223, 79, 252, 181, 231, 162, 131, 234, 126, 111, 9, 165, 4, 208, 226, 86)
];
DNA should be stored in the content
field of the Spore:
{
contentType: "dob/0",
content: {
dna: "0xefc2866a311da5b6dfcdfc4e3c22d00d024a53217ebc33855eeab1068990ed9d"
},
// or content: "0xefc2866a311da5b6dfcdfc4e3c22d00d024a53217ebc33855eeab1068990ed9d",
// or content: ["0xefc2866a311da5b6dfcdfc4e3c22d00d024a53217ebc33855eeab1068990ed9d"]
content_id: "0x3b0e340b6c77d7b6e4f1fb2946d526ba65bfd196a27d9a7e5b6f06b82af5d07e"
}
Pattern
Pattern is the common data for a set of DOBs specified when creating the Spore Cluster. It is parsed in the DOB/0 decoder as a JSON array:
[
// ["name", "type", "offset", "len", "pattern" (optional), "args" (Optional)]
["Face", "string", 0, 1, "options", ["Laugh", "Smile", "Sad", "Angry"]],
["Age", "number", 1, 1, "range", [0, 100]],
["BirthMonth", "number", 2, 1, "options", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]
...
]
name
: Name of the attribute.type
: Type of the attribute.offset
&len
: Specify a segment in DNA to derive data based on the pattern. Segments that exceed the DNA's length will be trimmed.pattern.options
: Randomly select one option from theargs
array.pattern.range
: The type field must benumber
. Randomly select a number within [args[0], args[1]].pattern.utf8
: The type field must bestring
. The DNA segment is parsed according to UTF-8 encoding, ignoring all 0x00 at the end.pattern.raw
: Parse the DNA into an unsigned number in little-endian order (fornumber
type) or prefixed hex string (forstring
type).
Decoder
The decoder interprets DNA
and Pattern
, specified when the Spore Cluster is released. The configuration is a JSON object encoded in UTF-8:
{
"description": "This is the description for cluster",
"dob": {
"ver": 0,
"decoder": {
"type": "code_hash", // or "type_id"
"hash": "...",
},
"pattern": [] // Any type
}
}
description
: Description of the Spore Cluster.dob.ver
: DOB protocol version number (always 0 in Spore DOB-0).dob.decoder.type
: Method to find a decoder:code_hash
: Finds the Cell whose CKB hash value of its data isdob.decoder.hash
type_id
: Find the Cell whosetype_script.args
isdob.decoder.hash
. Cells Type Script must be Type ID
dob.decoder.hash
: Hash value to locate the decoder Cell.dob.pattern
: Pattern data, determined by the decoder.
Deployed Info
The Spore DOB-0 has been deployed to CKB's Mainnet Mirana and Testnet Pudge. The following are the deployment details:
Mainnet
parameter | value |
---|---|
code_hash | 0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8 |
hash_type | type |
tx_hash | 0xa84f9426f378109dfa717cb3a29fb79b764bf466a7c2588aebcdecc874bcc984 |
index | 0x0 |
dep_type | code |
Testnet
parameter | value |
---|---|
code_hash | 0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8 |
hash_type | type |
tx_hash | 0xc877aca405da6a3038054cb5da20f2db0ed46bb643007d4e0b1d3fe7da155bf0 |
index | 0x0 |
dep_type | code |
Examples
Create a Cluster
To create a Cluster using spore-sdk:
import { createCluster } from '@spore-sdk/api';
import { bytifyRawString } from '@spore-sdk/helpers/buffer';
const account = ...;
const dob_metadata = {
description: 'this is the description for cluster',
dob: {
ver: 0,
decoder: {
type: 'code_hash',
hash: '...',
},
pattern: [["Age", "number", 1, 1, "range", [0, 100]]],
}
};
const { txSkeleton, outputIndex } = await createCluster({
data: {
name: 'My First DOB Cluster',
description: bytifyRawString(JSON.strinify(dob_metadata)),
},
fromInfos: [account.address],
toLock: account.lock
});
Create a DOB
To create a DOB with content_type
as dob/0
:
import { createSpore } from '@spore-sdk/api';
import { bytifyRawString } from '@spore-sdk/helpers/buffer';
const account = ...;
const dob_cluster_id = ...;
const dob_content = {
dna: 'df4ffcb5e7a283ea7e6f09a504d0e256'
};
const { txSkeleton, outputIndex } = await createSpore({
data: {
contentType: 'dob/0',
content: bytifyRawString(JSON.strinify(dob_content)),
clusterId: dob_cluster_id
},
fromInfos: [account.address],
toLock: account.lock
});
Decode a DOB
After creating the Spore DOB, you can decode its DNA through the spore_id
and the decoding server. First, install the decoding server locally:
git clone https://github.com/sporeprotocol/dob-decoder-standalone-server
RUST_LOG=dob_decoder_server=debug cargo run
The decoding server runs on CKB Testnet by default. To run it on CKB Mainnet, change the setting.mainnet.toml
configuration in the root directory with the setting.toml
configuration.
After starting the server, decode a specified Spore DOB with the following request:
echo '{
"id": 2,
"jsonrpc": "2.0",
"method": "dob_decode",
"params": [
"<spore_id in hex format without 0x prefix>"
]
}' \
| curl -H 'content-type: application/json' -d @- \
http://localhost:8090