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
# ...blockchain | |
# ...Block class definition | |
miner_address = "q3nf394hjg-random-miner-address-34nf3i4nflkn3oi" | |
def proof_of_work(last_proof): | |
# Create a variable that we will use to find | |
# our next proof of work | |
incrementor = last_proof + 1 | |
# Keep incrementing the incrementor until |
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
@node.route('/blocks', methods=['GET']) | |
def get_blocks(): | |
chain_to_send = blockchain | |
# Convert our blocks into dictionaries | |
# so we can send them as json objects later | |
for block in chain_to_send: | |
block_index = str(block.index) | |
block_timestamp = str(block.timestamp) | |
block_data = str(block.data) | |
block_hash = block.hash |
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
from flask import Flask | |
from flask import request | |
import json | |
import requests | |
import hashlib as hasher | |
import datetime as date | |
node = Flask(__name__) | |
# Define what a Snakecoin block is | |
class Block: |
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
var crypto = require('crypto'); | |
// Create a new random 32-byte private key. | |
function createPrivateKey(){ | |
return crypto.randomBytes(32); | |
} |
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
var eccrypto = require('eccrypto'); | |
// Uncompressed (65-byte) public key | |
// that corresponds to the given private key | |
function getPublicKey(privateKey){ | |
return eccrypto.getPublic(privateKey); | |
} |
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
var crypto = require('crypto'); | |
function createAddress(publicKey){ | |
let sha256 = crypto.createHash("sha256"); | |
sha256.update(publicKey); | |
return sha256.digest('hex'); | |
} |
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
function createWallet(){ | |
let privateKey = createPrivateKey(); | |
let publicKey = getPublicKey(privateKey); | |
let address = createAddress(publicKey); | |
return ({ | |
private: privateKey.toString('hex'), | |
public: publicKey.toString('hex'), | |
address: address | |
}); | |
} |
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
var request = require('request'); | |
function createTransaction(fromAddress, toAddress, amount, peerUrl){ | |
// Send a post request | |
request.post( | |
// ...to the provided url | |
peerUrl, | |
{ | |
// ...in JSON | |
json: { |
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
// Grabbed from: https://github.com/ethereum/EIPs/issues/20 | |
contract ERC20 { | |
function totalSupply() constant returns (uint theTotalSupply); | |
function balanceOf(address _owner) constant returns (uint balance); | |
function transfer(address _to, uint _value) returns (bool success); | |
function transferFrom(address _from, address _to, uint _value) returns (bool success); | |
function approve(address _spender, uint _value) returns (bool success); | |
function allowance(address _owner, address _spender) constant returns (uint remaining); | |
event Transfer(address indexed _from, address indexed _to, uint _value); | |
event Approval(address indexed _owner, address indexed _spender, uint _value); |
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
contract MyERCToken { | |
// In this case, the total supply | |
// of MyERCToken is fixed, but | |
// it can very much be changed | |
uint256 _totalSupply = 1000000; | |
function totalSupply() constant returns (uint256 theTotalSupply) { | |
// Because our function signature | |
// states that the returning variable | |
// is "theTotalSupply", we'll just set that variable |