pub struct Blocktrail {
pub id: Option<String>,
pub type_: String,
pub version: Option<String>,
pub profile: Option<String>,
pub pubkey_base: Option<String>,
pub chain: Option<String>,
pub genesis: Option<String>,
pub states: Vec<Value>,
pub txo: Vec<BlocktrailTxo>,
}Expand description
A trail as blocktrails.json carries it: what a verifier reads.
The shape is blocktrails/spec gitmark profile §5.2, the one the live trails
use and blocktrails/git-mark b852d7d trail() writes:
{
"@type": "Blocktrail",
"version": "0.0.3",
"profile": "gitmark",
"pubkeyBase": "02…",
"chain": "tbtc4",
"states": ["<genesis_commit>", "<hash>"],
"txo": ["txo:tbtc4:…:0?amount=…&commit=…", "txo:tbtc4:…"]
}pubkeyBase is the base key as a full compressed point (02/03 + x), so a
verifier has nothing to guess. states holds one state per mark, in order:
a string state (a git-mark commit) is hashed as its text, an object state
as its JCS. A git-mark trail may leave states empty; the commits are then
read from the TXO URIs.
The earlier shape this crate wrote, with @id, genesis and txo
entries {outpoint, blockheight} and no base key, still parses: its
fields are kept in id and genesis and its
entries as legacy BlocktrailTxos, and it serialises back as it was
read. A trail built here (Blocktrail::gitmark) has neither field.
§Examples
use solid_pod_rs::blocktrail::{Blocktrail, BlocktrailTxo};
let commit = "9adc596cfd1100333393a12f2f41b2d820f16d0b";
let txid = "51d87101b7cbb01cc5a68785bf3141ec6fd00894d71ab1168d4daa20420eeacf";
let trail = Blocktrail::gitmark(
"0273c7f6cf0f135a63bc95a2e676bcf0a592c8b508fae8697e43f778c74e232b24",
"tbtc4",
vec![commit.to_string()],
vec![BlocktrailTxo::new("tbtc4", txid, 0).with_amount(999_700).with_commit(commit)],
);
let json: serde_json::Value = serde_json::from_str(&trail.to_blocktrails_json().unwrap()).unwrap();
assert_eq!(json["@type"], "Blocktrail");
assert_eq!(json["profile"], "gitmark");
assert_eq!(json["txo"][0], format!("txo:tbtc4:{txid}:0?amount=999700&commit={commit}"));
assert!(json.get("@id").is_none());Fields§
§id: Option<String>The earlier shape’s @id (gitmark:<first-commit>:0); None in the
§5.2 shape.
type_: StringAlways BLOCKTRAIL_TYPE.
version: Option<String>The schema version (BLOCKTRAIL_VERSION for a trail built here).
profile: Option<String>The profile (gitmark, or a plain profile id); a trail with none is
read as DEFAULT_PROFILE.
pubkey_base: Option<String>The base key as a full compressed point (02/03 + x).
chain: Option<String>The chain token the marks live on (tbtc4, mainnet, gitmark, …).
genesis: Option<String>The earlier shape’s genesis (gitmark:<first-commit>:0); None in
the §5.2 shape.
states: Vec<Value>One state per mark, in order.
txo: Vec<BlocktrailTxo>The marks, in order.
Implementations§
Source§impl Blocktrail
impl Blocktrail
Sourcepub fn gitmark(
pubkey_base: impl Into<String>,
chain: impl Into<String>,
commits: Vec<String>,
txo: Vec<BlocktrailTxo>,
) -> Self
pub fn gitmark( pubkey_base: impl Into<String>, chain: impl Into<String>, commits: Vec<String>, txo: Vec<BlocktrailTxo>, ) -> Self
A git-mark trail in the §5.2 shape: pubkey_base as a full compressed
point, the marks on chain, the commits as its states.
Sourcepub fn profile_name(&self) -> String
pub fn profile_name(&self) -> String
The profile, lower-cased, or DEFAULT_PROFILE when none is set (as
blocktrails/verify reads it).
Sourcepub fn is_gitmark(&self) -> bool
pub fn is_gitmark(&self) -> bool
Whether this is a git-mark trail.
Sourcepub fn is_legacy(&self) -> bool
pub fn is_legacy(&self) -> bool
Whether the trail carries anything of the earlier shape (@id,
genesis, or a {outpoint, blockheight} entry).
Sourcepub fn state_strings(&self) -> Result<Vec<String>, String>
pub fn state_strings(&self) -> Result<Vec<String>, String>
The states, one per mark, as the strings that are hashed: a string
state as its text, an object state as its JCS
(crate::mrc20::bt_state_string). A git-mark trail with no states
takes them from its TXO URIs’ commits, as blocktrails/verify does.
§Errors
The message blocktrails/verify gives: the trail has M marks and S states when the counts differ, mark i has no state for a null state.
Sourcepub fn to_blocktrails_json(&self) -> Result<String, ProvenanceError>
pub fn to_blocktrails_json(&self) -> Result<String, ProvenanceError>
Serialise to blocktrails.json text (pretty-printed).
§Errors
ProvenanceError::Store if serialisation fails.