remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
remix-project/remix-resolve
Omkara d09e4e16f6 Add http call handle, add tests, add more typings 6 years ago
..
src Add http call handle, add tests, add more typings 6 years ago
tests Add http call handle, add tests, add more typings 6 years ago
.gitignore add dist to gitignore 6 years ago
README.md update readme; remove unused requires 6 years ago
package.json Add typescript tests 6 years ago
tsconfig.json Try to implement resolve function in TS 6 years ago
tslint.json Try typescript 6 years ago

README.md

Remix resolve engine

Input

[ 'greeter.sol': { content: 'pragma solidity ^0.5.0;\nimport "./mortal.sol";\n\ncontract Greeter is Mortal {\n    /* Define variable greeting of the type string */\n    string greeting;\n\n    /* This runs when the contract is executed */\n    constructor(string memory _greeting) public {\n        greeting = _greeting;\n    }\n\n    /* Main function */\n    function greet() public view returns (string memory) {\n        return greeting;\n    }\n}\n' } ]

Output

{
	'mortal.sol': { content: 'pragma solidity ^0.5.0;\n\ncontract Mortal {\n    /* Define variable owner of the type address */\n    address payable owner;\n\n    /* This function is executed at initialization and sets the owner of the contract */\n    function mortal() public { owner = msg.sender; }\n\n    /* Function to recover the funds on the contract */\n    function kill() public { if (msg.sender == owner) selfdestruct(owner); }\n}\n' },
	'greeter.sol': { content: 'pragma solidity ^0.5.0;\nimport \'mortal.sol\';\n\ncontract Greeter is Mortal {\n    /* Define variable greeting of the type string */\n    string greeting;\n\n    /* This runs when the contract is executed */\n    constructor(string memory _greeting) public {\n        greeting = _greeting;\n    }\n\n    /* Main function */\n    function greet() public view returns (string memory) {\n        return greeting;\n    }\n}\n' }
}

API

combineSource(sources)

Returns json object with exact same path as import statement.

Output

{
	'./mortal.sol': { content: '...' },
	'greeter.sol': { content: '...' }
}

resolve(path, combinedSources) function should be called from within handleImportCb function of solc.compile(input, handleImportCb).

const rr = require('remix-resolve')
function handleImportCb(path) {
	return rr.resolve(path, combinedSources)
}