Skip to content

Commit

Permalink
L-10 Only allow external in sol_interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rory-ocl committed Aug 21, 2024
1 parent 4167123 commit 6737f50
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
15 changes: 11 additions & 4 deletions stylus-proc/src/calls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub fn sol_interface(input: TokenStream) -> TokenStream {

// determine the purity
let mut purity = None;
let mut external = false;
for attr in &func.attributes.0 {
match attr {
FunctionAttribute::Mutability(mutability) => {
Expand All @@ -69,14 +70,20 @@ pub fn sol_interface(input: TokenStream) -> TokenStream {
}
});
}
FunctionAttribute::Visibility(vis) => {
if let Visibility::Internal(_) | Visibility::Private(_) = vis {
error!(vis.span(), "internal method in interface");
FunctionAttribute::Visibility(vis) => match vis {
Visibility::External(_) => {
external = true;
}
}
_ => {
error!(vis.span(), "visibility must be `external`");
}
},
_ => error!(attr.span(), "unsupported function attribute"),
}
}
if !external {
error!(func.span(), "visibility must be explicty set to `external`");
}
let purity = purity.unwrap_or(Write);

// determine which context and kind of call to use
Expand Down
8 changes: 4 additions & 4 deletions stylus-proc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ pub fn sol_storage(input: TokenStream) -> TokenStream {
/// ```ignore
/// sol_interface! {
/// interface IMethods {
/// function pureFoo() pure;
/// function viewFoo() view;
/// function writeFoo();
/// function payableFoo() payable;
/// function pureFoo() external pure;
/// function viewFoo() external view;
/// function writeFoo() external;
/// function payableFoo() external payable;
/// }
/// }
///
Expand Down
4 changes: 2 additions & 2 deletions stylus-sdk/src/call/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
///
/// sol_interface! {
/// interface IService {
/// function makePayment(address user) payable returns (string);
/// function makePayment(address user) external payable returns (string);
/// }
/// }
///
Expand Down Expand Up @@ -185,7 +185,7 @@ cfg_if! {
///
/// sol_interface! {
/// interface IService {
/// function makePayment(address user) payable returns (string);
/// function makePayment(address user) external payable returns (string);
/// }
/// }
///
Expand Down

0 comments on commit 6737f50

Please sign in to comment.