Skip to content
Permalink
Browse files

refactor: replace AccountId with raw Uuid

  • Loading branch information
bstrie committed Nov 27, 2019
1 parent 2a52abc commit 78141d0f48ad9bbff5f85fbad310ae6170e9f72c
Showing with 320 additions and 352 deletions.
  1. +10 −4 Cargo.lock
  2. +1 −1 crates/ilp-node/Cargo.toml
  3. +3 −5 crates/ilp-node/src/node.rs
  4. +3 −6 crates/ilp-node/tests/test_helpers.rs
  5. +1 −0 crates/interledger-api/Cargo.toml
  6. +8 −15 crates/interledger-api/src/lib.rs
  7. +22 −24 crates/interledger-api/src/routes/accounts.rs
  8. +1 −0 crates/interledger-btp/Cargo.toml
  9. +8 −7 crates/interledger-btp/src/lib.rs
  10. +2 −1 crates/interledger-btp/src/service.rs
  11. +1 −0 crates/interledger-ccp/Cargo.toml
  12. +3 −2 crates/interledger-ccp/src/lib.rs
  13. +5 −5 crates/interledger-ccp/src/routing_table.rs
  14. +34 −33 crates/interledger-ccp/src/server.rs
  15. +10 −13 crates/interledger-ccp/src/test_helpers.rs
  16. +1 −0 crates/interledger-router/Cargo.toml
  17. +3 −2 crates/interledger-router/src/lib.rs
  18. +21 −20 crates/interledger-router/src/router.rs
  19. +3 −0 crates/interledger-service-util/Cargo.toml
  20. +8 −7 crates/interledger-service-util/src/echo_service.rs
  21. +3 −2 crates/interledger-service-util/src/exchange_rates_service.rs
  22. +8 −7 crates/interledger-service-util/src/expiry_shortener_service.rs
  23. +10 −8 crates/interledger-service-util/src/validator_service.rs
  24. +1 −1 crates/interledger-service/Cargo.toml
  25. +5 −41 crates/interledger-service/src/lib.rs
  26. +1 −1 crates/interledger-settlement/Cargo.toml
  27. +2 −2 crates/interledger-settlement/src/api/fixtures.rs
  28. +4 −3 crates/interledger-settlement/src/api/node_api.rs
  29. +16 −16 crates/interledger-settlement/src/api/test_helpers.rs
  30. +9 −12 crates/interledger-settlement/src/core/backends_common/redis/mod.rs
  31. +8 −7 crates/interledger-settlement/src/core/types.rs
  32. +1 −1 crates/interledger-store/Cargo.toml
  33. +8 −10 crates/interledger-store/src/account.rs
  34. +45 −51 crates/interledger-store/src/redis/mod.rs
  35. +4 −3 crates/interledger-store/tests/redis/accounts_test.rs
  36. +4 −4 crates/interledger-store/tests/redis/balances_test.rs
  37. +5 −4 crates/interledger-store/tests/redis/rate_limiting_test.rs
  38. +8 −7 crates/interledger-store/tests/redis/routing_test.rs
  39. +4 −4 crates/interledger-store/tests/redis/settlement_test.rs
  40. +2 −1 crates/interledger-stream/Cargo.toml
  41. +2 −1 crates/interledger-stream/src/client.rs
  42. +13 −11 crates/interledger-stream/src/lib.rs
  43. +9 −10 crates/interledger-stream/src/server.rs

Some generated files are not rendered by default. Learn more.

@@ -37,7 +37,7 @@ url = { version = "2.1.0", default-features = false }
libc = { version = "0.2.62", default-features = false }
warp = { version = "0.1.20", default-features = false, features = ["websocket"] }
secrecy = { version = "0.5.0", default-features = false, features = ["alloc", "serde"] }
uuid = { version = "0.8.1", default-features = false, features = ["v4"] }
uuid = { version = "0.8.1", default-features = false}

