-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kyeongwook ma
committed
Sep 4, 2017
1 parent
4df1e35
commit 0a0b39f
Showing
5 changed files
with
129 additions
and
82 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,92 @@ | ||
import datetime | ||
|
||
from sqlalchemy import Column, String, Integer, DateTime | ||
|
||
from app import storage | ||
|
||
|
||
class Block(storage.Base): | ||
__tablename__ = 'blocks' | ||
|
||
_id = Column(Integer, primary_key=True, autoincrement=True) | ||
type = Column(String) | ||
prev_block_id = Column(String) | ||
prev_block_hash = Column(String) | ||
tx_list = Column(String) | ||
merkle_root = Column(String) | ||
time_stamp = Column(DateTime) | ||
block_id = Column(String) | ||
block_hash = Column(String) | ||
nonce = Column(String) | ||
block_info = Column(String) | ||
block_miner = Column(Integer) | ||
|
||
def __init__(self, prev_block_id, prev_block_hash, tx_list, merkle_root, nonce, block_info): | ||
self.type = 'B' | ||
self.prev_block_id = prev_block_id | ||
self.prev_block_hash = prev_block_hash | ||
self.tx_list = tx_list | ||
self.merkle_root = merkle_root | ||
self.time_stamp = datetime.datetime.now() | ||
self.block_id = self.type + self.time_stamp.strftime('%Y%m%d%H%M%S') | ||
self.block_hash = '' | ||
self.nonce = nonce | ||
self.block_info = block_info | ||
self.block_miner = 1 | ||
|
||
def __str__(self): | ||
return self.to_json() | ||
|
||
def to_json(self): | ||
return json.dumps({ | ||
'type': self.type, | ||
'time_stamp': self.time_stamp.strftime('%Y%m%d%H%M%S'), | ||
'prev_block_id': self.prev_block_id, | ||
'prev_block_hash': self.prev_block_hash, | ||
'merkle_root': self.merkle_root, | ||
'block_hash': self.block_hash, | ||
'nonce': self.nonce, | ||
'block_id': self.block_id | ||
}) | ||
|
||
|
||
class GenesisBlock(object): | ||
def __init__(self): | ||
self.type = 'B' | ||
self.prev_block_id = 'B000000000000' | ||
self.prev_block_hash = 'block_hash' | ||
self.tx_list = 'sechain' | ||
self.timp_stamp = '0000-00-00-00-00-00' | ||
self.block_id = 'B000000000000' | ||
self.merkle_root = 'sogangfinotek2017' | ||
self.block_hash = 'sechainfinochain2017' | ||
self.nonce = 2010101010 | ||
|
||
|
||
def create_block(block): | ||
storage.insert(block) | ||
storage.insert(block) | ||
|
||
|
||
def get_my_block(): | ||
return 0 | ||
|
||
|
||
def count(): | ||
storage.count(Block) | ||
|
||
|
||
def get_all_block(): | ||
return storage.get_all(Block) | ||
|
||
|
||
def get_last_block(): | ||
return get_all_block()[-1] | ||
|
||
|
||
if __name__ == '__main__': | ||
import json | ||
|
||
t = GenesisBlock() | ||
temp = json.dumps(t, indent=4, default=lambda o: o.__dict__, sort_keys=True) | ||
temps = json.loads(temp) | ||
print(type(temps['nonce'])) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import netifaces | ||
import socket | ||
|
||
1 | ||
|
||
|
||
def get_ip_address(ifname): | ||
|
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