Continuous vesting smart contract

Continuous vesting is a smart contract I wrote a while back that allows you to continuously pay someone ethereum (extendible to tokens too).

How it works is simple:

There's a certain vesting rate weiPerSecond.
Each second, more wei is allowed to be withdrawn by either party (payer or payee).

This could be used to pay for freelancers, rent, employees, or really anyone you can imagine. It allows you to better estimate your costs in real-time too.

Here's the code and the github:

pragma solidity ^0.4.15;

//TODO: Allow the contract to be reused

contract ContinuousPayment {

    address public contractor;
    address public employer;
    uint public weiPerSecond;
    uint public startTime;

    event Withdrew(uint amount, address indexed withdrawer);

    function ContinuousPayment(uint _weiPerSecond) {
        weiPerSecond = _weiPerSecond;
        contractor = msg.sender;

    function() payable {

    function depositPayment() payable {
        require(employer == 0x0); //don't allow this to be set twice
        employer = msg.sender;
        startTime = getTime();

    function withdrawPayment() {
        uint owed = balanceOwed();
        startTime = getTime();
        if (contractor == msg.sender) {
            require(owed > 0);
            Withdrew(owed, msg.sender);
        if (employer == msg.sender) {
            uint employerOwed = address(this).balance - owed;
            require(employerOwed > 0);
            Withdrew(employerOwed, msg.sender);

    function balanceOwed() constant returns (uint) {
        uint owed = weiPerSecond * (getTime() - startTime);
        uint balance = address(this).balance;
        if (owed > balance) {
            owed = balance;
        return owed;

    //overridden in test files
    function getTime() constant returns (uint) {
        return now;

It hasn't been audited yet so don't use it in production! Perhaps someone here could do an audit? 🙏

Maybe @dev_zl or @dougiebuckets give me some feedback? 😉