
    8'hhz                         d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZm	Z	 d dl
mZ ddlmZmZ d dlmZ d dlZd dlZd dlZd dlZd dlZd dlZddlmZmZmZ  G d	 d
e      Z G d de      Z G d de      Zy)    N)RegisterOptionsCallDetails)ApplicationErrorTransportLost)ApplicationSession   )unpack_uint256pack_uint256)time_ns)hlrecover_eip712_signersign_eip712_datac                   F    e Zd ZdZd
dZed        Zd Zd Zd Z	d Z
d	 Zy)	KeySeriesz}
    Data encryption key series with automatic (time-based) key rotation
    and key offering (to the XBR market maker).
    Nc                 :   t        |      t        k(  rt        |      dk(  sJ t        |      t        k(  r|dkD  sJ t        |      t        k(  r|dkD  sJ |t	        |      sJ || _        || _        || _        || _        d| _	        d| _
        d| _        i | _        y)a}  

        :param api_id: ID of the API for which to generate keys.
        :type api_id: bytes

        :param price: Price per key in key series.
        :type price: int

        :param interval: Key rotation interval in seconds.
        :type interval: int

        :param on_rotate: Optional user callback fired after key was rotated.
        :type on_rotate: callable
           r   N)typebyteslenintcallable_api_id_price	_interval
_on_rotate_id_key_box_archive)selfapi_idpriceinterval	on_rotates        P/var/www/html/trade_iq/venv/lib/python3.12/site-packages/autobahn/xbr/_seller.py__init__zKeySeries.__init__8   s     F|u$V):::E{c!eai//H~$A55 HY$777!#		    c                     | j                   S )z
        Get current XBR data encryption key ID (of the keys being rotated
        in a series).

        :return: Current key ID in key series (16 bytes).
        :rtype: bytes
        )r   r    s    r%   key_idzKeySeries.key_idV   s     xxr'   c                     t        j                  |      }| j                  j                  |      }| j                  d|fS )z
        Encrypt data with the current XBR data encryption key.

        :param payload: Application payload to encrypt.
        :type payload: object

        :return: The ciphertext for the encrypted application payload.
        :rtype: bytes
        cbor)cbor2dumpsr   encryptr   )r    payloaddata
ciphertexts       r%   r/   zKeySeries.encrypta   s7     {{7#YY&&t,
xx++r'   c                    t        |      t        k(  rt        |      dk(  sJ t        |      t        k(  rt        |      dk(  sJ | j                  |   \  }}t        j
                  j                  t        j
                  j                  |t        j                  j                              }|j                  |t        j                  j                        }|S )a  
        Encrypt a (previously used) XBR data encryption key with a buyer public key.

        :param key_id: ID of the data encryption key to encrypt.
        :type key_id: bytes

        :param buyer_pubkey: Buyer WAMP public key (Ed25519) to asymmetrically encrypt
            the data encryption key (selected by ``key_id``) against.
        :type buyer_pubkey: bytes

        :return: The ciphertext for the encrypted data encryption key.
        :rtype: bytes
        r       )encoder)r   r   r   r   naclpublic	SealedBox	PublicKeyencoding
RawEncoderr/   )r    r*   buyer_pubkeykey_sendkey_boxencrypted_keys          r%   encrypt_keyzKeySeries.encrypt_keyp   s     F|u$V):::L!U*s</@B/FFFv&Qkk++DKK,A,A,JN--JbJb -B -d e $++C9Q9Q+Rr'   c                     t               NNotImplementedErrorr)   s    r%   startzKeySeries.start       !##r'   c                     t               rC   rD   r)   s    r%   stopzKeySeries.stop   rG   r'   c           
        K   t        j                  d      | _        t        j                  j                  t        j                  j                  j                        | _	        t        j                  j                  | j                        | _
        | j                  | j                  f| j                  | j                  <   | j                  j                  dt        dd      t        t        j                   | j                              t        t        j                   | j"                                     | j$                  r| j%                  |        d {    y y 7 w)Nr   z4{tx_type} key "{key_id}" rotated [api_id="{api_id}"]z
XBR ROTATEmagentacolorr   )tx_typer*   r!   )osurandomr   r6   utilsrandomsecret	SecretBoxKEY_SIZEr   r   r   loginfor   uuidUUIDr   r   r)   s    r%   _rotatezKeySeries._rotate   s     ::b> JJ%%dkk&;&;&D&DE	 KK))$))4	 $(99dii"8dhhB|95diidhh/0diidll34	 	 	6 ??//$''' 's   EE!EE!rC   )__name__
__module____qualname____doc__r&   propertyr*   r/   rA   rF   rI   r[    r'   r%   r   r   2   s9    
<  ,4$$(r'   r   c                       e Zd Zd Zy)PayingChannelc                     t        |      t        k(  rt        |      dk(  sJ t        |      t        k(  r|dkD  sJ t        |      t        k(  r|dk\  sJ || _        || _        || _        y )N   r   )r   r   r   r   _adr_seq_balance)r    adrseqbalances       r%   r&   zPayingChannel.__init__   sc    CyE!c#h"n44CyCC!G++G}#144		r'   N)r\   r]   r^   r&   ra   r'   r%   rc   rc      s     r'   rc   c                   r    e Zd ZdZdZdZdZdZdZdZ	ddZ
ed        Zdd	Zd
 Zd Zd Zd Z	 ddZddZy)SimpleSellerNr   r            c                    t        |      t        k(  rt        |      dk(  sJ dj                  |             t        |      t        k(  rt        |      dk(  sJ dj                  |             |(t        |      t        k(  sJ dj                  |             t        j                         | _        t        j                  | _
        || _        || _        t        j                  j                  |      | _        d| _        | j                   j$                  j'                         | _        d| _        |xs t	        | j                   j$                        | _        i | _        d| _        d| _        d| _        i | _        i | _        d| _        d| _        y)a  

        :param market_maker_adr: Market maker public Ethereum address (20 bytes).
        :type market_maker_adr: bytes

        :param seller_key: Seller (delegate) private Ethereum key (32 bytes).
        :type seller_key: bytes

        :param provider_id: Optional explicit data provider ID. When not given, the seller delegate
            public WAMP key (Ed25519 in Hex) is used as the provider ID. This must be a valid WAMP URI part.
        :type provider_id: string
        re   z0market_maker_adr must be bytes[20], but got "{}"r4   z/seller delegate must be bytes[32], but got "{}"Nz0provider_id must be None or string, but got "{}"r   )r   r   r   formatstrtxaiomake_loggerrW   rm   
STATE_NONE_state_market_maker_adr	_pkey_raweth_keyskeys
PrivateKey_pkey_acct
public_keyto_canonical_address_addr_caddr_provider_id	_channels_channelrh   rg   _keys	_keys_map_session_session_regs)r    market_maker_adr
seller_keyprovider_ids       r%   r&   zSimpleSeller.__init__   s    $%.37G3HB3N  	\  QC  QJ  QJ  K[  Q\  	\NJ5(S_-B  	IDuD|D|  ~H  EI  	IB"d;&73&>  	G@r@y@y  {F  AG  	G>$$& #-- "2 $ ]]--j9

 
 ZZ**??A

  (E3tzz/D/D+E   	
 !r'   c                 .    | j                   j                  S )z
        This seller delegate public Ethereum key.

        :return: Ethereum public key of this seller delegate.
        :rtype: bytes
        )r}   r   r)   s    r%   r   zSimpleSeller.public_key   s     zz$$$r'   c                     t              t        k(  rt              dk(  r j                  vsJ t              t        k(  rdkD  sJ t        |      t        k(  r|dkD  sJ Gt              t
        k(  r.d j                         D        rd j                         D        sJ d        fd} j                  ||      }| j                  <    j                  j                  d|       |S )	a  
        Add a new (rotating) private encryption key for encrypting data on the given API.

        :param api_id: API for which to create a new series of rotating encryption keys.
        :type api_id: bytes

        :param price: Price in XBR token per key.
        :type price: int

        :param interval: Interval (in seconds) in which to auto-rotate the encryption key.
        :type interval: int
        r   r   c              3   @   K   | ]  }t        |      t        k(    y wrC   r   rs   ).0ks     r%   	<genexpr>z#SimpleSeller.add.<locals>.<genexpr>  s     CnWXDGsNCn   c              3   @   K   | ]  }t        |      t        k(    y wrC   r   )r   vs     r%   r   z#SimpleSeller.add.<locals>.<genexpr>  s2       ta  HItxyzt{  @C  uC  tar   zZinvalid categories type (must be dict) or category key or value type (must both be string)c                   K   | j                   }| j                  |<   d}|rX	 t               dz
  }j                  }t	        j
                  d      }j                  }j                  j                  d|	|||d t              nd 
d d |       d {   }j                  j                  dt        dd	      t        t        j                  |
            t        t        j                  	
            t        t        t!        dz        nd      dz   d	      t        t#        j$                  |      j'                               t                     j                  j)                  d|       y y y 7 # t*        $ rT}|j,                  dk(  rj                  j/                  d       nj                  j1                          Y d }~y Y d }~nId }~wt2        $ r j                  j/                  d       Y y  j                  j1                          Y nxY w|dz  }j                  j/                  d|       t5        j6                  d       d {  7   |r@w)N   l    d(	 A   zxbr.marketmaker.place_offer)privkeyr"   
categoriesexpirescopiesr   zh{tx_type} key "{key_id}" offered for {price} [api_id={api_id}, prefix="{prefix}", delegate="{delegate}"]z
XBR OFFER rK   rL   rN        NZor    XBR)rO   r*   r!   r"   delegateprefixzoffer={offer})offerzwamp.error.no_such_procedurez-xbr.marketmaker.offer: procedure unavailable!z2TransportLost while calling xbr.marketmaker.offer!r   z6Failed to place offer for key! Retrying {retries}/5 ..)retries)r*   r   r   r   rP   rQ   r   r   callr
   rW   rX   r   rY   rZ   rs   r   binasciib2a_hexdecodedebugr   errorwarnfailurer   asynciosleep)
key_seriesr*   r   
valid_fromr   	signaturer   r   er!   r   r   r"   r    s            r%   r$   z#SimpleSeller.add.<locals>.on_rotate  s    &&F%/DNN6"
 G,'!(\!9J#zzH "

2I"&"3"3K"&--"4"45R5;5;5;5?5=5>=ARWRc<;Nim@J=A<@AL #5 #N NE HHMM C "<y A!$))&"9:!$))&"9: e>OS)9%:UV!WZ`!`hqr!#H$4$4X$>$E$E$G!H!&z " + HHNN?%N@C N6 ( ww"@@&UV((* W % HHMM"VW'HH$$&1V`ghmmA&&&c s[   !I%A2E? E=C"E? :I%=E? ?	HAG
I%'H>I% H?I%II%z#Created new key series {key_series})r   )r   r   r   r   r   dictr{   valuesr   rW   rX   )r    r!   r   r"   r#   r   r$   r   s   ```` `  r%   addzSimpleSeller.add  s    F|u$V):vTZZ?WWWE{c!eai//H~$A55!d:&6$&>Cn\f\k\k\mCn  ta  MW  M^  M^  M`  ta  	@  d@  	@  b;	' ;	'z ^^FE8YG
'

6;
Sr'   c           
      B  K   t        |t              sJ dj                  |             | j                  t        j
                  t        j                  fv sJ d       t        j                  | _        || _        g | _	        | j                  j                  dt        | j                        t        j                  | j                   j"                  dd       j%                                dj                  | j&                        }|j)                  | j*                  |t-        d	      
       d{   }| j                  j/                  |       | j                  j1                  dt        |j2                               dj                  | j&                        }|j)                  | j4                  |t-        d	      
       d{   }| j                  j/                  |       | j                  j1                  dt        |j2                               | j6                  j9                         D ]  }|j;                          d{     |j=                  d| j>                         d{   }|j=                  d|d          d{   }tA        |d         tB        k(  rtE        |d         |d<   | j                  j                  dt        dt        j                  |d         j%                         z                tG        |d   |d   |d         | jH                  |d   <   t        jJ                  | _        || _&        |d   | _'        tA        | jN                        tB        k(  rtE        | jN                        | _'        |d   | _(        |d   S 7 b7 7 R7 /7 w)z
        Start rotating keys and placing key offers with the XBR market maker.

        :param session: WAMP session over which to communicate with the XBR market maker.
        :type session: :class:`autobahn.wamp.protocol.ApplicationSession`
        z/session must be an ApplicationSession, was "{}"zseller already runningzRStart selling from seller delegate address {address} (public key 0x{public_key}..)N
   )addressr   zxbr.provider.{}.selldetails)details_arg)optionsz"Registered procedure "{procedure}")	procedurezxbr.provider.{}.close_channelz)xbr.marketmaker.get_active_paying_channelz*xbr.marketmaker.get_paying_channel_balancechannel	remainingzIDelegate has currently active paying channel address {paying_channel_adr}0x)paying_channel_adrrj   ))
isinstancer   rr   rw   rm   rv   STATE_STOPPEDSTATE_STARTINGr   r   rW   rX   r   r   r   r   r}   r   r   r   registersellr   appendr   r   close_channelr   r   rF   r   r   r   r   r	   rc   r   STATE_STARTEDr   rh   rg   )r    sessionr   regr   r   paying_balances          r%   rF   zSimpleSeller.start]  s     '#56y8i8p8pqx8yy6{{|668R8RSSmUmmS"11j o!)!1!1$**2G2G2L!M!T!T!V 	 	X +11$2C2CD	$$TYY	?_hCi$jj!!#&;r#--GXY3::4;L;LM	$$T%7%7OhqLr$ss!!#&;r#--GXY**++- 	%J""$$$	%  %PRVR\R\]]  '||,XZabkZlmm{+,5*89T*UN;'a)+D83C3CGIDV3W3^3^3`,`)a 	 	c .;79;M~^cOdft  vA  gB  .Cwy)*"00  &{3%'*4==9DM"5)	k**E k
 t
 % ^ ns]   D,N.N/BNNA?NN%N*N+NND	NNNNNc                   K   | j                   t        j                  fv sJ d       t        j                  | _         g }| j                  j                         D ]#  }|j                         }|j                  |       % | j                  r_| j                  rL| j                  j                         r2| j                  D ]#  }|j                         }|j                  |       % d| _        t        j                  |      }	 | d{    t        j                   | _         d| _	        y7 !#  | j                  j                          Y =xY w# t        j                   | _         d| _	        w xY ww)zF
        Stop rotating/offering keys to the XBR market maker.
        seller not runningN)rw   rm   r   STATE_STOPPINGr   r   rI   r   r   r   is_attached
unregisterrt   gatherrW   r   r   )r    dlr   dr   s        r%   rI   zSimpleSeller.stop  s%     {{|99::P<PP:"11**++- 	J!AIIaL	 }}!:!:!<-- !C(AIIaL! "&DLL	!GG '44DK DM 	HH&44DK DMs<   C<E*?D( D&D( 	E*&D( (EE	 	E''E*c                 &  K   | j                   t        j                  fvrt        d      | j                  r| j                  j                         st        d      | j                  j                  d| j                  d          d{   }|S 7 w)a  
        Return current (off-chain) balance of paying channel:

        * ``amount``: The initial amount with which the paying channel was opened.
        * ``remaining``: The remaining amount of XBR in the paying channel that can be earned.
        * ``inflight``: The amount of XBR allocated to sell transactions that are currently processed.

        :return: Current paying balance.
        :rtype: dict
        r   z!market-maker session not attachedz+xbr.marketmaker.get_payment_channel_balancer   N)rw   rm   r   RuntimeErrorr   r   r   r   )r    r   s     r%   rk   zSimpleSeller.balance  s~      ;;|99::344}}DMM$=$=$?BCC#}}112_aeananoxayzz {s   BBB	Bc                    K   t        |      t        k(  rt        |      dk(  r|| j                  v sJ t        |      t        k(  sJ |J | j                  |   }|j                  |      \  }}}|||fS w)aG  
        Encrypt and wrap application payload for a given API and destined for a specific WAMP URI.

        :param api_id: API for which to encrypt and wrap the application payload for.
        :type api_id: bytes

        :param uri: WAMP URI the application payload is destined for (eg the procedure or topic URI).
        :type uri: str

        :param payload: Application payload to encrypt and wrap.
        :type payload: object

        :return: The encrypted and wrapped application payload: a tuple with ``(key_id, serializer, ciphertext)``.
        :rtype: tuple
        r   )r   r   r   r   rs   r/   )r    r!   urir0   	keyseriesr*   
serializerr2   s           r%   wrapzSimpleSeller.wrap  s       F|u$V):v?SSSCyC"""JJv&	)2):):7)C&
Jz:--s   A2A4c                  
   t        |      t        k(  rt        |      dk(  sJ dj                  t        |                   t        |      t        k(  rt        |      dk(  sJ dj                  t        |                   t        |      t        k(  sJ dj                  t        |                   t        |      t        k(  rt        |      dk(  sJ dj                  t        |                   t        |      t
        k(  sJ dj                  t        |                   t        |      t        k(  rt        |      dk(  sJ d	j                  t        |                   |t        |t              sJ d
       || j                  k7  r}t        ddj                  | j                  j                  t        j                  | j                        j                         t        j                  |      j                                     || j                  d   k7  r| j                   j#                          t        ddj                  | j                  j                  t        j                  | j                  d         j                         t        j                  |      j                                     || j$                  k7  r>t        ddj                  | j                  j                  | j$                  dz   |            t'        |      }|| j(                  k7  r;t        ddj                  | j                  j                  | j(                  |            t+        |||||      }||k7  r| j,                  j/                  d| j                  j                  t1        t        j                  |      j                               t1        t        j                  |      j                                      t        ddj                  | j                  j                              t3        | j4                  ||||      }	| j6                  |t9        |      ||	d}
| j,                  j;                  d| j                  j                  t1        dd      t1        t=        t	        |dz              dz   d      t1        |      t1        t        j                  |      j                               t1        |j>                        t1        |j@                                |
S )!zI
        Called by a XBR Market Maker to close a paying channel.
        re   z.market_maker_adr must be bytes[20], but was {}z)channel_adr must be bytes[20], but was {}z#channel_seq must be int, but was {}r4   z-channel_balance must be bytes[32], but was {}z)channel_is_final must be bool, but was {}r   z3marketmaker_signature must be bytes[65], but was {}/details must be autobahn.wamp.types.CallDetailsz!xbr.error.unexpected_delegate_adrzS{}.sell() - unexpected market maker (delegate) address: expected 0x{}, but got 0x{}r    xbr.error.unexpected_channel_adrJ{}.sell() - unexpected paying channel address: expected 0x{}, but got 0x{} xbr.error.unexpected_channel_seqR{}.sell() - unexpected channel (after tx) sequence number: expected {}, but got {}r   $xbr.error.unexpected_channel_balanceJ{}.sell() - unexpected channel (after tx) balance: expected {}, but got {}t{klass}.sell()::XBRSIG[4/8] - EIP712 signature invalid: signer_address={signer_address}, delegate_adr={delegate_adr}klasssigner_addressdelegate_adrxbr.error.invalid_signatureO{}.sell()::XBRSIG[4/8] - EIP712 signature invalid or not signed by market maker)r   rj   rk   is_finalr   z{klass}.close_channel() - {tx_type} closing channel {channel_adr}, closing balance {channel_balance}, closing sequence {channel_seq} [caller={caller}, caller_authid="{caller_authid}"]zXBR CLOSE  rK   rL   r   r   )r   rO   channel_balancechannel_seqchannel_adrcallercaller_authid)!r   r   r   rr   r   boolr   r   rx   r   	__class__r\   r   r   r   r   r   leaverg   r	   rh   r   rW   r   r   r   ry   r   r
   rX   rs   r   r   )r    r   r   r   r   channel_is_finalmarketmaker_signaturer   r   seller_signaturereceipts              r%   r   zSimpleSeller.close_channel  s*   
 $%.37G3HB3N  	`  QA  QH  QH  IM  N^  I_  Q`  	`NK E)c+.>".D  	LFqFxFxy}  J  zK  GL  	LDK C'h)N)U)UVZ[fVg)hh'O$-#o2F"2L  	\N}  OE  OE  FJ  KZ  F[  O\  	\L$%-y/Z/a/abfgwbx/yy-)*e3<Q8RWb8c  	  f[  fb  fb  cg  h}  c~  f  	c*Wk"BuDuuB t555"#F#x##  AE  AO  AO  AX  AX  Zb  Zj  Zj  ko  kA  kA  ZB  ZI  ZI  ZK  MU  M]  M]  ^n  Mo  Mv  Mv  Mx  $yz z $--	22MM!"#E#o#v#vw{  xF  xF  xO  xO  QY  Qa  Qa  bf  bo  bo  py  bz  Q{  QB  QB  QD  FN  FV  FV  Wb  Fc  Fj  Fj  Fl  $mn n $))#"#E#w#~#~  @D  @N  @N  @W  @W  Y]  Yb  Yb  ef  Yf  hs  $tu u )9dmm+"#I#o#v#vw{  xF  xF  xO  xO  QU  Q^  Q^  `o  $pq q /{KZj  mB  C--HHMM  Q $ 7 7)+H,<,<^,L,S,S,U)V')(*:*:;K*L*S*S*U'V  X ##@  CT  C[  C[  \`  \j  \j  \s  \s  Ct  u  u ,DNNKVegwx 

#O4()
 	  P NN33 i@&(S81K-L)MPV)V^g&h"$[/"$X%5%5k%B%I%I%K"L/$&w'<'<$= 	 	? r'   c
                    t        |      t        k(  rt        |      dk(  sJ d       t        |      t        k(  rt        |      dk(  sJ d       t        |      t        k(  rt        |      dk(  sJ d       t        |      t        k(  rt        |      dk(  sJ d       t        |      t        k(  sJ d       t        |      t        k(  rt        |      dk(  sJ d	j	                  t        |                   t        |      t        k(  rt        |      dk(  sJ d
j	                  t        |                   t        |      t        k(  rt        |      dk(  sJ d       |	t        |	t              sJ d       t        |      }t        |      }|| j                  k7  r}t        ddj	                  | j                  j                  t        j                  | j                        j                         t        j                  |      j                                     || j                  vr0t        ddj	                  | j                  j                  |            | j                  |   }
|| j                   d   k7  r| j"                  j%                          t        ddj	                  | j                  j                  t        j                  | j                   d         j                         t        j                  |      j                                     || j&                  dz   k7  r>t        ddj	                  | j                  j                  | j&                  dz   |            || j(                  |z
  k7  r>t        ddj	                  | j                  j                  | j(                  |z
  |            t+        |||d|      }||k7  r| j,                  j/                  d| j                  j                  t1        t        j                  |      j                               t1        t        j                  |      j                                      t        ddj	                  | j                  j                              | xj&                  dz  c_        | xj(                  |z  c_        |
j3                  ||      }t        |      t        k(  rt        |      dk(  s+J d j	                  | j                  j                  |             t5        | j6                  | j                   d   | j&                  | j(                        }|| j8                  ||| j&                  || j(                  |d!}| j,                  j;                  d"| j                  j                  t1        d#d$%      t1        t=        j>                  |&            t1        tA        t        |d'z              d(z   d$%      t1        tA        t        | j(                  d'z              d(z   d$%      t1        |	jB                        t1        |	jD                        t1        t        j                  |      j                               )	       |S )*al  
        Called by a XBR Market Maker to buy a data encyption key. The XBR Market Maker here is
        acting for (triggered by) the XBR buyer delegate.

        :param market_maker_adr: The market maker Ethereum address. The technical buyer is usually the
            XBR market maker (== the XBR delegate of the XBR market operator).
        :type market_maker_adr: bytes of length 20

        :param buyer_pubkey: The buyer delegate Ed25519 public key.
        :type buyer_pubkey: bytes of length 32

        :param key_id: The UUID of the data encryption key to buy.
        :type key_id: bytes of length 16

        :param channel_adr: The on-chain channel contract address.
        :type channel_adr: bytes of length 20

        :param channel_seq: Paying channel sequence off-chain transaction number.
        :type channel_seq: int

        :param amount: The amount paid by the XBR Buyer via the XBR Market Maker.
        :type amount: bytes

        :param balance: Balance remaining in the payment channel (from the market maker to the
            seller) after successfully buying the key.
        :type balance: bytes

        :param signature: Signature over the supplied buying information, using the Ethereum
            private key of the market maker (which is the delegate of the marker operator).
        :type signature: bytes of length 65

        :param details: Caller details. The call will come from the XBR Market Maker.
        :type details: :class:`autobahn.wamp.types.CallDetails`

        :return: The data encryption key, itself encrypted to the public key of the original buyer.
        :rtype: bytes
        re   zdelegate_adr must be bytes[20]r4   zbuyer_pubkey must be bytes[32]r   zkey_id must be bytes[16]zchannel_adr must be bytes[20]zchannel_seq must be intz)amount_paid must be bytes[32], but was {}z*post_balance must be bytes[32], but was {}r   zsignature must be bytes[65]r   z$xbr.error.unexpected_marketmaker_adrzH{}.sell() - unexpected market maker address: expected 0x{}, but got 0x{}zcrossbar.error.no_such_objectz{}.sell() - no key with ID "{}"r   r   r   r   r   r   r   r   Fr   r   r   r   P   zC{}.sell() - unexpected sealed key computed (expected bytes[80]): {})r*   r   r<   
sealed_keyr   amountrk   r   z{klass}.sell() - {tx_type} key "{key_id}" sold for {amount_earned} - balance is {balance} [caller={caller}, caller_authid="{caller_authid}", buyer_pubkey="{buyer_pubkey}"]z
XBR SELL  rK   rL   rN   r   r   )r   rO   r*   amount_earnedrk   r   r   r<   )#r   r   r   r   rr   r   r   r	   rx   r   r   r\   r   r   r   r   r   r   r   rg   rh   r   rW   r   r   rA   r   ry   r   rX   rY   rZ   rs   r   r   )r    r   r<   r*   r   r   r   rk   r   r   r   r   r   r   r   s                  r%   r   zSimpleSeller.sell#  s#   L $%.37G3HB3NpPppNL!U*s</@B/FhHhhFF|u$V):V<VV:K E)c+.>".DeFeeDK C'B)BB'F|u$V):|<g<n<nostzo{<||:G}%#f+*;=i=p=pquv}q~=;I%'C	N{,KjMjjK*Wk"BuDuuB' ) t555"#I#m#t#tuy  vD  vD  vM  vM  OW  O_  O_  `d  `v  `v  Ow  O~  O~  O@  BJ  BR  BR  Sc  Bd  Bk  Bk  Bm  $no o '"#BDeDlDlmqm{m{  nE  nE  GM  EN  O  O^^F+
 $--	22MM!"#E#o#v#vw{  xF  xF  xO  xO  QY  Qa  Qa  bf  bo  bo  py  bz  Q{  QB  QB  QD  FN  FV  FV  Wb  Fc  Fj  Fj  Fl  $mn n $))a-'"#E#w#~#~  @D  @N  @N  @W  @W  Y]  Yb  Yb  ef  Yf  hs  $tu u dmmf,,"#I#o#v#vw{  xF  xF  xO  xO  QU  Q^  Q^  ag  Qg  ip  $qr r /{KRWYbc--HHMM  Q $ 7 7)+H,<,<^,L,S,S,U)V')(*:*:;K*L*S*S*U'V  X ##@  CT  C[  C[  \`  \j  \j  \s  \s  Ct  u  u 			Q	  ++FLA
J5(S_-B  	v  EJ  EQ  EQ  RV  R`  R`  Ri  Ri  ku  Ev  	vB ,DNNDMM)<TVZV_V_aeanano  

 )
 %  99  }} *3
8 	  D NN33 Y?		 78$&s3v/@+A'BV'KS\$] S)A%B!Cf!LT]^/$&w'<'<$=#%h&6&6|&D&K&K&M#N 	 		P r'   rC   )r\   r]   r^   rW   r   rv   r   r   r   r   r&   r`   r   r   rF   rI   rk   r   r   r   ra   r'   r%   rm   rm      sm    
CIJNMNM?"B % %Sj5+n!>(.6 6:@DJr'   rm   )r   r   rP   rY   autobahn.wamp.typesr   r   autobahn.wamp.exceptionr   r   autobahn.wamp.protocolr   _utilr	   r
   zlmdbr   r-   rz   nacl.secretr6   
nacl.utilsnacl.publicrt   r   r   r   objectr   rc   rm   ra   r'   r%   <module>r     se   6   	  < C 5 /        ? >s( s(l F  {6 {r'   