From 5fef99f43dc1bc03559146d1bbc57af2a0c15f0f Mon Sep 17 00:00:00 2001 From: Dan Emmons Date: Thu, 15 Mar 2018 17:40:39 -0500 Subject: [PATCH] introducing LOCIregister --- contracts/LOCIregister.sol | 70 +++++++++++++++++++++++++++++ migrations/4_deploy_LOCIregister.js | 34 ++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 contracts/LOCIregister.sol create mode 100644 migrations/4_deploy_LOCIregister.js diff --git a/contracts/LOCIregister.sol b/contracts/LOCIregister.sol new file mode 100644 index 0000000..984c6da --- /dev/null +++ b/contracts/LOCIregister.sol @@ -0,0 +1,70 @@ +pragma solidity ^0.4.18; + +import 'zeppelin-solidity/contracts/math/SafeMath.sol'; +import 'zeppelin-solidity/contracts/ownership/Ownable.sol'; +import 'zeppelin-solidity/contracts/ownership/Contactable.sol'; +import 'zeppelin-solidity/contracts/token/StandardToken.sol'; + +contract LOCIregister is Ownable, Contactable { + using SafeMath for uint256; + + // this is the already deployed coin from the token sale + StandardToken token; + + // Register every withdrawal we make from a linked LOCIsearch payment + event RegisterWithdrawal(address indexed register, /* address the customer sent payment to */ + address indexed beneficiary, /* recipent of funds after withdrawal */ + address indexed linked, /* original linked customer address */ + uint256 amount, /* amount of wei to transfer */ + uint reason); /* 0=refund, 1=payment, 2=stake, 3=bid */ + + // After this contract is deployed, we will grant access to this contract + // by calling methods on the LOCIcoin since we are using the same owner + // and granting the distribution of tokens to this contract + function LOCIregister( address _token, string _contactInformation ) public { + require(_token != 0x0); + + token = StandardToken(_token); + contactInformation = _contactInformation; + } + + function withdrawFrom( address _register, address _beneficiary, address _linked, uint256 _amount, uint _reason ) onlyOwner public { + require(_register != 0x0); + require(_beneficiary != 0x0 ); + require(_beneficiary != address(token)); + + token.transferFrom( _register, _beneficiary, _amount ); + RegisterWithdrawal( _register, _beneficiary, _linked, _amount, _reason ); + } + + function withdrawFromAll( address[] _register, address[] _beneficiary, address[] _linked, uint256[] _amount, uint[] _reason ) onlyOwner public { + require( _register.length == _beneficiary.length && _beneficiary.length == _amount.length && _amount.length == _reason.length ); + + for (uint i = 0; i < _register.length; i += 1) { + token.transferFrom( _register[i], _beneficiary[i], _amount[i] ); + RegisterWithdrawal( _register[i], _beneficiary[i], _linked[i], _amount[i], _reason[i] ); + } + } + + // in the event ether is accidentally sent to our contract, we can retrieve it + function ownerTransferWei(address _beneficiary, uint256 _value) external onlyOwner { + require(_beneficiary != 0x0); + require(_beneficiary != address(token)); + + // if zero requested, send the entire amount, otherwise the amount requested + uint256 _amount = _value > 0 ? _value : this.balance; + + _beneficiary.transfer(_amount); + } + + // after we distribute the bonus tokens, we will send them back to the coin itself + function ownerRecoverTokens(address _beneficiary) external onlyOwner { + require(_beneficiary != 0x0); + require(_beneficiary != address(token)); + + uint256 _tokensRemaining = token.balanceOf(address(this)); + if (_tokensRemaining > 0) { + token.transfer(_beneficiary, _tokensRemaining); + } + } +} \ No newline at end of file diff --git a/migrations/4_deploy_LOCIregister.js b/migrations/4_deploy_LOCIregister.js new file mode 100644 index 0000000..cee5ba0 --- /dev/null +++ b/migrations/4_deploy_LOCIregister.js @@ -0,0 +1,34 @@ +const SafeMath = artifacts.require('zeppelin-solidity/contracts/math/SafeMath.sol'); +const Ownable = artifacts.require('zeppelin-solidity/contracts/ownership/Ownable.sol'); +const Contactable = artifacts.require('zeppelin-solidity/contracts/ownership/Contactable.sol'); +const LOCIcoin = artifacts.require("./LOCIcoin.sol"); +const LOCIregister = artifacts.require("./LOCIregister.sol"); + +const BigNumber = require('bignumber.js'); + +module.exports = (deployer, network, accounts) => { + + let deployAddress = accounts[0]; // by convention + + console.log('Preparing for deployment of LOCIregister...'); + + if( network == "live" ) { + console.log("Using LOCIcoin at:" + LOCIcoin.address); + throw "Halt. Sanity check. Not ready for deployment to live network. Manually remove this throw and try again."; + } + + console.log('deploying from:' + deployAddress); + console.log('deploying SafeMath Ownable Contactable'); + //deployer.deploy(SafeMath, {from: deployAddress}); + //deployer.deploy(Ownable, {from: deployAddress}); + //deployer.deploy(Contactable, {from: deployAddress}); + + console.log('linking Ownable SafeMath Contactable'); + deployer.link(Ownable, [LOCIregister], {from: deployAddress}); + deployer.link(SafeMath, [LOCIregister], {from: deployAddress}); + deployer.link(Contactable, [LOCIregister], {from: deployAddress}); + + console.log('deploying LOCIregister'); + deployer.deploy(LOCIregister, LOCIcoin.address, 'LOCIpro.com', {from: deployAddress}); + +}; \ No newline at end of file