async fn redis_insert_account(
        &self,
        encrypted: &AccountWithEncryptedTokens,
    ) -> Result<(), NodeStoreError> {
        let account = &encrypted.account;
        let id = accounts_key(&self.db_prefix, account.id);
        let mut connection = self.connection.clone();
        let routing_table = self.routes.clone();
        // Check that there isn't already an account with values that MUST be unique
        let mut pipe = redis_crate::pipe();
        pipe.exists(&id);
        pipe.hexists(
            &*prefixed_key(&self.db_prefix, USERNAMES_KEY),
            account.username().as_ref(),
        );
        if account.routing_relation == RoutingRelation::Parent {
            pipe.exists(&*prefixed_key(&self.db_prefix, PARENT_ILP_KEY));
        }

        let results: Vec<bool> = pipe.query_async(&mut connection).await?;
        if results.iter().any(|val| *val) {
            warn!(
                "An account already exists with the same {}. Cannot insert account: {:?}",
                account.id, account
            );
            return Err(NodeStoreError::AccountExists(account.username.to_string()));
        }

        let mut pipe = redis_crate::pipe();
        pipe.atomic();

        // Add the account key to the list of accounts
        pipe.sadd(
            &*prefixed_key(&self.db_prefix, ACCOUNTS_KEY),
            RedisAccountId(account.id),
        )
        .ignore();

        // Save map for Username -> Account ID
        pipe.hset(
            &*prefixed_key(&self.db_prefix, USERNAMES_KEY),
            account.username().as_ref(),
            RedisAccountId(account.id),
        )
        .ignore();

        // Set balance-related details
        pipe.hset_multiple(&id, &[("balance", 0), ("prepaid_amount", 0)])
            .ignore();

        if account.should_send_routes() {
            pipe.sadd(
                &*prefixed_key(&self.db_prefix, SEND_ROUTES_KEY),
                RedisAccountId(account.id),
            )
            .ignore();
        }

        if account.should_receive_routes() {
            pipe.sadd(
                &*prefixed_key(&self.db_prefix, RECEIVE_ROUTES_FROM_KEY),
                RedisAccountId(account.id),
            )
            .ignore();
        }

        if account.ilp_over_btp_url.is_some() {
            pipe.sadd(
                &*prefixed_key(&self.db_prefix, BPT_OUTGOING),
                RedisAccountId(account.id),
            )
            .ignore();
        }

        // Add route to routing table
        pipe.hset(
            &*prefixed_key(&self.db_prefix, ROUTES_KEY),
            account.ilp_address.as_bytes(),
            RedisAccountId(account.id),
        )
        .ignore();

        // Set account details
        pipe.cmd("HMSET").arg(&id).arg(encrypted).ignore();

        // The parent account settings are done via the API. We just
        // had to check for the existence of a parent
        pipe.query_async(&mut connection).await?;

        update_routes(connection, routing_table, &self.db_prefix).await?;
        debug!(
            "Inserted account {} (ILP address: {})",
            account.id, account.ilp_address
        );
        Ok(())
    }
/// Inserts the account corresponding to the provided `AccountWithEncryptedtokens`
/// in Redis. Returns the provided account (tokens remain encrypted)
Inserts the account corresponding to the provided `AccountWithEncryptedtokens`
in Redis. Returns the provided account (tokens remain encrypted)
Inserts the account corresponding to the provided ` AccountWithEncryptedtokens ` in Redis . Returns the provided account ( tokens remain encrypted )
async fn redis_insert_account(
        &self,
        encrypted: &AccountWithEncryptedTokens,
    ) -> Result<(), NodeStoreError> {
        let account = &encrypted.account;
        let id = accounts_key(&self.db_prefix, account.id);
        let mut connection = self.connection.clone();
        let routing_table = self.routes.clone();
        // Check that there isn't already an account with values that MUST be unique
        let mut pipe = redis_crate::pipe();
        pipe.exists(&id);
        pipe.hexists(
            &*prefixed_key(&self.db_prefix, USERNAMES_KEY),
            account.username().as_ref(),
        );
        if account.routing_relation == RoutingRelation::Parent {
            pipe.exists(&*prefixed_key(&self.db_prefix, PARENT_ILP_KEY));
        }
        let results: Vec<bool> = pipe.query_async(&mut connection).await?;
        if results.iter().any(|val| *val) {
            warn!(
                "An account already exists with the same {}. Cannot insert account: {:?}",
                account.id, account
            );
            return Err(NodeStoreError::AccountExists(account.username.to_string()));
        }
        let mut pipe = redis_crate::pipe();
        pipe.atomic();
        // Add the account key to the list of accounts
        pipe.sadd(
            &*prefixed_key(&self.db_prefix, ACCOUNTS_KEY),
            RedisAccountId(account.id),
        )
        .ignore();
        // Save map for Username -> Account ID
        pipe.hset(
            &*prefixed_key(&self.db_prefix, USERNAMES_KEY),
            account.username().as_ref(),
            RedisAccountId(account.id),
        )
        .ignore();
        // Set balance-related details
        pipe.hset_multiple(&id, &[("balance", 0), ("prepaid_amount", 0)])
            .ignore();
        if account.should_send_routes() {
            pipe.sadd(
                &*prefixed_key(&self.db_prefix, SEND_ROUTES_KEY),
                RedisAccountId(account.id),
            )
            .ignore();
        }
        if account.should_receive_routes() {
            pipe.sadd(
                &*prefixed_key(&self.db_prefix, RECEIVE_ROUTES_FROM_KEY),
                RedisAccountId(account.id),
            )
            .ignore();
        }
        if account.ilp_over_btp_url.is_some() {
            pipe.sadd(
                &*prefixed_key(&self.db_prefix, BPT_OUTGOING),
                RedisAccountId(account.id),
            )
            .ignore();
        }
        // Add route to routing table
        pipe.hset(
            &*prefixed_key(&self.db_prefix, ROUTES_KEY),
            account.ilp_address.as_bytes(),
            RedisAccountId(account.id),
        )
        .ignore();
        // Set account details
        pipe.cmd("HMSET").arg(&id).arg(encrypted).ignore();
        // The parent account settings are done via the API. We just
        // had to check for the existence of a parent
        pipe.query_async(&mut connection).await?;
        update_routes(connection, routing_table, &self.db_prefix).await?;
        debug!(
            "Inserted account {} (ILP address: {})",
            account.id, account.ilp_address
        );
        Ok(())
    }
