Skip to content

Commit

Permalink
human-readable fix after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Sep 5, 2024
1 parent 1523cbb commit f634b3f
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 71 deletions.
26 changes: 12 additions & 14 deletions Cargo.lock

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

22 changes: 7 additions & 15 deletions data/human-readable/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ pub fn decode_human_readable_value(
type_name: &str,
contract_abi: &ContractAbi,
) -> Result<AnyValue, Box<dyn Error>> {
let type_description =
if let Some(type_description) = contract_abi.type_descriptions.0.get(type_name) {
type_description.to_owned()
} else {
TypeDescription {
docs: Vec::new(),
name: type_name.to_string(),
contents: TypeContents::NotSpecified,
}
};

let type_description = contract_abi.type_descriptions.find_or_default(type_name);
decode_any_value(input, &type_description, &contract_abi)

Check warning on line 22 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L22

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:22:48 | 22 | decode_any_value(input, &type_description, &contract_abi) | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
Raw output
data/human-readable/src/decode.rs:22:48:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/decode.rs:22:48
   |
22 |     decode_any_value(input, &type_description, &contract_abi)
   |                                                ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
   = note: `#[warn(clippy::needless_borrow)]` on by default


__END__

Check warning on line 22 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L22

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:22:48 | 22 | decode_any_value(input, &type_description, &contract_abi) | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
Raw output
data/human-readable/src/decode.rs:22:48:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/decode.rs:22:48
   |
22 |     decode_any_value(input, &type_description, &contract_abi)
   |                                                ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
   = note: `#[warn(clippy::needless_borrow)]` on by default


__END__
}

