You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Should return balances of the observed wallets with non zero balances. Wallets balance observation is enabled by the [POST] /api/balances/{address}/observation and disabled by the [DELETE] /api/balances/{address}/observation.
Amount of the returned balances should not exceed take . Optional continuation contains context of the previous request, to let Blockchain.Api resume reading of the balances from the previous position. If continuation is empty, balances should be read from the beginning.
Response:
{{// Flag, which indicates that the address is valid“isValid”: boolean,// Continuation token, that// can be used to continue data reading// from the current position.// Should be null or empty string if no more data// to read.“continuation”: “string”,// Current batch of the items// Should be empty array if there are no items“items”:
[{// Wallet address“address”: “string”,// Asset ID , defaults to SKY“assetId”: “string”,// Balance is integer as string, aligned// to the asset accuracy. Actual value can be// calculated as// x = sourceBalance * (10 ^ asset.Accuracy)“balance”: “string”,// Incremental ID of the moment, when balance// is updated. It should be the same sequence// as for block in the// [GET] /api/transactions/broadcast/* responses// In other words , block number/height.“block”: integer64}]}
Since there are no constraints on tokens returned for continuation , some performance improvements should be obtained by returning the last address itself as continuation token for pagination. Should be stored in Redis index .
Python implementation
@api.route('/balances', methods=['GET'])defget_balances():
""" Get balances of addresses in observation list """update_index()
take=request.args.get('take')
iftakeisNone:
take=app_config.DEFAULT_LIST_LENGTHelse:
take=max(int(take), app_config.DEFAULT_LIST_LENGTH)
continuation=request.args.get('continuation') #Holds the continuation address previously sent to clientifcontinuationisNone:
continuation=""#Get address list from mongodbaddresses=get_addresses_balance_observation()
items= []
#define search boundariesstart_index=0ifcontinuation==""orcontinuationnotinaddresseselseaddresses.index(continuation)
total_items=takeiftake!=0elselen(addresses)
blockheight=get_indexed_blockheight()
if'error'inblockheight:
returnmake_response(jsonify(build_error(blockheight["error"])), blockheight["status"])
whilelen(items) <total_itemsandstart_index<len(addresses):
item= {}
#Get balance from index balance=get_indexed_balance(addresses[start_index])
if'error'inbalance: #If there is an error in balance, continue with the next addressstart_index+=1continue#Generate output responseitem['address'] =addresses[start_index]
item['assetId'] =app_config.SKYCOIN_FIBER_ASSETitem['balance'] =str(balance['balance']) #TODO: Asset accuracy. Find endpoint for thatitem['block'] =blockheight['blockheight']
ifbalance['balance'] !=0:
items.append(item)
start_index+=1#Add continuation addressifstart_index<len(addresses): #Still data to read #If it is the first call and need continuation create the tokenifcontinuation==""andtake!=0andtake<len(addresses):
continuation=addresses[start_index]
else:
continuation=""response= {"continuation": continuation, "items": items}
returnjsonify(response)
The text was updated successfully, but these errors were encountered:
[GET] /api/balances?take=integer&[continuation=string]
Should return balances of the observed wallets with non zero balances. Wallets balance observation is enabled by the
[POST] /api/balances/{address}/observation
and disabled by the[DELETE] /api/balances/{address}/observation
.Amount of the returned balances should not exceed
take
. Optional continuation contains context of the previous request, to let Blockchain.Api resume reading of the balances from the previous position. If continuation is empty, balances should be read from the beginning.Response:
Since there are no constraints on tokens returned for continuation , some performance improvements should be obtained by returning the last address itself as continuation token for pagination. Should be stored in Redis index .
Python implementation
The text was updated successfully, but these errors were encountered: