-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add _ethpm_packages dir to each example
- Loading branch information
1 parent
6daa7a4
commit 167ca23
Showing
46 changed files
with
680 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.8; | ||
|
||
|
||
import {SafeSendLib} from "./SafeSendLib.sol"; | ||
|
||
|
||
/// @title Contract for holding funds in escrow between two semi trusted parties. | ||
/// @author Piper Merriam <[email protected]> | ||
contract Escrow { | ||
using SafeSendLib for address; | ||
|
||
address public sender; | ||
address public recipient; | ||
|
||
constructor(address _recipient) public { | ||
sender = msg.sender; | ||
recipient = _recipient; | ||
} | ||
|
||
/// @dev Releases the escrowed funds to the other party. | ||
/// @notice This will release the escrowed funds to the other party. | ||
function releaseFunds() public { | ||
if (msg.sender == sender) { | ||
recipient.sendOrThrow(address(this).balance); | ||
} else if (msg.sender == recipient) { | ||
sender.sendOrThrow(address(this).balance); | ||
} else { | ||
revert(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
examples/escrow/_ethpm_packages/escrow/_src/SafeSendLib.sol
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,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.8; | ||
|
||
|
||
/// @title Library for safe sending of ether. | ||
/// @author Piper Merriam <[email protected]> | ||
library SafeSendLib { | ||
/// @dev Attempts to send the specified amount to the recipient throwing an error if it fails | ||
/// @param recipient The address that the funds should be to. | ||
/// @param value The amount in wei that should be sent. | ||
function sendOrThrow(address recipient, uint value) public returns (bool) { | ||
if (value > address(this).balance) | ||
revert(); | ||
|
||
if (!payable(recipient).send(value)) | ||
revert(); | ||
|
||
return true; | ||
} | ||
} |
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 @@ | ||
{"compilers":[{"contractTypes":["Escrow","SafeSendLib"],"name":"solc","settings":{"optimize":false},"version":"0.6.8+commit.0bbfe453"}],"contractTypes":{"Escrow":{"abi":[{"inputs":[{"internalType":"address","name":"_recipient","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"recipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"releaseFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sender","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}],"deploymentBytecode":{"bytecode":"0x608060405234801561001057600080fd5b506040516104e83803806104e88339818101604052602081101561003357600080fd5b8101908080519060200190929190505050336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610413806100d56000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806366d003ac1461004657806367e404ce1461009057806369d89575146100da575b600080fd5b61004e6100e4565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61009861010a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100e261012f565b005b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561028257600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16730000000000000000000000000000000000000000639341231c9091476040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060206040518083038186803b15801561024157600080fd5b505af4158015610255573d6000803e3d6000fd5b505050506040513d602081101561026b57600080fd5b8101908080519060200190929190505050506103db565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156103d5576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16730000000000000000000000000000000000000000639341231c9091476040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060206040518083038186803b15801561039457600080fd5b505af41580156103a8573d6000803e3d6000fd5b505050506040513d60208110156103be57600080fd5b8101908080519060200190929190505050506103da565b600080fd5b5b56fea2646970667358221220c0256c8fdbb9d70e72b54b5dcae800eb0d0723c366103209d2e40e60b6f352e564736f6c63430006080033","linkReferences":[{"length":20,"name":"SafeSendLib","offsets":[660,999]}]},"devdoc":{"author":"Piper Merriam <[email protected]>","methods":{"releaseFunds()":{"details":"Releases the escrowed funds to the other party."}},"title":"Contract for holding funds in escrow between two semi trusted parties."},"runtimeBytecode":{"bytecode":"0x608060405234801561001057600080fd5b50600436106100415760003560e01c806366d003ac1461004657806367e404ce1461009057806369d89575146100da575b600080fd5b61004e6100e4565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61009861010a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100e261012f565b005b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561028257600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16730000000000000000000000000000000000000000639341231c9091476040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060206040518083038186803b15801561024157600080fd5b505af4158015610255573d6000803e3d6000fd5b505050506040513d602081101561026b57600080fd5b8101908080519060200190929190505050506103db565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156103d5576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16730000000000000000000000000000000000000000639341231c9091476040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060206040518083038186803b15801561039457600080fd5b505af41580156103a8573d6000803e3d6000fd5b505050506040513d60208110156103be57600080fd5b8101908080519060200190929190505050506103da565b600080fd5b5b56fea2646970667358221220c0256c8fdbb9d70e72b54b5dcae800eb0d0723c366103209d2e40e60b6f352e564736f6c63430006080033","linkReferences":[{"length":20,"name":"SafeSendLib","offsets":[447,786]}]},"sourceId":"Escrow.sol"},"SafeSendLib":{"abi":[],"deploymentBytecode":{"bytecode":"0x610132610026600b82828239805160001a60731461001957fe5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361060335760003560e01c80639341231c146038575b600080fd5b818015604357600080fd5b50608d60048036036040811015605857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505060a7565b604051808215151515815260200191505060405180910390f35b60004782111560b557600080fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505060f257600080fd5b600190509291505056fea26469706673582212203471502f8b953b5622ae380d01fe3a6c574e1b7ae3ba80ebae95d88771f6714564736f6c63430006080033"},"devdoc":{"author":"Piper Merriam <[email protected]>","methods":{"sendOrThrow(address,uint256)":{"details":"Attempts to send the specified amount to the recipient throwing an error if it fails","params":{"recipient":"The address that the funds should be to.","value":"The amount in wei that should be sent."}}},"title":"Library for safe sending of ether."},"runtimeBytecode":{"bytecode":"0x730000000000000000000000000000000000000000301460806040526004361060335760003560e01c80639341231c146038575b600080fd5b818015604357600080fd5b50608d60048036036040811015605857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505060a7565b604051808215151515815260200191505060405180910390f35b60004782111560b557600080fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505060f257600080fd5b600190509291505056fea26469706673582212203471502f8b953b5622ae380d01fe3a6c574e1b7ae3ba80ebae95d88771f6714564736f6c63430006080033"},"sourceId":"SafeSendLib.sol"}},"deployments":{"blockchain://d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3/block/752820c0ad7abc1200f9ad42c4adc6fbb4bd44b5bed4667990e64565102c1ba6":{"Escrow":{"address":"0x41B8E7F94F92aE75266054f7029b2f5C30D19171","block":"0xe29b6d17dc4da99bbd985dd62c69cf70f3437c2c104eee24fa7a41d73e4a6524","contractType":"Escrow","runtimeBytecode":{"linkDependencies":[{"offsets":[447,786],"type":"reference","value":"SafeSendLib"}]},"transaction":"0x6f1bdf9e303c866dc74452cb418e05737c9b8c3a5ddfcd1c09509d5ec1fc23e9"},"SafeSendLib":{"address":"0x379EdD01a8c6E56649C092D2699eA877CC89414B","block":"0xb05e03a8ba4b744d5754f93fcb9c48e836fa624d9c2942c7081661a0e9e3134b","contractType":"SafeSendLib","transaction":"0x32a498696bd9924f34ac01f755c126d5628947f9935188098dc8eb6f7a30c418"}}},"manifest":"ethpm/3","name":"escrow","sources":{"./Escrow.sol":{"installPath":"./Escrow.sol","type":"solidity","urls":["ipfs://QmNLpdCi4UakwJ9rBoL7rDnEzNeA6f8uvKbiMhZVqTucu1"]},"./SafeSendLib.sol":{"installPath":"./SafeSendLib.sol","type":"solidity","urls":["ipfs://QmbEnqvCSAAYwQ474S1vCSBdMgdiRZ4gZWEmSmdXepXQJq"]}},"version":"1.0.0"} |
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,11 @@ | ||
{ | ||
"escrow": { | ||
"alias": "escrow", | ||
"install_uri": "ipfs://QmNpLojZo471M357NTUZ1qKDwjUZrfYctWhzPtNFEXcSaL", | ||
"registry_address": null, | ||
"resolved_content_hash": "QmNpLojZo471M357NTUZ1qKDwjUZrfYctWhzPtNFEXcSaL", | ||
"resolved_package_name": "escrow", | ||
"resolved_uri": "ipfs://QmNpLojZo471M357NTUZ1qKDwjUZrfYctWhzPtNFEXcSaL", | ||
"resolved_version": "1.0.0" | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"owned": { | ||
"alias": "owned", | ||
"install_uri": "ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", | ||
"registry_address": null, | ||
"resolved_content_hash": "QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", | ||
"resolved_package_name": "owned", | ||
"resolved_uri": "ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", | ||
"resolved_version": "1.0.0" | ||
} | ||
} |
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,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.8; | ||
|
||
contract Owned { | ||
address owner; | ||
|
||
modifier onlyOwner { require(msg.sender == owner); _; } | ||
|
||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
} |
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 @@ | ||
{"manifest":"ethpm/3","meta":{"authors":["Piper Merriam <[email protected]>"],"description":"Reusable contracts which implement a privileged 'owner' model for authorization.","keywords":["authorization"],"license":"MIT","links":{"documentation":"ipfs://QmUYcVzTfSwJoigggMxeo2g5STWAgJdisQsqcXHws7b1FW"}},"name":"owned","sources":{"Owned.sol":{"installPath":"./Owned.sol","type":"solidity","urls":["ipfs://QmU8QUSt56ZoBDJgjjXvAZEPro9LmK1m2gjVG5Q4s9x29W"]}},"version":"1.0.0"} |
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,11 @@ | ||
{ | ||
"piper-coin": { | ||
"alias": "piper-coin", | ||
"install_uri": "ipfs://QmNbvXM5ig6Qtz6abRuG52KgjFqfXDyBCdRTz7QDENgxzv", | ||
"registry_address": null, | ||
"resolved_content_hash": "QmNbvXM5ig6Qtz6abRuG52KgjFqfXDyBCdRTz7QDENgxzv", | ||
"resolved_package_name": "piper-coin", | ||
"resolved_uri": "ipfs://QmNbvXM5ig6Qtz6abRuG52KgjFqfXDyBCdRTz7QDENgxzv", | ||
"resolved_version": "1.0.0" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/ethpm.lock
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,11 @@ | ||
{ | ||
"standard-token": { | ||
"alias": "standard-token", | ||
"install_uri": "ipfs://QmQNffBrmbB3TuBCtYfYsJWJVLssatWXa3H6CkGeyNUySA", | ||
"registry_address": null, | ||
"resolved_content_hash": "QmQNffBrmbB3TuBCtYfYsJWJVLssatWXa3H6CkGeyNUySA", | ||
"resolved_package_name": "standard-token", | ||
"resolved_uri": "ipfs://QmQNffBrmbB3TuBCtYfYsJWJVLssatWXa3H6CkGeyNUySA", | ||
"resolved_version": "1.0.0" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...per-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/_src/AbstractToken.sol
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,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.8; | ||
|
||
|
||
/// Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20 | ||
|
||
/// @title Abstract token contract - Functions to be implemented by token contracts. | ||
/// @author Stefan George - <[email protected]> | ||
abstract contract Token { | ||
// This is not an abstract function, because solc won't recognize generated getter functions for public variables as functions | ||
function totalSupply() external view virtual returns (uint256 supply) {} | ||
function balanceOf(address owner) public view virtual returns (uint256 balance); | ||
function transfer(address to, uint256 value) public virtual returns (bool success); | ||
function transferFrom(address from, address to, uint256 value) public virtual returns (bool success); | ||
function approve(address spender, uint256 value) public virtual returns (bool success); | ||
function allowance(address owner, address spender) public view virtual returns (uint256 remaining); | ||
|
||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
event Approval(address indexed owner, address indexed spender, uint256 value); | ||
} |
84 changes: 84 additions & 0 deletions
84
...per-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/_src/StandardToken.sol
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,84 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.8; | ||
|
||
|
||
import "./AbstractToken.sol"; | ||
|
||
|
||
/// @title Standard token contract | ||
/// @author Stefan George - <[email protected]> | ||
contract StandardToken is Token { | ||
/* | ||
* Data structures | ||
*/ | ||
mapping (address => uint256) balances; | ||
mapping (address => mapping (address => uint256)) allowed; | ||
uint256 override public totalSupply; | ||
|
||
constructor (uint _totalSupply) public { | ||
totalSupply = _totalSupply; | ||
balances[msg.sender] = _totalSupply; | ||
emit Transfer(address(0), msg.sender, _totalSupply); | ||
} | ||
|
||
/* | ||
* Read and write storage functions | ||
*/ | ||
/// @dev Transfers sender's tokens to a given address. Returns success. | ||
/// @param _to Address of token receiver. | ||
/// @param _value Number of tokens to transfer. | ||
function transfer(address _to, uint256 _value) public override returns (bool success) { | ||
if (balances[msg.sender] >= _value && _value > 0) { | ||
balances[msg.sender] -= _value; | ||
balances[_to] += _value; | ||
emit Transfer(msg.sender, _to, _value); | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success. | ||
/// @param _from Address from where tokens are withdrawn. | ||
/// @param _to Address to where tokens are sent. | ||
/// @param _value Number of tokens to transfer. | ||
function transferFrom(address _from, address _to, uint256 _value) public override returns (bool success) { | ||
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { | ||
balances[_to] += _value; | ||
balances[_from] -= _value; | ||
allowed[_from][msg.sender] -= _value; | ||
emit Transfer(_from, _to, _value); | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
/// @dev Returns number of tokens owned by given address. | ||
/// @param _owner Address of token owner. | ||
function balanceOf(address _owner) public override view returns (uint256 balance) { | ||
return balances[_owner]; | ||
} | ||
|
||
/// @dev Sets approved amount of tokens for spender. Returns success. | ||
/// @param _spender Address of allowed account. | ||
/// @param _value Number of approved tokens. | ||
function approve(address _spender, uint256 _value) public override returns (bool success) { | ||
allowed[msg.sender][_spender] = _value; | ||
emit Approval(msg.sender, _spender, _value); | ||
return true; | ||
} | ||
|
||
/* | ||
* Read storage functions | ||
*/ | ||
/// @dev Returns number of allowed tokens for given address. | ||
/// @param _owner Address of token owner. | ||
/// @param _spender Address of token spender. | ||
function allowance(address _owner, address _spender) public override view returns (uint256 remaining) { | ||
return allowed[_owner][_spender]; | ||
} | ||
|
||
} |
Oops, something went wrong.