Skip to content

Commit

Permalink
fix: export RawGenesisBlockFile instead of RawGenesisBlock in schema
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed May 8, 2024
1 parent ca6bd56 commit 5a328e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions docs/source/references/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3053,15 +3053,15 @@
}
]
},
"RawGenesisBlock": {
"RawGenesisBlockFile": {
"Struct": [
{
"name": "transactions",
"type": "Vec<GenesisTransactionBuilder>"
},
{
"name": "executor",
"type": "Executor"
"name": "executor_file",
"type": "String"
}
]
},
Expand Down
21 changes: 13 additions & 8 deletions genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl GenesisNetwork {
/// The initial block of the network
///
/// Use [`RawGenesisBlockFile`] to read it from a file.
#[derive(Debug, Clone, IntoSchema)]
#[derive(Debug, Clone)]
pub struct RawGenesisBlock {
/// Transactions
transactions: Vec<GenesisTransactionBuilder>,
Expand All @@ -93,22 +93,27 @@ impl RawGenesisBlock {
/// A (de-)serializable version of [`RawGenesisBlock`].
///
/// The conversion is performed using [`TryFrom`].
#[derive(Debug, Clone, Deserialize, Serialize)]
#[derive(Debug, Clone, Deserialize, Serialize, IntoSchema)]
pub struct RawGenesisBlockFile {
/// Transactions
transactions: Vec<GenesisTransactionBuilder>,
/// Path to the [`Executor`] file
executor_file: PathBuf,
executor_file: ExecutorPath,
}

/// Path to [`Executor`] file
#[derive(Debug, Clone, Deserialize, Serialize, IntoSchema)]
#[schema(transparent = "String")]
pub struct ExecutorPath(PathBuf);

impl TryFrom<RawGenesisBlockFile> for RawGenesisBlock {
type Error = Report;

fn try_from(value: RawGenesisBlockFile) -> Result<Self> {
let wasm = fs::read(&value.executor_file).wrap_err_with(|| {
let wasm = fs::read(&value.executor_file.0).wrap_err_with(|| {
eyre!(
"failed to read the executor from {}",
&value.executor_file.display()
&value.executor_file.0.display()
)
})?;
Ok(Self {
Expand Down Expand Up @@ -143,11 +148,11 @@ impl RawGenesisBlockFile {
path.as_ref().display()
)
})?;
value.executor_file = path
value.executor_file.0 = path
.as_ref()
.parent()
.expect("genesis must be a file in some directory")
.join(value.executor_file);
.join(value.executor_file.0);
Ok(value)
}

Expand Down Expand Up @@ -296,7 +301,7 @@ impl RawGenesisBlockBuilder<executor_state::SetPath> {
pub fn build(self) -> RawGenesisBlockFile {
RawGenesisBlockFile {
transactions: vec![self.transaction],
executor_file: self.state.0,
executor_file: ExecutorPath(self.state.0),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn build_schemas() -> MetaMap {
MerkleTree<SignedTransaction>,

// Genesis file - used by SDKs to generate the genesis block
iroha_genesis::RawGenesisBlock,
iroha_genesis::RawGenesisBlockFile,
}
}

Expand Down

0 comments on commit 5a328e9

Please sign in to comment.