From 3bc66347db81ff28db427a9110c0c1f48281f23e Mon Sep 17 00:00:00 2001 From: Christoph Burgdorf Date: Thu, 26 May 2022 15:03:28 +0200 Subject: [PATCH] Fix regression of stateMutability not being included in ABI --- crates/abi/src/function.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/abi/src/function.rs b/crates/abi/src/function.rs index fb204e6fe9..242e970eb0 100644 --- a/crates/abi/src/function.rs +++ b/crates/abi/src/function.rs @@ -4,6 +4,16 @@ 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")] @@ -11,6 +21,8 @@ pub struct AbiFunction { name: String, inputs: Vec, outputs: Vec, + #[serde(rename = "stateMutability")] + state_mutability: StateMutability } impl AbiFunction { @@ -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 } } @@ -137,7 +153,7 @@ mod tests { &[ Token::Struct { name: "AbiFunction", - len: 4, + len: 5, }, Token::Str("type"), Token::UnitVariant { @@ -185,6 +201,8 @@ mod tests { Token::String("uint64"), Token::MapEnd, Token::SeqEnd, + Token::Str("stateMutability"), + Token::UnitVariant { name: "StateMutability", variant: "payable", }, Token::StructEnd, ], )