Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions inscribe-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn implement_get_inscription(dstruct: &DataStruct) -> TokenStream {
use decree::decree::FSInput;

let mut serial_out: Vec<u8> = Vec::new();
let mut hasher = TupleHash::v256(self.get_mark().as_bytes());
let mut hasher = TupleHash::v256(Self::MARK.as_bytes());

// Add the struct members into the TupleHash
#center
Expand All @@ -196,12 +196,10 @@ fn implement_default_mark(ast: &DeriveInput) -> TokenStream {
let ident = &ast.ident;
let ident_str = ident.to_string();

let get_mark = quote!{
fn get_mark(&self) -> &'static str {
return #ident_str;
}
let mark = quote!{
const MARK: &'static str = #ident_str;
};
get_mark
mark
}

fn implement_get_addl(ast: &DeriveInput) -> TokenStream {
Expand Down Expand Up @@ -255,9 +253,7 @@ fn implement_get_mark(ast: &DeriveInput) -> TokenStream {
if let Some(meta) = nested.iter().next() {
match meta {
Meta::Path(path) => { mark_implementation = quote!{
fn get_mark(&self) -> &'static str {
self.#path()
}
const MARK: &'static str = #path;
}},
_ => { panic!("Invalid metadata for field attribute"); },
}
Expand Down
6 changes: 3 additions & 3 deletions src/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ pub type InscribeBuffer = [u8; INSCRIBE_LENGTH];
/// contextual data into Fiat-Shamir transcripts. There are two main methods that the trait
/// requires:
///
/// `fn get_mark(&self) -> &'static str`
/// `const MARK: &'static str`
///
/// and
///
/// `fn get_inscription(&self) -> FSInput`
///
/// For derived structs, the `get_inscription` method will do the following:
/// - Initialize a TupleHash with the results of `get_mark`
/// - Initialize a TupleHash with the contents of `MARK`
/// - For each member of the struct, do one of three things:
/// + For `Inscribe` implementers, call `get_inscription` and add the results to the
/// TupleHash
Expand Down Expand Up @@ -124,7 +124,7 @@ pub type InscribeBuffer = [u8; INSCRIBE_LENGTH];
/// ```
///
pub trait Inscribe {
fn get_mark(&self) -> &'static str;
const MARK: &'static str;
fn get_inscription(&self) -> DecreeResult<FSInput>;
fn get_additional(&self) -> DecreeResult<FSInput> {
let x: Vec<u8> = Vec::new();
Expand Down
8 changes: 1 addition & 7 deletions tests/inscribe_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod tests {
const MARK_TEST_DATA: &str = "Atypical mark!";

#[derive(Inscribe)]
#[inscribe_mark(atypical_mark)]
#[inscribe_mark(MARK_TEST_DATA)]
struct Point {
#[inscribe(serialize)]
#[inscribe_name(input_2)]
Expand All @@ -22,12 +22,6 @@ mod tests {
y: i32,
}

impl Point {
fn atypical_mark(&self) -> &'static str {
MARK_TEST_DATA
}
}

#[derive(Inscribe)]
#[inscribe_addl(additional_data_method)]
struct InscribeTest {
Expand Down