Skip to content

Instantly share code, notes, and snippets.

View grrrrreee's full-sized avatar
๐Ÿ™ƒ
yeahhhhahahhah

grrrrreee grrrrreee

๐Ÿ™ƒ
yeahhhhahahhah
View GitHub Profile
@grrrrreee
grrrrreee / mine.py
Created October 17, 2020 10:07
์ฑ„๊ตด์— ๋Œ€ํ•œ ๋ณด์ƒ์„ ๊ตฌํ˜„ํ•œ ์ฝ”๋“œ์ด๋‹ค.
import hashlib
import json
from time import time
from uuid import uuid4
from flask import Flask, jsonify, request
...
@grrrrreee
grrrrreee / addnew_transaction.py
Last active October 17, 2020 10:00
์ƒˆ๋กœ์šด ๊ฑฐ๋ž˜๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ์ฝ”๋“œ์ด๋‹ค.
import hashlib
import json
from textwrap import dedent
from time import time
from uuid import uuid4
from flask import Flask, jsonify, request
...
@grrrrreee
grrrrreee / flask.py
Created October 17, 2020 09:55
flask๋ฅผ ์ด์šฉํ•˜์—ฌ ๋‹จ์ผ ๋…ธ๋“œ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ฝ”๋“œ์ด๋‹ค.
import hashlib
import json
from textwrap import dedent
from time import time
from uuid import uuid4
from flask import Flask
class Blockchain(object):
@grrrrreee
grrrrreee / proofowwork.py
Created October 17, 2020 09:52
PoW์™€ ์ด๋ฅผ ๊ฒ€์ฆํ•˜๋Š” ๊ณผ์ •์ด ๋‹ด๊ฒจ์žˆ๋Š” ์ฝ”๋“œ์ด๋‹ค.
import hashlib
import json
from time import time
from uuid import uuid4
class Blockchain(object):
...
@grrrrreee
grrrrreee / hash.py
Created October 17, 2020 09:38
PoW ๊ณผ์ •์„ ๋ณด์—ฌ์ฃผ๋Š” ์ฝ”๋“œ์ด๋‹ค.
from hashlib import sha256
x = 5
y = 0
while sha256(f'{x*y}'.encode()).hexdigest()[-1] != "0":
y += 1
print(f'The solution is y = {y}')
@grrrrreee
grrrrreee / blockchain.py
Created October 17, 2020 09:35
๋ธ”๋ก์˜ ๊ตฌ์กฐ๋ฅผ ์ถ”๊ฐ€ํ•œ ์ฝ”๋“œ์ด๋‹ค.
import hashlib
impot json
from time import time
class Blockchain(object):
def __init__(self):
self.current_transactions = []
self.chain = []
# ์ƒˆ๋กœ์šด ์ œ๋„ค์‹œ์Šค ๋ธ”๋ก ๋งŒ๋“ค๊ธฐ
@grrrrreee
grrrrreee / new_transaction.py
Created October 17, 2020 09:07
์ƒˆ๋กœ์šด ๊ฑฐ๋ž˜๊ตฌ์กฐ๋ฅผ ํ‘œํ˜„ํ•œ ์ฝ”๋“œ์ด๋‹ค.
class Blockchain(object):
...
def new_transaction(self, sender, recipient, amount):
"""
์ƒˆ๋กœ์šด ๊ฑฐ๋ž˜๋Š” ๋‹ค์Œ์œผ๋กœ ์ฑ„๊ตด๋  ๋ธ”๋ก์— ํฌํ•จ๋˜๊ฒŒ ๋œ๋‹ค. ๊ฑฐ๋ž˜๋Š” 3๊ฐœ์˜ ์ธ์ž๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.
sender์™€ recipient๋Š” string์œผ๋กœ ๊ฐ๊ฐ ์ˆ˜์‹ ์ž์™€ ์†ก์‹ ์ž์˜ ์ฃผ์†Œ์ด๋‹ค.
amount๋Š” int๋กœ ์ „์†ก๋˜๋Š” ์–‘์„ ์˜๋ฏธํ•œ๋‹ค. return์€ ํ•ด๋‹น ๊ฑฐ๋ž˜๊ฐ€ ์†ํ•ด์งˆ ๋ธ”๋ก์˜ ์ˆซ์ž๋ฅผ ์˜๋ฏธํ•œ๋‹ค.
"""
@grrrrreee
grrrrreee / block.json
Created October 17, 2020 08:58
๋ธ”๋ก์˜ ๊ตฌ์กฐ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ์ฝ”๋“œ์ด๋‹ค
block = {
'index': 1,
'timestamp': 1506057125.900785,
'transactions': [
{
'sender': "8527147fe1f5426f9dd545de4b27ee00",
'recipient': "a77f5cdfa2934df3954a5c7c7da5df1f",
'amount': 5,
}
],
@grrrrreee
grrrrreee / blueprint.py
Created October 17, 2020 08:55
๋ธ”๋ก์ฒด์ธ ๋ธ”๋ฃจํ”„๋ฆฐํŠธ์— ๋Œ€ํ•œ ์ฝ”๋“œ์ด๋‹ค.
class Blockchain(object):
def __init__(self):
self.chain=[]
self.current_transactions=[]
def new_block(self):
# ์ƒˆ๋กœ์šด ๋ธ”๋ก์„ ์ƒ์„ฑํ•˜๊ณ  ์ฒด์ธ์— ๋„ฃ๋Š”๋‹ค
pass
@staticmethod
@grrrrreee
grrrrreee / cli_send.go
Created September 8, 2020 16:11
send ๋ช…๋ น์–ด๋ฅผ ๊ตฌํ˜„ํ•œ ๊ฒƒ
// cli.go
// send ๋ช…๋ น์–ด๋ฅผ ๊ตฌํ˜„ํ•œ ๊ฒƒ
func (cli *CLI) send(from, to string, amount int) {
bc := NewBlockchain(from)
defer bc.db.Close()
tx := NewUTXOTransaction(from, to, amount, bc)
bc.MineBlock([]*Transaction{tx})
fmt.Println("Success!")