-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable transpilation of contracts with @Custom:stateless in peerProj…
…ect mode (#132) Co-authored-by: Francisco <fg@frang.io>
- Loading branch information
Showing
12 changed files
with
112 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
/// @custom:stateless | ||
contract SomeStatelessContract {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import path from 'path'; | ||
|
||
import { Transform } from './transform'; | ||
import { extractContractStorageSize, extractContractStateless } from './utils/natspec'; | ||
import { isStorageVariable } from './transformations/utils/is-storage-variable'; | ||
|
||
export function preparePeerProject(transform: Transform, peerProject: string) { | ||
for (const ast of transform.asts()) { | ||
let shouldExclude = true; | ||
for (const node of ast.nodes) { | ||
switch (node.nodeType) { | ||
case 'ContractDefinition': { | ||
if (node.contractKind === 'contract') { | ||
if (!extractContractStateless(node)) { | ||
shouldExclude = false; | ||
break; | ||
} | ||
if (extractContractStorageSize(node) !== undefined) { | ||
throw transform.error( | ||
node, | ||
'Contract marked as stateless should not have an associated storage size', | ||
); | ||
} | ||
for (const decl of node.nodes) { | ||
if ( | ||
decl.nodeType == 'VariableDeclaration' && | ||
isStorageVariable(decl, transform.resolver) | ||
) { | ||
throw transform.error( | ||
node, | ||
'Contract marked as stateless should not contain storage variable declarations', | ||
); | ||
} | ||
if (decl.nodeType == 'FunctionDefinition' && decl.kind == 'constructor') { | ||
throw transform.error( | ||
node, | ||
'Contract marked as stateless should not have a constructor', | ||
); | ||
} | ||
} | ||
} | ||
transform.getData(node).importFromPeer = path.join(peerProject, ast.absolutePath); | ||
break; | ||
} | ||
case 'EnumDefinition': | ||
case 'ErrorDefinition': | ||
case 'FunctionDefinition': | ||
case 'StructDefinition': | ||
case 'UserDefinedValueTypeDefinition': | ||
case 'VariableDeclaration': { | ||
transform.getData(node).importFromPeer = path.join(peerProject, ast.absolutePath); | ||
break; | ||
} | ||
case 'ImportDirective': | ||
case 'PragmaDirective': | ||
case 'UsingForDirective': { | ||
break; | ||
} | ||
} | ||
} | ||
if (shouldExclude) { | ||
transform.exclude(ast.absolutePath); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters