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
#!/bin/bash | |
# Updates your slack installation on MAC to use dark mode | |
# adjust this URL for your chosen darkmode. | |
theme_url="https://cdn.rawgit.com/laCour/slack-night-mode/master/css/raw/black.css" | |
ssbj_dir="/Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/" | |
# ensure we are root | |
if [[ "$EUID" -ne 0 ]]; then |
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
Just for title |
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
import time | |
class Transaction: | |
def __init__(self, sender, recipient, amount): | |
""" | |
Creates a new transaction | |
:param sender: <str> sender account | |
:param recipient: <str> recipient account |
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
import hashlib | |
from api.schema.block import BlockSchema | |
from time import time | |
class Block: | |
def __init__(self, index, transactions, nonce, previous_hash): | |
""" | |
Constructs a new 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
def create_transaction(self, sender, recipient, amount): | |
""" | |
Creates a new transaction to go into the next block | |
:param sender: <str> sender address | |
:param recipient: <str> recipient address | |
:param amount: <float> amount | |
:return: <Transaction> generated transaction | |
""" | |
transaction = Transaction(sender, recipient, amount) |
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
def __init__(self): | |
self.__current_transactions = [] | |
self.__chain = [] | |
# Create genesis block | |
self.create_genesis() | |
def create_genesis(self): | |
""" | |
Creates the Genesis block and passes it to the chain |
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
@staticmethod | |
def validate_proof_of_work(last_nonce, last_hash, nonce): | |
""" | |
Validates the nonce | |
:param last_nonce: <int> Nonce of the last block | |
:param nonce: <int> Current nonce to be validated | |
:param last_hash: <str> Hash of the last block | |
:return: <bool> True if correct, False if not. | |
""" |
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
def mine(self, reward_address): | |
""" | |
Mines a new block into the chain | |
:param reward_address: <str> address where the reward coin will be transferred to | |
:return: result of the mining attempt and the new block | |
""" | |
last_block = self.last_block | |
index = last_block.index + 1 | |
previous_hash = last_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
def add_block(self, block): | |
""" | |
Creates a new block and passes it to the chain | |
:param block: <Block> Block to add to the chain | |
:return: <bool> True if the block is added to the chain, False if not. | |
""" | |
if self.validate_block(block, self.last_block): | |
self.__chain.append(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
def validate_chain(self, chain_to_validate): | |
""" | |
Verifies if a given chain is valid | |
:param chain_to_validate: <[Block]> | |
:return: <bool> True if the chain is valid | |
""" | |
# First validate both genesis blocks | |
if chain_to_validate[0].hash_block() != self.__chain[0].hash_block(): | |
return False |
OlderNewer