a
    bg>                     @   sx   d dl Z d dlZd dlmZmZmZmZ d dlmZ d dl	m
Z
mZ d dlmZmZ G dd de
ZG dd	 d	eZdS )
    N)ListOptionalTypeUnion)AsyncCallbackManagerForToolRun)	BaseModelField)AINBaseToolOperationTypec                   @   s   e Zd ZU dZedZeed< edddZe	ed< edddZ
eee	ee	 f  ed	< ed
ddZee ed< ed
ddZee ed< ed
ddZee ed< ed
ddZee ed< dS )
RuleSchemazSchema for owner operations..typezBlockchain reference path)descriptionpathNz'A single address or a list of addressesaddressFz2Authority to edit the `owner` property of the pathwrite_ownerz+Authority to edit `write rule` for the path
write_rulez(Authority to `set function` for the pathwrite_functionz,Authority to initialize `owner` of sub-pathsbranch_owner)__name__
__module____qualname____doc__r   r   r
   __annotations__r   strr   r   r   r   r   boolr   r   r    r   r   w/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/tools/ainetwork/owner.pyr      s$   
r   c                   @   s~   e Zd ZU dZdZeed< dZeed< eZ	e
e ed< deeeeeee f  ee ee ee ee ee ed	d	d
ZdS )AINOwnerOpszTool for owner operations.ZAINownerOpsnamea  
Rules for `owner` in AINetwork Blockchain database.
An address set as `owner` can modify permissions according to its granted authorities

## Path Rule
- (/[a-zA-Z_0-9]+)+
- Permission checks ascend from the most specific (child) path to broader (parent) paths until an `owner` is located.

## Address Rules
- 0x[0-9a-fA-F]{40}: 40-digit hexadecimal address
- *: All addresses permitted
- Defaults to the current session's address

## SET
- `SET` alters permissions for specific addresses, while other addresses remain unaffected.
- When removing an address of `owner`, set all authorities for that address to false.
- message `write_owner permission evaluated false` if fail

### Example
- type: SET
- path: /apps/langchain
- address: [<address 1>, <address 2>]
- write_owner: True
- write_rule: True
- write_function: True
- branch_owner: True

## GET
- Provides all addresses with `owner` permissions and their authorities in the path.

### Example
- type: GET
- path: /apps/langchain
r   args_schemaN)	r   r   r   r   r   r   r   run_managerreturnc	              
      s  ddl m}	 z|tju r||d u r,| jjjj}t|t	r<|g}| jj
|j|	dd fdd|D iiddI d H }
n4|tju r| jj
| I d H }
ntd	| d
tj|
ddW S  t y } z&t|j dt	| W  Y d }~S d }~0 0 d S )Nr   )ValueOnlyTransactionInputz.ownerZownersc                    s,   i | ]$}|pd pd pd  p"d dqS )F)r   r   r   r   r   ).0r   r   r   r   r   r   r   
<dictcomp>`   s   z%AINOwnerOps._arun.<locals>.<dictcomp>)value)ZtransactionInputzUnsupported 'type': .F)ensure_asciiz: )Z	ain.typesr"   r
   ZSETZ	interfaceZwalletZdefaultAccountr   
isinstancer   dbrefZsetOwnerGETZgetOwner
ValueErrorjsondumps	Exceptionbuiltinsr   r   )selfr   r   r   r   r   r   r   r    r"   reser   r$   r   _arunI   s.    


zAINOwnerOps._arun)NNNNNN)r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r5   r   r   r   r   r   !   s*   
"      r   )r1   r.   typingr   r   r   r   Zlangchain_core.callbacksr   Zpydanticr   r   Z(langchain_community.tools.ainetwork.baser	   r
   r   r   r   r   r   r   <module>   s   