Last active
December 3, 2017 05:36
-
-
Save rjmacarthy/4278cdd3fdb811fa6a3d9372868822ca to your computer and use it in GitHub Desktop.
Escrow Contract Solidity
This file contains hidden or 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
var EscrowContract = artifacts.require("./EscrowContract.sol"); | |
var BaseContract = artifacts.require("./BaseContract.sol"); | |
var Ownable = artifacts.require("./Ownable.sol"); | |
module.exports = function(deployer) { | |
deployer.deploy(EscrowContract, 100, "0x7b2a27ab88e5ea22a5b87183f881e262bed99f1b", "0x08c9db1edc1052e632ed836638fbe6da5a2af1fa"); | |
deployer.deploy(Ownable); | |
}; |
This file contains hidden or 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
pragma solidity ^0.4.4; | |
import './Ownable.sol'; | |
contract EscrowContract is Ownable { | |
address public owner; | |
address public recipientAddress; | |
address public parent; | |
uint public escrowAmount; | |
EscrowStatuses public status = EscrowStatuses.Pending; | |
enum EscrowStatuses { Paid, Pending, Complete, Cancelled, Partial } | |
event EscrowPaid(string _msg, uint balance); | |
event EscrowPaymentRecieved(string _msg, uint amount); | |
event EscrowPartiallyPaid(string _msg, uint balance); | |
event EscrowCompleted(string _msg); | |
event EscrowCancelled(string _msg); | |
event OverPay(string _msg); | |
function EscrowContract(uint _escrowAmount, address _recipientAddress, address _parent) { | |
require(_parent != 0x0 && _escrowAmount > 0 && _recipientAddress != 0x0); | |
owner = msg.sender; | |
parent = _parent; | |
escrowAmount = _escrowAmount; | |
recipientAddress = _recipientAddress; | |
} | |
function getBalance () constant returns (uint) { | |
return this.balance; | |
} | |
function fundEscrow() payable { | |
require(this.balance <= escrowAmount); | |
if(this.balance == escrowAmount) { | |
EscrowPaid('Escrow paid', this.balance); | |
status = EscrowStatuses.Paid; | |
} else { | |
EscrowPartiallyPaid('Partial payment', this.balance); | |
} | |
} | |
} |
This file contains hidden or 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
pragma solidity ^0.4.4; | |
contract Ownable { | |
address public owner = msg.sender; | |
address public parent; | |
modifier onlyOwner { | |
require(msg.sender != owner); | |
_; | |
} | |
function changeOwner(address _newOwner) onlyOwner | |
{ | |
if(_newOwner == 0x0) | |
owner = _newOwner; | |
} | |
} |
This file contains hidden or 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
EscrowContract.deployed().then(i => app = i) | |
app.getBalance() | |
app.fundEscrow({value: 100}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment