Giter Site home page Giter Site logo

solidity-flattener's Introduction

Solidity smart-contract flattened source file generation

Build Status Known Vulnerabilities Coverage Status

Utility to combine all imports to one flatten .sol file

Installation from npm

npm i @poanet/solidity-flattener

Usage

./node_modules/.bin/poa-solidity-flattener ./contracts/example.sol

It will save flattened source of Solidity smart-contract into ./out directory

Installation from source

git clone https://github.com/poanetwork/solidity-flattener
cd solidity-flattener
npm install

You can start script either

npm start "path_to_not_flat_contract_definition_file.sol"

or without paramaters (path to input file will be extracted from ./config.json)

npm start

Expected result:

Success! Flat file ORIGINAL_FILE_NAME_flat.sol is generated to ./out directory

./flatContract.sol - flat .sol file is created in output directory (./out/ by default)

Note: utility doesn't support aliases at import statements

Config

path ./config.json

{
	"inputFilePath": "./demo/src/Oracles.sol",
	"outputDir": "./out"
}

solidity-flattener's People

Contributors

artursudnik avatar dependabot[bot] avatar igorbarinov avatar karimkawambwa avatar kongliangzhong avatar oceanapplications avatar vbaranov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

solidity-flattener's Issues

(Fix) rename repo and

Problem:

  • repo has oracles in the name
  • combine-solidity is not
    Solutions:
  • remove oracles. not sure if we need to add poa- prefix

@rstormsf what do you think will be a good name?
solidity-flattener is taken

solc-flattener ?

Blank lines between classes and functions

The result file does not contains blank lines between classes and functions. That affects readability of source code. I believe there should be blank lines.

0d77e81e615299fde665cd68fb2a4692

I've attached screenshot. Left side is result of sol-merger, right side is result of oracles-combine-solidity

node v18 support

Is there a chance to support 18 nodejs in a near future, please?

Bug when you have no `pragma experimental`

The output is empty because const { firstIndex, lastIndex } = getFirstPragmaExp(content) the firstIndex and lastIndex are -1 -1.

function removeDuplicatedExpHeaders(content) {
//1st pragma solidity declaration
const { firstIndex, lastIndex } = getFirstPragmaExp(content)
const contentPart = content.substr(lastIndex)
let contentFiltered = contentPart
//remove other pragma solidity declarations
const regex = new RegExp(pragmaExperimentalstr,'gi')
let result
while ( (result = regex.exec(contentPart)) ) {
const start = result.index
const end = start + contentPart.substr(start).indexOf(SEMICOLON) + 1
if (start != firstIndex) contentFiltered = contentFiltered.replace(contentPart.substring(start, end), EMPTY)
}
return contentFiltered
}

Recursive search fails and hangs for ./ imports

The recursive search for imports such as import './BasicToken.sol'; fails and hangs.

For example it hangs like so after:

!!!zeppelin-solidity/contracts/token/StandardToken.sol SOURCE FILE NOT FOUND. TRY TO FIND IT RECURSIVELY!!!
###zeppelin-solidity/contracts/token/StandardToken.sol SOURCE FILE FOUND###
!!!../myproject/node_modules/zeppelin-solidity/contracts/token/./BasicToken.sol SOURCE FILE NOT FOUND. TRY TO FIND IT RECURSIVELY!!!

Issue with totalSupply()

Guys can someone help me with error i'm getting while testing ,

3 passing (5s)
1 failing

  1. Contract: Color
    minting
    creates a new token:
    TypeError: contract.totalSupply is not a function

Weird behavior double contracts

Steps:

https://github.com/rstormsf/oracles-presale/tree/removeWhitelist - git clone this branch
run npm start contracts/PresaleOracles.sol

get generated file:
https://gist.github.com/rstormsf/d5f14b4280fe956f95df66582d78a461

Notice a few issues:

  1. Double BasicToken
  2. Double Safemath
  3. Double PresaleOracles

Critical:
I don't understand where BasicToken comes from with safeSub code.
Example:
https://gist.github.com/rstormsf/d5f14b4280fe956f95df66582d78a461#file-presaleoracles_flat-sol-L197

It should only have this BasicToken contract:
https://gist.github.com/rstormsf/d5f14b4280fe956f95df66582d78a461#file-presaleoracles_flat-sol-L90

Everything below line 187 should be removed:
https://gist.github.com/rstormsf/d5f14b4280fe956f95df66582d78a461#file-presaleoracles_flat-sol-L187

Another question: Where does it get wrong BasicToken with old usage of old SafeMath lib?

Uncertainty of pragma compiler directive

Result file contains only one pragma compiler version that was chosen with some algorithm.
If input files contain different pragma compiler versions then it could makes sense to display warning about that.

contracts under openzeppelin are not included

used poa-solidity-flattener to flatten my contract to upload to etherscan. xxx_flat.sol was generated successfully but we have some @OpenZeppelin dependencies, like IERC20, Context... were not be included in the final xxx_falt.sol. Not sure what happened. Here are some messages saying those files are not found in the beginning, but found later. But they are not included in the output file.