async fn redis_insert_account ( & self , encrypted : & AccountWithEncryptedTokens , ) -> Result < ( ) , NodeStoreError > { let account = & encrypted . account ; let id = accounts_key ( & self . db_prefix , account . id ) ; let mut connection = self . connection . clone ( ) ; let routing_table = self . routes . clone ( ) ; // Check that there isn't already an account with values that MUST be unique let mut pipe = redis_crate :: pipe ( ) ; pipe . exists ( & id ) ; pipe . hexists ( & * prefixed_key ( & self . db_prefix , USERNAMES_KEY ) , account . username ( ) . as_ref ( ) , ) ; if account . routing_relation == RoutingRelation :: Parent { pipe . exists ( & * prefixed_key ( & self . db_prefix , PARENT_ILP_KEY ) ) ; } let results : Vec < bool > = pipe . query_async ( & mut connection ) . await ? ; if results . iter ( ) . any ( | val | * val ) { warn ! ( " " account id account ) ; return Err ( NodeStoreError :: AccountExists ( account . username . to_string ( ) ) ) ; } let mut pipe = redis_crate :: pipe ( ) ; pipe . atomic ( ) ; // Add the account key to the list of accounts pipe . sadd ( & * prefixed_key ( & self . db_prefix , ACCOUNTS_KEY ) , RedisAccountId ( account . id ) , ) . ignore ( ) ; // Save map for Username -> Account ID pipe . hset ( & * prefixed_key ( & self . db_prefix , USERNAMES_KEY ) , account . username ( ) . as_ref ( ) , RedisAccountId ( account . id ) , ) . ignore ( ) ; // Set balance-related details pipe . hset_multiple ( & id , & [ ( " " , 0 ) , ( " " , 0 ) ] ) . ignore ( ) ; if account . should_send_routes ( ) { pipe . sadd ( & * prefixed_key ( & self . db_prefix , SEND_ROUTES_KEY ) , RedisAccountId ( account . id ) , ) . ignore ( ) ; } if account . should_receive_routes ( ) { pipe . sadd ( & * prefixed_key ( & self . db_prefix , RECEIVE_ROUTES_FROM_KEY ) , RedisAccountId ( account . id ) , ) . ignore ( ) ; } if account . ilp_over_btp_url . is_some ( ) { pipe . sadd ( & * prefixed_key ( & self . db_prefix , BPT_OUTGOING ) , RedisAccountId ( account . id ) , ) . ignore ( ) ; } // Add route to routing table pipe . hset ( & * prefixed_key ( & self . db_prefix , ROUTES_KEY ) , account . ilp_address . as_bytes ( ) , RedisAccountId ( account . id ) , ) . ignore ( ) ; // Set account details pipe . cmd ( " " ) . arg ( & id ) . arg ( encrypted ) . ignore ( ) ; // The parent account settings are done via the API. We just // had to check for the existence of a parent pipe . query_async ( & mut connection ) . await ? ; update_routes ( connection , routing_table , & self . db_prefix ) . await ? ; debug ! ( " " account id account ilp_address ) ; Ok ( ( ) ) }
Inserts the account corresponding to the provided `AccountWithEncryptedtokens`
in Redis.
Inserts the account corresponding to the provided ` AccountWithEncryptedtokens ` in Redis .
&self
encrypted
&AccountWithEncryptedTokens
&self
encrypted
&AccountWithEncryptedTokens