work on new block system

This commit is contained in:
Kevin Froman 2018-06-08 02:46:05 -05:00
parent 2703731053
commit ee04c6d2bf
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
2 changed files with 8 additions and 8 deletions

View File

@ -211,12 +211,10 @@ class API:
elif action == 'getData':
resp = ''
if self._utils.validateHash(data):
if os.path.exists('data/blocks/' + data + '.db'):
try:
block = Block(data, core=self._core)()
resp = base64.b64encode(block.getRaw())
except TypeError:
resp = ""
if not os.path.exists('data/blocks/' + data + '.db'):
block = Block(data.encode(), core=self._core)
resp = base64.b64encode(block.getRaw()).decode()
if len(resp) == 0:
abort(404)
resp = ""

View File

@ -96,8 +96,10 @@ class Block:
if filelocation is None:
if self.getHash() is None:
return False
filelocation = 'data/blocks/%s.dat' % self.getHash()
try:
filelocation = 'data/blocks/%s.dat' % self.getHash().decode()
except AttributeError:
filelocation = 'data/blocks/%s.dat' % self.getHash()
with open(filelocation, 'rb') as f:
blockdata = f.read().decode('utf-8')