Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program would not terminate if two contracts import each other. #2

Open
Jonah246 opened this issue Aug 30, 2018 · 1 comment
Open

Comments

@Jonah246
Copy link

Reproduce

pragma solidity ^0.4.24;
import "./B.sol";
contract A {
  B kid;
  constructor() public {
    kid = new B();
  }
}
pragma solidity ^0.4.24;
import "./A.sol";
contract B {
  A mom;
  constructor() publicv{
    mom = A(msg.sender);
  }
}

Recommend fix

def unfold_imports(imports, infile):
    buffer = []

    if infile not in imports:
        # should add to traversed paths here.
        imports.append(infile)
        with open(infile, "r+") as f:
            for line in f:
                # Remove the pragma line in all imports
                if "pragma" in line[:6]:
                    continue

                # Read the imports
                if "import" in line[:6]:
                    match = re.search(r".*[\'|\"](.*)[\'|\"]", line)
                    if match:
                        dirname = os.path.dirname(infile)
                        file = os.path.join(dirname, match.group(1))
                        absfile = os.path.abspath(file)

                        buffer.append(unfold_imports(imports, absfile))
                        # imports.append(absfile)
                    else:
                        print("There's syntax error of import in {}".format(infile))
                        sys.exit(-3)
                else:
                    buffer.append(line)

    return ''.join(buffer)
@Jonah246
Copy link
Author

最近寫合約真的有用到這支程式!!有用有推

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant