Skip to content
Merged
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
32 changes: 32 additions & 0 deletions exchange-contract/exchange/contracts/token_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,38 @@ const std::string capability_generation_key("capability_generation_key");

static ww::exchange::LedgerStore ledger_store("token_ledger");

// -----------------------------------------------------------------
// NAME: get_token_metadata
//
// Pulls the stored token metadata (which is a serialized JSON object),
// verifies the schema of the metadata, and returns it in the
// token_metadata parameter. The expectation is that this function
// will be called by token classes that specialize token behavior.
// -----------------------------------------------------------------
bool ww::exchange::token_object::get_token_metadata(
const std::string& schema,
ww::value::Object& token_metadata)
{
std::string serialized_token_metadata;
ERROR_IF_NOT(token_object_store.get(token_metadata_key, serialized_token_metadata),
"unexpected error: failed to get token metadata");

ww::value::Object deserialized_token_metadata;
ERROR_IF_NOT(deserialized_token_metadata.deserialize(serialized_token_metadata.c_str()),
"unexpected error: failed to deserialize token metadata");

ww::value::Object token_metadata_schema;
ERROR_IF_NOT(token_metadata_schema.deserialize(schema.c_str()),
"unexpected error: failed to deserialize token metadata schema");

ERROR_IF_NOT(deserialized_token_metadata.validate_schema(token_metadata_schema),
"unexpected error: token metadata does not match schema");

token_metadata.set(deserialized_token_metadata);
return true;
}


// -----------------------------------------------------------------
// METHOD: initialize_contract
// -----------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions exchange-contract/exchange/token_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ namespace token_object
const ww::value::Object& parameters,
ww::value::Object& capability_result);

bool get_token_metadata(
const std::string& schema,
ww::value::Object& token_metadata);

}; // token_object
}; // exchange
}; // ww