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

Temporary default stateMutability to payable in ABI #705

Merged
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
3 changes: 2 additions & 1 deletion crates/abi/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::elements::{
Component, Contract, Event, EventField, FuncInput, FuncOutput, FuncType, Function, JsonAbi,
ModuleAbis,
ModuleAbis, StateMutability,
};
use crate::AbiError;
use fe_analyzer::namespace::items::{ContractId, FunctionId, ModuleId};
Expand Down Expand Up @@ -97,6 +97,7 @@ fn function_def(db: &dyn AnalyzerDb, name: &str, fn_id: FunctionId, typ: FuncTyp
typ,
inputs,
outputs,
state_mutability: StateMutability::Payable,
}
}

Expand Down
12 changes: 9 additions & 3 deletions crates/abi/src/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub struct EventField {

/// A function interface.
#[derive(Serialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Function {
/// The function's name.
pub name: String,
Expand All @@ -183,6 +184,8 @@ pub struct Function {
pub inputs: Vec<FuncInput>,
/// All function outputs.
pub outputs: Vec<FuncOutput>,
/// Mutability of the function
pub state_mutability: StateMutability,
}

/// Component of an ABI tuple.
Expand Down Expand Up @@ -250,7 +253,6 @@ pub enum FuncType {
}

/// The mutability of a public function.
#[allow(dead_code)]
#[derive(Serialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "lowercase")]
pub enum StateMutability {
Expand All @@ -262,7 +264,9 @@ pub enum StateMutability {

#[cfg(test)]
mod tests {
use crate::elements::{Contract, Event, EventField, FuncInput, FuncOutput, FuncType, Function};
use crate::elements::{
Contract, Event, EventField, FuncInput, FuncOutput, FuncType, Function, StateMutability,
};

#[test]
fn contract_json() {
Expand Down Expand Up @@ -291,6 +295,7 @@ mod tests {
typ: "uint256".to_string(),
components: vec![],
}],
state_mutability: StateMutability::Payable,
}],
};

Expand All @@ -313,7 +318,8 @@ mod tests {
"name":"function_name",
"type":"function",
"inputs":[{"name":"input_name","type":"address"}],
"outputs":[{"name":"output_name","type":"uint256"}]
"outputs":[{"name":"output_name","type":"uint256"}],
"stateMutability":"payable"
}
]"#
.split_whitespace()
Expand Down
5 changes: 5 additions & 0 deletions newsfragments/705.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Temporary default stateMutability to payable in ABI

The ABI metadata that the compiler currently generates does not include the `stateMutability` field. This piece of information is important for tooling such as hardhat because it determines whether a function needs to be called with or without sending a transaction.

As soon as we have support for `mut self` and `mut ctx` we will be able to derive that information from the function signature. In the meantime we now default to `payable`.