Skip to content

Instantly share code, notes, and snippets.

View Perseverance's full-sized avatar
🪄

George Spasov Perseverance

🪄
View GitHub Profile
pragma solidity ^0.4.20;
contract KeyValueStorage {
mapping(bytes32=>uint256) public uints;
mapping(bytes32=>bytes32) public bytes32s;
mapping(bytes32=>bool) public bools;
// And any other type you like
modifier onlyWhitelisted() {
_;
pragma solidity 0.4.15;
contract SharedStorage {
address public contractImplementation;
}
contract Forwardable {
/**
* @dev Performs a delegatecall and returns whatever the delegatecall returned (entire context execution will return!)
* @param _dst Destination address to perform the delegatecall
<script src="https://unpkg.com/ipfs/dist/index.js"></script>
const node = new Ipfs()
node.on('ready', () => {
console.log("IPFS Ready");
});
<script src="https://unpkg.com/ipfs/dist/index.js"></script>
const node = new Ipfs()
node.on('ready', () => {
console.log('IPFS Ready');
const file = 'File contents';
let fileBuffer = new buffer.Buffer(file);
node.files.add(fileBuffer, (err, hash) => {
const ethEcies = require('eth-ecies');
function encrypt(publicKey, userData) {
let userPublicKey = new Buffer(publicKey, 'hex');
let bufferUserData = new Buffer(userData);
let encryptedUserData = ethEcies.encrypt(userPublicKey, bufferUserData);
return encryptedUserData.toString('base64');
}
struct CatchedPoke {
uint caughtTime;
uint playerArrayIndex;
}
mapping(bytes32=>CatchedPoke) pokeLookupTable;
function addPoke(uint pokeId) {
bytes32 key = keccak256(msg.sender, pokeId);
CatchedPoke poke = pokeLookupTable[key];
@Perseverance
Perseverance / metamask.js
Created April 10, 2018 12:37
Ethers.js Metamask Provider and Wallet
function MetamaskSigner(web3, provider) {
this.provider = provider;
this.getAddress = function () {
return web3.eth.accounts[0];
}
Object.defineProperty(this, 'address', {
get: function () {
if (web3.eth.accounts.length == 0) {
@Perseverance
Perseverance / ECTools.sol
Last active September 27, 2018 17:39
ECTools.sol
pragma solidity ^0.4.18;
library ECTools {
/**
* @dev Recover signer address from a message by using his signature
* @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
* @param sig bytes signature
*/
function recover(bytes32 hash, bytes sig) public pure returns (address) {
const ethers = require('ethers');
const providers = ethers.providers;
const Wallet = ethers.Wallet;
const utils = ethers.utils;
const contractABI = require('../build/contracts/ECToolsTest.json').abi;
var provider;
(async function () {
declare var require: any;
function MetamaskSigner(web3, provider) {
this.provider = provider;
this.getAddress = function () {
return web3.eth.accounts[0];
};
Object.defineProperty(this, 'address', {