def ipfs_ledger_deconstruct(): data, nhash = ipfs_ledger_getter() #generate.initailize_new_genesis_chain(nhash) ledger = writer.Ledger(nhash) with open(ledger.filename, 'wb') as file: file.write(data) writer.ledger_parse(ledger.filename) print(chain.c_hash)
def initailize_genesis_chain(ledgername): ###### DANGER THIS FUNCTION WILL CREATE A NEW GENESIS BLOCK ON THE SELECTED LEDGER #### USE ONLY FOR FRESH LEDGER OR USE initailize_new_genesis_chain() ledger = writer.Ledger(ledgername) # create ledger object for filename reference genesis_block = g_g_block() # generate the genesis block chain.blockchain.append(genesis_block) # add genesis block to the block chain list print_block(chain.blockchain,0) # print genesis block info gblocklist = [genesis_block.previous_hash, genesis_block.current_hash, genesis_block.next_hash] # generate genesis block value list writer.ledger_constructor(ledger.filename, gblocklist) # write genesis block to ledger
def new_block(ledgerfilename): # ledger class instance for file name reference ledger = writer.Ledger(ledgerfilename) # parse the selected ledger writer.ledger_parse(ledger.filename) # data gets stored in lists in module chain.py l = bc_l() # blockchain length calc l -= 1 # generate the next block in the chain newblock = Block(chain.c_hash[l], chain.n_hash[l]) chain.blockchain.append(newblock) nblocklist = [ newblock.previous_hash, newblock.current_hash, newblock.next_hash ] #TODO: concensus check to eliminate duplicate blocks # add new block to the ledger writer.ledger_constructor(ledger.filename, nblocklist)
def chash_analyzer(incoming_chash): # check if incoming client hash is a trusted hash # create file abject TODO: make this object in the setup script thfile = writer.Ledger('trustedhashes') # parse trusted hash file and append trusted hashes to dynamic list writer.ledger_parse(thfile.filename) log('BEGIN HASH CHECK') for i in range(0, len(trusted_hashes)): if incoming_chash != trusted_hashes[i]: log('CHASH CHECK FAIL') handshake.clear() handshake.append(0) return 'fail' elif incoming_chash == trusted_hashes[i]: log('CHASH CHECK PASS') # hs_key is setup function contained in the setup script handshake.clear() handshake.append(hs_key) return hs_key else: log('CHASH CHECK COMPLETELY FAILED') handshake.clear() handshake.append(0) return 'fail'
def upload_g_chain(): name = input('ledger>\t') ledger = writer.Ledger(name) add_file(ledger.filename)