Skip to content

Instantly share code, notes, and snippets.

View aunyks's full-sized avatar
Increasing potential

Gerald Nash aunyks

Increasing potential
View GitHub Profile
import hashlib as hasher
import datetime as date
# Define what a Snakecoin block is
class Block:
def __init__(self, index, timestamp, data, previous_hash):
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
@aunyks
aunyks / erc721-example.sol
Last active April 12, 2024 00:56
My implementation of the ERC721 token standard. WARNING: THIS CODE IS FOR EDUCATIONAL PURPOSES. DO NOT DEPLOY TO THE NETWORK.
pragma solidity ^0.4.19;
contract ERC721 {
string constant private tokenName = "My ERC721 Token";
string constant private tokenSymbol = "MET";
uint256 constant private totalTokens = 1000000;
mapping(address => uint) private balances;
mapping(uint256 => address) private tokenOwners;
mapping(uint256 => bool) private tokenExists;
mapping(address => mapping (address => uint256)) private allowed;
mapping(address => mapping(uint256 => uint256)) private ownerTokens;
@aunyks
aunyks / snakecoin-server-full-code.py
Last active March 8, 2024 19:22
The code in this gist isn't as succinct as I'd like it to be. Please bare with me and ask plenty of questions that you may have about it.
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:
@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
from flask import Flask
from flask import request
node = Flask(__name__)
# Store the transactions that
# this node has in a list
this_nodes_transactions = []
@node.route('/txion', methods=['POST'])
def transaction():
{
"from": "71238uqirbfh894-random-public-key-a-alkjdflakjfewn204ij",
"to": "93j4ivnqiopvh43-random-public-key-b-qjrgvnoeirbnferinfo",
"amount": 3
}
# Create the blockchain and add the genesis block
blockchain = [create_genesis_block()]
previous_block = blockchain[0]
# How many blocks should we add to the chain
# after the genesis block
num_of_blocks_to_add = 20
# Add blocks to the chain
for i in range(0, num_of_blocks_to_add):
def next_block(last_block):
this_index = last_block.index + 1
this_timestamp = date.datetime.now()
this_data = "Hey! I'm block " + str(this_index)
this_hash = last_block.hash
return Block(this_index, this_timestamp, this_data, this_hash)
import datetime as date
def create_genesis_block():
# Manually construct a block with
# index zero and arbitrary previous hash
return Block(0, date.datetime.now(), "Genesis Block", "0")
@aunyks
aunyks / snakecoin-block.py
Last active March 8, 2024 18:49
The block structure for SnakeCoin.
import hashlib as hasher
class Block:
def __init__(self, index, timestamp, data, previous_hash):
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
self.hash = self.hash_block()