README
Solc import
Install
npm install solc-import
usage
- combineSource
let myDB = new Map();
myDB.set('lib.sol', 'library L { function f() internal returns (uint) { return 7; } }');
const getImportContent = async function (path) {
return myDB.get(path);
};
const sourceCodeIncludeImport = `
import 'lib.sol';
contract Casino {
using SafeMath for uint256;
function example(uint256 _value) {
uint number = msg.value.add(_value);
}
}`;
let sources = await solcImport.combineSource(sourceCodeIncludeImport, getImportContent);
// [{ path: 'lib.sol', content: '....'}]
- getImports
const sourceCode = `
import 'https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol';
contract Casino {
using SafeMath for uint256;
function example(uint256 _value) {
uint number = msg.value.add(_value);
}
}`;
let imports = solcImport.getImports(sourceCode);
// ['https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol']
- getReadCallback
const sourceCode = `
pragma solidity >0.4.99 <0.6.0;
import "lib.sol";
library OldLibrary {
function someFunction(uint8 a) public returns(bool);
}
contract NewContract {
function f(uint8 a) public returns (bool) {
return OldLibrary.someFunction(a);
}
}`;
let libContent = 'library L { function f() internal returns (uint) { return 7; } }';
let myDB = new Map();
myDB.set('lib.sol', libContent);
const getImportContent = async function (path) {
return myDB.get(path);
};
let readCallback = await solcImport.getReadCallback(sourceCode, getImportContent); // function
- isExistImport
const sourceCode = `
pragma solidity >0.4.99 <0.6.0;
import "lib.sol";
library OldLibrary {
function someFunction(uint8 a) public returns(bool);
}
contract NewContract {
function f(uint8 a) public returns (bool) {
return OldLibrary.someFunction(a);
}
}`;
let isExist = solcImport.isExistImport(sourceCode); // true
License
MIT © alincode