Skip to main content

Blocktrail

Struct Blocktrail 

Source
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_: String§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

Source

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.

Source

pub fn profile_name(&self) -> String

The profile, lower-cased, or DEFAULT_PROFILE when none is set (as blocktrails/verify reads it).

Source

pub fn is_gitmark(&self) -> bool

Whether this is a git-mark trail.

Source

pub fn is_legacy(&self) -> bool

Whether the trail carries anything of the earlier shape (@id, genesis, or a {outpoint, blockheight} entry).

Source

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.

Source

pub fn to_blocktrails_json(&self) -> Result<String, ProvenanceError>

Serialise to blocktrails.json text (pretty-printed).

§Errors

ProvenanceError::Store if serialisation fails.

Trait Implementations§

Source§

impl Clone for Blocktrail

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Blocktrail

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Blocktrail

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Blocktrail

Source§

impl PartialEq for Blocktrail

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Blocktrail

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Blocktrail

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more