Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions web/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ def GetApi() :

return html

def GetJsonForBlock(block) :
data = {}

data['height'] = block['height']
data['time'] = block['time']
data['hash'] = block['hash']
data['previousblockhash'] = block['previousblockhash']
data['merkleroot'] = block['merkleroot']
data['miner'] = block['nextminer']
data['size'] = block['size']
data['version'] = block['version']
data['txnum'] = block['txnum']

json_str = json.dumps(data)

return json_str

def Api_V1_Address_Get_Value(address) :
data = {}
data['address'] = address
Expand Down Expand Up @@ -101,13 +118,25 @@ def Api_V1_Block_Get_Current_Height() :
return json_str

def Api_V1_Block_Get_Current_Block() :
return ''

def Api_V1_Block_Get_Block() :
return ''

def Api_V1_Block_Get_Block(height,hash) :
return ''
block = web.collection_blocks.find().sort("height",-1).limit(1)

return GetJsonForBlock(block[0])

def Api_V1_Block_Get_Block_By_Height(height) :
block = web.collection_blocks.find_one({"height":height})

if block :
return GetJsonForBlock(block)
else
return 'Block not found'

def Api_V1_Block_Get_Block_By_Hash(hash) :
block = web.collection_blocks.find_one({"hash":hash})

if block:
return GetJsonForBlock(block)
else
return 'Block not found'

def Api_V1_Tx_Get_Tx(txid) :
return ''
4 changes: 2 additions & 2 deletions web/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,11 @@ def Api_V1_Block_Get_Current_Block() :

@app.route('/api/v1/block/get_block/<int:height>')
def Api_V1_Block_Get_Block_By_Height(height) :
return api.Api_V1_Block_Get_Block(height,None), {'content-type':'application/json'}
return api.Api_V1_Block_Get_Block_By_Height(height), {'content-type':'application/json'}

@app.route('/api/v1/block/get_block/<regex("[a-zA-Z0-9]{64}"):hash>')
def Api_V1_Block_Get_Block_By_Hash(hash) :
return api.Api_V1_Block_Get_Block(None,hash), {'content-type':'application/json'}
return api.Api_V1_Block_Get_Block_By_Hash(hash), {'content-type':'application/json'}

@app.route('/api/v1/tx/get_tx/<regex("[a-zA-Z0-9]{64}"):txid>')
def Api_V1_Tx_Get_Tx(txid) :
Expand Down