a
    bg                     @   s   d dl Z d dlZd dlm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 G dd deeZG d	d
 d
eZG dd deZdS )    N)Enum)ListOptionalTypeUnion)AsyncCallbackManagerForToolRun)	BaseModelField)AINBaseToolc                   @   s   e Zd ZdZdZdZdS )AppOperationTypez$Type of app operation as enumerator.	SET_ADMIN
GET_CONFIGN)__name__
__module____qualname____doc__r   r    r   r   u/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/tools/ainetwork/app.pyr      s   r   c                   @   sZ   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	< dS )
	AppSchemazSchema for app operations..typez)Name of the application on the blockchain)descriptionappNameNzKA single address or a list of addresses. Default: current session's addressaddress)r   r   r   r   r	   r   r   __annotations__r   strr   r   r   r   r   r   r   r   r      s   
r   c                   @   sf   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dd	d
ZdS )	AINAppOpszTool for app operations.Z	AINappOpsnamea7  
Create an app in the AINetwork Blockchain database by creating the /apps/<appName> path.
An address set as `admin` can grant `owner` rights to other addresses (refer to `AINownerOps` for more details).
Also, `admin` is initialized to have all `owner` permissions and `rule` allowed for that path.

## appName Rule
- [a-z_0-9]+

## address Rules
- 0x[0-9a-fA-F]{40}
- Defaults to the current session's address
- Multiple addresses can be specified if needed

## SET_ADMIN Example 1
- type: SET_ADMIN
- appName: ain_project

### Result:
1. Path /apps/ain_project created.
2. Current session's address registered as admin.

## SET_ADMIN Example 2
- type: SET_ADMIN
- appName: test_project
- address: [<address1>, <address2>]

### Result:
1. Path /apps/test_project created.
2. <address1> and <address2> registered as admin.

r   args_schemaN)r   r   r   run_managerreturnc           	   
      s  ddl m} ddlm} z|tju r|d u r8| jjjj	}t
|trH|g}| jjd| d|  j|ddd |D id	d
I d H }n<|tju r| jjd| d 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   )ValueOnlyTransactionInput)getTimestampz/manage_app/z/create/Zadminc                 S   s   i | ]
}|d qS )Tr   ).0r   r   r   r   
<dictcomp>[       z#AINAppOps._arun.<locals>.<dictcomp>)value)ZtransactionInputz/configzUnsupported 'type': .F)ensure_asciiz: )Z	ain.typesr    Z	ain.utilsr!   r   r   Z	interfaceZwalletZdefaultAccountr   
isinstancer   dbrefZsetValuer   ZgetValue
ValueErrorjsondumps	Exceptionbuiltinsr   r   )	selfr   r   r   r   r    r!   reser   r   r   _arunF   s.    



zAINAppOps._arun)NN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r3   r   r   r   r   r   !   s   
  r   )r/   r,   enumr   typingr   r   r   r   Zlangchain_core.callbacksr   Zpydanticr   r	   Z(langchain_community.tools.ainetwork.baser
   r   r   r   r   r   r   r   r   <module>   s   