-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from SuperuserLabs/dev/addressregistrar
Implemented donate contract (with address registrar)
- Loading branch information
Showing
11 changed files
with
8,794 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
.PHONY: build test | ||
|
||
build: | ||
truffle compile | ||
npx truffle compile | ||
|
||
develop: | ||
npx truffle develop | ||
|
||
ganache: | ||
npx ganache-cli --port 9545 | ||
|
||
stop-develop: | ||
kill $$(ps -x | grep ganache | awk '{print $$1;}') | ||
|
||
migrate: | ||
npx truffle migrate | ||
|
||
test: | ||
truffle test | ||
npx truffle test | ||
|
||
clean: | ||
rm -r build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
import './AddressRegistrar.sol'; | ||
|
||
contract AddressRegistrar { | ||
// TODO: Make contract extend Ownable (for onlyOwner modifiers etc.) | ||
// https://medium.com/codexprotocol/a-simple-framework-for-deploying-ownable-contracts-63ed4bd3c657 | ||
// The owner is the verifier | ||
address public owner; | ||
|
||
mapping(string => Creator) creators; | ||
|
||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
struct Creator { | ||
address addr; | ||
} | ||
|
||
// Associate an email with a wallet address | ||
function associate(string _email, address _address) public { | ||
require(msg.sender == owner); | ||
creators[_email].addr = _address; | ||
} | ||
|
||
function getAddressByEmail(string _email) public constant returns (address) { | ||
return creators[_email].addr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
import './AddressRegistrar.sol'; | ||
|
||
contract DonationHandler { | ||
address public owner; | ||
AddressRegistrar public registrar; | ||
|
||
mapping(string => PendingDonations) pending; | ||
|
||
constructor(AddressRegistrar _registrar) public { | ||
owner = msg.sender; | ||
registrar = _registrar; | ||
} | ||
|
||
struct Donation { | ||
address sender; | ||
uint amount; | ||
uint256 expires; | ||
} | ||
|
||
struct PendingDonations { | ||
Donation[] donations; | ||
uint n_pending; | ||
uint refunded; | ||
} | ||
|
||
// Donate to a creator, add to pending if email has no connected address. | ||
function donate(string _email, uint32 _expires_in) public payable { | ||
require(msg.value > 0); | ||
address _addr = registrar.getAddressByEmail(_email); | ||
if(_addr != 0x0) { | ||
_addr.transfer(msg.value); | ||
} else { | ||
pending[_email].donations.push(Donation(msg.sender, msg.value, now + _expires_in)); | ||
pending[_email].n_pending++; | ||
} | ||
} | ||
|
||
// Refund pending transaction that has expired | ||
function refund(string _email, uint32 _pending_idx) public { | ||
require(now > pending[_email].donations[_pending_idx].expires); | ||
delete pending[_email].donations[_pending_idx]; | ||
pending[_email].refunded++; | ||
} | ||
|
||
// Pay out last pending transaction for creator if email has an assigned address | ||
function payOut(string _email) public returns (bool) { | ||
address _addr = registrar.getAddressByEmail(_email); | ||
require(_addr != 0x0 && pending[_email].n_pending > 0); | ||
Donation storage d = pending[_email].donations[idx]; | ||
if(d.amount != 0x0) { | ||
uint idx = pending[_email].n_pending - 1; | ||
_addr.transfer(d.amount); | ||
return true; | ||
} else { | ||
pending[_email].n_pending--; | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
import 'openzeppelin-solidity/contracts/ownership/Ownable.sol'; | ||
// import 'openzeppelin-solidity/contracts/ownership/Ownable.sol'; | ||
|
||
contract SupporterToken is Ownable { | ||
contract SupporterToken /*is Ownable*/ { | ||
// Nothing here yet | ||
// Will be a ERC721 token, see this issue: https://github.com/SuperuserLabs/thankful/issues/3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let AddressRegistrar = artifacts.require("AddressRegistrar"); | ||
let DonationHandler = artifacts.require("DonationHandler"); | ||
|
||
module.exports = async function(deployer) { | ||
deployer.deploy(AddressRegistrar).then(() => { | ||
return deployer.deploy(DonationHandler, AddressRegistrar.address); | ||
}); | ||
}; |
Oops, something went wrong.