{"name":"solidity-flattener","hostname":"kimiwude-mbp.lan","pid":96101,"level":40,"msg":"!!! @openzeppelin/contracts-ethereum-package/contracts/math/SignedSafeMath.sol SOURCE FILE WAS NOT FOUND. I'M TRYING TO FIND IT RECURSIVELY !!!","time":"2020-10-26T07:47:54.428Z","v":0}
{"name":"solidity-flattener","hostname":"kimiwude-mbp.lan","pid":96101,"level":30,"msg":"@openzeppelin/contracts-ethereum-package/contracts/math/SignedSafeMath.sol SOURCE FILE WAS FOUND","time":"2020-10-26T07:47:54.439Z","v":0}
...
{"name":"solidity-flattener","hostname":"kimiwude-mbp.lan","pid":95092,"level":40,"msg":"!!! @openzeppelin/contracts/token/ERC20/IERC20.sol SOURCE FILE WAS NOT FOUND. I'M TRYING TO FIND IT RECURSIVELY !!!","time":"2020-10-26T07:32:36.865Z","v":0}
{"name":"solidity-flattener","hostname":"kimiwude-mbp.lan","pid":95092,"level":30,"msg":"@openzeppelin/contracts/token/ERC20/IERC20.sol SOURCE FILE WAS FOUND","time":"2020-10-26T07:32:36.875Z","v":0}

poa-solidity-flattener version: 3.0.6
build environment: buidler

File outside of allowed directories

Getting this error:

Error: Source "util/Ownable.sol" not found: File outside of allowed directories.
import "../util/Ownable.sol";

Usually can be solved with solc using:

--allow-paths `pwd`/util

But how about your tool?

there is issue with the commit: "change-relative-path-to-absolute helper"

After i reverted the change, the lib works.
It stops when try to find "../math/SafeMath.sol".

Error message is:

!!!zeppelin-solidity/contracts/crowdsale/Crowdsale.sol SOURCE FILE NOT FOUND. TRY TO FIND IT RECURSIVELY!!!
###zeppelin-solidity/contracts/crowdsale/Crowdsale.sol SOURCE FILE FOUND###
!!!zeppelin-solidity/contracts/token/MintableToken.sol SOURCE FILE NOT FOUND. TRY TO FIND IT RECURSIVELY!!!
###zeppelin-solidity/contracts/token/MintableToken.sol SOURCE FILE FOUND###
###./Token.sol SOURCE FILE FOUND###
!!!../math/SafeMath.sol SOURCE FILE NOT FOUND. TRY TO FIND IT RECURSIVELY!!!

Error: Cannot find module 'glob'

I'm getting the following:

module.js:557
    throw err;
    ^

Error: Cannot find module 'glob'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/glaksmono/Documents/solidity-flattener/index.js:3:14)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node index.js "../LYKECOIN/contracts/LykeCoinCrowdsale.sol"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/glaksmono/.npm/_logs/2018-02-19T14_01_14_587Z-debug.log

Flattener hangs due to css import rule

Contracts may use the css @import rule when constructing svgs, the flattener mistakes these for solidity imports and hangs due to being unable to find the file, which doesn't exist

string[0] memory parts;
parts[0] = '<svg xmlns="http://www.w3.org/2000/svg"><style>@import url("https://use.typekit.net/nln0qsp.css");</style></svg>';

Publish to NPM

Hey thanks for working on this.

Is there any reason this isn't published to npm?

Not combining all scripts at windows

Hi,
i tested oracles-combine-solidity with my smart contracts and smart contracts that were published on github for educational purposes - and used in youtube tutorial (https://www.youtube.com/watch?v=ShW2zQcY4LY) .

Issue is that when i run npm start path_to_sol_file i get this otuput:

[email protected] start C:\oracles-combine-solidity

node index.js "C:\emx\contracts\emxCrowdSale.sol"

!!!zeppelin-solidity/contracts/crowdsale/Crowdsale.sol SOURCE FILE NOT FOUND. TRY TO FIND IT RECURSIVELY!!!
###zeppelin-solidity/contracts/crowdsale/Crowdsale.sol SOURCE FILE FOUND###
!!!zeppelin-solidity/contracts/token/MintableToken.sol SOURCE FILE NOT FOUND. TRY TO FIND IT RECURSIVELY!!!
###zeppelin-solidity/contracts/token/MintableToken.sol SOURCE FILE FOUND###
###./emrToken.sol SOURCE FILE FOUND###
!!!zeppelin-solidity/contracts/token/MintableToken.sol SOURCE FILE NOT FOUND. TRY TO FIND IT RECURSIVELY!!!
###zeppelin-solidity/contracts/token/MintableToken.sol SOURCE FILE FOUND###
Success! Flat file is generated to ./out directory

but in output file there are only functions/contracts that i created (or the ones from test project that i mentioned above) and not any other like MintableToken etc. What could i do?

My npm details:

npm version
{ 'oracles-combine-solidity': '1.0.0',
npm: '5.4.2',
ares: '1.10.1-DEV',
cldr: '31.0.1',
http_parser: '2.7.0',
icu: '59.1',
modules: '57',
nghttp2: '1.25.0',
node: '8.5.0',
openssl: '1.0.2l',
tz: '2017b',
unicode: '9.0',
uv: '1.14.1',
v8: '6.0.287.53',
zlib: '1.2.11' }

best regards,
Tadej

Remove duplicate license items

To elimiate errors like this:

ParserError: Multiple SPDX license identifiers found in source file. Use “AND” or “OR” to combine multiple licenses. Please see https://spdx.org for more information.

Import from node_modules

It doesn't work for imports like:

import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";

Contracts placed in wrong order

Sometimes Iterface/Parent contracts are placed after the inheritant contract, will lead to the following error:

Error: Identifier not found or not unique.
  --> out/SignedRequest_flat.sol:18:27:
   |
18 | contract SecurityStore is DataStore
   |                           ^^^^^^^^^

Wrong order

myc:32:24: TypeError: Definition of base has to precede definition of derived contract
contract BasicToken is ERC20Basic {
                       ^--------^

when I tried to combine some token contract it didn't give me the correct order.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.