completed chunk read and write
This commit is contained in:
parent
16fb32cf35
commit
bed230d728
31
util.py
31
util.py
@ -2,6 +2,7 @@ from secretsharing import PlaintextToHexSecretSharer
|
||||
import subprocess
|
||||
import json
|
||||
from Crypto.Cipher import AES
|
||||
from more_itertools import sliced
|
||||
|
||||
# This function splits the secret and returns a list of shares
|
||||
def splitSecret(secret,threshold,splits):
|
||||
@ -28,9 +29,29 @@ def readUnitFromBlockchain(txid):
|
||||
text = content['floData']
|
||||
return text
|
||||
|
||||
#TODO write data chunk to blockchain
|
||||
#TODO read data chunk from blockchain
|
||||
#write data chunk to blockchain
|
||||
def writeDatatoBlockchain(text):
|
||||
splits = len(text)//350 + 1
|
||||
#TODO create a sliced list of strings
|
||||
#TODO for each string in the list create a transaction with txid of previous string
|
||||
n_splits = len(text)//350 + 1 #number of splits to be created
|
||||
splits = list(sliced(text, n_splits)) #create a sliced list of strings
|
||||
tail = writeUnitToBlockchain(splits[n_splits]) #create a transaction which will act as a tail for the data
|
||||
cursor = tail
|
||||
if n_splits == 1:
|
||||
return cursor #if only single transaction was created then tail is the cursor
|
||||
|
||||
#for each string in the list create a transaction with txid of previous string
|
||||
for i in range(n_splits-1,0):
|
||||
splits[i] = 'next:'+cursor+splits[i]
|
||||
cursor = writeUnitToBlockchain(splits[i])
|
||||
return cursor
|
||||
|
||||
#TODO read data chunk from blockchain
|
||||
def readDatafromBlockchain(cursor):
|
||||
text = []
|
||||
cursor_data = readUnitFromBlockchain(cursor)
|
||||
text.append(cursor_data[:])
|
||||
while(cursor_data[:5]=='next:'):
|
||||
cursor = cursor_data[:]
|
||||
cursor_data = readUnitFromBlockchain(cursor)
|
||||
text.append(cursor_data[:])
|
||||
text.join('')
|
||||
return text
|
||||
Loading…
Reference in New Issue
Block a user