Skip to content

Instantly share code, notes, and snippets.

@rjmacarthy
Last active December 3, 2017 05:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjmacarthy/4278cdd3fdb811fa6a3d9372868822ca to your computer and use it in GitHub Desktop.
Save rjmacarthy/4278cdd3fdb811fa6a3d9372868822ca to your computer and use it in GitHub Desktop.
Escrow Contract Solidity
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);
};
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);
}
}
}
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;
}
}
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