Function sc_cli::utils::read_uri

source ·
pub fn read_uri(uri: Option<&String>) -> Result<String>
Expand description

helper method to fetch uri from Option<String> either as a file or read from stdin

Examples found in repository?
src/commands/sign.rs (line 56)
54
55
56
57
58
59
60
61
62
63
64
	pub fn run(&self) -> error::Result<()> {
		let message = utils::read_message(self.message.as_ref(), self.hex)?;
		let suri = utils::read_uri(self.suri.as_ref())?;
		let password = self.keystore_params.read_password()?;

		let signature =
			with_crypto_scheme!(self.crypto_scheme.scheme, sign(&suri, password, message))?;

		println!("{}", signature);
		Ok(())
	}
More examples
Hide additional examples
src/commands/verify.rs (line 59)
56
57
58
59
60
61
62
63
	pub fn run(&self) -> error::Result<()> {
		let message = utils::read_message(self.message.as_ref(), self.hex)?;
		let sig_data = array_bytes::hex2bytes(&self.sig)?;
		let uri = utils::read_uri(self.uri.as_ref())?;
		let uri = if let Some(uri) = uri.strip_prefix("0x") { uri } else { &uri };

		with_crypto_scheme!(self.crypto_scheme.scheme, verify(sig_data, message, uri))
	}
src/commands/inspect_key.rs (line 82)
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
	pub fn run(&self) -> Result<(), Error> {
		let uri = utils::read_uri(self.uri.as_ref())?;
		let password = self.keystore_params.read_password()?;

		if self.public {
			with_crypto_scheme!(
				self.crypto_scheme.scheme,
				print_from_public(
					&uri,
					self.network_scheme.network,
					self.output_scheme.output_type,
				)
			)?;
		} else {
			if let Some(ref expect_public) = self.expect_public {
				with_crypto_scheme!(
					self.crypto_scheme.scheme,
					expect_public_from_phrase(expect_public, &uri, password.as_ref())
				)?;
			}

			with_crypto_scheme!(
				self.crypto_scheme.scheme,
				print_from_uri(
					&uri,
					password,
					self.network_scheme.network,
					self.output_scheme.output_type,
				)
			);
		}

		Ok(())
	}
src/commands/insert_key.rs (line 60)
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	pub fn run<C: SubstrateCli>(&self, cli: &C) -> Result<(), Error> {
		let suri = utils::read_uri(self.suri.as_ref())?;
		let base_path = self
			.shared_params
			.base_path()?
			.unwrap_or_else(|| BasePath::from_project("", "", &C::executable_name()));
		let chain_id = self.shared_params.chain_id(self.shared_params.is_dev());
		let chain_spec = cli.load_spec(&chain_id)?;
		let config_dir = base_path.config_dir(chain_spec.id());

		let (keystore, public) = match self.keystore_params.keystore_config(&config_dir)? {
			(_, KeystoreConfig::Path { path, password }) => {
				let public = with_crypto_scheme!(self.scheme, to_vec(&suri, password.clone()))?;
				let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::open(path, password)?);
				(keystore, public)
			},
			_ => unreachable!("keystore_config always returns path and password; qed"),
		};

		let key_type =
			KeyTypeId::try_from(self.key_type.as_str()).map_err(|_| Error::KeyTypeInvalid)?;

		SyncCryptoStore::insert_unknown(&*keystore, key_type, &suri, &public[..])
			.map_err(|_| Error::KeyStoreOperation)?;

		Ok(())
	}