Skip to content

Commit

Permalink
Fix regression of stateMutability not being included in ABI
Browse files Browse the repository at this point in the history
Closes #557
  • Loading branch information
cburgdorf committed May 26, 2022
1 parent 4d290ae commit 3bdd9cd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit 3bdd9cd

Please sign in to comment.