solc-import-fix

0.0.2 • Public • Published

Solc import

Travis codecovnpm downloads Dependency Status

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

Package Sidebar

Install

npm i solc-import-fix

Weekly Downloads

8

Version

0.0.2

License

MIT

Unpacked Size

15.4 kB

Total Files

17

Last publish

Collaborators

  • koishi