diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eeede9be9..a1f32397a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -150,6 +150,7 @@ test-registry-publish-install: - echo -e '[registries]\nestuary = { index = "http://0.0.0.0:7878/git/index" }' > .cargo/config.toml - echo 0000 | cargo login --registry estuary - rusty-cachier snapshot create + - cd transcode && cargo publish --registry estuary && cd .. - cargo publish --registry estuary - cargo install cargo-contract --index http://0.0.0.0:7878/git/index diff --git a/Cargo.lock b/Cargo.lock index 3e4a59ad4..969b38a88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -480,7 +480,6 @@ dependencies = [ "heck", "hex", "impl-serde", - "ink_metadata", "jsonrpsee", "pallet-contracts-primitives", "parity-scale-codec", @@ -640,7 +639,7 @@ dependencies = [ [[package]] name = "contract-transcode" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "assert_matches", diff --git a/Cargo.toml b/Cargo.toml index bbcf5880a..4e88f1850 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ toml = "0.5.9" rustc_version = "0.4.0" blake2 = "0.10.4" contract-metadata = { version = "1", path = "./metadata" } -transcode = { package = "contract-transcode", version = "0.1.0", path = "./transcode" } +transcode = { package = "contract-transcode", version = "0.2.0", path = "./transcode" } semver = { version = "1.0.13", features = ["serde"] } serde = { version = "1.0.144", default-features = false, features = ["derive"] } serde_json = "1.0.85" @@ -47,7 +47,6 @@ regex = "1.6.0" # dependencies for extrinsics (deploying and calling a contract) async-std = { version = "1.12.0", features = ["attributes", "tokio1"] } -ink_metadata = { version = "3.3", features = ["derive"] } sp-core = "6.0.0" pallet-contracts-primitives = "6.0.0" subxt = "0.23.0" diff --git a/src/cmd/decode.rs b/src/cmd/decode.rs index bff8527f3..4495f008d 100644 --- a/src/cmd/decode.rs +++ b/src/cmd/decode.rs @@ -15,10 +15,7 @@ // along with cargo-contract. If not, see . use crate::{ - cmd::extrinsics::{ - load_metadata, - ContractMessageTranscoder, - }, + crate_metadata::CrateMetadata, util::decode_hex, DEFAULT_KEY_COL_WIDTH, }; @@ -27,6 +24,7 @@ use anyhow::{ Result, }; use colored::Colorize as _; +use transcode::ContractMessageTranscoder; #[derive(Debug, Clone, clap::Args)] #[clap( @@ -51,8 +49,8 @@ enum DataType { impl DecodeCommand { pub fn run(&self) -> Result<()> { - let (_, contract_metadata) = load_metadata(None)?; - let transcoder = ContractMessageTranscoder::new(&contract_metadata); + let crate_metadata = CrateMetadata::from_manifest_path(None)?; + let transcoder = ContractMessageTranscoder::load(crate_metadata.metadata_path())?; const ERR_MSG: &str = "Failed to decode specified data as a hex value"; let decoded_data = match self.r#type { diff --git a/src/cmd/extrinsics/call.rs b/src/cmd/extrinsics/call.rs index ea275a481..ba2f36f1a 100644 --- a/src/cmd/extrinsics/call.rs +++ b/src/cmd/extrinsics/call.rs @@ -18,7 +18,6 @@ use super::{ display_contract_exec_result, display_events, error_details, - load_metadata, parse_balance, prompt_confirm_tx, state_call, @@ -26,6 +25,7 @@ use super::{ Balance, Client, ContractMessageTranscoder, + CrateMetadata, DefaultConfig, ExtrinsicOpts, PairSigner, @@ -74,9 +74,10 @@ pub struct CallCommand { impl CallCommand { pub fn run(&self) -> Result<()> { - let (_, contract_metadata) = - load_metadata(self.extrinsic_opts.manifest_path.as_ref())?; - let transcoder = ContractMessageTranscoder::new(&contract_metadata); + let crate_metadata = CrateMetadata::from_manifest_path( + self.extrinsic_opts.manifest_path.as_ref(), + )?; + let transcoder = ContractMessageTranscoder::load(crate_metadata.metadata_path())?; let call_data = transcoder.encode(&self.message, &self.args)?; tracing::debug!("Message data: {:?}", hex::encode(&call_data)); @@ -146,7 +147,7 @@ impl CallCommand { client: &Client, data: Vec, signer: &PairSigner, - transcoder: &ContractMessageTranscoder<'_>, + transcoder: &ContractMessageTranscoder, ) -> Result<()> { tracing::debug!("calling contract {:?}", self.contract); diff --git a/src/cmd/extrinsics/events.rs b/src/cmd/extrinsics/events.rs index 403031742..085d67952 100644 --- a/src/cmd/extrinsics/events.rs +++ b/src/cmd/extrinsics/events.rs @@ -98,7 +98,11 @@ pub fn display_events( name }); - let decoded_field = events_transcoder.decode(*field_ty, event_data)?; + let decoded_field = events_transcoder.decode( + &runtime_metadata.types, + *field_ty, + event_data, + )?; maybe_println!( verbosity, "{:width$}{}", diff --git a/src/cmd/extrinsics/instantiate.rs b/src/cmd/extrinsics/instantiate.rs index 8e7d23a34..714635c0a 100644 --- a/src/cmd/extrinsics/instantiate.rs +++ b/src/cmd/extrinsics/instantiate.rs @@ -28,6 +28,7 @@ use super::{ CodeHash, ContractAccount, ContractMessageTranscoder, + CrateMetadata, DefaultConfig, ExtrinsicOpts, PairSigner, @@ -121,9 +122,10 @@ impl InstantiateCommand { /// Creates an extrinsic with the `Contracts::instantiate` Call, submits via RPC, then waits for /// the `ContractsEvent::Instantiated` event. pub fn run(&self) -> Result<()> { - let (crate_metadata, contract_metadata) = - super::load_metadata(self.extrinsic_opts.manifest_path.as_ref())?; - let transcoder = ContractMessageTranscoder::new(&contract_metadata); + let crate_metadata = CrateMetadata::from_manifest_path( + self.extrinsic_opts.manifest_path.as_ref(), + )?; + let transcoder = ContractMessageTranscoder::load(crate_metadata.metadata_path())?; let data = transcoder.encode(&self.constructor, &self.args)?; let signer = super::pair_signer(self.extrinsic_opts.signer()?); let url = self.extrinsic_opts.url_to_string(); @@ -190,17 +192,17 @@ struct InstantiateArgs { salt: Vec, } -pub struct Exec<'a> { +pub struct Exec { opts: ExtrinsicOpts, args: InstantiateArgs, verbosity: Verbosity, url: String, client: Client, signer: PairSigner, - transcoder: ContractMessageTranscoder<'a>, + transcoder: ContractMessageTranscoder, } -impl<'a> Exec<'a> { +impl Exec { async fn exec(&self, code: Code, dry_run: bool) -> Result<()> { tracing::debug!("instantiate data {:?}", self.args.data); if dry_run { diff --git a/src/cmd/extrinsics/mod.rs b/src/cmd/extrinsics/mod.rs index b90d5ef6a..574da3df3 100644 --- a/src/cmd/extrinsics/mod.rs +++ b/src/cmd/extrinsics/mod.rs @@ -36,7 +36,6 @@ use jsonrpsee::{ ws_client::WsClientBuilder, }; use std::{ - fs::File, io::{ self, Write, @@ -48,7 +47,6 @@ use self::events::display_events; use crate::{ crate_metadata::CrateMetadata, name_value_println, - workspace::ManifestPath, Verbosity, VerbosityFlags, DEFAULT_KEY_COL_WIDTH, @@ -58,7 +56,6 @@ use scale::{ Decode, Encode, }; -use serde_json::Value; use sp_core::{ crypto::Pair, sr25519, @@ -144,40 +141,6 @@ impl ExtrinsicOpts { } } -/// For a contract project with its `Cargo.toml` at the specified `manifest_path`, load the cargo -/// [`CrateMetadata`] along with the contract metadata [`ink_metadata::InkProject`]. -pub fn load_metadata( - manifest_path: Option<&PathBuf>, -) -> Result<(CrateMetadata, ink_metadata::InkProject)> { - let manifest_path = ManifestPath::try_from(manifest_path)?; - let crate_metadata = CrateMetadata::collect(&manifest_path)?; - let path = crate_metadata.metadata_path(); - - if !path.exists() { - return Err(anyhow!( - "Metadata file not found. Try building with `cargo contract build`." - )) - } - - let file = File::open(&path) - .context(format!("Failed to open metadata file {}", path.display()))?; - let metadata: contract_metadata::ContractMetadata = serde_json::from_reader(file) - .context(format!( - "Failed to deserialize metadata file {}", - path.display() - ))?; - let ink_metadata = - serde_json::from_value(Value::Object(metadata.abi)).context(format!( - "Failed to deserialize ink project metadata from file {}", - path.display() - ))?; - if let ink_metadata::MetadataVersioned::V3(ink_project) = ink_metadata { - Ok((crate_metadata, ink_project)) - } else { - Err(anyhow!("Unsupported ink metadata version. Expected V1")) - } -} - /// Parse Rust style integer balance literals which can contain underscores. fn parse_balance(input: &str) -> Result { input diff --git a/src/cmd/extrinsics/upload.rs b/src/cmd/extrinsics/upload.rs index d31daa5d0..f6c857931 100644 --- a/src/cmd/extrinsics/upload.rs +++ b/src/cmd/extrinsics/upload.rs @@ -24,6 +24,7 @@ use super::{ Client, CodeHash, ContractMessageTranscoder, + CrateMetadata, DefaultConfig, ExtrinsicOpts, PairSigner, @@ -59,9 +60,10 @@ pub struct UploadCommand { impl UploadCommand { pub fn run(&self) -> Result<()> { - let (crate_metadata, contract_metadata) = - super::load_metadata(self.extrinsic_opts.manifest_path.as_ref())?; - let transcoder = ContractMessageTranscoder::new(&contract_metadata); + let crate_metadata = CrateMetadata::from_manifest_path( + self.extrinsic_opts.manifest_path.as_ref(), + )?; + let transcoder = ContractMessageTranscoder::load(crate_metadata.metadata_path())?; let signer = super::pair_signer(self.extrinsic_opts.signer()?); let wasm_path = match &self.wasm_path { @@ -135,7 +137,7 @@ impl UploadCommand { client: &Client, code: Vec, signer: &PairSigner, - transcoder: &ContractMessageTranscoder<'_>, + transcoder: &ContractMessageTranscoder, ) -> Result> { let call = super::runtime_api::api::tx() .contracts() diff --git a/src/crate_metadata.rs b/src/crate_metadata.rs index ea675af84..1c7d98b09 100644 --- a/src/crate_metadata.rs +++ b/src/crate_metadata.rs @@ -55,6 +55,12 @@ pub struct CrateMetadata { } impl CrateMetadata { + /// Attempt to construct [`CrateMetadata`] from the given manifest path. + pub fn from_manifest_path(manifest_path: Option<&PathBuf>) -> Result { + let manifest_path = ManifestPath::try_from(manifest_path)?; + Self::collect(&manifest_path) + } + /// Parses the contract manifest and returns relevant metadata. pub fn collect(manifest_path: &ManifestPath) -> Result { let (metadata, root_package) = get_cargo_metadata(manifest_path)?; diff --git a/transcode/Cargo.toml b/transcode/Cargo.toml index 0fdf33dc8..6a2200843 100644 --- a/transcode/Cargo.toml +++ b/transcode/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "contract-transcode" -version = "0.1.0" +version = "0.2.0" authors = ["Parity Technologies "] edition = "2021" diff --git a/transcode/README.md b/transcode/README.md index 1a1c9d5a5..e29f394fd 100644 --- a/transcode/README.md +++ b/transcode/README.md @@ -5,37 +5,4 @@ Contains utilities for encoding smart contract calls to SCALE. Currently part of [`cargo-contract`](https://github.com/paritytech/cargo-contract), the build tool for smart contracts written in [ink!](https://github.com/paritytech/ink). - -# Example - -```rust -use transcode::ContractMessageTranscoder; - -fn main() { - let metadata_path = "/path/to/metadata.json"; - - let metadata = load_metadata(&metadata_path.into())?; - let transcoder = ContractMessageTranscoder::new(&metadata); - - let constructor = "new"; - let args = ["foo", "bar"]; - let data = transcoder.encode(&constructor, &args).unwrap(); - - println!("Encoded constructor data {:?}", data); -} - -fn load_metadata(path: &Path) -> anyhow::Result { - let file = File::open(&path).expect("Failed to open metadata file"); - let metadata: ContractMetadata = - serde_json::from_reader(file).expect("Failed to deserialize metadata file"); - let ink_metadata = serde_json::from_value(serde_json::Value::Object(metadata.abi)) - .expect("Failed to deserialize ink project metadata"); - - if let ink_metadata::MetadataVersioned::V3(ink_project) = ink_metadata { - Ok(ink_project) - } else { - Err(anyhow!("Unsupported ink metadata version. Expected V3")) - } -} - -``` +See [crate docs](https://docs.rs/contract-transcode/latest/contract_transcode/) for example usage. diff --git a/transcode/src/lib.rs b/transcode/src/lib.rs index 538eb84ee..19c671498 100644 --- a/transcode/src/lib.rs +++ b/transcode/src/lib.rs @@ -80,6 +80,21 @@ //! //! As with the example for the primitive `bool` above, this works in the other direction for //! decoding SCALE encoded bytes and converting them into a human readable string. +//! +//! # Example +//! ```no_run +//! # use contract_metadata::ContractMetadata; +//! # use contract_transcode::ContractMessageTranscoder; +//! # use std::{path::Path, fs::File}; +//! let metadata_path = Path::new("/path/to/metadata.json"); +//! let transcoder = ContractMessageTranscoder::load(metadata_path).unwrap(); +//! +//! let constructor = "new"; +//! let args = ["foo", "bar"]; +//! let data = transcoder.encode(&constructor, &args).unwrap(); +//! +//! println!("Encoded constructor data {:?}", data); +//! ``` mod decode; mod encode; @@ -99,7 +114,10 @@ pub use self::{ }, }; -use anyhow::Result; +use anyhow::{ + Context, + Result, +}; use ink_metadata::{ ConstructorSpec, InkProject, @@ -117,17 +135,21 @@ use scale_info::{ }, Field, }; -use std::fmt::Debug; +use std::{ + fmt::Debug, + fs::File, + path::Path, +}; /// Encode strings to SCALE encoded smart contract calls. /// Decode SCALE encoded smart contract events and return values into `Value` objects. -pub struct ContractMessageTranscoder<'a> { - metadata: &'a InkProject, - transcoder: Transcoder<'a>, +pub struct ContractMessageTranscoder { + metadata: InkProject, + transcoder: Transcoder, } -impl<'a> ContractMessageTranscoder<'a> { - pub fn new(metadata: &'a InkProject) -> Self { +impl ContractMessageTranscoder { + pub fn new(metadata: InkProject) -> Self { let transcoder = TranscoderBuilder::new(metadata.registry()) .register_custom_type_transcoder::<::AccountId, _>(env_types::AccountId) .register_custom_type_decoder::<::Hash, _>(env_types::Hash) @@ -138,6 +160,35 @@ impl<'a> ContractMessageTranscoder<'a> { } } + /// Attempt to create a [`ContractMessageTranscoder`] from the metadata file at the given path. + pub fn load