# For google-pubsub
base64 = { version = "0.10.1", default-features = false, optional = true }
@@ -25,7 +25,7 @@ use interledger::{
packet::{ErrorCode, RejectBuilder},
router::Router,
service::{
outgoing_service_fn, Account as AccountTrait, AccountId, IncomingService, OutgoingRequest,
outgoing_service_fn, Account as AccountTrait, IncomingService, OutgoingRequest,
OutgoingService, Username,
},
service_util::{
@@ -47,6 +47,7 @@ use tokio::spawn;
use tracing::{debug, debug_span, error, info};
use tracing_futures::Instrument;
use url::Url;
use uuid::Uuid;
use warp::{
self,
http::{Response, StatusCode},
@@ -522,10 +523,7 @@ impl InterledgerNode {

#[doc(hidden)]
#[allow(dead_code)]
pub fn insert_account(
&self,
account: AccountDetails,
) -> impl Future<Item = AccountId, Error = ()> {
pub fn insert_account(&self, account: AccountDetails) -> impl Future<Item = Uuid, Error = ()> {
let redis_secret = generate_redis_secret(&self.secret_seed);
result(self.redis_connection.clone().into_connection_info())
.map_err(|err| error!(target: "interledger-node", "Invalid Redis connection details: {:?}", err))
@@ -1,18 +1,15 @@
use futures::{stream::Stream, Future};
use hex;
use interledger::stream::StreamDelivery;
use interledger::{
packet::Address,
service::{Account as AccountTrait, AccountId},
store::account::Account,
};
use interledger::{packet::Address, service::Account as AccountTrait, store::account::Account};
use ring::rand::{SecureRandom, SystemRandom};
use serde::Serialize;
use serde_json::json;
use std::collections::HashMap;
use std::fmt::{Debug, Display};
use std::str;
use tracing_subscriber;
use uuid::Uuid;

pub fn install_tracing_subscriber() {
tracing_subscriber::fmt::Subscriber::builder()
@@ -129,7 +126,7 @@ pub fn get_all_accounts(
}

#[allow(unused)]
pub fn accounts_to_ids(accounts: Vec<Account>) -> HashMap<Address, AccountId> {
pub fn accounts_to_ids(accounts: Vec<Account>) -> HashMap<Address, Uuid> {
let mut map = HashMap::new();
for a in accounts {
map.insert(a.ilp_address().clone(), a.id());
@@ -29,6 +29,7 @@ serde_json = { version = "1.0.41", default-features = false }
serde_path_to_error = { version = "0.1", default-features = false }
reqwest = { version = "0.9.22", default-features = false, features = ["default-tls"] }
url = { version = "2.1.0", default-features = false, features = ["serde"] }
uuid = { version = "0.8.1", default-features = false}
warp = { version = "0.1.20", default-features = false }
secrecy = { version = "0.5.0", default-features = false, features = ["serde"] }

@@ -3,14 +3,13 @@ use futures::Future;
use interledger_http::{HttpAccount, HttpStore};
use interledger_packet::Address;
use interledger_router::RouterStore;
use interledger_service::{
Account, AccountId, AddressStore, IncomingService, OutgoingService, Username,
};
use interledger_service::{Account, AddressStore, IncomingService, OutgoingService, Username};
use interledger_service_util::{BalanceStore, ExchangeRateStore};
use interledger_settlement::core::types::{SettlementAccount, SettlementStore};
use interledger_stream::StreamNotificationsStore;
use serde::{de, Deserialize, Serialize};
use std::{boxed::*, collections::HashMap, fmt::Display, net::SocketAddr, str::FromStr};
use uuid::Uuid;
use warp::{self, Filter};
mod routes;
use interledger_btp::{BtpAccount, BtpOutgoingService};
@@ -80,20 +79,17 @@ pub trait NodeStore: AddressStore + Clone + Send + Sync + 'static {
account: AccountDetails,
) -> Box<dyn Future<Item = Self::Account, Error = ()> + Send>;

fn delete_account(
&self,
id: AccountId,
) -> Box<dyn Future<Item = Self::Account, Error = ()> + Send>;
fn delete_account(&self, id: Uuid) -> Box<dyn Future<Item = Self::Account, Error = ()> + Send>;

fn update_account(
&self,
id: AccountId,
id: Uuid,
account: AccountDetails,
) -> Box<dyn Future<Item = Self::Account, Error = ()> + Send>;

fn modify_account_settings(
&self,
id: AccountId,
id: Uuid,
settings: AccountSettings,
) -> Box<dyn Future<Item = Self::Account, Error = ()> + Send>;

@@ -102,18 +98,15 @@ pub trait NodeStore: AddressStore + Clone + Send + Sync + 'static {

fn set_static_routes<R>(&self, routes: R) -> Box<dyn Future<Item = (), Error = ()> + Send>
where
R: IntoIterator<Item = (String, AccountId)>;
R: IntoIterator<Item = (String, Uuid)>;

fn set_static_route(
&self,
prefix: String,
account_id: AccountId,
account_id: Uuid,
) -> Box<dyn Future<Item = (), Error = ()> + Send>;

fn set_default_route(
&self,
account_id: AccountId,
) -> Box<dyn Future<Item = (), Error = ()> + Send>;
fn set_default_route(&self, account_id: Uuid) -> Box<dyn Future<Item = (), Error = ()> + Send>;

fn set_settlement_engines(
&self,
@@ -11,8 +11,7 @@ use interledger_ildcp::IldcpRequest;
use interledger_ildcp::IldcpResponse;
use interledger_router::RouterStore;
use interledger_service::{
Account, AccountId, AddressStore, AuthToken, IncomingService, OutgoingRequest, OutgoingService,
Username,
Account, AddressStore, AuthToken, IncomingService, OutgoingRequest, OutgoingService, Username,
};
use interledger_service_util::{BalanceStore, ExchangeRateStore};
use interledger_settlement::core::types::SettlementAccount;
@@ -23,6 +22,7 @@ use serde::{Deserialize, Serialize};
use serde_json::json;
use std::convert::TryFrom;
use std::str::FromStr;
use uuid::Uuid;
use warp::{self, Filter, Rejection};

#[derive(Deserialize, Debug)]
@@ -126,9 +126,9 @@ where
.and_then(
|path_username: Username, auth_string: String, store: S, admin_auth_header: String| {
store.get_account_id_from_username(&path_username).then(
move |account_id: Result<AccountId, _>| {
move |account_id: Result<Uuid, _>| {
if account_id.is_err() {
return Either::A(err::<AccountId, Rejection>(
return Either::A(err::<Uuid, Rejection>(
ApiError::account_not_found().into(),
));
}
@@ -237,20 +237,18 @@ where
.and(admin_only.clone())
.and(deserialize_json())
.and(with_store.clone())
.and_then(
move |id: AccountId, account_details: AccountDetails, store: S| {
let store_clone = store.clone();
let handler = outgoing_handler.clone();
let btp = btp.clone();
store
.update_account(id, account_details)
.map_err::<_, Rejection>(move |_| ApiError::internal_server_error().into())
.and_then(move |account| {
connect_to_external_services(handler, account, store_clone, btp)
})
.and_then(|account: A| Ok(warp::reply::json(&account)))
},
)
.and_then(move |id: Uuid, account_details: AccountDetails, store: S| {
let store_clone = store.clone();
let handler = outgoing_handler.clone();
let btp = btp.clone();
store
.update_account(id, account_details)
.map_err::<_, Rejection>(move |_| ApiError::internal_server_error().into())
.and_then(move |account| {
connect_to_external_services(handler, account, store_clone, btp)
})
.and_then(|account: A| Ok(warp::reply::json(&account)))
})
.boxed();

// GET /accounts/:username
@@ -259,7 +257,7 @@ where
.and(warp::path::end())
.and(admin_or_authorized_user_only.clone())
.and(with_store.clone())
.and_then(|id: AccountId, store: S| {
.and_then(|id: Uuid, store: S| {
store
.get_accounts(vec![id])
.map_err::<_, Rejection>(|_| ApiError::account_not_found().into())
@@ -274,7 +272,7 @@ where
.and(warp::path::end())
.and(admin_or_authorized_user_only.clone())
.and(with_store.clone())
.and_then(|id: AccountId, store: S| {
.and_then(|id: Uuid, store: S| {
// TODO reduce the number of store calls it takes to get the balance
store
.get_accounts(vec![id])
@@ -301,7 +299,7 @@ where
.and(warp::path::end())
.and(admin_only.clone())
.and(with_store.clone())
.and_then(|id: AccountId, store: S| {
.and_then(|id: Uuid, store: S| {
store
.delete_account(id)
.map_err::<_, Rejection>(move |_| {
@@ -320,7 +318,7 @@ where
.and(admin_or_authorized_user_only.clone())
.and(deserialize_json())
.and(with_store.clone())
.and_then(|id: AccountId, settings: AccountSettings, store: S| {
.and_then(|id: Uuid, settings: AccountSettings, store: S| {
store
.modify_account_settings(id, settings)
.map_err::<_, Rejection>(move |_| {
@@ -340,7 +338,7 @@ where
.and(admin_or_authorized_user_only.clone())
.and(warp::ws2())
.and(with_store.clone())
.map(|id: AccountId, ws: warp::ws::Ws2, store: S| {
.map(|id: Uuid, ws: warp::ws::Ws2, store: S| {
ws.on_upgrade(move |ws: warp::ws::WebSocket| {
let (tx, rx) = futures::sync::mpsc::unbounded::<PaymentNotification>();
store.add_payment_notification_subscription(id, tx);
@@ -391,7 +389,7 @@ where
.and(warp::path("spsp"))
.and(warp::path::end())
.and(with_store.clone())
.and_then(move |id: AccountId, store: S| {
.and_then(move |id: Uuid, store: S| {
let server_secret_clone = server_secret_clone.clone();
store
.get_accounts(vec![id])
@@ -25,6 +25,7 @@ tokio-timer = { version = "0.2.11", default-features = false }
tokio-tungstenite = { version = "0.9.0", default-features = false, features = ["tls", "connect"] }
tungstenite = { version = "0.9.1", default-features = false }
url = { version = "2.1.0", default-features = false }
uuid = { version = "0.8.1", default-features = false}
warp = { version = "0.1.20", default-features = false, features = ["websocket"] }

[dev-dependencies]

0 comments on commit 78141d0

Please sign in to comment.
You can’t perform that action at this time.