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
var request = require('request');
function createTransaction(fromAddress, toAddress, amount, peerUrl){
// Send a post request
request.post(
// ...to the provided url
peerUrl,
{
// ...in JSON
json: {
function createWallet(){
let privateKey = createPrivateKey();
let publicKey = getPublicKey(privateKey);
let address = createAddress(publicKey);
return ({
private: privateKey.toString('hex'),
public: publicKey.toString('hex'),
address: address
});
}
var crypto = require('crypto');
function createAddress(publicKey){
let sha256 = crypto.createHash("sha256");
sha256.update(publicKey);
return sha256.digest('hex');
}
var eccrypto = require('eccrypto');
// Uncompressed (65-byte) public key
// that corresponds to the given private key
function getPublicKey(privateKey){
return eccrypto.getPublic(privateKey);
}
var crypto = require('crypto');
// Create a new random 32-byte private key.
function createPrivateKey(){
return crypto.randomBytes(32);
}
@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
# ...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
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
}