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

Fix regression of stateMutability not being included in ABI #722

Merged
merged 1 commit into from
May 26, 2022
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
23 changes: 22 additions & 1 deletion crates/abi/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@ use serde::Serialize;

use super::types::AbiType;

/// The mutability of a public function.
#[derive(Serialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "lowercase")]
pub enum StateMutability {
Pure,
View,
Nonpayable,
Payable,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct AbiFunction {
#[serde(rename = "type")]
func_type: AbiFunctionType,
name: String,
inputs: Vec<AbiFunctionParamInner>,
outputs: Vec<AbiFunctionParamInner>,
#[serde(rename = "stateMutability")]
state_mutability: StateMutability,
}

impl AbiFunction {
Expand All @@ -33,6 +45,10 @@ impl AbiFunction {
name,
inputs,
outputs,
// In the future we will derive that based on the fact whether `self` or `ctx` are taken as `mut` or not.
// For now, we default to payable so that tooling such as hardhat simply assumes all functions need to be
// called with a transaction.
state_mutability: StateMutability::Payable,
}
}

Expand Down Expand Up @@ -137,7 +153,7 @@ mod tests {
&[
Token::Struct {
name: "AbiFunction",
len: 4,
len: 5,
},
Token::Str("type"),
Token::UnitVariant {
Expand Down Expand Up @@ -185,6 +201,11 @@ mod tests {
Token::String("uint64"),
Token::MapEnd,
Token::SeqEnd,
Token::Str("stateMutability"),
Token::UnitVariant {
name: "StateMutability",
variant: "payable",
},
Token::StructEnd,
],
)
Expand Down
1 change: 1 addition & 0 deletions newsfragments/722.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a regression where the `stateMutability` field would not be included in the generated ABI