Skip to content

Instantly share code, notes, and snippets.

contract ContractSignerVerifier {
// returns keccak256("isValidSigner") if signer is valid
function isValidSigner(address _signer, bytes memory data) public view returns (bytes32);
}
interface IChannelArbiter {
function channelValueForUpdate(address sender, address receiver, uint256 nonce) external view returns (uint256 value);
}
contract ChannelIdentifier {
@cwhinfrey
cwhinfrey / LibraryEncapsulation.sol
Created March 22, 2019 03:55
LibraryEncapsulation.sol
pragma solidity ^0.5.5;
// Libs
library FooLib {
struct Foo {
uint a;
uint b;
uint c;
}
@cwhinfrey
cwhinfrey / Create2Factory.sol
Created February 27, 2019 06:47
Create2Factory.sol
pragma solidity ^0.5.2;
contract Create2FactoryBase {
bytes private contractCode;
constructor(bytes memory _contractCode) public {
contractCode = _contractCode;
}
@cwhinfrey
cwhinfrey / AccountFactory.sol
Last active February 16, 2019 22:26
Meta Tx Create2 Contract Factory
pragma solidity ^0.5.0;
library ECDSA {
/**
* @dev Recover signer address from a message by using their signature
* @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
* @param signature bytes signature, the signature is generated using web3.eth.sign()
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
bytes32 r;
@cwhinfrey
cwhinfrey / OracleInterfaces.sol
Last active January 8, 2019 01:14
OracleInterfaces.sol
interface Oracle {
function isResultSetFor(uint256 id) external view returns (bool isSet);
function resultFor(uint256 id) external view returns (bytes32 result);
}
// Optional, OraclePrimary must implement Oracle
interface OraclePrimary {
event ResultSet(bytes32 _result, uint256 _id);
}
@cwhinfrey
cwhinfrey / PaymentChannelPOC.sol
Created December 21, 2018 17:09
PaymentChannelPOC.sol
pragma solidity ^0.4.24;
library ECDSA {
/**
* @dev Recover signer address from a message by using their signature
* @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
* @param signature bytes signature, the signature is generated using web3.eth.sign()
*/
function recover(bytes32 hash, bytes signature) internal pure returns (address) {
bytes32 r;
@cwhinfrey
cwhinfrey / MemoryAndStorageViewer.sol
Created November 7, 2018 18:44
MemoryAndStorageViewer.sol
contract MemoryAndStorageViewer {
uint256 storageVar1 = 23;
bytes32 storageVar2 = 0x12345;
uint8 storageVar3 = 55;
uint8 storageVar4 = 123;
function printStorage()
public
view
@cwhinfrey
cwhinfrey / ERC721 with updated _clearApproval
Created October 18, 2018 06:22
ERC721 with updated _clearApproval
pragma solidity ^0.4.24;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
import "../../introspection/ERC165.sol";
/**
@cwhinfrey
cwhinfrey / Escrow Comment Recommendations.md
Last active October 14, 2018 20:03
Escrow Comment Recommendations

Proposed directory structure:

contracts/
  escrow/
    ConditionalEscrow.sol
    Escrow.sol
    RefundEscrow.sol
  payment/
    PullPayment.sol
    SplitPayment.sol
@cwhinfrey
cwhinfrey / SafeERC20.sol
Created October 14, 2018 18:01
SafeERC20 Example
pragma solidity ^0.4.24;
/**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.