bbc_core module

Copyright (c) 2017 beyond-blockchain.org.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

BBcCoreService([ipv6, p2p_port, core_port, ...])
class bbc_core.BBcCoreService(ipv6=None, p2p_port=None, core_port=None, use_global=False, workingdir='.bbc1', configfile=None, loglevel='all', logname='-', server_start=True)[source]

Bases: object

add_cross_ref_into_list(asset_group_id, txid)[source]

(internal use) register cross_ref info in the list

Parameters:
  • asset_group_id
  • txid
Returns:

asset_group_setup(domain_id, asset_group_id, storage_type=1, storage_path=None, advertise_in_domain0=False, config_update=False)[source]

Setup asset_group in a specified domain

Parameters:
  • domain_id
  • asset_group_id
  • storage_type
  • storage_path
  • advertise_in_domain0
  • config_update
Returns:

check_asset_in_response(query_entry)[source]

(internal use) Check asset in the transaction

Parameters:query_entry
Returns:
distribute_transaction_to_gather_signatures(asset_group_id, dat)[source]

Request to distribute sign_request to users

Parameters:
  • asset_group_id
  • dat
Returns:

error_reply(msg=None, err_code=-1, txt='')[source]
failure_response(query_entry)[source]

(internal use) Called when transaction search fails

Parameters:query_entry
Returns:
handler(socket, address)[source]

Message wait loop

Parameters:
  • socket
  • address
Returns:

insert_transaction(asset_group_id, txdata, asset_files, no_network_put=False)[source]

Insert transaction into ledger subsystem

Parameters:
  • asset_group_id – asset_group_id to insert into
  • txdata – BBcTransaction data
  • asset_files – dictionary of { asid=>asset_content,,, }
  • no_network_put – If false, skip networking.put()
param_check(param, dat)[source]

Check if the param is included

Parameters:
  • param – string or list of strings
  • dat
Returns:

pop_cross_refs(num=1)[source]

Return TxIDs for cross_refs

Parameters:num – The number of set of (txid, domain_id) to return
Returns:
process(socket, dat, payload_type)[source]

Process received message

Parameters:
  • socket
  • dat
  • payload_type – PayloadType value of msg
Returns:

quit_program()[source]
search_asset_by_asid(asset_group_id, asid, source_id, query_id)[source]

Search asset in the storage by asset_id. If not found, search it in the network

Parameters:
  • asset_group_id – asset_group_id to search in
  • asid – asset_id in byte format
  • source_id – the user_id of the sender
  • query_id
Returns:

dictionary data of transaction_data, asset_file (if exists)

search_transaction_by_txid(asset_group_id, txid, source_id, query_id)[source]

Search transaction_data by transaction_id

Parameters:
  • asset_group_id – asset_group_id to search in
  • txid – transaction_id
  • source_id – the user_id of the sender
  • query_id
Returns:

dictionary data of transaction_data

search_transaction_for_asset(query_entry)[source]

(internal use) Search transaction that includes the specified asset_id

Parameters:query_entry
Returns:
send_error_response(response_info)[source]

(internal use) send error response

Parameters:response_info
Returns:
send_message(dat)[source]

Send message to bbc_app (TCP client) :param dat: :return:

send_raw_message(socket, dat)[source]
send_response(response_info, dat)[source]

(internal use) send response message

Parameters:
  • response_info
  • dat
Returns:

send_to_other_user(asset_group_id, dst_user_id, src_user_id, msg)[source]
start_server(port, ipv6=False)[source]
succeed_to_find_transaction(query_entry)[source]

(internal use) Called when transaction search is successful

Parameters:query_entry
Returns:
validate_asset_file(txobj, asid, asset_file)[source]

Validate asset in storage by verifying SHA256 digest

Parameters:
  • txobj
  • asset_file
Returns:

validate_transaction(txid, txdata, asset_files)[source]

Validate transaction by verifying signature

Parameters:
  • txid – transaction_id
  • txdata – BBcTransaction data
  • asset_files – dictionary of { asid=>asset_content,,, }
bbc_core.check_transaction_if_having_asset_file(txdata, asid)[source]
bbc_core.daemonize(pidfile='/tmp/bbc1.pid')[source]
bbc_core.error_response(err_code=-255, txt='')[source]

(internal use) Create error response with reason text

Parameters:
  • err_code – error code (defined in bbc_error.py)
  • txt – reason text
Returns:

dictionary type data

bbc_core.make_message_structure(cmd, asgid, dstid, qid)[source]

(internal use) Create a base structure of message

Parameters:
  • cmd
  • asgid – asset_group_id
  • dstid – destination_user_id
  • qid – query_id
Returns: