Skip to content

Commit

Permalink
Merge pull request #75 from naddison36/feat/storage
Browse files Browse the repository at this point in the history
Fixed finding inherited contracts for storage diagrams
  • Loading branch information
naddison36 authored Jul 25, 2022
2 parents b2f3a80 + 6296c04 commit 5105bc8
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 15 deletions.
Binary file added examples/inheritanceDiamond.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions examples/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,20 @@ This is a contrived example where structs depend on other structs [fileLevel.sol

![FileLevel](./FileLevel-storage.png)

## Contract Inheritance

The following example shows the storage slots with contract inheritance. This includes diamond inheritance, imports from other files and import aliases.

![Inheritance Class Diagram](../inheritanceDiamond.png)

```
sol2uml class -c -f png -o examples/inheritanceDiamond.png ./src/contracts/inheritance
```

The storage slots for contract `D` in [inheritance/common.sol](../../src/contracts/inheritance/common.sol).

![Inheritance](./inheritanceStorage.png)

```
storage -v -c D -o examples/storage/inheritanceStorage.svg ./src/contracts/inheritance
```
Binary file modified examples/storage/TestStorage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/storage/inheritanceStorage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions lib/converterClasses2Storage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions lib/sol2uml.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sol2uml",
"version": "2.0.0",
"version": "2.0.1",
"description": "Unified Modeling Language (UML) class diagram generator for Solidity contracts",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
7 changes: 3 additions & 4 deletions src/ts/converterClasses2Storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Attribute, AttributeType, ClassStereotype, UmlClass } from './umlClass'
import { findAssociatedClass } from './associations'

export enum StorageType {
Contract,
Expand Down Expand Up @@ -83,12 +84,10 @@ const parseStorage = (
)
// Recursively parse each new inherited contract
newInheritedContracts.forEach((parent) => {
const parentClass = umlClasses.find(
(umlClass) => umlClass.name === parent.targetUmlClassName
)
const parentClass = findAssociatedClass(parent, umlClass, umlClasses)
if (!parentClass)
throw Error(
`Failed to find parent contract ${parent.targetUmlClassName} of ${umlClass.name}`
`Failed to find parent contract ${parent.targetUmlClassName} of ${umlClass.absolutePath}`
)
// recursively parse inherited contract
parseStorage(
Expand Down
7 changes: 1 addition & 6 deletions src/ts/sol2uml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,9 @@ program
combinedOptions
)

const filteredUmlClasses = classesConnectedToBaseContracts(
umlClasses,
[combinedOptions.contractName || contractName]
)

const storageObjects = convertClasses2StorageObjects(
combinedOptions.contractName || contractName,
filteredUmlClasses
umlClasses
)
if (isAddress(fileFolderAddress)) {
// The first object is the contract
Expand Down

0 comments on commit 5105bc8

Please sign in to comment.