Skip to content

Instantly share code, notes, and snippets.

@mcveat
mcveat / JsBSONHandlers.scala
Last active December 18, 2015 22:59 — forked from nevang/JsBSONHandlers.scala
Supports spray 1.1-M8 and spray-json 1.2.5
import spray.json._
import reactivemongo.bson._
import scala.util.{ Try, Success, Failure }
import org.apache.commons.codec.binary.Hex
import org.joda.time.format.ISODateTimeFormat
import org.joda.time.{DateTime, DateTimeZone}
import java.nio.ByteBuffer
/**
* From https://gist.github.com/nevang/4690568
implicit def eitherFormat[A, B](implicit af: Format[A], bf: Format[B]) = new Format[Either[A, B]] {
override def writes(o: Either[A, B]): JsValue = o match {
case Left(a) => af.writes(a)
case Right(b) => bf.writes(b)
}
override def reads(json: JsValue): JsResult[Either[A, B]] =
json.validate[B].map(Right.apply).orElse(json.validate[A].map(Left.apply))
}

Keybase proof

I hereby claim:

  • I am mcveat on github.
  • I am mcveat (https://keybase.io/mcveat) on keybase.
  • I have a public key ASBJkE7VqvqBmo3Y-AOdKqG10e1jSNrayzivXqkJcyCSLwo

To claim this, I am signing this object:

@mcveat
mcveat / genesis.json
Last active August 2, 2017 07:57
genesis.json for local test network
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "400",
"gasLimit": "2100000",
"alloc": {}
@mcveat
mcveat / genesis.json
Last active August 2, 2017 07:57
genesis.json for local test network with accounts preloaded
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "400",
"gasLimit": "2100000",
"alloc": {
bob = eth.accounts[0]
abi = [{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"initialSupply","type":"uint256"}],"payable":false,"type":"constructor"}]
contract = eth.contract(abi)
code = "0x6060604052341561000f57600080fd5b604051602080610310833981016040528080519060200190919050505b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b505b61028f806100816000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806370a0823114610049578063a9059cbb14610096575b600080fd5b341561005457600080fd5b610080600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506100d8565b604051808281526020019150506040518
john = eth.accounts[1]
KrugerToken = contract.at(receipt.contractAddress)
KrugerToken.transfer.sendTransaction(john, 10, {from: bob})
miner.start(1)
admin.sleepBlocks(2)
miner.stop()
bob = personal.newAccount("bobs password")
john = personal.newAccount("johns password")
miner.setEtherbase(bob)
miner.start(1)
admin.sleepBlocks(2) // halts script execution until 2 blocks are mined
miner.stop()
abi = [{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"initialSupply","type":"uint256"}],"payable":false,"type":"constructor"}]
contract = eth.contract(abi)
code = "0x6060604052341561000f57600080fd5b604051602080610310833981016040528080519060200190919050505b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b505b61028f806100816000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806370a08
#!/bin/bash
brew update
brew upgrade
brew tap ethereum/ethereum
brew install ethereum
brew install ethereum/ethereum/solidity
wget https://gist.githubusercontent.com/mcveat/6ddbc73d1dde311c3ff46e7ec9bcf456/raw/48dc522a571642a4d42f6eb31424b1bcd482197c/genesis.json
mkdir scripts
wget https://gist.githubusercontent.com/mcveat/583a5296d6f69a1838571f47ab2b99f2/raw/abf419908f582d57542dba357dcdaa6c156ebd36/all.js -O scripts/all.js
pragma solidity ^0.4.14;
contract KrugerToken {
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
/* Initializes contract with initial supply tokens to the creator of the contract */
function KrugerToken(uint256 initialSupply) {
balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
}