Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nourharidy committed Sep 5, 2018
1 parent 70e8168 commit 6a2bd8f
Show file tree
Hide file tree
Showing 17 changed files with 3,955 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Lamarkaz
Copyright (c) 2018 Nour Haridy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 20 additions & 0 deletions docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var Handlebars = require('handlebars');
var template = require('./template.js');
var fs = require('fs')

module.exports = function(contracts){
for (var contract in contracts) {
contracts[contract].source = Object.keys(contracts[contract].sources)[0]
for (var func in contracts[contract].output.abi) {
for (var dd in contracts[contract].output.devdoc.methods) {
if(dd.startsWith(contracts[contract].output.abi[func].name)){
contracts[contract].output.abi[func].devdoc = contracts[contract].output.devdoc.methods[dd]
}
}
}
}
//console.log(JSON.stringify(contracts[0].output.abi, null, 2))
var templ = Handlebars.compile(template);
var output = templ({contracts});
fs.writeFileSync(process.cwd() + '/docs/README.md',output,{encoding:'utf8',flag:'w'})
}
1 change: 1 addition & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
secrets.json
135 changes: 135 additions & 0 deletions example/ABI/Token_sol-Token.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
[
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function",
"signature": "0x06fdde03"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function",
"signature": "0x18160ddd"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function",
"signature": "0x313ce567"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "balance",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function",
"signature": "0x70a08231"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function",
"signature": "0x95d89b41"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function",
"signature": "0xa9059cbb"
},
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_from",
"type": "address"
},
{
"indexed": true,
"name": "_to",
"type": "address"
},
{
"indexed": false,
"name": "_value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event",
"signature": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
}
]
45 changes: 45 additions & 0 deletions example/contractor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module.exports = {
dev: { // Ganache-cli options (https://github.com/trufflesuite/ganache-cli)
port:8555,
total_accounts:10,
locked:false,
debug:false,
//logger:console,
gasPrice: 0
},
contracts : "*", // To select specific contracts, replace it with an array: ["File1.sol", "Folder/File2.sol"]
solc: { // Solidity compiler options (https://solidity.readthedocs.io/en/develop/using-the-compiler.html)
optimizer: {
enabled: true,
// Optimize for how many times you intend to run the code.
// Lower values will optimize more for initial deployment cost, higher values will optimize more for high-frequency usage.
runs: 200
},
evmVersion: "byzantium", // Version of the EVM to compile for. Affects type checking and code generation. Can be homestead, tangerineWhistle, spuriousDragon, byzantium or constantinople
// UNCOMMENT IF USING LIBRARIES: Addresses of the libraries. If not all libraries are given here, it can result in unlinked objects whose output data is different.
// libraries: {
// // The top level key is the the name of the source file where the library is used.
// // If remappings are used, this source file should match the global path after remappings were applied.
// // If this key is an empty string, that refers to a global level.
// "myFile.sol": {
// "MyLib": "0x123123..."
// }
// },
outputSelection: {
"*": {
"*": [ "metadata", "evm.bytecode", "devdoc" ]
}
}
},
deployer: async function (contracts, network, web3, test) {
for (var contract in contracts) {
var gasPrice = "50000000000"; //50 Gwei
if(network === "dev") {
gasPrice = "0";
}
contracts[contract] = await contracts[contract].deploy().send({from: web3.eth.accounts[0], gasPrice, gas:1000000})
console.log(contract + " deployed at address " + contracts[contract].options.address)
}
test(contracts, network) // Call the test function if you want to run unit tests after deployment. Tests will only run if network is dev
}
}
38 changes: 38 additions & 0 deletions example/contracts/Token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pragma solidity ^0.4.24;

/// @title A very minimal token contract
contract Token {

uint256 public totalSupply = 1*10**28;
string public name = "Token";
uint8 public decimals = 18;
string public symbol = "TOK";
mapping (address => uint256) balances;
event Transfer(address indexed _from, address indexed _to, uint256 _value);

constructor() public {
balances[msg.sender] = totalSupply;
}

/// @author Nour Haridy
/// @dev Transfers tokens
/// @param _to The address of the transfer recipient
/// @param _value The amount of tokens to be transferred
/// @return true if tokens transferred successfully
function transfer(address _to, uint256 _value) public returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}

/// @author Nour Haridy
/// @dev Checks balance of address
/// @param _owner The queried address
/// @return balance of address
function balanceOf(address _owner) constant public returns (uint256 balance) {
return balances[_owner];
}

}
46 changes: 46 additions & 0 deletions example/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

# Smart Contract Documentation


## [Token.sol:Token](../contracts/Token.sol)
`Solidity version 0.4.24+commit.e67f0147`
A very minimal token contract

##### function name constant view `0x06fdde03`


##### function totalSupply constant view `0x18160ddd`


##### function decimals constant view `0x313ce567`


##### function balanceOf constant view `0x70a08231` by Nour Haridy
Checks balance of address

Type | Name |
--- | --- |
| address | _owner |
##### function symbol constant view `0x95d89b41`


##### function transfer nonpayable `0xa9059cbb` by Nour Haridy
Transfers tokens

Type | Name |
--- | --- |
| address | _to |
| uint256 | _value |
##### constructor nonpayable `constructor`


##### event Transfer `0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef`


Type | Name |
--- | --- |
| address | _from |
| address | _to |
| uint256 | _value |

---
7 changes: 7 additions & 0 deletions example/tests/Token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe('Token.sol', function() {
describe('Transfer()', function() {
it('should revert when transferred amount is smaller than 0', function() {
contracts['Token.sol:Token'].methods.transfer(address0, -1).send().on('error', (e) => assertRevert(e))
});
});
});
Loading

0 comments on commit 6a2bd8f

Please sign in to comment.