Skip to content

Commit

Permalink
genesis: convert the layout command to use the GenesisBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill authored and bors-libra committed Jun 4, 2021
1 parent 176d642 commit e0864f8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions config/management/genesis/src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use diem_management::{config::ConfigPath, constants, error::Error, secure_backend::SharedBackend};
use crate::builder::GenesisBuilder;
use diem_management::{config::ConfigPath, error::Error, secure_backend::SharedBackend};
use diem_secure_storage::Storage;
use serde::{Deserialize, Serialize};
use std::{
fs::File,
Expand Down Expand Up @@ -58,14 +60,21 @@ pub struct SetLayout {
impl SetLayout {
pub fn execute(self) -> Result<Layout, Error> {
let layout = Layout::from_disk(&self.path)?;
let data = layout.to_toml()?;

let config = self
.config
.load()?
.override_shared_backend(&self.backend.shared_backend)?;
let mut storage = config.shared_backend_with_namespace(constants::COMMON_NS.to_string());
storage.set(constants::LAYOUT, data)?;

// In order to not break cli compatibility we need to clear the namespace set via cli since
// it was previously ignored.
let mut shared_backend = config.shared_backend;
shared_backend.clear_namespace();

let storage = Storage::from(&shared_backend);
GenesisBuilder::new(storage)
.set_layout(&layout)
.map_err(|e| Error::StorageWriteError("shared", "layout", e.to_string()))?;

Ok(layout)
}
Expand Down

0 comments on commit e0864f8

Please sign in to comment.