Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions crates/core/src/decode/function_call_decoder.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
use serde::Serialize;
use serde_json::Value;

pub type JsonValue = Value;

#[derive(Debug, Clone, Serialize)]
pub struct DecodedArgument {
pub name: String,

pub value: JsonValue,

pub formatted: String,
}

#[derive(Debug, Clone, Serialize)]
pub struct DecodedFunctionCall {
pub function_name: String,

pub arguments: Vec<DecodedArgument>,

pub return_value: Option<JsonValue>,

pub formatted_return_value: Option<String>,
}

pub struct FunctionCallDecoder;

impl FunctionCallDecoder {
pub fn new() -> Self {
Self
}
}
1 change: 0 additions & 1 deletion crates/core/src/decode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod auth;
pub mod auth_address_nonce;
pub mod auth_signature;
pub mod chain_analyzer;
pub mod context;
pub mod contract_error;
pub mod contract_error_resolver;
pub mod cross_contract;
Expand Down
10 changes: 5 additions & 5 deletions crates/core/src/decode/return_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl ReturnValueDecoder {
},
ScSpecTypeDef::Address => match val {
ScVal::Address(addr) => {
json!(crate::types::address::Address::from_sc_address(addr).to_string())
json!(addr.to_string())
}
_ => Self::decode_dynamic(val),
},
Expand Down Expand Up @@ -400,7 +400,7 @@ impl ReturnValueDecoder {
ScVal::String(s) => json!(s.to_string()),
ScVal::Symbol(s) => json!(s.to_string()),
ScVal::Address(addr) => {
json!(crate::types::address::Address::from_sc_address(addr).to_string())
json!(addr.to_string())
}
ScVal::Error(e) => json!(format!("{e:?}")),
ScVal::Vec(Some(v)) => {
Expand Down Expand Up @@ -438,7 +438,7 @@ impl ReturnValueDecoder {
mod tests {
use super::*;
use crate::spec::decoder::{ContractStructField, ContractStructDef};
use stellar_xdr::curr::{ScSymbol, ScVec, VecM};
use stellar_xdr::curr::{ScString, ScSymbol};

#[test]
fn test_primitive_return_decoding() {
Expand Down Expand Up @@ -498,7 +498,7 @@ mod tests {
},
stellar_xdr::curr::ScMapEntry {
key: ScVal::Symbol(ScSymbol("name".try_into().unwrap())),
val: ScVal::String("Alice".try_into().unwrap()),
val: ScVal::String(ScString("Alice".try_into().unwrap())),
},
]
.try_into()
Expand All @@ -508,7 +508,7 @@ mod tests {
let decoded = decoder.decode(
&map_val,
Some(&ScSpecTypeDef::Udt(stellar_xdr::curr::ScSpecTypeUdt {
name: ScSymbol("User".try_into().unwrap()),
name: "User".try_into().unwrap(),
})),
Some(&contract_spec),
);
Expand Down
120 changes: 53 additions & 67 deletions crates/core/src/spec/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,72 +221,51 @@ pub fn decode_contract_spec(wasm_bytes: &[u8]) -> GratResult<ContractSpec> {
doc,
});
}
ScSpecEntry::UdtUnionV0(union_spec) => {
let union_name = union_spec.name.to_string();
let doc = if union_spec.doc.is_empty() {
None
} else {
Some(union_spec.doc.to_string())
};
let mut cases = Vec::new();
for case in union_spec.cases.iter() {
match case {
stellar_xdr::curr::ScSpecUdtUnionCaseV0::VoidV0(c) => {
let case_doc = if c.doc.is_empty() {
None
} else {
Some(c.doc.to_string())
};
cases.push(ContractUnionCase {
name: c.name.to_string(),
doc: case_doc,
value_types: None,
fields: None,
});
}
stellar_xdr::curr::ScSpecUdtUnionCaseV0::TupleV0(c) => {
let case_doc = if c.doc.is_empty() {
None
} else {
Some(c.doc.to_string())
};
let value_types: Vec<ScSpecTypeDef> =
c.type_.iter().cloned().collect();
cases.push(ContractUnionCase {
name: c.name.to_string(),
doc: case_doc,
value_types: Some(value_types),
fields: None,
});
}
stellar_xdr::curr::ScSpecUdtUnionCaseV0::StructV0(c) => {
let case_doc = if c.doc.is_empty() {
None
} else {
Some(c.doc.to_string())
};
let mut fields = Vec::new();
for field in c.fields.iter() {
let field_doc = if field.doc.is_empty() {
None
} else {
Some(field.doc.to_string())
};
fields.push(ContractStructField {
name: field.name.to_string(),
type_name: format_type_def(&field.type_),
doc: field_doc,
type_def: Some(field.type_.clone()),
});
}
cases.push(ContractUnionCase {
name: c.name.to_string(),
doc: case_doc,
value_types: None,
fields: Some(fields),
});
}
enums.push(ContractEnumDef {
name: enum_name,
cases,
doc,
});
}
ScSpecEntry::UdtUnionV0(union_spec) => {
let union_name = union_spec.name.to_string();
let doc = if union_spec.doc.is_empty() {
None
} else {
Some(union_spec.doc.to_string())
};
let mut cases = Vec::new();
for case in union_spec.cases.iter() {
match case {
stellar_xdr::curr::ScSpecUdtUnionCaseV0::VoidV0(c) => {
let case_doc = if c.doc.is_empty() {
None
} else {
Some(c.doc.to_string())
};
cases.push(ContractUnionCase {
name: c.name.to_string(),
doc: case_doc,
value_types: None,
fields: None,
});
}
stellar_xdr::curr::ScSpecUdtUnionCaseV0::TupleV0(c) => {
let case_doc = if c.doc.is_empty() {
None
} else {
Some(c.doc.to_string())
};
let value_types: Vec<ScSpecTypeDef> =
c.type_.iter().cloned().collect();
cases.push(ContractUnionCase {
name: c.name.to_string(),
doc: case_doc,
value_types: Some(value_types),
fields: None,
});
}

}
unions.push(ContractUnionDef {
name: union_name,
Expand Down Expand Up @@ -324,8 +303,13 @@ pub fn decode_contract_spec(wasm_bytes: &[u8]) -> GratResult<ContractSpec> {
doc,
});
}
},
Err(_) => break,

structs.push(ContractStructDef {
name: struct_name,
fields,
doc,
});
}
}
}

Expand Down Expand Up @@ -557,6 +541,8 @@ mod tests {
unions: Vec::new(),
name: None,
version: None,
enums: Vec::new(),
unions: Vec::new(),
};
assert!(resolve_error_code(&spec, 99).is_none());
assert!(resolve_error_code(&spec, 1).is_some());
Expand Down
4 changes: 3 additions & 1 deletion crates/core/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ pub use decoder::{
ContractStructDef, ContractStructField, ContractUnionCase, ContractUnionDef, SpecParser,
};
pub use resolver::{ContractId, ResolverStats, SCSpecResolver};
pub use stellar_xdr::curr::ScSpecUdtStructV0;

#[cfg(test)]
mod tests;
1 change: 1 addition & 0 deletions crates/core/src/spec/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod wasm_tests;
Loading