Skip to content

Commit

Permalink
Cli: Encode bridge_address as KT1 address as opposed to a tz4 address
Browse files Browse the repository at this point in the history
  • Loading branch information
johnyob authored and alanmarkoTrilitech committed Oct 19, 2023
1 parent e3f6c9a commit 26c3893
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 33 deletions.
112 changes: 108 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions jstz_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tezos-smart-rollup = "0.2.1"
tezos-smart-rollup-mock = "0.2.1"
tezos-smart-rollup-installer-config = "0.2.1"
serde_yaml = "0.8"
tezos_crypto_rs = "0.5.1"

[[bin]]
name = "jstz"
Expand Down
66 changes: 37 additions & 29 deletions jstz_cli/src/sandbox/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use std::{
use anyhow::Result;
use fs_extra::dir::CopyOptions;
use jstz_core::kv::value::serialize;
use jstz_crypto::public_key_hash::PublicKeyHash;
use nix::libc::{SIGINT, SIGTERM};
use signal_hook::iterator::Signals;
use tempfile::TempDir;
use tezos_crypto_rs::hash::ContractKt1Hash;
use tezos_smart_rollup_installer_config::yaml::{Instr, SetArgs, YamlConfig};

use crate::{
Expand Down Expand Up @@ -179,13 +179,11 @@ fn start_rollup_node(cfg: &Config) -> Result<Child> {

fn smart_rollup_installer(cfg: &Config, bridge_address: &str) -> Result<()> {
//Convert address
let address_encoding =
serialize(&PublicKeyHash::from_base58(&bridge_address).unwrap());
let hex_address = hex::encode(address_encoding.clone());
let bridge_address = ContractKt1Hash::from_base58_check(bridge_address)?;

let instructions = YamlConfig {
instructions: vec![Instr::Set(SetArgs {
value: hex_address.clone(),
value: hex::encode(serialize(&bridge_address)),
to: "/ticketer".to_owned(),
})],
};
Expand All @@ -199,29 +197,39 @@ fn smart_rollup_installer(cfg: &Config, bridge_address: &str) -> Result<()> {
let setup_file_path = temp_file.path().to_owned();

// Create an installer kernel
let _output = Command::new("smart-rollup-installer")
.args(&[
"get-reveal-installer",
"--setup-file",
&setup_file_path.to_str().expect("Invalid path"),
"--output",
cfg.jstz_path
.join("target/kernel/jstz_kernel_installer.hex")
.to_str()
.expect("Invalid path"),
"--preimages-dir",
&cfg.jstz_path
.join("target/kernel")
.join("preimages/")
.to_str()
.expect("Invalid path"),
"--upgrade-to",
&cfg.jstz_path
.join("target/wasm32-unknown-unknown/release/jstz_kernel.wasm")
.to_str()
.expect("Invalid path"),
])
.output();
let mut installer_command = Command::new("smart-rollup-installer");

installer_command.args(&[
"get-reveal-installer",
"--setup-file",
&setup_file_path.to_str().expect("Invalid path"),
"--output",
cfg.jstz_path
.join("target/kernel/jstz_kernel_installer.hex")
.to_str()
.expect("Invalid path"),
"--preimages-dir",
&cfg.jstz_path
.join("target/kernel")
.join("preimages/")
.to_str()
.expect("Invalid path"),
"--upgrade-to",
&cfg.jstz_path
.join("target/wasm32-unknown-unknown/release/jstz_kernel.wasm")
.to_str()
.expect("Invalid path"),
]);

let installer_output = installer_command.output()?;

if !installer_output.status.success() {
return Err(anyhow::anyhow!(
"Command {:?} failed:\n {}",
installer_command,
String::from_utf8_lossy(&installer_output.stderr)
));
}

Ok(())
}
Expand Down Expand Up @@ -409,7 +417,7 @@ pub fn main(cfg: &mut Config) -> Result<()> {
cfg.save()?;

// 4. Wait for the sandbox to shutdown (either by the user or by an error)
OctezThread::join(vec![rollup_node, baker, node])?;
OctezThread::join(vec![baker, rollup_node, node])?;

cfg.sandbox = None;
cfg.save()?;
Expand Down

0 comments on commit 26c3893

Please sign in to comment.