6 from .mininode
import *
12 self.
blockDB = dbm.open(datadir +
"/blocks",
'c')
19 def get(self, blockhash):
20 serialized_block =
None 22 serialized_block = self.
blockDB[repr(blockhash)]
25 f = BytesIO(serialized_block)
41 if current_tip
is None:
43 current_block_header = self.
get_header(current_tip)
44 if current_block_header
is None:
48 headersList = [ current_block_header ]
50 while (headersList[0].sha256
not in locator.vHave):
51 prevBlockHash = headersList[0].hashPrevBlock
52 prevBlockHeader = self.
get_header(prevBlockHash)
53 if prevBlockHeader
is not None:
54 headersList.insert(0, prevBlockHeader)
57 headersList = headersList[:maxheaders]
58 hashList = [x.sha256
for x
in headersList]
59 index = len(headersList)
60 if (hash_stop
in hashList):
61 index = hashList.index(hash_stop)+1
62 response.headers = headersList[:index]
68 self.
blockDB[repr(block.sha256)] = bytes(block.serialize())
69 except TypeError
as e:
70 print "Unexpected error: ", sys.exc_info()[0], e.args
81 block = self.
get(i.hash)
87 if current_tip
is None:
92 lastBlock = self.
get(current_tip)
93 while lastBlock
is not None:
94 r.append(lastBlock.hashPrevBlock)
96 lastBlock = self.
get(lastBlock.hashPrevBlock)
108 self.
txDB = dbm.open(datadir +
"/transactions",
'c')
116 serialized_tx = self.
txDB[repr(txhash)]
119 f = BytesIO(serialized_tx)
128 self.
txDB[repr(tx.sha256)] = bytes(tx.serialize())
129 except TypeError
as e:
130 print "Unexpected error: ", sys.exc_info()[0], e.args
136 tx = self.
get(i.hash)
138 responses.append(
msg_tx(tx))
def get_locator(self, current_tip=None)
def add_transaction(self, tx)
def __init__(self, datadir)
def get_transactions(self, inv)
def headers_for(self, locator, hash_stop, current_tip=None)
def add_header(self, header)
def __init__(self, datadir)
def add_block(self, block)
def get_blocks(self, inv)
def get_header(self, blockhash)