def create_child_account(**in_data): inputs = [ addresser.create_organization_account_address( account_id=in_data["parent_zero_pub"], index=0), addresser.child_account_address( account_id=in_data["txn_key"].get_public_key().as_hex(), index=0), ] outputs = [ addresser.create_organization_account_address( account_id=in_data["parent_zero_pub"], index=0), addresser.child_account_address( account_id=in_data["txn_key"].get_public_key().as_hex(), index=0), ] account = payload_pb2.CreateChildAccount( parent_zero_pub=in_data["parent_zero_pub"], parent_idx=in_data["parent_idx"], parent_role=in_data["parent_role"], org_name=in_data["org_name"], first_name=in_data["first_name"], last_name=in_data["last_name"], user_id=in_data["user_id"], 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"], time=in_data["time"], indian_time=in_data["indian_time"], role=in_data["role"], deactivate=in_data["deactivate"], deactivate_on=in_data["deactivate_on"], nonce=in_data["nonce"], nonce_hash=in_data["nonce_hash"], signed_nonce=in_data["signed_nonce"], ) 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_CHILD_ACCOUNT, create_child_account=account) logging.info(payload) return make_header_and_batch(payload=payload, inputs=inputs, outputs=outputs, txn_key=in_data["txn_key"], batch_key=in_data["batch_key"])
def get_child(self, public_key, index): try: address = addresser.child_account_address(account_id=public_key, index=0) logging.info("Child address in get_account is {}".format(address)) except Exception as e: logging.error(e) raise InvalidTransaction("get_child error =={}".format(e)) ##entries will be a weird list of the form ##[address: "318c9fa5d39e9ccd2769115795e384b8e83b3267172ae518136ac49ddc5adf71d87814" ##data: "\nB02dbf0f4a3defef38df754122ef7c10fee6a4bb363312367524f86d230e205d459\022$b6de5d5b-7870-49df-971e-0885986bfa96\032 ##\006seller\"\021978-0-9956537-6-4*\0161-191-790-04532\r1-932866-82-5:\001\000"] entries = self._context.get_state(addresses=[address], timeout=self._timeout) try: entry = entries[0] except Exception as e: logging.info("No account with address {} and publickey {} can be \ found".format(address, public_key)) return False account = create_empty_child() account.ParseFromString(entry.data) logging.info("This is the account at {} stored on blockchain \ {}".format(address, account)) return account
async def child_details(self, public): child_address = addresser.child_account_address(public, 0) child_state = await deserialize_state.deserialize_child( self.app.config.REST_API_URL, child_address) child_db = await accounts_query.find_on_key(self.app, "user_id", child_state["user_id"]) return child_address, child_state, child_db
async def children(self): child_account_idxs, nth_keys = await self.indexes_n_pub_priv_pairs( "child_account_idxs") address_list = [] for key_index in child_account_idxs: public_key = nth_keys[str(key_index)]["public_key"] child_address = addresser.child_account_address( account_id=public_key, index=0) address_list.append(child_address) logging.info(f"child account addresses <<{address_list}>>") return address_list
def handle_receive_asset(receive_asset, header, state): """Handles creating a Receive Asset Transaction. """ logging.info("handle receive asset function execution is starting") if not signatures.ecdsa_signature_verify(receive_asset.org_zero_pub, receive_asset.signed_nonce, receive_asset.nonce): raise InvalidTransaction( "Signatures with account public key coudnt be verified") else: logging.info("Signatures verified") ##users zeroth public key has signed this transaction org_account = state.get_organization(public_key=receive_asset.org_zero_pub) if not org_account: raise InvalidTransaction("Account with public key {}\ doesnt exists".format( receive_asset.org_zero_pub)) if receive_asset.idx in org_account.receive_asset_idxs: raise InvalidTransaction( "This idx {} has already have been used in org\ {}".format(receive_asset.idx, receive_asset.org_address)) if receive_asset.child_zero_pub: child_account = state.get_child( public_key=receive_asset.child_zero_pub, index=0) if not child_account: raise InvalidTransaction("THe child for orgnisation {} doesnt\ exists on the with public_key{} at index {} with orgs zeroth \ public key {}" .format(receive_asset.org_name,\ receive_asset.child_zero_pub, 0,\ receive_asset.org_zero_pub)) if child_account.org_name != receive_asset.org_name: raise InvalidTransaction( "Child org name and receive asset org name doesnt match") child_address = addresser.child_account_address( receive_asset.child_zero_pub, index=0) else: child_address = None child_account = None try: logging.info(receive_asset) state.receive_asset(header.signer_public_key, org_account, child_address, child_account, receive_asset) except Exception as e: raise InvalidTransaction("Receive asset at index {}\ and with public key{} \ on an orgnization address <<{}>>"\ .format(receive_asset.idx, header.signer_public_key, receive_asset.org_address ))
def 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) return make_header_and_batch(payload=payload, inputs=inputs, outputs=outputs, txn_key=in_data["txn_key"], batch_key=in_data["batch_key"])
def set_child_float_account_idxs(self, public_key, key_index): child_account = self.get_child(public_key, 0) address = addresser.child_account_address(account_id=public_key, index=0) if key_index in child_account.float_account_idxs: raise InvalidTransaction( "Key index is already present in float_account_idxs") child_account.float_account_idxs.append(key_index) self._context.set_state({address: child_account.SerializeToString()}, self._timeout) return
def set_child(self, public_key, payload): logging.info(type(payload)) logging.info(dir(payload)) self.set_organization_children(payload.parent_zero_pub, payload.parent_idx) address = addresser.child_account_address(public_key, 0) child_account = create_empty_child() child_account.parent_idx = payload.parent_idx child_account.parent_zero_pub = payload.parent_zero_pub child_account.parent_role = payload.parent_role child_account.first_name = payload.first_name child_account.last_name = payload.last_name child_account.org_name = payload.org_name child_account.user_id = payload.user_id child_account.pancard = payload.pancard child_account.gst_number = payload.gst_number child_account.tan_number = payload.tan_number child_account.phone_number = payload.phone_number child_account.email = payload.email ##this was required to check the signed_nonce signed by the zeroth private ##key of the creator child_account.time = payload.time child_account.indian_time = payload.indian_time child_account.role = payload.role child_account.public = public_key child_account.deactivate = payload.deactivate child_account.deactivate_on = payload.deactivate_on ##so that we can later check who actually made this float_account and ## and was a vald account child_account.nonce = payload.nonce child_account.nonce_hash = payload.nonce_hash child_account.signed_nonce = payload.signed_nonce logging.info(child_account) logging.info("Account after serialization %s", child_account.SerializeToString()) return self._context.set_state( {address: child_account.SerializeToString()}, self._timeout)
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_child_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.child_account_address( account_id=in_data["txn_key"].get_public_key().as_hex(), index=0), ] outputs = [ addresser.create_organization_account_address( account_id=in_data["parent_zero_pub"], index=0), addresser.child_account_address( account_id=in_data["txn_key"].get_public_key().as_hex(), index=0), ] account = payload_pb2.CreateChildAccount( parent_zero_pub=in_data["parent_zero_pub"], parent_idx=in_data["parent_idx"], parent_role=in_data["parent_role"], org_name=in_data["org_name"], first_name=in_data["first_name"], last_name=in_data["last_name"], user_id=in_data["user_id"], 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"], time=in_data["time"], indian_time=in_data["indian_time"], role = in_data["role"], deactivate=in_data["deactivate"], deactivate_on=in_data["deactivate_on"], nonce=in_data["nonce"], nonce_hash=in_data["nonce_hash"], signed_nonce=in_data["signed_nonce"], ) 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_CHILD_ACCOUNT, create_child_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
def create_asset(**in_data): """ Inputs will have asset_address, account_address (The key index will be appended to the account address) float_accout (if the user only has a float_account till now, key_index will be appended to the float_account address) child_account_address (In case the asset being created by the child) """ ##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) return make_header_and_batch(payload=payload, inputs=inputs, outputs=outputs, txn_key=in_data["txn_key"], batch_key=in_data["batch_key"])
def create_float_account(**in_data): """Create a CreateAccount txn and wrap it in a batch and list. Args: txn_key(sawtooth_signing.Signer): signer created from user zeroth public key parent_zero_pub(string): zeroth account key of the pub who floated this trnasaction 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) parent_zero_pub: parent zero pub required for calcualting parent address parent_role=parent["role"], user_role=user_data["role"] Returns: tuple: List of Batch, signature tuple """ logging.info(f"THis is the data received in trsaction ceratrion {in_data}") 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) return make_header_and_batch(payload=payload, inputs=inputs, outputs=outputs, txn_key=in_data["txn_key"], batch_key=in_data["batch_key"])
def share_asset(self, payload, public): ##original asset shared_with key must be appended with the new random index ##at which this shared_asset has been created, so if original asset is revoked ## all the shared_assets will be revoked as well by iterating over the ## shared_with keys ##this will add the idx to the shared_with array of the asset original_asset = self.asset_at_address(payload.original_asset_address) original_asset.shared_with.append(payload.idx) self._context.set_state( { payload.original_asset_address: original_asset.SerializeToString() }, self._timeout) issuer_account = self.account_at_address( payload.issuer_account_address) self.update_share_index(payload.issuer_account_address, issuer_account, payload.idx) ##if its been shared with a child append shared_asset_array of the child too if payload.child_zero_pub: child_address = addresser.child_account_address( payload.child_zero_pub, 0) child_account = self.get_child(payload.child_zero_pub, 0) child_account.share_asset_idxs.append(payload.idx) self._context.set_state( {child_address: child_account.SerializeToString()}, self._timeout) share_asset_address = addresser.share_asset_address( public, payload.idx) share_asset = create_empty_share_asset() share_asset.key = payload.key share_asset.time = payload.time share_asset.url = payload.url share_asset.master_key = payload.master_key share_asset.master_url = payload.master_url share_asset.indiantime = payload.indiantime share_asset.file_name = payload.file_name share_asset.file_hash = payload.file_hash share_asset.idx = payload.idx share_asset.account_signature = payload.account_signature share_asset.asset_signature = payload.asset_signature share_asset.nonce = payload.nonce share_asset.nonce_hash = payload.nonce_hash share_asset.to_org_name = payload.to_org_name share_asset.to_org_address = payload.to_org_address share_asset.public = public share_asset.revoked_on = payload.revoked_on share_asset.original_asset_address = payload.original_asset_address share_asset.issuer_account_address = payload.issuer_account_address share_asset.receive_asset_address = payload.receive_asset_address share_asset.child_zero_pub = payload.child_zero_pub share_asset.unique_code_hash = payload.unique_code_hash logging.info(share_asset) logging.info("share_asset after serialization %s", share_asset.SerializeToString()) self._context.set_state( {share_asset_address: share_asset.SerializeToString()}, self._timeout) return
def set_asset(self, public, payload): """ payload will have the CreateAsset in the payload public: hex public key with whose private key transaction was signed account: could be a float account or account account_type: could be FLOAT_ACCOUNT or CREATE_ACCOUNT """ logging.info("Payload in set_asset <<{}>>".format(payload)) if payload.flt_account_parent_pub: account_address = addresser.float_account_address( account_id=payload.flt_account_parent_pub, index=payload.flt_account_parent_idx) logging.info("Updating create_asset_idxs in float_account\ at {}".format(account_address)) float_account = self.get_flt_account( public_key=payload.flt_account_parent_pub, index=payload.flt_account_parent_idx) self.update_asset_index(account_address, float_account, payload.idx) else: account_address = addresser.create_organization_account_address( account_id=payload.zero_pub, index=0) logging.info("Updating create_asset_idxs in \ organization_account at {}".format(account_address)) organization_account = self.get_organization( public_key=payload.zero_pub) self.update_asset_index(account_address, organization_account, payload.idx) ##if this is present that means that this asset is being created by child ##of the organization, so the payload.idx needs to be appended to the ##create_asset_idxs array of the child too if payload.child_zero_pub: account_address = addresser.child_account_address( account_id=payload.child_zero_pub, index=0) child_account = self.get_child(payload.child_zero_pub, 0) self.update_asset_index(account_address, child_account, payload.idx) address = addresser.create_asset_address(asset_id=public, index=payload.idx) asset = create_empty_asset() asset.key = payload.key asset.url = payload.url asset.time = payload.time asset.indiantime = payload.indiantime asset.file_name = payload.file_name asset.file_hash = payload.file_hash asset.idx = payload.idx asset.master_key = payload.master_key asset.master_url = payload.master_url asset.expired_on = payload.expired_on asset.role = payload.role asset.public = public asset.child_zero_pub = payload.child_zero_pub if payload.scope: asset.scope.group = payload.scope.group asset.scope.sub_group = payload.scope.sub_group asset.scope.field = payload.scope.field asset.scope.nature = payload.scope.nature asset.scope.operations = payload.scope.operations asset.scope.description = payload.scope.description logging.info(asset) logging.info("Account after serialization %s", asset.SerializeToString()) return self._context.set_state({address: asset.SerializeToString()}, self._timeout)