Expand All @@ -38,7 +28,9 @@ pub fn decode_any_value(
contract_abi: &ContractAbi,
) -> Result<AnyValue, Box<dyn Error>> {
match &type_description.contents {
TypeContents::NotSpecified => decode_single_value(input, type_description.name.as_str()),
TypeContents::NotSpecified => {
decode_single_value(input, type_description.names.abi.as_str())
},
TypeContents::Enum(variants) => decode_enum(input, &variants, &contract_abi),

Check warning on line 34 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L34

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:34:60 | 34 | TypeContents::Enum(variants) => decode_enum(input, &variants, &contract_abi), | ^^^^^^^^^ help: change this to: `variants` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:34:60:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/decode.rs:34:60
   |
34 |         TypeContents::Enum(variants) => decode_enum(input, &variants, &contract_abi),
   |                                                            ^^^^^^^^^ help: change this to: `variants`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 34 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L34

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:34:71 | 34 | TypeContents::Enum(variants) => decode_enum(input, &variants, &contract_abi), | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:34:71:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/decode.rs:34:71
   |
34 |         TypeContents::Enum(variants) => decode_enum(input, &variants, &contract_abi),
   |                                                                       ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 34 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L34

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:34:60 | 34 | TypeContents::Enum(variants) => decode_enum(input, &variants, &contract_abi), | ^^^^^^^^^ help: change this to: `variants` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:34:60:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/decode.rs:34:60
   |
34 |         TypeContents::Enum(variants) => decode_enum(input, &variants, &contract_abi),
   |                                                            ^^^^^^^^^ help: change this to: `variants`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 34 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L34

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:34:71 | 34 | TypeContents::Enum(variants) => decode_enum(input, &variants, &contract_abi), | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:34:71:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/decode.rs:34:71
   |
34 |         TypeContents::Enum(variants) => decode_enum(input, &variants, &contract_abi),
   |                                                                       ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__
TypeContents::Struct(fields) => decode_struct(input, &fields, &contract_abi),

Check warning on line 35 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L35

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:35:62 | 35 | TypeContents::Struct(fields) => decode_struct(input, &fields, &contract_abi), | ^^^^^^^ help: change this to: `fields` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:35:62:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/decode.rs:35:62
   |
35 |         TypeContents::Struct(fields) => decode_struct(input, &fields, &contract_abi),
   |                                                              ^^^^^^^ help: change this to: `fields`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 35 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L35

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:35:71 | 35 | TypeContents::Struct(fields) => decode_struct(input, &fields, &contract_abi), | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:35:71:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/decode.rs:35:71
   |
35 |         TypeContents::Struct(fields) => decode_struct(input, &fields, &contract_abi),
   |                                                                       ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 35 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L35

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:35:62 | 35 | TypeContents::Struct(fields) => decode_struct(input, &fields, &contract_abi), | ^^^^^^^ help: change this to: `fields` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:35:62:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/decode.rs:35:62
   |
35 |         TypeContents::Struct(fields) => decode_struct(input, &fields, &contract_abi),
   |                                                              ^^^^^^^ help: change this to: `fields`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 35 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L35

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:35:71 | 35 | TypeContents::Struct(fields) => decode_struct(input, &fields, &contract_abi), | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:35:71:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/decode.rs:35:71
   |
35 |         TypeContents::Struct(fields) => decode_struct(input, &fields, &contract_abi),
   |                                                                       ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__
TypeContents::ExplicitEnum(_) => panic!("not supported"),
Expand Down Expand Up @@ -141,7 +133,7 @@ pub fn decode_struct(
let value = input
.child(&field.name)
.ok_or_else(|| Box::new(DecodeError("missing field")))?;
let value = decode_human_readable_value(&value, &field.field_type, &contract_abi)?;
let value = decode_human_readable_value(&value, &field.field_type.abi, &contract_abi)?;

Check warning on line 136 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L136

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:136:80 | 136 | let value = decode_human_readable_value(&value, &field.field_type.abi, &contract_abi)?; | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:136:80:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> data/human-readable/src/decode.rs:136:80
    |
136 |         let value = decode_human_readable_value(&value, &field.field_type.abi, &contract_abi)?;
    |                                                                                ^^^^^^^^^^^^^ help: change this to: `contract_abi`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 136 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L136

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:136:80 | 136 | let value = decode_human_readable_value(&value, &field.field_type.abi, &contract_abi)?; | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:136:80:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> data/human-readable/src/decode.rs:136:80
    |
136 |         let value = decode_human_readable_value(&value, &field.field_type.abi, &contract_abi)?;
    |                                                                                ^^^^^^^^^^^^^ help: change this to: `contract_abi`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__
field_values.push(StructField {
name: field.name.clone(),
value,
Expand Down Expand Up @@ -196,7 +188,7 @@ pub fn decode_enum(
if variant.is_tuple_variant() && variant.fields.len() == 1 {
let value = input.child(variant.name.as_str()).unwrap();
let value =
decode_human_readable_value(&value, &variant.fields[0].field_type, contract_abi)?;
decode_human_readable_value(&value, &variant.fields[0].field_type.abi, contract_abi)?;
return Ok(AnyValue::Enum(Box::new(crate::EnumVariant {
discriminant: variant.discriminant,
value,
Expand All @@ -219,7 +211,7 @@ pub fn decode_enum(
let value = value.get(i).unwrap();
let value = decode_human_readable_value(
&(value.to_owned().into()),
&field.field_type,
&field.field_type.abi,
&contract_abi,

Check warning on line 215 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L215

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:215:17 | 215 | &contract_abi, | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:215:17:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> data/human-readable/src/decode.rs:215:17
    |
215 |                 &contract_abi,
    |                 ^^^^^^^^^^^^^ help: change this to: `contract_abi`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 215 in data/human-readable/src/decode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/decode.rs#L215

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/decode.rs:215:17 | 215 | &contract_abi, | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/decode.rs:215:17:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> data/human-readable/src/decode.rs:215:17
    |
215 |                 &contract_abi,
    |                 ^^^^^^^^^^^^^ help: change this to: `contract_abi`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__
)?;
field_values.push(StructField {
Expand Down
20 changes: 5 additions & 15 deletions data/human-readable/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ pub fn default_value_for_abi_type(
type_name: &str,
contract_abi: &ContractAbi,
) -> Result<AnyValue, Box<dyn Error>> {
let type_description =
if let Some(type_description) = contract_abi.type_descriptions.0.get(type_name) {
type_description.to_owned()
} else {
TypeDescription {
docs: Vec::new(),
name: type_name.to_string(),
contents: TypeContents::NotSpecified,
}
};

let type_description = contract_abi.type_descriptions.find_or_default(type_name);
default_value_for_any_value(&type_description, contract_abi)
}

Expand All @@ -33,7 +23,7 @@ pub fn default_value_for_any_value(
) -> Result<AnyValue, Box<dyn Error>> {
match &type_description.contents {
TypeContents::NotSpecified => {
default_value_for_single_value(type_description.name.as_str())
default_value_for_single_value(type_description.names.abi.as_str())
},
TypeContents::Enum(variants) => default_value_for_enum(&variants, contract_abi),

Check warning on line 28 in data/human-readable/src/defaults.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/defaults.rs#L28

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/defaults.rs:28:64 | 28 | TypeContents::Enum(variants) => default_value_for_enum(&variants, contract_abi), | ^^^^^^^^^ help: change this to: `variants` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/defaults.rs:28:64:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/defaults.rs:28:64
   |
28 |         TypeContents::Enum(variants) => default_value_for_enum(&variants, contract_abi),
   |                                                                ^^^^^^^^^ help: change this to: `variants`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 28 in data/human-readable/src/defaults.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/defaults.rs#L28

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/defaults.rs:28:64 | 28 | TypeContents::Enum(variants) => default_value_for_enum(&variants, contract_abi), | ^^^^^^^^^ help: change this to: `variants` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/defaults.rs:28:64:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/defaults.rs:28:64
   |
28 |         TypeContents::Enum(variants) => default_value_for_enum(&variants, contract_abi),
   |                                                                ^^^^^^^^^ help: change this to: `variants`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__
TypeContents::Struct(fields) => default_value_for_struct(&fields, contract_abi),

Check warning on line 29 in data/human-readable/src/defaults.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/defaults.rs#L29

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/defaults.rs:29:66 | 29 | TypeContents::Struct(fields) => default_value_for_struct(&fields, contract_abi), | ^^^^^^^ help: change this to: `fields` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/defaults.rs:29:66:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/defaults.rs:29:66
   |
29 |         TypeContents::Struct(fields) => default_value_for_struct(&fields, contract_abi),
   |                                                                  ^^^^^^^ help: change this to: `fields`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 29 in data/human-readable/src/defaults.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/defaults.rs#L29

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/defaults.rs:29:66 | 29 | TypeContents::Struct(fields) => default_value_for_struct(&fields, contract_abi), | ^^^^^^^ help: change this to: `fields` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/defaults.rs:29:66:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/defaults.rs:29:66
   |
29 |         TypeContents::Struct(fields) => default_value_for_struct(&fields, contract_abi),
   |                                                                  ^^^^^^^ help: change this to: `fields`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__
Expand Down Expand Up @@ -66,7 +56,7 @@ pub fn default_value_for_struct(
let mut field_values: Vec<StructField> = vec![];

for field in fields.iter() {
let value = default_value_for_abi_type(&field.field_type, &contract_abi)?;
let value = default_value_for_abi_type(&field.field_type.abi, &contract_abi)?;

Check warning on line 59 in data/human-readable/src/defaults.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/defaults.rs#L59

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/defaults.rs:59:71 | 59 | let value = default_value_for_abi_type(&field.field_type.abi, &contract_abi)?; | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/defaults.rs:59:71:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/defaults.rs:59:71
   |
59 |         let value = default_value_for_abi_type(&field.field_type.abi, &contract_abi)?;
   |                                                                       ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 59 in data/human-readable/src/defaults.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/defaults.rs#L59

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/defaults.rs:59:71 | 59 | let value = default_value_for_abi_type(&field.field_type.abi, &contract_abi)?; | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/defaults.rs:59:71:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/defaults.rs:59:71
   |
59 |         let value = default_value_for_abi_type(&field.field_type.abi, &contract_abi)?;
   |                                                                       ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__
field_values.push(StructField {
name: field.name.clone(),
value,
Expand Down Expand Up @@ -94,15 +84,15 @@ pub fn default_value_for_enum(

// handle tuple with only one field as a special case (we don't need a wrapper array)
if variant.is_tuple_variant() && variant.fields.len() == 1 {
let value = default_value_for_abi_type(&variant.fields[0].field_type, contract_abi)?;
let value = default_value_for_abi_type(&variant.fields[0].field_type.abi, contract_abi)?;
return Ok(AnyValue::Enum(Box::new(crate::EnumVariant {
discriminant: variant.discriminant,
value,
})));
} else if variant.is_tuple_variant() {
let mut field_values: Vec<StructField> = vec![];
for field in variant.fields.iter() {
let value = default_value_for_abi_type(&field.field_type, &contract_abi)?;
let value = default_value_for_abi_type(&field.field_type.abi, &contract_abi)?;

Check warning on line 95 in data/human-readable/src/defaults.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/defaults.rs#L95

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/defaults.rs:95:75 | 95 | let value = default_value_for_abi_type(&field.field_type.abi, &contract_abi)?; | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/defaults.rs:95:75:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/defaults.rs:95:75
   |
95 |             let value = default_value_for_abi_type(&field.field_type.abi, &contract_abi)?;
   |                                                                           ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 95 in data/human-readable/src/defaults.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/defaults.rs#L95

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/defaults.rs:95:75 | 95 | let value = default_value_for_abi_type(&field.field_type.abi, &contract_abi)?; | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/defaults.rs:95:75:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/defaults.rs:95:75
   |
95 |             let value = default_value_for_abi_type(&field.field_type.abi, &contract_abi)?;
   |                                                                           ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__
field_values.push(StructField {
name: field.name.clone(),
value,
Expand Down
29 changes: 12 additions & 17 deletions data/human-readable/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ pub fn encode_human_readable_value(
type_name: &str,
contract_abi: &ContractAbi,
) -> Result<HumanReadableValue, Box<dyn Error>> {
let type_description =
if let Some(type_description) = contract_abi.type_descriptions.0.get(type_name) {
type_description.to_owned()
} else {
TypeDescription {
docs: Vec::new(),
name: type_name.to_string(),
contents: TypeContents::NotSpecified,
}
};

let type_description = contract_abi.type_descriptions.find_or_default(type_name);
encode_any_value(input, &type_description, &contract_abi)

Check warning on line 17 in data/human-readable/src/encode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/encode.rs#L17

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/encode.rs:17:48 | 17 | encode_any_value(input, &type_description, &contract_abi) | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/encode.rs:17:48:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/encode.rs:17:48
   |
17 |     encode_any_value(input, &type_description, &contract_abi)
   |                                                ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 17 in data/human-readable/src/encode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/encode.rs#L17

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/encode.rs:17:48 | 17 | encode_any_value(input, &type_description, &contract_abi) | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/encode.rs:17:48:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/encode.rs:17:48
   |
17 |     encode_any_value(input, &type_description, &contract_abi)
   |                                                ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__
}

Expand All @@ -33,7 +23,9 @@ pub fn encode_any_value(
contract_abi: &ContractAbi,
) -> Result<HumanReadableValue, Box<dyn Error>> {
match &type_description.contents {
TypeContents::NotSpecified => encode_single_value(input, type_description.name.as_str()),
TypeContents::NotSpecified => {
encode_single_value(input, type_description.names.abi.as_str())
},
TypeContents::Enum(variants) => encode_enum(input, &variants, &contract_abi),

Check warning on line 29 in data/human-readable/src/encode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/encode.rs#L29

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/encode.rs:29:60 | 29 | TypeContents::Enum(variants) => encode_enum(input, &variants, &contract_abi), | ^^^^^^^^^ help: change this to: `variants` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/encode.rs:29:60:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/encode.rs:29:60
   |
29 |         TypeContents::Enum(variants) => encode_enum(input, &variants, &contract_abi),
   |                                                            ^^^^^^^^^ help: change this to: `variants`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 29 in data/human-readable/src/encode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/encode.rs#L29

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/encode.rs:29:71 | 29 | TypeContents::Enum(variants) => encode_enum(input, &variants, &contract_abi), | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/encode.rs:29:71:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/encode.rs:29:71
   |
29 |         TypeContents::Enum(variants) => encode_enum(input, &variants, &contract_abi),
   |                                                                       ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 29 in data/human-readable/src/encode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/encode.rs#L29

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/encode.rs:29:60 | 29 | TypeContents::Enum(variants) => encode_enum(input, &variants, &contract_abi), | ^^^^^^^^^ help: change this to: `variants` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/encode.rs:29:60:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/encode.rs:29:60
   |
29 |         TypeContents::Enum(variants) => encode_enum(input, &variants, &contract_abi),
   |                                                            ^^^^^^^^^ help: change this to: `variants`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 29 in data/human-readable/src/encode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/encode.rs#L29

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/encode.rs:29:71 | 29 | TypeContents::Enum(variants) => encode_enum(input, &variants, &contract_abi), | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/encode.rs:29:71:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/encode.rs:29:71
   |
29 |         TypeContents::Enum(variants) => encode_enum(input, &variants, &contract_abi),
   |                                                                       ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__
TypeContents::Struct(fields) => encode_struct(input, &fields, &contract_abi),

Check warning on line 30 in data/human-readable/src/encode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/encode.rs#L30

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/encode.rs:30:62 | 30 | TypeContents::Struct(fields) => encode_struct(input, &fields, &contract_abi), | ^^^^^^^ help: change this to: `fields` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/encode.rs:30:62:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/encode.rs:30:62
   |
30 |         TypeContents::Struct(fields) => encode_struct(input, &fields, &contract_abi),
   |                                                              ^^^^^^^ help: change this to: `fields`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 30 in data/human-readable/src/encode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/encode.rs#L30

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/encode.rs:30:71 | 30 | TypeContents::Struct(fields) => encode_struct(input, &fields, &contract_abi), | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/encode.rs:30:71:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/encode.rs:30:71
   |
30 |         TypeContents::Struct(fields) => encode_struct(input, &fields, &contract_abi),
   |                                                                       ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 30 in data/human-readable/src/encode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/encode.rs#L30

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/encode.rs:30:62 | 30 | TypeContents::Struct(fields) => encode_struct(input, &fields, &contract_abi), | ^^^^^^^ help: change this to: `fields` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/encode.rs:30:62:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/encode.rs:30:62
   |
30 |         TypeContents::Struct(fields) => encode_struct(input, &fields, &contract_abi),
   |                                                              ^^^^^^^ help: change this to: `fields`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__

Check warning on line 30 in data/human-readable/src/encode.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] data/human-readable/src/encode.rs#L30

warning: this expression creates a reference which is immediately dereferenced by the compiler --> data/human-readable/src/encode.rs:30:71 | 30 | TypeContents::Struct(fields) => encode_struct(input, &fields, &contract_abi), | ^^^^^^^^^^^^^ help: change this to: `contract_abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Raw output
data/human-readable/src/encode.rs:30:71:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> data/human-readable/src/encode.rs:30:71
   |
30 |         TypeContents::Struct(fields) => encode_struct(input, &fields, &contract_abi),
   |                                                                       ^^^^^^^^^^^^^ help: change this to: `contract_abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow


__END__
TypeContents::ExplicitEnum(_) => panic!("not supported"),
Expand Down Expand Up @@ -146,7 +138,7 @@ pub fn encode_struct(
.find(|f| f.name == field.name)
.ok_or_else(|| Box::new(EncodeError("missing field")))?;

let value = encode_human_readable_value(&value.value, &field.field_type, contract_abi)?;
let value = encode_human_readable_value(&value.value, &field.field_type.abi, contract_abi)?;
field_values.insert(field.name.to_owned(), value.get_value().to_owned());
}

Expand All @@ -173,7 +165,7 @@ pub fn encode_enum(
if variant.is_tuple_variant() && variant.fields.len() == 1 {
let value = encode_human_readable_value(
&enum_value.value,
&variant.fields[0].field_type,
&variant.fields[0].field_type.abi,
contract_abi,
)?;
return Ok(JsonValue::Object(
Expand All @@ -192,8 +184,11 @@ pub fn encode_enum(
let mut field_values: Vec<JsonValue> = vec![];

for (field, field_type) in variant.fields.iter().zip(variant_fields.0.iter()) {
let value =
encode_human_readable_value(&field_type.value, &field.field_type, contract_abi)?;
let value = encode_human_readable_value(
&field_type.value,
&field.field_type.abi,
contract_abi,
)?;
field_values.push(value.get_value().to_owned());
}

Expand All @@ -212,7 +207,7 @@ pub fn encode_enum(
let mut field_values: Map<String, JsonValue> = Map::new();
for (field, field_type) in variant.fields.iter().zip(variant_fields.0.iter()) {
let value =
encode_human_readable_value(&field_type.value, &field.field_type, contract_abi)?;
encode_human_readable_value(&field_type.value, &field.field_type.abi, contract_abi)?;
field_values.insert(field.name.to_owned(), value.get_value().to_owned());
}

Expand Down
7 changes: 7 additions & 0 deletions framework/base/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ impl TypeNames {
rust: alloc::string::String::new(),
}
}

pub const fn from_abi(abi_name: alloc::string::String) -> Self {
TypeNames {
abi: abi_name,
rust: alloc::string::String::new(),
}
}
}
23 changes: 23 additions & 0 deletions framework/base/src/abi/type_description_container.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use alloc::borrow::ToOwned;
use multiversx_sc_codec::Vec;

pub trait TypeDescriptionContainer {
Expand All @@ -20,6 +21,28 @@ pub trait TypeDescriptionContainer {
#[derive(Clone, Default, Debug)]
pub struct TypeDescriptionContainerImpl(pub Vec<(TypeNames, TypeDescription)>);

impl TypeDescriptionContainerImpl {
pub fn find(&self, abi_type_name: &str) -> Option<&TypeDescription> {
self.0
.iter()
.find(|(existing_type_name, _)| &existing_type_name.abi == abi_type_name)

Check warning on line 28 in framework/base/src/abi/type_description_container.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] framework/base/src/abi/type_description_container.rs#L28

warning: needlessly taken reference of left operand --> framework/base/src/abi/type_description_container.rs:28:45 | 28 | .find(|(existing_type_name, _)| &existing_type_name.abi == abi_type_name) | -----------------------^^^^^^^^^^^^^^^^^ | | | help: use the left value directly: `existing_type_name.abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref = note: `#[warn(clippy::op_ref)]` on by default
Raw output
framework/base/src/abi/type_description_container.rs:28:45:w:warning: needlessly taken reference of left operand
  --> framework/base/src/abi/type_description_container.rs:28:45
   |
28 |             .find(|(existing_type_name, _)| &existing_type_name.abi == abi_type_name)
   |                                             -----------------------^^^^^^^^^^^^^^^^^
   |                                             |
   |                                             help: use the left value directly: `existing_type_name.abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
   = note: `#[warn(clippy::op_ref)]` on by default


__END__

Check warning on line 28 in framework/base/src/abi/type_description_container.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] framework/base/src/abi/type_description_container.rs#L28

warning: needlessly taken reference of left operand --> framework/base/src/abi/type_description_container.rs:28:45 | 28 | .find(|(existing_type_name, _)| &existing_type_name.abi == abi_type_name) | -----------------------^^^^^^^^^^^^^^^^^ | | | help: use the left value directly: `existing_type_name.abi` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref = note: `#[warn(clippy::op_ref)]` on by default
Raw output
framework/base/src/abi/type_description_container.rs:28:45:w:warning: needlessly taken reference of left operand
  --> framework/base/src/abi/type_description_container.rs:28:45
   |
28 |             .find(|(existing_type_name, _)| &existing_type_name.abi == abi_type_name)
   |                                             -----------------------^^^^^^^^^^^^^^^^^
   |                                             |
   |                                             help: use the left value directly: `existing_type_name.abi`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
   = note: `#[warn(clippy::op_ref)]` on by default


__END__
.map(|(_, description)| description)
}

pub fn find_or_default(&self, abi_type_name: &str) -> TypeDescription {
if let Some(type_description) = self.find(abi_type_name) {
type_description.clone()
} else {
TypeDescription {
docs: Vec::new(),
names: TypeNames::from_abi(abi_type_name.to_owned()),
contents: TypeContents::NotSpecified,
macro_attributes: Vec::new(),
}
}
}
}

impl TypeDescriptionContainer for TypeDescriptionContainerImpl {
fn new() -> Self {
TypeDescriptionContainerImpl(Vec::new())
Expand Down
5 changes: 4 additions & 1 deletion framework/meta-lib/src/abi_json/contract_abi_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ pub fn convert_json_to_type_descriptions(
) -> TypeDescriptionContainerImpl {
let mut type_descriptions = TypeDescriptionContainerImpl::new();
for (type_name, type_description) in types.into_iter() {
type_descriptions.insert(type_name, TypeDescription::from(&type_description));
type_descriptions.insert(
TypeNames::from_abi(type_name),
TypeDescription::from(&type_description),
);
}
type_descriptions
}
Expand Down
4 changes: 2 additions & 2 deletions framework/meta-lib/src/abi_json/endpoint_abi_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl From<&InputAbiJson> for InputAbi {
fn from(abi: &InputAbiJson) -> Self {
InputAbi {
arg_name: abi.arg_name.to_string(),
type_names: abi.type_names.clone(),
type_names: TypeNames::from_abi(abi.type_name.clone()),
multi_arg: abi.multi_arg.unwrap_or(false),
}
}
Expand Down Expand Up @@ -69,7 +69,7 @@ impl From<&OutputAbiJson> for OutputAbi {
fn from(abi: &OutputAbiJson) -> Self {
OutputAbi {
output_name: abi.output_name.clone(),
type_names: abi.type_name.clone(),
type_names: TypeNames::from_abi(abi.type_name.clone()),
multi_result: abi.multi_result.unwrap_or(false),
}
}
Expand Down
3 changes: 2 additions & 1 deletion framework/meta-lib/src/abi_json/type_abi_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ impl From<&TypeDescriptionJson> for TypeDescription {
};
TypeDescription {
docs: abi.docs.iter().map(|line| line.to_string()).collect(),
name: "".to_string(),
names: TypeNames::new(),
contents: content_type,
macro_attributes: Vec::new(),
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions framework/scenario/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ pathdiff = "0.2.1"
itertools = "0.13.0"
colored = "2.0"
unwrap-infallible = "0.1.5"
clap = { version = "4.4.7", features = ["derive"] }
tokio = { version = "1.24" }

[[bin]]
name = "sc-scenario"
path = "src/main.rs"

[features]
default = ["wasm-incompatible"]
Expand Down

0 comments on commit f634b3f

Please sign in to comment.