(metadata_path: P) -> Result + where + P: AsRef, + { + let path = metadata_path.as_ref(); + let file = File::open(path) + .context(format!("Failed to open metadata file {}", path.display()))?; + let metadata: contract_metadata::ContractMetadata = serde_json::from_reader(file) + .context(format!( + "Failed to deserialize metadata file {}", + path.display() + ))?; + let ink_metadata = serde_json::from_value(serde_json::Value::Object( + metadata.abi, + )) + .context(format!( + "Failed to deserialize ink project metadata from file {}", + path.display() + ))?; + if let ink_metadata::MetadataVersioned::V3(ink_project) = ink_metadata { + Ok(Self::new(ink_project)) + } else { + Err(anyhow::anyhow!( + "Unsupported ink metadata version. Expected V1" + )) + } + } + pub fn encode(&self, name: &str, args: I) -> Result> where I: IntoIterator, @@ -166,12 +217,21 @@ impl<'a> ContractMessageTranscoder<'a> { let mut encoded = selector.to_bytes().to_vec(); for (spec, arg) in spec_args.iter().zip(args) { let value = scon::parse_value(arg.as_ref())?; - self.transcoder - .encode(spec.ty().ty().id(), &value, &mut encoded)?; + self.transcoder.encode( + self.metadata.registry(), + spec.ty().ty().id(), + &value, + &mut encoded, + )?; } Ok(encoded) } + pub fn decode(&self, type_id: u32, input: &mut &[u8]) -> Result { + self.transcoder + .decode(self.metadata.registry(), type_id, input) + } + fn constructors(&self) -> impl Iterator> { self.metadata.spec().constructors().iter() } @@ -213,7 +273,7 @@ impl<'a> ContractMessageTranscoder<'a> { let mut args = Vec::new(); for arg in event_spec.args() { let name = arg.label().to_string(); - let value = self.transcoder.decode(arg.ty().ty().id(), data)?; + let value = self.decode(arg.ty().ty().id(), data)?; args.push((Value::String(name), value)); } @@ -240,7 +300,7 @@ impl<'a> ContractMessageTranscoder<'a> { let mut args = Vec::new(); for arg in msg_spec.args() { let name = arg.label().to_string(); - let value = self.transcoder.decode(arg.ty().ty().id(), data)?; + let value = self.decode(arg.ty().ty().id(), data)?; args.push((Value::String(name), value)); } @@ -267,7 +327,7 @@ impl<'a> ContractMessageTranscoder<'a> { let mut args = Vec::new(); for arg in msg_spec.args() { let name = arg.label().to_string(); - let value = self.transcoder.decode(arg.ty().ty().id(), data)?; + let value = self.decode(arg.ty().ty().id(), data)?; args.push((Value::String(name), value)); } @@ -282,7 +342,7 @@ impl<'a> ContractMessageTranscoder<'a> { anyhow::anyhow!("Failed to find message spec with name '{}'", name) })?; if let Some(return_ty) = msg_spec.return_type().opt_type() { - self.transcoder.decode(return_ty.ty().id(), data) + self.decode(return_ty.ty().id(), data) } else { Ok(Value::Unit) } @@ -434,7 +494,7 @@ mod tests { #[test] fn encode_single_primitive_arg() -> Result<()> { let metadata = generate_metadata(); - let transcoder = ContractMessageTranscoder::new(&metadata); + let transcoder = ContractMessageTranscoder::new(metadata); let encoded = transcoder.encode("new", &["true"])?; // encoded args follow the 4 byte selector @@ -447,7 +507,7 @@ mod tests { #[test] fn encode_account_id_custom_ss58_encoding() -> Result<()> { let metadata = generate_metadata(); - let transcoder = ContractMessageTranscoder::new(&metadata); + let transcoder = ContractMessageTranscoder::new(metadata); let encoded = transcoder.encode( "set_account_id", @@ -468,7 +528,7 @@ mod tests { #[test] fn encode_account_ids_vec_args() -> Result<()> { let metadata = generate_metadata(); - let transcoder = ContractMessageTranscoder::new(&metadata); + let transcoder = ContractMessageTranscoder::new(metadata); let encoded = transcoder.encode( "set_account_ids_vec", @@ -495,7 +555,7 @@ mod tests { #[test] fn encode_primitive_vec_args() -> Result<()> { let metadata = generate_metadata(); - let transcoder = ContractMessageTranscoder::new(&metadata); + let transcoder = ContractMessageTranscoder::new(metadata); let encoded = transcoder.encode("primitive_vec_args", &["[1, 2]"])?; @@ -510,7 +570,7 @@ mod tests { #[test] fn encode_uint_hex_literals() -> Result<()> { let metadata = generate_metadata(); - let transcoder = ContractMessageTranscoder::new(&metadata); + let transcoder = ContractMessageTranscoder::new(metadata); let encoded = transcoder.encode( "uint_args", @@ -540,7 +600,7 @@ mod tests { #[test] fn encode_uint_arr_hex_literals() -> Result<()> { let metadata = generate_metadata(); - let transcoder = ContractMessageTranscoder::new(&metadata); + let transcoder = ContractMessageTranscoder::new(metadata); let encoded = transcoder.encode("uint_array_args", &["[0xDE, 0xAD, 0xBE, 0xEF]"])?; @@ -556,7 +616,7 @@ mod tests { #[test] fn decode_primitive_return() -> Result<()> { let metadata = generate_metadata(); - let transcoder = ContractMessageTranscoder::new(&metadata); + let transcoder = ContractMessageTranscoder::new(metadata); let encoded = true.encode(); let decoded = transcoder.decode_return("get", &mut &encoded[..])?; @@ -568,7 +628,7 @@ mod tests { #[test] fn decode_contract_event() -> Result<()> { let metadata = generate_metadata(); - let transcoder = ContractMessageTranscoder::new(&metadata); + let transcoder = ContractMessageTranscoder::new(metadata); // raw encoded event with event index prefix let encoded = (0u8, [0u32; 32], [1u32; 32]).encode(); @@ -582,7 +642,7 @@ mod tests { #[test] fn decode_hash_as_hex_encoded_string() -> Result<()> { let metadata = generate_metadata(); - let transcoder = ContractMessageTranscoder::new(&metadata); + let transcoder = ContractMessageTranscoder::new(metadata); let hash = [ 52u8, 40, 235, 225, 70, 245, 184, 36, 21, 218, 130, 114, 75, 207, 117, 240, @@ -615,7 +675,7 @@ mod tests { #[test] fn decode_contract_message() -> Result<()> { let metadata = generate_metadata(); - let transcoder = ContractMessageTranscoder::new(&metadata); + let transcoder = ContractMessageTranscoder::new(metadata); let encoded_bytes = hex::decode("633aa551").unwrap(); let _ = transcoder.decode_contract_message(&mut &encoded_bytes[..])?; diff --git a/transcode/src/transcoder.rs b/transcode/src/transcoder.rs index a64775fc3..d72074de3 100644 --- a/transcode/src/transcoder.rs +++ b/transcode/src/transcoder.rs @@ -41,56 +41,55 @@ use std::{ /// Encode strings to SCALE encoded output. /// Decode SCALE encoded input into `Value` objects. -pub struct Transcoder<'a> { - registry: &'a PortableRegistry, +pub struct Transcoder { env_types: EnvTypesTranscoder, } -impl<'a> Transcoder<'a> { - pub fn new(registry: &'a PortableRegistry, env_types: EnvTypesTranscoder) -> Self { - Self { - registry, - env_types, - } - } - - pub fn encoder(&self) -> Encoder { - Encoder::new(self.registry, &self.env_types) +impl Transcoder { + pub fn new(env_types: EnvTypesTranscoder) -> Self { + Self { env_types } } - pub fn encode(&self, type_id: u32, value: &Value, output: &mut O) -> Result<()> + pub fn encode( + &self, + registry: &PortableRegistry, + type_id: u32, + value: &Value, + output: &mut O, + ) -> Result<()> where O: Output + Debug, { - self.encoder().encode(type_id, value, output) - } - - pub fn decoder(&self) -> Decoder { - Decoder::new(self.registry, &self.env_types) + let encoder = Encoder::new(registry, &self.env_types); + encoder.encode(type_id, value, output) } - pub fn decode(&self, type_id: u32, input: &mut &[u8]) -> Result { - self.decoder().decode(type_id, input) + pub fn decode( + &self, + registry: &PortableRegistry, + type_id: u32, + input: &mut &[u8], + ) -> Result { + let decoder = Decoder::new(registry, &self.env_types); + decoder.decode(type_id, input) } } /// Construct a [`Transcoder`], allows registering custom transcoders for certain types. -pub struct TranscoderBuilder<'a> { - registry: &'a PortableRegistry, +pub struct TranscoderBuilder { types_by_path: TypesByPath, encoders: HashMap>, decoders: HashMap>, } -impl<'a> TranscoderBuilder<'a> { - pub fn new(registry: &'a PortableRegistry) -> Self { +impl TranscoderBuilder { + pub fn new(registry: &PortableRegistry) -> Self { let types_by_path = registry .types() .iter() .map(|ty| (PathKey::from(ty.ty().path()), ty.id())) .collect::(); Self { - registry, types_by_path, encoders: HashMap::new(), decoders: HashMap::new(), @@ -171,9 +170,9 @@ impl<'a> TranscoderBuilder<'a> { this } - pub fn done(self) -> Transcoder<'a> { + pub fn done(self) -> Transcoder { let env_types_transcoder = EnvTypesTranscoder::new(self.encoders, self.decoders); - Transcoder::new(self.registry, env_types_transcoder) + Transcoder::new(env_types_transcoder) } } @@ -221,8 +220,8 @@ mod tests { let value = scon::parse_value(input)?; let mut output = Vec::new(); - transcoder.encode(ty, &value, &mut output)?; - let decoded = transcoder.decode(ty, &mut &output[..])?; + transcoder.encode(®istry, ty, &value, &mut output)?; + let decoded = transcoder.decode(®istry, ty, &mut &output[..])?; assert_eq!(expected_output, decoded, "decoding"); Ok(()) } @@ -236,13 +235,13 @@ mod tests { #[test] fn transcode_char_unsupported() -> Result<()> { let (registry, ty) = registry_with_type::()?; - let transcoder = Transcoder::new(®istry, Default::default()); + let transcoder = Transcoder::new(Default::default()); let encoded = u32::from('c').encode(); assert!(transcoder - .encode(ty, &Value::Char('c'), &mut Vec::new()) + .encode(®istry, ty, &Value::Char('c'), &mut Vec::new()) .is_err()); - assert!(transcoder.decode(ty, &mut &encoded[..]).is_err()); + assert!(transcoder.decode(®istry, ty, &mut &encoded[..]).is_err()); Ok(()) }