Skip to content

Instantly share code, notes, and snippets.

@jachiang
Created May 25, 2019 09:16
Show Gist options
  • Save jachiang/afb55511dd7f41aeee84e7b1ef700a5f to your computer and use it in GitHub Desktop.
Save jachiang/afb55511dd7f41aeee84e7b1ef700a5f to your computer and use it in GitHub Desktop.
Escrow Solidity Example
pragma solidity >= 0.4.0 <0.6.0;
contract escrow {
// State variables
uint256 escrow_balance;
address payout_address;
struct authority
{
address auth_address;
bool auth_authorization;
}
authority[] authority_vector;
constructor(address a, address b, address c, address payout_address_) public
{
authority memory auth_a;
auth_a.auth_address = a;
auth_a.auth_authorization = false;
authority_vector.push(auth_a);
authority memory auth_b;
auth_b.auth_address = b;
auth_b.auth_authorization = false;
authority_vector.push(auth_b);
authority memory auth_c;
auth_c.auth_address = c;
auth_c.auth_authorization = false;
authority_vector.push(auth_c);
payout_address = payout_address_;
}
function withdraw_funds() public
{
uint256 vector_size = authority_vector.length;
uint8 signoff_counter;
for (uint256 i = 0; i<vector_size; i++)
{
if (authority_vector[i].auth_authorization == true)
{
signoff_counter += 1;
}
}
require(signoff_counter >=2);
require(escrow_balance > 0);
msg.sender.transfer(address(this).balance);
}
function fund() public payable
{
escrow_balance = msg.value;
}
function authorize() public
{
uint256 vector_size = authority_vector.length;
for (uint256 i = 0; i<=vector_size; i++)
{
if (authority_vector[i].auth_address == msg.sender)
{
authority_vector[i].auth_authorization = true;
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment