async def __send_user_account(**in_data): """ """ inputs = [ addresser.user_address( public=in_data["txn_key"].get_public_key().as_hex(), index=0), ] outputs = [ addresser.user_address( public=in_data["txn_key"].get_public_key().as_hex(), index=0), ] account = payload_pb2.CreateUserAccount( role=in_data["role"], phone_number=in_data["phone_number"], pancard=in_data["pancard"], first_name=in_data["first_name"], last_name=in_data["last_name"], user_id=in_data["user_id"], email=in_data["email"], time=in_data["time"], indian_time=in_data["indian_time"], deactivate=in_data["deactivate"], deactivate_on=in_data["deactivate_on"], ) logging.info(account) logging.info(f"THe address for the user on blockchain {inputs[0]}") payload = payload_pb2.TransactionPayload( payload_type=payload_pb2.TransactionPayload.CREATE_USER_ACCOUNT, create_user_account=account) logging.info(payload) transaction_ids, batches, batch_id, batch_list_bytes = make_header_and_batch( payload=payload, inputs=inputs, outputs=outputs, txn_key=in_data["txn_key"], batch_key=in_data["batch_key"]) logging.info(f"This is the batch_id {batch_id}") rest_api_response = await messaging.send(batch_list_bytes, in_data["config"]) try: result = await messaging.wait_for_status(batch_id, in_data["config"]) except (ApiBadRequest, ApiInternalError) as err: #await auth_query.remove_auth_entry(request.app.config.DB_CONN, request.json.get('email')) raise err return False, False return transaction_ids, batch_id
async def send_transfer_asset(**in_data): inputs = [in_data["receiver_address"], in_data["issuer_address"]] outputs = [in_data["receiver_address"], in_data["issuer_address"]] transfer_asset = payload_pb2.CreateTransferAsset( key=in_data["key"], url=in_data["url"], time=in_data["time"], indiantime=in_data["indiantime"], file_name=in_data["file_name"], file_hash=in_data["file_hash"], master_key=in_data["master_key"], master_url=in_data["master_url"], expired_on=in_data["expired_on"], scope=in_data["scope"], receiver_address=in_data["receiver_address"], issuer_address=in_data["issuer_address"], issuer_pub=in_data["issuer_pub"], issuer_zero_pub=in_data["issuer_zero_pub"], signed_nonce=in_data["signed_nonce"], nonce=in_data["nonce"], issuer_child_zero_pub=in_data["issuer_child_zero_pub"], ) payload = payload_pb2.TransactionPayload( payload_type=payload_pb2.TransactionPayload.TRANSFER_ASSET, transfer_asset=transfer_asset) transaction_ids, batches, batch_id, batch_list_bytes = make_header_and_batch( payload=payload, inputs=inputs, outputs=outputs, txn_key=in_data["txn_key"], batch_key=in_data["batch_key"]) logging.info(f"This is the batch_id {batch_id}") rest_api_response = await messaging.send(batch_list_bytes, in_data["config"]) try: result = await messaging.wait_for_status(batch_id, in_data["config"]) except (ApiBadRequest, ApiInternalError) as err: #await auth_query.remove_auth_entry(request.app.config.DB_CONN, request.json.get('email')) logging.error(f"Transaction Failed with error {err}") raise ApiInternalError(err) return transaction_ids, batch_id
async def __send_organization_account(**in_data): """ txn_key(sawtooth_signing.Signer): signer created from user zeroth public key batch_key(sawtooth_signing.Signer): signer created from QCI mnemonic zero private key, pancard(str): pancard of the user , phone_number(str): phone_number of the user, email(str): email of the user, claimed(bool): If this float account is claimed or not, claimed_by(str): Public key of the user for whom this float_acc transaction, create_asset_index(int): random key index at which the first asset was created, parent_pub(str): public key of the parent , parent_idx(str): Required to be appened to parent accoutn flt_key_inds, key_index, time=time.time(); indian_time=indian_time_stamp(), claimed_on(str): Date on which this flt account was claimed and converted to create account) """ inputs = [ addresser.organization_address( public=in_data["txn_key"].get_public_key().as_hex(), index=0), ] outputs = [ addresser.organization_address( public=in_data["txn_key"].get_public_key().as_hex(), index=0), ] account = payload_pb2.CreateOrganizationAccount( role=in_data["role"], phone_number=in_data["phone_number"], pancard=in_data["pancard"], user_id=in_data["user_id"], email=in_data["email"], org_name=in_data["org_name"], gst_number=in_data["gst_number"], tan_number=in_data["tan_number"], time=in_data["time"], indian_time=in_data["indian_time"], deactivate=in_data["deactivate"], deactivate_on=in_data["deactivate_on"], create_asset_idxs=in_data["create_asset_idxs"], ) logging.info(account) logging.info(f"THe address for the user on blockchain {inputs[0]}") payload = payload_pb2.TransactionPayload( payload_type=payload_pb2.TransactionPayload. CREATE_ORGANIZATION_ACCOUNT, create_organization_account=account) logging.info(payload) transaction_ids, batches, batch_id, batch_list_bytes = make_header_and_batch( payload=payload, inputs=inputs, outputs=outputs, txn_key=in_data["txn_key"], batch_key=in_data["batch_key"]) logging.info(f"This is the batch_id {batch_id}") rest_api_response = await messaging.send(batch_list_bytes, in_data["config"]) try: result = await messaging.wait_for_status(batch_id, in_data["config"]) except (ApiBadRequest, ApiInternalError) as err: #await auth_query.remove_auth_entry(request.app.config.DB_CONN, request.json.get('email')) raise err return False, False return transaction_ids, batch_id
async def send_create_asset(**in_data): """ Args key(str), hex_encoded: encrypted AES key with user publickey present at random index url(str): s3 url encrypted with user public key time(str): when this asset was created indiantime(str): time in indian format file_name(str): file_name file_hash(str): sha3_512 hash of file content child_idx(int): random index parent_zero_pub(str): Parent zero public key of the parent master_key(str): encrypted s3 url, encrypted with aes key generated with qci_public and user private key master_url(str): encrypted s3 url, encrypted with aes key generated with private key of user and public of QCI scope(Scope(defined in asset.proto)): string expired_on=13; //the date on which this certificate is intended """ ##TODO: Processor side : Float this asset and make change to create_asset_idxs ## to either float_Account_Address or create_Account_Address depending upon ##whther the user has been claimed or not inputs = [ addresser.create_asset_address( asset_id=in_data["txn_key"].get_public_key().as_hex(), index=in_data["idx"]), ] outputs = [ addresser.create_asset_address( asset_id=in_data["txn_key"].get_public_key().as_hex(), index=in_data["idx"]) ] ##ideally if account is claimed, we should have nothing to do with float account ## but we are sending both addresses to the processor and let processor handle ## the logic i.e float_account should exists and is_claimed shall be true ##to append create_asset_idxs to the account_transaction if not in_data["is_acc_claimed"]: ##implies user havent claimed his float_account_address, so the ## create_asset_idx aill be chnaged on flt_account_addresslogging.info("Float account parent pub %s"%in_data["flt_account_parent_pub"]) logging.info("Float account parent idx %s" % str(in_data["flt_account_parent_idx"])) float_account_address = addresser.float_account_address( account_id=in_data["flt_account_parent_pub"], index=in_data["flt_account_parent_idx"]) inputs.append(float_account_address) outputs.append(float_account_address) else: account_address = addresser.create_organization_account_address( account_id=in_data["zero_pub"], index=0) inputs.append(account_address) outputs.append(account_address) if in_data["child_zero_pub"]: child_address = addresser.child_account_address( account_id=in_data["child_zero_pub"], index=0) inputs.append(child_address) outputs.append(child_address) if in_data["scope"]: scope = payload_pb2.PayloadScope( group=in_data["scope"]["group"], sub_group=in_data["scope"]["sub_group"], field=in_data["scope"]["field"], nature=in_data["scope"]["nature"], operations=in_data["scope"]["operations"], description=in_data["scope"]["description"], ) else: scope = None logging.info(f"Input Address<<{inputs}>>") logging.info(f"Output Address<<{outputs}>>") asset = payload_pb2.CreateAsset( key=in_data["key"], url=in_data["url"], time=in_data["time"], indiantime=in_data["indiantime"], file_name=in_data["file_name"], file_hash=in_data["file_hash"], idx=in_data["idx"], master_key=in_data["master_key"], master_url=in_data["master_url"], role=in_data["role"], scope=scope, zero_pub=in_data["zero_pub"], flt_account_parent_pub=in_data["flt_account_parent_pub"], flt_account_parent_idx=in_data["flt_account_parent_idx"], child_zero_pub=in_data["child_zero_pub"]) logging.info(f"Create asset transaction {asset}") payload = payload_pb2.TransactionPayload( payload_type=payload_pb2.TransactionPayload.CREATE_ASSET, create_asset=asset) transaction_ids, batches, batch_id, batch_list_bytes = make_header_and_batch( payload=payload, inputs=inputs, outputs=outputs, txn_key=in_data["txn_key"], batch_key=in_data["batch_key"]) logging.info(f"This is the batch_id {batch_id}") rest_api_response = await messaging.send(batch_list_bytes, in_data["config"]) try: result = await messaging.wait_for_status(batch_id, in_data["config"]) except (ApiBadRequest, ApiInternalError) as err: #await auth_query.remove_auth_entry(request.app.config.DB_CONN, request.json.get('email')) logging.error(f"Transaction failed with {err}") raise ApiInternalError(err) #raise err return transaction_ids, batch_id
async def send_share_asset(**in_data): inputs = [ in_data["original_asset_address"], addresser.share_asset_address( in_data["txn_key"].get_public_key().as_hex(), in_data["idx"]), in_data["issuer_account_address"] #issuer_account_address ] outputs = [ in_data["original_asset_address"], addresser.share_asset_address( in_data["txn_key"].get_public_key().as_hex(), in_data["idx"]), in_data["issuer_account_address"] #issuer_account_address ] if in_data["child_zero_pub"]: child_account_address = addresser.child_account_address( in_data["child_zero_pub"], 0) inputs.append(child_account_address) outputs.append(child_account_address) share_asset = payload_pb2.CreateShareAsset( key=in_data["key"], url=in_data["url"], master_key=in_data["master_key"], master_url=in_data["master_url"], time=in_data["time"], indiantime=in_data["indiantime"], file_name=in_data["file_name"], file_hash=in_data["file_hash"], original_asset_address=in_data["original_asset_address"], revoked_on=in_data["revoked_on"], #details=in_data["details"], idx=in_data["idx"], account_signature=in_data["account_signature"], asset_signature=in_data["asset_signature"], nonce=in_data["nonce"], nonce_hash=in_data["nonce_hash"], to_org_name=in_data["to_org_name"], to_org_address=in_data["to_org_address"], issuer_account_address=in_data["issuer_account_address"], receive_asset_address=in_data["receive_asset_address"], child_zero_pub=in_data["child_zero_pub"], unique_code_hash=in_data["unique_code_hash"], ) logging.info(pprint(share_asset)) payload = payload_pb2.TransactionPayload( payload_type=payload_pb2.TransactionPayload.SHARE_ASSET, share_asset=share_asset) transaction_ids, batches, batch_id, batch_list_bytes = make_header_and_batch( payload=payload, inputs=inputs, outputs=outputs, txn_key=in_data["txn_key"], batch_key=in_data["batch_key"]) logging.info(f"This is the batch_id {batch_id}") rest_api_response = await messaging.send(batch_list_bytes, in_data["config"]) try: result = await messaging.wait_for_status(batch_id, in_data["config"]) except (ApiBadRequest, ApiInternalError) as err: #await auth_query.remove_auth_entry(request.app.config.DB_CONN, request.json.get('email')) logging.error(f"Transaction failed with {err}") raise ApiInternalError(err) #raise err return transaction_ids, batch_id
async def send_receive_asset(**in_data): """ """ address = addresser.receive_asset_address( asset_id=in_data["txn_key"].get_public_key().as_hex(), index=in_data["idx"]) inputs = [in_data["org_address"], address] outputs = [in_data["org_address"], address] logging.info(in_data) if in_data["child_zero_pub"]: child_address = addresser.child_account_address( account_id=in_data["child_zero_pub"], index=0) logging.info(f"CHILD address is {child_address}") inputs.append(child_address) outputs.append(child_address) if in_data["receive_asset_details"]: receive_asset_details = payload_pb2.ReceiveAssetDetails( name=in_data["receive_asset_details"]["name"], description=in_data["receive_asset_details"]["description"], ) receive_asset = payload_pb2.CreateReceiveAsset( _id_=in_data["_id_"], time=in_data["time"], indiantime=in_data["indiantime"], idx=in_data["idx"], at_which_asset_expires=in_data["at_which_asset_expires"], org_name=in_data["org_name"], org_address=in_data["org_address"], org_role=in_data["org_role"], org_zero_pub=in_data["org_zero_pub"], receive_asset_details=receive_asset_details, child_zero_pub=in_data["child_zero_pub"], signed_nonce=in_data["signed_nonce"], nonce=in_data["nonce"], nonce_hash=in_data["nonce_hash"], unique_code_hash=in_data["unique_code_hash"], encrypted_unique_code=in_data["encrypted_unique_code"], encrypted_admin_unique_code=in_data["encrypted_admin_unique_code"]) payload = payload_pb2.TransactionPayload( payload_type=payload_pb2.TransactionPayload.RECEIVE_ASSET, receive_asset=receive_asset) logging.info(payload) transaction_ids, batches, batch_id, batch_list_bytes = make_header_and_batch( payload=payload, inputs=inputs, outputs=outputs, txn_key=in_data["txn_key"], batch_key=in_data["batch_key"]) logging.info(f"This is the batch_id {batch_id}") rest_api_response = await messaging.send(batch_list_bytes, in_data["config"]) try: result = await messaging.wait_for_status(batch_id, in_data["config"]) except (ApiBadRequest, ApiInternalError) as err: #await auth_query.remove_auth_entry(request.app.config.DB_CONN, request.json.get('email')) logging.error(f"Transaction failed with {err}") raise ApiInternalError(err) #raise err return transaction_ids, batch_id
async def send_float_account(**in_data): """ txn_key(sawtooth_signing.Signer): signer created from user zeroth public key batch_key(sawtooth_signing.Signer): signer created from QCI mnemonic zero private key, pancard(str): pancard of the user , phone_number(str): phone_number of the user, email(str): email of the user, claimed(bool): If this float account is claimed or not, claimed_by(str): Public key of the user for whom this float_acc transaction, create_asset_index(int): random key index at which the first asset was created, parent_pub(str): public key of the parent , parent_idx(str): Required to be appened to parent accoutn flt_key_inds, key_index, time=time.time(); indian_time=indian_time_stamp(), claimed_on(str): Date on which this flt account was claimed and converted to create account) """ inputs = [addresser.create_organization_account_address( account_id=in_data["parent_zero_pub"], index=0), addresser.float_account_address( account_id=in_data["txn_key"].get_public_key().as_hex(), index=in_data["parent_idx"] ) ] logging.info(f"THe account address for the parent on blockchain {inputs[0]}") logging.info(f"THe float account address for the user {inputs[1]}") outputs = [addresser.create_organization_account_address( account_id=in_data["parent_zero_pub"], index=0), addresser.float_account_address( account_id=in_data["txn_key"].get_public_key().as_hex(), index=in_data["parent_idx"] ) ] if in_data["child_zero_pub"]: child_address = addresser.child_account_address( account_id=in_data["child_zero_pub"], index=0 ) logging.info(f"CHILD address is {child_address}") inputs.append(child_address) outputs.append(child_address) logging.info(f"INPUTS ADDRESSES --<{inputs}>--") logging.info(f"OUTPUTS ADDRESSES --<{outputs}>--") float_account = payload_pb2.CreateFloatAccount( claimed_on=in_data["claimed_on"], org_name=in_data["org_name"], pancard=in_data["pancard"], gst_number=in_data["gst_number"], tan_number=in_data["tan_number"], phone_number=in_data["phone_number"], email=in_data["email"], claimed=in_data["claimed"], claimed_by=in_data["claimed_by"], create_asset_idxs=in_data["create_asset_idxs"], parent_idx=in_data["parent_idx"], time=in_data["time"], indian_time=in_data["indian_time"], parent_role=in_data["parent_role"], role=in_data["role"], parent_zero_pub=in_data["parent_zero_pub"], nonce=in_data["nonce"], nonce_hash=in_data["nonce_hash"], signed_nonce=in_data["signed_nonce"], child_zero_pub=in_data["child_zero_pub"] ) logging.info(float_account) logging.info(f"THe serialized protobuf for float_account is {float_account}") payload = payload_pb2.TransactionPayload( payload_type=payload_pb2.TransactionPayload.CREATE_FLOAT_ACCOUNT, create_float_account=float_account) transaction_ids, batches, batch_id, batch_list_bytes= make_header_and_batch( payload=payload, inputs=inputs, outputs=outputs, txn_key=in_data["txn_key"], batch_key=in_data["batch_key"]) logging.info(f"This is the batch_id {batch_id}") rest_api_response = await messaging.send( batch_list_bytes, in_data["config"]) try: result = await messaging.wait_for_status(batch_id, in_data["config"]) except (ApiBadRequest, ApiInternalError) as err: #await auth_query.remove_auth_entry(request.app.config.DB_CONN, request.json.get('email')) raise err return False, False return transaction_ids, batch_id