Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to string if bytevector decoding fails #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/model/transaction/invoke_script_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
}

impl InvokeScriptTransaction {
pub fn from_json(value: &Value) -> Result<InvokeScriptTransaction> {

Check failure on line 154 in src/model/transaction/invoke_script_transaction.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large

error: the `Err`-variant returned from this function is very large --> src/model/transaction/invoke_script_transaction.rs:154:40 | 154 | pub fn from_json(value: &Value) -> Result<InvokeScriptTransaction> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ::: src/error.rs:62:5 | 62 | / UnsupportedTransactionVersion { 63 | | actual_version: u8, 64 | | supported_version: u8, 65 | | tx_type: TransactionData, 66 | | }, | |_____- the largest variant contains at least 434 bytes | = help: try reducing the size of `error::Error`, for example by boxing large elements or replacing it with `Box<error::Error>` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
let dapp =
Address::from_string(&JsonDeserializer::safe_to_string_from_field(value, "dApp")?)?;
let function: Function = value.try_into()?;
Expand Down Expand Up @@ -198,7 +198,7 @@
List(Vec<Arg>),
}

fn map_payment(value: &Value) -> Result<Vec<Amount>> {

Check failure on line 201 in src/model/transaction/invoke_script_transaction.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large

error: the `Err`-variant returned from this function is very large --> src/model/transaction/invoke_script_transaction.rs:201:34 | 201 | fn map_payment(value: &Value) -> Result<Vec<Amount>> { | ^^^^^^^^^^^^^^^^^^^ | ::: src/error.rs:62:5 | 62 | / UnsupportedTransactionVersion { 63 | | actual_version: u8, 64 | | supported_version: u8, 65 | | tx_type: TransactionData, 66 | | }, | |_____- the largest variant contains at least 434 bytes | = help: try reducing the size of `error::Error`, for example by boxing large elements or replacing it with `Box<error::Error>` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
JsonDeserializer::safe_to_array_from_field(value, "payment")?
.iter()
.map(|payment| {
Expand All @@ -212,7 +212,7 @@
.collect::<Result<Vec<Amount>>>()
}

fn map_args(value: &Value) -> Result<Vec<Arg>> {

Check failure on line 215 in src/model/transaction/invoke_script_transaction.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large

error: the `Err`-variant returned from this function is very large --> src/model/transaction/invoke_script_transaction.rs:215:31 | 215 | fn map_args(value: &Value) -> Result<Vec<Arg>> { | ^^^^^^^^^^^^^^^^ | ::: src/error.rs:62:5 | 62 | / UnsupportedTransactionVersion { 63 | | actual_version: u8, 64 | | supported_version: u8, 65 | | tx_type: TransactionData, 66 | | }, | |_____- the largest variant contains at least 434 bytes | = help: try reducing the size of `error::Error`, for example by boxing large elements or replacing it with `Box<error::Error>` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
let mut args: Vec<Arg> = vec![];
for arg in JsonDeserializer::safe_to_array(value)? {
let arg = match JsonDeserializer::safe_to_string_from_field(&arg, "type")?.as_str() {
Expand All @@ -225,9 +225,13 @@
"integer" | "Int" => {
Arg::Integer(JsonDeserializer::safe_to_int_from_field(&arg, "value")?)
}
"binary" | "ByteVector" => Arg::Binary(Base64String::from_string(
&JsonDeserializer::safe_to_string_from_field(&arg, "value")?,
)?),
"binary" | "ByteVector" => {
let val = JsonDeserializer::safe_to_string_from_field(&arg, "value")?;
match Base64String::from_string(&val) {
Ok(b) => Arg::Binary(b),
Err(_) => Arg::String(val),
}
}
"list" | "List" | "Array" => {
let result = map_args(&arg["value"])?;
Arg::List(result)
Expand Down
Loading