merge bootstrap

This commit is contained in:
Ricardo Guilherme Schmidt 2019-02-14 01:58:09 -02:00
commit 39c3ab481f
No known key found for this signature in database
GPG Key ID: BFB3F5C8ED618A94
34 changed files with 475 additions and 504 deletions

View File

@ -1,4 +1,3 @@
{
"plugins": ["transform-object-rest-spread"],
"presets": ["stage-2"]
"presets": ["@babel/preset-env"]
}

3
.gitignore vendored
View File

@ -6,8 +6,7 @@ __pycache__/
# embark
.embark/
chains.json
config/production/password
config/livenet/password
.password
# egg-related
viper.egg-info/

View File

@ -18,4 +18,4 @@ Usage:
| token/TestToken | Yes | Yes | Yes |
| token/ERC20Token | No | Yes | Yes |
| deploy/Instance | No | No | No |
| deploy/Factory | No | No | No |
| deploy/Factory | No | No | No |

View File

@ -1,10 +1,9 @@
import EmbarkJS from 'Embark/EmbarkJS';
import TestToken from 'Embark/contracts/TestToken';
import StatusRoot from 'Embark/contracts/StatusRoot';
import MiniMeToken from 'Embark/contracts/MiniMeToken';
import React from 'react';
import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap';
import ERC20TokenUI from './erc20token';
import { connect } from 'react-redux';
import { actions as accountActions } from '../reducers/accounts';
class TestTokenUI extends React.Component {
@ -19,25 +18,18 @@ class TestTokenUI extends React.Component {
this.setState({amountToMint: e.target.value});
}
mint(e){
const { addToBalance } = this.props;
async mint(e){
e.preventDefault();
await EmbarkJS.enableEthereum();
var value = parseInt(this.state.amountToMint, 10);
if (EmbarkJS.isNewWeb3()) {
TestToken.methods.mint(value).send({from: web3.eth.defaultAccount})
.then(r => { addToBalance(value) });
} else {
TestToken.mint(value).send({from: web3.eth.defaultAccount})
.then(r => { addToBalance(value) });
}
console.log(TestToken.options.address +".mint("+value+").send({from: " + web3.eth.defaultAccount + "})");
StatusRoot.methods.mint(value).send({ gas: 1000000 })
console.log(StatusRoot.options.address +".mint("+value+").send({from: " + web3.eth.defaultAccount + "})");
}
render(){
return (<React.Fragment>
<h3> Mint Test Token</h3>
<h3> Test Status Network</h3>
<Form inline>
<FormGroup>
<FormControl
@ -48,17 +40,11 @@ class TestTokenUI extends React.Component {
</FormGroup>
</Form>
<ERC20TokenUI address={ TestToken.options.address } />
<ERC20TokenUI address={ MiniMeToken.options.address } />
</React.Fragment>
);
}
}
const mapDispatchToProps = dispatch => ({
addToBalance(amount) {
dispatch(accountActions.addToErc20TokenBalance(amount));
},
});
export default connect(null, mapDispatchToProps)(TestTokenUI);
export default TestTokenUI;

View File

@ -1,37 +0,0 @@
.identicon {
border-radius: 50%;
}
.selectedIdenticon {
border-radius: 50%;
overflow: hidden;
float: left;
margin: 7px 0;
}
.accountHexString {
margin-left: 7px;
width: 267px;
overflow: hidden;
text-overflow: ellipsis;
display:inline-block;
}
.accountBalance {
margin-left: 10px;
overflow: hidden;
display: inline-block;
width:77px;
text-align: center;
text-overflow: ellipsis;
}
.accountList {
float: left;
margin-left: 10px;
}
.account {
display: flex;
align-items: center;
}

View File

@ -1,66 +0,0 @@
import web3 from 'Embark/web3'
import React from 'react';
import { connect } from 'react-redux';
import { Nav, MenuItem, NavDropdown } from 'react-bootstrap';
import Blockies from 'react-blockies';
import { string, bool, func, arrayOf, shape } from 'prop-types';
import { getAccounts, getDefaultAccount, accountsIsLoading, actions as accountActions } from '../reducers/accounts';
import './accountlist.css';
const AccList = ({
accounts, defaultAccount, changeAccount, isLoading, classNameNavDropdown,
}) => (
<React.Fragment>
{!isLoading ?
<div className="accounts">
<div className="selectedIdenticon">
<Blockies seed={defaultAccount} />
</div>
<div className="accountList">
<Nav>
<NavDropdown key={1} title={defaultAccount} id="basic-nav-dropdown" className={classNameNavDropdown}>
{accounts.map(account => (
<MenuItem key={account.address} onClick={() => changeAccount(account.address)}>
<div className="account">
<div className="accountIdenticon">
<Blockies seed={account.address} />
</div>
<div className="accountHexString">
{account.address}
</div>
<div className="accountBalance">
Ξ {account.balance / (10 ** 18)}
</div>
</div>
</MenuItem>
))}
</NavDropdown>
</Nav>
</div>
</div>
: <div>Loading...</div>}
</React.Fragment>
);
AccList.propTypes = {
accounts: arrayOf(shape({ address: string, balance: string })).isRequired,
defaultAccount: string,
changeAccount: func.isRequired,
isLoading: bool.isRequired,
classNameNavDropdown: string
}
const mapStateToProps = state => ({
accounts: getAccounts(state),
defaultAccount: getDefaultAccount(state),
isLoading: accountsIsLoading(state),
});
const mapDispatchToProps = dispatch => ({
changeAccount(address) {
web3.eth.defaultAccount = address;
dispatch(accountActions.updateDefaultAccount(address));
},
});
export default connect(mapStateToProps, mapDispatchToProps)(AccList);

View File

@ -1,9 +1,7 @@
import EmbarkJS from 'Embark/EmbarkJS';
import ERC20Token from 'Embark/contracts/ERC20Token';
import React from 'react';
import { connect } from 'react-redux';
import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap';
import { getCurrentAccount, accountsIsLoading } from '../reducers/accounts';
class ERC20TokenUI extends React.Component {
@ -30,39 +28,34 @@ class ERC20TokenUI extends React.Component {
transfer(e){
var to = this.state.transferTo;
var amount = this.state.transferAmount;
var tx = ERC20Token.methods.transfer(to, amount).send({from: web3.eth.defaultAccount});
this._addToLog(ERC20Token.options.address+".transfer(" + to + ", "+amount+")");
this._addToLog(ERC20Token.options.address+".methods.transfer(" + to + ", "+amount+").send({from: " + web3.eth.defaultAccount + "})");
var tx = ERC20Token.methods.transfer(to, amount);
tx.estimateGas().then((r) => {
tx.send({gas: r, from: web3.eth.defaultAccount});
});
}
approve(e){
var to = this.state.transferTo;
var amount = this.state.transferAmount;
this._addToLog(ERC20Token.options.address+".methods.approve(" + to + ", "+amount+").send({from: " + web3.eth.defaultAccount + "})");
var tx = ERC20Token.methods.approve(to, amount).send({from: web3.eth.defaultAccount});
this._addToLog(ERC20Token.options.address+".approve(" + to + ", "+amount+")");
}
balanceOf(e){
e.preventDefault();
var who = e.target.value;
if (EmbarkJS.isNewWeb3()) {
ERC20Token.methods.balanceOf(who).call()
.then(_value => this.setState({balanceOf: _value}))
} else {
ERC20Token.balanceOf(who)
.then(_value => this.x({balanceOf: _value}));
}
this._addToLog(ERC20Token.options.address+".balanceOf(" + who + ")");
this._addToLog(ERC20Token.options.address+".methods.balanceOf(" + who + ").call()");
ERC20Token.methods.balanceOf(who).call()
.then(_value => this.setState({balanceOf: _value}))
}
getDefaultAccountBalance(){
if (EmbarkJS.isNewWeb3()) {
ERC20Token.methods.balanceOf(web3.eth.defaultAccount).call()
.then(_value => this.setState({accountBalance: _value}))
} else {
ERC20Token.balanceOf(web3.eth.defaultAccount)
.then(_value => this.x({valueGet: _value}))
}
this._addToLog(ERC20Token.options.address + ".balanceOf(" + web3.eth.defaultAccount + ")");
this._addToLog(ERC20Token.options.address + ".methods.balanceOf(" + web3.eth.defaultAccount + ").call()");
ERC20Token.methods.balanceOf(web3.eth.defaultAccount).call()
.then(_value => this.setState({accountBalance: _value}))
}
_addToLog(txt){
@ -70,16 +63,9 @@ class ERC20TokenUI extends React.Component {
}
render() {
const { account, isLoading } = this.props;
return (
<React.Fragment>
<h3> Read your account token balance </h3>
<Form inline>
<FormGroup>
{!isLoading && <HelpBlock>Your test token balance is <span className="accountBalance">{account.ERC20TokenBalance}</span></HelpBlock>}
</FormGroup>
</Form>
<h3> Read account token balance</h3>
<Form inline>
<FormGroup>
@ -122,11 +108,7 @@ class ERC20TokenUI extends React.Component {
</React.Fragment>
);
}
}
}
const mapStateToProps = state => ({
account: getCurrentAccount(state),
isLoading: accountsIsLoading(state),
});
export default connect(mapStateToProps)(ERC20TokenUI);
export default ERC20TokenUI;

View File

@ -1,33 +0,0 @@
import EmbarkJS from 'Embark/EmbarkJS';
import React from 'react';
import { Navbar, NavItem, Nav, MenuItem , NavDropdown} from 'react-bootstrap';
import AccountList from './accountList';
class TopNavbar extends React.Component {
constructor(props) {
super(props);
this.state = {
}
}
render(){
return (
<React.Fragment>
<Navbar>
<Navbar.Header>
<Navbar.Brand>
<a href="#home">Status.im Demo</a>
</Navbar.Brand>
</Navbar.Header>
<AccountList classNameNavDropdown="pull-right" />
</Navbar>
</React.Fragment>
);
}
}
export default TopNavbar;

View File

@ -1,14 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Tabs, Tab } from 'react-bootstrap';
import EmbarkJS from 'Embark/EmbarkJS';
import TopNavbar from './components/topnavbar';
import TestTokenUI from './components/testtoken';
import TestStatusNetworkUI from './components/TestStatusNetwork';
import './dapp.css';
class App extends React.Component {
class DApp extends React.Component {
constructor(props) {
super(props);
@ -17,9 +14,7 @@ class App extends React.Component {
}
componentDidMount(){
__embarkContext.execWhenReady(() => {
});
}
@ -34,14 +29,14 @@ class App extends React.Component {
render(){
return (
<div>
<TopNavbar />
<Tabs defaultActiveKey={1} id="uncontrolled-tab-example">
<Tab eventKey={1} title="TestToken">
<TestTokenUI />
<Tab eventKey={1} title="TestStatusNetwork">
<TestStatusNetworkUI />
</Tab>
</Tabs>
</div>);
}
}
export default App;
export default DApp;

View File

@ -1,16 +1,9 @@
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import store from './store/configureStore';
import App from './dapp';
import init from './store/init'
import DApp from './dapp';
import './dapp.css';
init();
render(
<Provider store={store}>
<App />
</Provider>,
<DApp />,
document.getElementById('app')
);

View File

@ -14,49 +14,60 @@ module.exports = {
rpcCorsDomain: "auto", // Comma separated list of domains from which to accept cross origin requests (browser enforced)
// When set to "auto", Embark will automatically set the cors to the address of the webserver
proxy: true, // Proxy is used to present meaningful information about transactions
account: {
// "address": "", // When specified, uses that address instead of the default one for the network
password: "config/development/password" // Password to unlock the account
},
accounts: [
{
nodeAccounts: true,
password: "config/development/.password"
}
],
targetGasLimit: 8000000, // Target gas limit sets the artificial target gas floor for the blocks to mine
wsRPC: true, // Enable the WS-RPC server
wsOrigins: "auto", // Origins from which to accept websockets requests
// When set to "auto", Embark will automatically set the cors to the address of the webserver
wsHost: "localhost", // WS-RPC server listening interface (default: "localhost")
wsPort: 8546, // WS-RPC server listening port (default: 8546)
simulatorMnemonic: "example exile argue silk regular smile grass bomb merge arm assist farm", // Mnemonic used by the simulator to generate a wallet
simulatorBlocktime: 0 // Specify blockTime in seconds for automatic mining. Default is 0 and no auto-mining.
},
testnet: {
enabled: true,
networkType: "testnet",
light: true,
syncMode: "light",
rpcHost: "localhost",
rpcPort: 8545,
rpcCorsDomain: "http://localhost:8000",
account: {
password: "config/testnet/password"
}
accounts: [
{
nodeAccounts: true,
password: "config/testnet/.password"
}
],
},
livenet: {
enabled: true,
enabled: false,
networkType: "livenet",
light: true,
syncMode: "light",
rpcHost: "localhost",
rpcPort: 8545,
rpcCorsDomain: "http://localhost:8000",
account: {
password: "config/livenet/password"
}
},
privatenet: {
accounts: [
{
nodeAccounts: true,
password: "config/livenet/.password"
}
],
},
rinkeby: {
enabled: true,
networkType: "custom",
networkType: "rinkeby",
syncMode: "light",
rpcHost: "localhost",
rpcPort: 8545,
rpcCorsDomain: "http://localhost:8000",
datadir: "yourdatadir",
networkId: "123",
bootnodes: ""
accounts: [
{
nodeAccounts: true,
password: "config/rinkeby/.password"
}
],
}
};

View File

@ -14,88 +14,70 @@ module.exports = {
"http://localhost:8545"
],
gas: "auto",
contracts: {
SafeMath: {
deploy: false
strategy: "explicit",
contracts: {
"MiniMeTokenFactory": {
"deploy": true
},
TestToken: {
deploy: false
"MiniMeToken": {
"deploy": true,
"args":["$MiniMeTokenFactory", "0x0", "0x0", "Status Test Token", 18, "STT", true],
},
ERC20Receiver: {
deploy: false
},
Factory: {
deploy: false
},
Instance: {
deploy: false
},
InstanceStorage: {
deploy: false
},
UpdatableInstance: {
deploy: false
},
MiniMeToken: {
deploy: false
},
MiniMeTokenFactory: {
deploy: false
},
DelegationProxy: {
deploy: false
},
DelegationProxyFactory: {
deploy: false
},
DelegationProxyView: {
deploy: false
},
DelegationProxyKernel: {
deploy: false
},
TrustNetwork: {
deploy: false
},
ProposalCuration: {
deploy: false
},
ProposalManager: {
deploy: false
},
Democracy: {
deploy: false
}
}
},
development: {
contracts: {
MiniMeTokenFactory : {
deploy: true
},
DelegationProxyFactory: {
deploy: true
},
SNT: {
deploy: true,
instanceOf: "MiniMeToken",
args: [
"$MiniMeTokenFactory",
0,
0,
"TestMiniMeToken",
18,
"TST",
true
"StatusRoot": {
"instanceOf": "TestStatusNetwork",
"deploy": true,
"args": ["0x0", "$MiniMeToken"],
"onDeploy": [
"await MiniMeToken.methods.changeController(StatusRoot.address).send()",
"await StatusRoot.methods.setOpen(true).send()",
]
}
},
Democracy: {
deploy: true,
args: [
"$SNT",
"$DelegationProxyFactory"
}
},
development: {
deployment: {
accounts: [
{
privateKey: "b2ab40d549e67ba67f278781fec03b3a90515ad4d0c898a6326dd958de1e46fa",
balance: "5 ether" // You can set the balance of the account in the dev environment
// Balances are in Wei, but you can specify the unit with its name
}
]
}
},
testnet: {
contracts: {
"MiniMeTokenFactory": {
"deploy": false,
"address": "0x6bFa86A71A7DBc68566d5C741F416e3009804279"
},
"MiniMeToken": {
"deploy": false,
"address": "0xc55cF4B03948D7EBc8b9E8BAD92643703811d162"
},
"StatusRoot": {
"instanceOf": "TestStatusNetwork",
"deploy": false,
"address": "0x34358C45FbA99ef9b78cB501584E8cBFa6f85Cef"
}
}
},
rinkeby: {
contracts: {
"MiniMeTokenFactory": {
"deploy": false,
"address": "0x5bA5C786845CaacD45f5952E1135F4bFB8855469"
},
"MiniMeToken": {
"deploy": false,
"address": "0x43d5adC3B49130A575ae6e4b00dFa4BC55C71621"
},
"StatusRoot": {
"instanceOf": "TestStatusNetwork",
"deploy": false,
"address": "0xEdEB948dE35C6ac414359f97329fc0b4be70d3f1"
}
}
}
};
}

View File

@ -1 +0,0 @@
dev_password

View File

@ -1,10 +1,11 @@
module.exports = {
// default applies to all environments
default: {
enabled: true,
ipfs_bin: "ipfs",
provider: "ipfs",
available_providers: ["ipfs"],
upload: {
provider: "ipfs",
host: "localhost",
port: 5001
},
@ -23,13 +24,36 @@ module.exports = {
},
swarmPath: "PATH/TO/SWARM/EXECUTABLE" // Path to swarm executable (default: swarm)*/
},
// default environment, merges with the settings in default
// assumed to be the intended environment by `embark run`
development: {
enabled: true,
provider: "ipfs",
upload: {
provider: "ipfs",
host: "localhost",
port: 5001,
getUrl: "http://localhost:8080/ipfs/"
}
}
},
// merges with the settings in default
// used with "embark run privatenet"
privatenet: {
},
// merges with the settings in default
// used with "embark run testnet"
testnet: {
},
// merges with the settings in default
// used with "embark run livenet"
livenet: {
},
// you can name an environment with specific settings and then specify with
// "embark run custom_name"
//custom_name: {
//}
};

View File

@ -1 +0,0 @@
test_password

View File

@ -1,14 +1,14 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;
contract Controlled {
/// @notice The address of the controller is the only address that can call
/// a function with this modifier
modifier onlyController {
require(msg.sender == controller);
require(msg.sender == controller, "Unauthorized");
_;
}
address public controller;
address payable public controller;
constructor() internal {
controller = msg.sender;
@ -16,7 +16,7 @@ contract Controlled {
/// @notice Changes the controller of the contract
/// @param _newController The new controller of the contract
function changeController(address _newController) public onlyController {
function changeController(address payable _newController) public onlyController {
controller = _newController;
}
}

View File

@ -1,13 +1,11 @@
pragma solidity ^0.4.21;
pragma solidity >=0.5.0 <0.6.0;
/**
* @notice Uses ethereum signed messages
*/
contract MessageSigned {
constructor() internal {
}
constructor() internal {}
/**
* @notice recovers address who signed the message
@ -16,10 +14,10 @@ contract MessageSigned {
*/
function recoverAddress(
bytes32 _signHash,
bytes _messageSignature
bytes memory _messageSignature
)
pure
internal
pure
returns(address)
{
uint8 v;
@ -42,8 +40,8 @@ contract MessageSigned {
function getSignHash(
bytes32 _hash
)
pure
internal
pure
returns (bytes32 signHash)
{
signHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _hash));
@ -52,9 +50,9 @@ contract MessageSigned {
/**
* @dev divides bytes signature into `uint8 v, bytes32 r, bytes32 s`
*/
function signatureSplit(bytes _signature)
pure
function signatureSplit(bytes memory _signature)
internal
pure
returns (uint8 v, bytes32 r, bytes32 s)
{
// The signature format is a compact form of:
@ -71,7 +69,7 @@ contract MessageSigned {
v := and(mload(add(_signature, 65)), 0xff)
}
require(v == 27 || v == 28);
require(v == 27 || v == 28, "Bad signature");
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;
/// @dev `Owned` is a base level contract that assigns an `owner` that can be
/// later changed
@ -7,23 +7,23 @@ contract Owned {
/// @dev `owner` is the only address that can call a function with this
/// modifier
modifier onlyOwner() {
require(msg.sender == owner);
require(msg.sender == owner, "Unauthorized");
_;
}
address public owner;
address payable public owner;
/// @notice The Constructor assigns the message sender to be `owner`
constructor() internal {
owner = msg.sender;
}
address public newOwner;
address payable public newOwner;
/// @notice `owner` can step down and assign some other address to this role
/// @param _newOwner The address of the new owner. 0x0 can be used to create
/// an unowned neutral vault, however that cannot be undone
function changeOwner(address _newOwner) public onlyOwner {
function changeOwner(address payable _newOwner) public onlyOwner {
newOwner = _newOwner;
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;
/**
* Math operations with safety checks

View File

@ -0,0 +1,90 @@
pragma solidity >=0.5.0 <0.6.0;
import "../token/TokenController.sol";
import "../common/Owned.sol";
import "../token/ERC20Token.sol";
import "../token/MiniMeToken.sol";
/**
* @title SNTController
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
* @notice enables economic abstraction for SNT
*/
contract SNTController is TokenController, Owned {
MiniMeToken public snt;
event ClaimedTokens(address indexed _token, address indexed _controller, uint256 _amount);
event ControllerChanged(address indexed _newController);
/**
* @notice Constructor
* @param _owner Authority address
* @param _snt SNT token
*/
constructor(address payable _owner, MiniMeToken _snt) internal {
if(_owner != address(0)){
owner = _owner;
}
snt = _snt;
}
/**
* @notice The owner of this contract can change the controller of the SNT token
* Please, be sure that the owner is a trusted agent or 0x0 address.
* @param _newController The address of the new controller
*/
function changeController(address payable _newController) public onlyOwner {
snt.changeController(_newController);
emit ControllerChanged(_newController);
}
/**
* @notice This method can be used by the controller to extract mistakenly
* sent tokens to this contract.
* @param _token The address of the token contract that you want to recover
* set to 0 in case you want to extract ether.
*/
function claimTokens(address _token) public onlyOwner {
if (snt.controller() == address(this)) {
snt.claimTokens(_token);
}
if (_token == address(0)) {
address(owner).transfer(address(this).balance);
return;
}
ERC20Token token = ERC20Token(_token);
uint256 balance = token.balanceOf(address(this));
token.transfer(owner, balance);
emit ClaimedTokens(_token, owner, balance);
}
/**
* @notice payment by address coming from controlled token
* @dev In between the offering and the network. Default settings for allowing token transfers.
*/
function proxyPayment(address) external payable returns (bool) {
//Uncomment above line when using parameters
//require(msg.sender == address(snt), "Unauthorized");
return false;
}
/**
* @notice register and authorizes transfer from token
* @dev called by snt when a transfer is made
*/
function onTransfer(address, address, uint256) external returns (bool) {
//Uncomment above line when using parameters
//require(msg.sender == address(snt), "Unauthorized");
return true;
}
/**
* @notice register and authorizes approve from token
* @dev called by snt when an approval is made
*/
function onApprove(address, address, uint256) external returns (bool) {
//Uncomment above line when using parameters
//require(msg.sender == address(snt), "Unauthorized");
return true;
}
}

View File

@ -0,0 +1,23 @@
pragma solidity >=0.5.0 <0.6.0;
import "./SNTController.sol";
/**
* @dev Status Network is implemented here
*/
contract StatusNetwork is SNTController {
/**
* @notice Constructor
* @param _owner Authority address
* @param _snt SNT token
*/
constructor(
address payable _owner,
MiniMeToken _snt
)
public
SNTController(_owner, _snt)
{ }
}

View File

@ -0,0 +1,55 @@
pragma solidity >=0.5.0 <0.6.0;
import "./StatusNetwork.sol";
/**
* @title SNTController
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
* @notice Test net version of SNTController which allow public mint
*/
contract TestStatusNetwork is StatusNetwork {
bool public open = false;
/**
* @notice Constructor
* @param _owner Authority address
* @param _snt SNT token
*/
constructor(address payable _owner, MiniMeToken _snt)
public
StatusNetwork(_owner, _snt)
{ }
function () external {
_generateTokens(msg.sender, 1000 * (10 ** uint(snt.decimals())));
}
function mint(uint256 _amount) external {
_generateTokens(msg.sender, _amount);
}
function generateTokens(address _who, uint _amount) external {
_generateTokens(_who, _amount);
}
function destroyTokens(address _who, uint _amount) external onlyOwner {
snt.destroyTokens(_who, _amount);
}
function setOpen(bool _open) external onlyOwner {
open = _open;
}
function _generateTokens(address _who, uint _amount) private {
require(msg.sender == owner || open, "Test Mint Disabled");
address statusNetwork = snt.controller();
if(statusNetwork == address(this)){
snt.generateTokens(_who, _amount);
} else {
TestStatusNetwork(statusNetwork).generateTokens(_who, _amount);
}
}
}

View File

@ -1,10 +1,5 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;
interface ApproveAndCallFallBack {
function receiveApproval(
address from,
uint256 _amount,
address _token,
bytes _data
) external;
contract ApproveAndCallFallBack {
function receiveApproval(address from, uint256 _amount, address _token, bytes memory _data) public;
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;
import "./ERC20Token.sol";
@ -43,7 +43,7 @@ contract ERC20Receiver {
)
external
{
require(_token.allowance(msg.sender, address(this)) >= _amount);
require(_token.allowance(msg.sender, address(this)) >= _amount, "Bad argument");
_depositToken(msg.sender, _token, _amount);
}
@ -65,7 +65,7 @@ contract ERC20Receiver {
)
private
{
require(_amount > 0);
require(_amount > 0, "Bad argument");
if (_token.transferFrom(_from, address(this), _amount)) {
tokenBalances[address(_token)][_from] += _amount;
emit TokenDeposited(address(_token), _from, _amount);
@ -79,10 +79,10 @@ contract ERC20Receiver {
)
private
{
require(_amount > 0);
require(tokenBalances[address(_token)][_from] >= _amount);
require(_amount > 0, "Bad argument");
require(tokenBalances[address(_token)][_from] >= _amount, "Insufficient funds");
tokenBalances[address(_token)][_from] -= _amount;
require(_token.transfer(_from, _amount));
require(_token.transfer(_from, _amount), "Transfer fail");
emit TokenWithdrawn(address(_token), _from, _amount);
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;
// Abstract contract for the full ERC 20 Token standard
// https://github.com/ethereum/EIPs/issues/20

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;
/*
Copyright 2016, Jordi Baylina
@ -29,7 +29,6 @@ pragma solidity ^0.4.23;
import "../common/Controlled.sol";
import "./TokenController.sol";
import "./ApproveAndCallFallBack.sol";
import "./MiniMeTokenInterface.sol";
import "./MiniMeTokenFactory.sol";
/**
@ -37,7 +36,7 @@ import "./MiniMeTokenFactory.sol";
* that deploys the contract, so usually this token will be deployed by a
* token controller contract, which Giveth will call a "Campaign"
*/
contract MiniMeToken is MiniMeTokenInterface, Controlled {
contract MiniMeToken is Controlled {
string public name; //The Token's name: e.g. DigixDAO Tokens
uint8 public decimals; //Number of decimals of the smallest unit
@ -71,7 +70,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
// `balances` is the map that tracks the balance of each address, in this
// contract when the balance changes the block number that the change
// occurred is also included in the map
// occurred is also included in the map
mapping (address => Checkpoint[]) balances;
// `allowed` tracks any extra transfer rights as in all ERC20 tokens
@ -109,19 +108,18 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
address _tokenFactory,
address _parentToken,
uint _parentSnapShotBlock,
string _tokenName,
string memory _tokenName,
uint8 _decimalUnits,
string _tokenSymbol,
string memory _tokenSymbol,
bool _transfersEnabled
)
public
{
require(_tokenFactory != address(0)); //if not set, clone feature will not work properly
tokenFactory = MiniMeTokenFactory(_tokenFactory);
name = _tokenName; // Set the name
decimals = _decimalUnits; // Set the decimals
symbol = _tokenSymbol; // Set the symbol
parentToken = MiniMeToken(_parentToken);
parentToken = MiniMeToken(address(uint160(_parentToken)));
parentSnapShotBlock = _parentSnapShotBlock;
transfersEnabled = _transfersEnabled;
creationBlock = block.number;
@ -139,7 +137,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
* @return Whether the transfer was successful or not
*/
function transfer(address _to, uint256 _amount) public returns (bool success) {
require(transfersEnabled);
require(transfersEnabled, "Transfers disabled");
return doTransfer(msg.sender, _to, _amount);
}
@ -165,7 +163,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
// controller of this contract, which in most situations should be
// another open source smart contract or 0x0
if (msg.sender != controller) {
require(transfersEnabled);
require(transfersEnabled, "Transfers disabled");
// The standard ERC 20 transferFrom functionality
if (allowed[_from][msg.sender] < _amount) {
@ -197,10 +195,10 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
return true;
}
require(parentSnapShotBlock < block.number);
require(parentSnapShotBlock < block.number, "Invalid block.number");
// Do not allow transfer to 0x0 or the token contract itself
require((_to != 0) && (_to != address(this)));
require((_to != address(0)) && (_to != address(this)), "Invalid _to");
// If the amount being transfered is more than the balance of the
// account the transfer returns false
@ -211,7 +209,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
// Alerts the token controller of the transfer
if (isContract(controller)) {
require(TokenController(controller).onTransfer(_from, _to, _amount));
require(TokenController(controller).onTransfer(_from, _to, _amount), "Unauthorized transfer");
}
// First update the balance array with the new value for the address
@ -221,7 +219,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
// Then update the balance array with the new value for the address
// receiving the tokens
uint256 previousBalanceTo = balanceOfAt(_to, block.number);
require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow
require(previousBalanceTo + _amount >= previousBalanceTo, "Balance overflow"); // Check for overflow
updateValueAtNow(balances[_to], previousBalanceTo + _amount);
// An event to make the transfer easy to find on the blockchain
@ -238,17 +236,17 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
internal
returns (bool)
{
require(transfersEnabled);
require(transfersEnabled, "Transfers disabled");
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender,0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_amount == 0) || (allowed[_from][_spender] == 0));
require((_amount == 0) || (allowed[_from][_spender] == 0), "Reset allowance first");
// Alerts the token controller of the approve function call
if (isContract(controller)) {
require(TokenController(controller).onApprove(_from, _spender, _amount));
require(TokenController(controller).onApprove(_from, _spender, _amount), "Unauthorized approve");
}
allowed[_from][_spender] = _amount;
@ -273,7 +271,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
* @return True if the approval was successful
*/
function approve(address _spender, uint256 _amount) external returns (bool success) {
doApprove(msg.sender, _spender, _amount);
return doApprove(msg.sender, _spender, _amount);
}
/**
@ -305,17 +303,17 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
function approveAndCall(
address _spender,
uint256 _amount,
bytes _extraData
bytes memory _extraData
)
external
public
returns (bool success)
{
require(doApprove(msg.sender, _spender, _amount));
require(doApprove(msg.sender, _spender, _amount), "Approve failed");
ApproveAndCallFallBack(_spender).receiveApproval(
msg.sender,
_amount,
this,
address(this),
_extraData
);
@ -356,7 +354,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
// genesis block for that token as this contains initial balance of
// this token
if ((balances[_owner].length == 0) || (balances[_owner][0].fromBlock > _blockNumber)) {
if (address(parentToken) != 0) {
if (address(parentToken) != address(0)) {
return parentToken.balanceOfAt(_owner, min(_blockNumber, parentSnapShotBlock));
} else {
// Has no parent
@ -382,7 +380,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
// genesis block for this token as that contains totalSupply of this
// token at this block number.
if ((totalSupplyHistory.length == 0) || (totalSupplyHistory[0].fromBlock > _blockNumber)) {
if (address(parentToken) != 0) {
if (address(parentToken) != address(0)) {
return parentToken.totalSupplyAt(min(_blockNumber, parentSnapShotBlock));
} else {
return 0;
@ -400,7 +398,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
/**
* @notice Creates a new clone token with the initial distribution being
* this token at `_snapshotBlock`
* this token at `snapshotBlock`
* @param _cloneTokenName Name of the clone token
* @param _cloneDecimalUnits Number of decimals of the smallest unit
* @param _cloneTokenSymbol Symbol of the clone token
@ -411,9 +409,9 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
* @return The address of the new MiniMeToken Contract
*/
function createCloneToken(
string _cloneTokenName,
string memory _cloneTokenName,
uint8 _cloneDecimalUnits,
string _cloneTokenSymbol,
string memory _cloneTokenSymbol,
uint _snapshotBlock,
bool _transfersEnabled
)
@ -425,7 +423,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
snapshotBlock = block.number;
}
MiniMeToken cloneToken = tokenFactory.createCloneToken(
this,
address(this),
snapshotBlock,
_cloneTokenName,
_cloneDecimalUnits,
@ -459,12 +457,12 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
returns (bool)
{
uint curTotalSupply = totalSupplyAt(block.number);
require(curTotalSupply + _amount >= curTotalSupply); // Check for overflow
require(curTotalSupply + _amount >= curTotalSupply, "Total overflow"); // Check for overflow
uint previousBalanceTo = balanceOfAt(_owner, block.number);
require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow
require(previousBalanceTo + _amount >= previousBalanceTo, "Balance overflow"); // Check for overflow
updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount);
updateValueAtNow(balances[_owner], previousBalanceTo + _amount);
emit Transfer(0, _owner, _amount);
emit Transfer(address(0), _owner, _amount);
return true;
}
@ -483,12 +481,12 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
returns (bool)
{
uint curTotalSupply = totalSupplyAt(block.number);
require(curTotalSupply >= _amount);
require(curTotalSupply >= _amount, "No enough supply");
uint previousBalanceFrom = balanceOfAt(_owner, block.number);
require(previousBalanceFrom >= _amount);
require(previousBalanceFrom >= _amount, "No enough balance");
updateValueAtNow(totalSupplyHistory, curTotalSupply - _amount);
updateValueAtNow(balances[_owner], previousBalanceFrom - _amount);
emit Transfer(_owner, 0, _amount);
emit Transfer(_owner, address(0), _amount);
return true;
}
@ -518,8 +516,8 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
Checkpoint[] storage checkpoints,
uint _block
)
view
internal
view
returns (uint)
{
if (checkpoints.length == 0) {
@ -555,10 +553,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
* @param _value The new number of tokens
*/
function updateValueAtNow(Checkpoint[] storage checkpoints, uint _value) internal {
if (
(checkpoints.length == 0) ||
(checkpoints[checkpoints.length - 1].fromBlock < block.number))
{
if ((checkpoints.length == 0) || (checkpoints[checkpoints.length -1].fromBlock < block.number)) {
Checkpoint storage newCheckPoint = checkpoints[checkpoints.length++];
newCheckPoint.fromBlock = uint128(block.number);
newCheckPoint.value = uint128(_value);
@ -575,19 +570,19 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
*/
function isContract(address _addr) internal view returns(bool) {
uint size;
if (_addr == 0) {
if (_addr == address(0)){
return false;
}
assembly {
size := extcodesize(_addr)
}
return size > 0;
return size>0;
}
/**
* @dev Helper function to return a min betwen the two uints
*/
function min(uint a, uint b) internal returns (uint) {
function min(uint a, uint b) internal pure returns (uint) {
return a < b ? a : b;
}
@ -596,9 +591,9 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
* set to 0, then the `proxyPayment` method is called which relays the
* ether and creates tokens as described in the token controller contract
*/
function () public payable {
require(isContract(controller));
require(TokenController(controller).proxyPayment.value(msg.value)(msg.sender));
function () external payable {
require(isContract(controller), "Deposit unallowed");
require(TokenController(controller).proxyPayment.value(msg.value)(msg.sender), "Deposit denied");
}
//////////
@ -612,12 +607,12 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
* set to 0 in case you want to extract ether.
*/
function claimTokens(address _token) public onlyController {
if (_token == 0x0) {
if (_token == address(0)) {
controller.transfer(address(this).balance);
return;
}
MiniMeToken token = MiniMeToken(_token);
MiniMeToken token = MiniMeToken(address(uint160(_token)));
uint balance = token.balanceOf(address(this));
token.transfer(controller, balance);
emit ClaimedTokens(_token, controller, balance);
@ -635,4 +630,4 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
uint256 _amount
);
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;
import "./MiniMeToken.sol";
@ -28,13 +28,13 @@ contract MiniMeTokenFactory {
function createCloneToken(
address _parentToken,
uint _snapshotBlock,
string _tokenName,
string memory _tokenName,
uint8 _decimalUnits,
string _tokenSymbol,
string memory _tokenSymbol,
bool _transfersEnabled
) public returns (MiniMeToken) {
MiniMeToken newToken = new MiniMeToken(
this,
address(this),
_parentToken,
_snapshotBlock,
_tokenName,

View File

@ -1,10 +1,10 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;
import "./ERC20Token.sol";
contract StandardToken is ERC20Token {
uint256 private supply;
uint256 public totalSupply;
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
@ -63,14 +63,6 @@ contract StandardToken is ERC20Token {
return balances[_owner];
}
function totalSupply()
external
view
returns(uint256 currentTotalSupply)
{
return supply;
}
function mint(
address _to,
uint256 _amount
@ -78,8 +70,8 @@ contract StandardToken is ERC20Token {
internal
{
balances[_to] += _amount;
supply += _amount;
emit Transfer(0x0, _to, _amount);
totalSupply += _amount;
emit Transfer(address(0x0), _to, _amount);
}
function transfer(

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;
import "./StandardToken.sol";

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;
/**
* @dev The token controller contract must implement these functions
*/

View File

@ -5,14 +5,14 @@
"js/index.js": ["app/index.js"],
"index.html": "app/index.html",
"images/": ["app/images/**"]
},
},
"buildDir": "dist/",
"config": "config/",
"versions": {
"web3": "1.0.0-beta",
"solc": "0.4.24",
"ipfs-api": "17.2.4"
"solc": "0.5.4",
"ipfs-api": "17.2.4",
"p-iteration": "1.1.7"
},
"plugins": {
}
"plugins": {}
}

View File

@ -17,25 +17,17 @@
"url": "https://github.com/status-im/contracts/issues"
},
"homepage": "https://github.com/status-im/contracts#readme",
"dependencies": {
"prop-types": "^15.6.1",
"react": "^16.3.2",
"react-blockies": "^1.3.0",
"react-bootstrap": "^0.32.1",
"react-dom": "^16.3.2",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"redux-action-creator": "^2.3.0",
"redux-thunk": "^2.3.0",
"reselect": "^3.0.1"
},
"devDependencies": {
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-stage-2": "^6.24.1",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.8.2"
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.2.3"
},
"dependencies": {
"elliptic-curve": "^0.1.0",
"ethereumjs-util": "^5.1.5",
"react": "^16.3.2",
"react-blockies": "^1.4.0",
"react-bootstrap": "0.32.1",
"react-dom": "^16.3.2",
"web3": "^1.0.0-beta.34"
}
}

53
test/teststatusnetwork.js Normal file
View File

@ -0,0 +1,53 @@
const Utils = require('../utils/testUtils');
const MiniMeToken = require('Embark/contracts/MiniMeToken');
const TestStatusNetwork = require('Embark/contracts/TestStatusNetwork');
const ERC20TokenSpec = require('./abstract/erc20tokenspec');
config({
contracts: {
"MiniMeTokenFactory": {},
"MiniMeToken": {
"args":["$MiniMeTokenFactory", "0x0", "0x0", "Status Test Token", 18, "STT", true],
},
"TestStatusNetwork": {
"deploy": true,
"args": ["0x0", "$MiniMeToken"],
"onDeploy": [
"await MiniMeToken.methods.changeController(TestStatusNetwork.address).send()",
"await TestStatusNetwork.methods.setOpen(true).send()",
]
}
}
});
contract("TestStatusNetwork", function() {
this.timeout(0);
var accounts;
before(function(done) {
web3.eth.getAccounts().then(function (res) {
accounts = res;
done();
});
});
it("should increase totalSupply in mint", async function() {
let initialSupply = await MiniMeToken.methods.totalSupply().call();
await TestStatusNetwork.methods.mint(100).send();
let result = await MiniMeToken.methods.totalSupply().call();
assert.equal(result, +initialSupply+100);
});
it("should increase accountBalance in mint", async function() {
let initialBalance = await MiniMeToken.methods.balanceOf(accounts[0]).call();
await TestStatusNetwork.methods.mint(100).send({from: accounts[0]});
let result = await MiniMeToken.methods.balanceOf(accounts[0]).call();
assert.equal(result, +initialBalance+100);
});
it("should burn account supply", async function() {
let initialBalance = await MiniMeToken.methods.balanceOf(accounts[0]).call();
await TestStatusNetwork.methods.destroyTokens(accounts[0], initialBalance).send({from: accounts[0]});
assert.equal(await MiniMeToken.methods.totalSupply().call(), 0);
assert.equal(await MiniMeToken.methods.balanceOf(accounts[0]).call(), 0);
})
});

View File

@ -1,55 +0,0 @@
const Utils = require('../utils/testUtils');
const TestToken = require('Embark/contracts/TestToken');
const ERC20TokenSpec = require('./abstract/erc20tokenspec');
config({
contracts: {
"TestToken": {
},
...ERC20TokenSpec.config.contracts
}
});
contract("TestToken", function() {
this.timeout(0);
var accounts;
before(function(done) {
web3.eth.getAccounts().then(function (res) {
accounts = res;
done();
});
});
it("should increase totalSupply in mint", async function() {
let initialSupply = await TestToken.methods.totalSupply().call();
await TestToken.methods.mint(100).send();
let result = await TestToken.methods.totalSupply().call();
assert.equal(result, +initialSupply+100);
});
it("should increase accountBalance in mint", async function() {
let initialBalance = await TestToken.methods.balanceOf(accounts[0]).call();
await TestToken.methods.mint(100).send({from: accounts[0]});
let result = await TestToken.methods.balanceOf(accounts[0]).call();
assert.equal(result, +initialBalance+100);
});
it("should burn account supply", async function() {
let initialBalance = await TestToken.methods.balanceOf(accounts[0]).call();
await TestToken.methods.transfer(Utils.zeroAddress, initialBalance).send({from: accounts[0]});
assert.equal(await TestToken.methods.totalSupply().call(), 0);
assert.equal(await TestToken.methods.balanceOf(accounts[0]).call(), 0);
})
it("should mint balances for ERC20TokenSpec", async function() {
let initialBalance = 7 * 10 ^ 18;
for(i=0;i<accounts.length;i++){
await TestToken.methods.mint(initialBalance).send({from: accounts[i]})
assert.equal(await TestToken.methods.balanceOf(accounts[i]).call(), initialBalance);
}
})
ERC20TokenSpec.Test(TestToken);
});