aboutsummaryrefslogtreecommitdiffstats
path: root/adenosine-pds
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-22 11:31:06 -0800
committerBryan Newbold <bnewbold@robocracy.org>2022-11-22 11:31:06 -0800
commitf1b80f13f9408db9f76410c717d67d4f9cf7ed2a (patch)
tree78e19b2422f82a8b040e68e50758f4f6299a67fb /adenosine-pds
parent4fd86c1b2191aaaabc2b8a6ec5fc1078d75a28b5 (diff)
downloadadenosine-f1b80f13f9408db9f76410c717d67d4f9cf7ed2a.tar.gz
adenosine-f1b80f13f9408db9f76410c717d67d4f9cf7ed2a.zip
clippy cleanups
Diffstat (limited to 'adenosine-pds')
-rw-r--r--adenosine-pds/src/bin/adenosine-pds.rs10
-rw-r--r--adenosine-pds/src/bsky.rs18
-rw-r--r--adenosine-pds/src/car.rs2
-rw-r--r--adenosine-pds/src/crypto.rs8
-rw-r--r--adenosine-pds/src/db.rs2
-rw-r--r--adenosine-pds/src/did.rs4
-rw-r--r--adenosine-pds/src/lib.rs20
-rw-r--r--adenosine-pds/src/mst.rs4
-rw-r--r--adenosine-pds/src/repo.rs14
-rw-r--r--adenosine-pds/src/web.rs1
10 files changed, 41 insertions, 42 deletions
diff --git a/adenosine-pds/src/bin/adenosine-pds.rs b/adenosine-pds/src/bin/adenosine-pds.rs
index 3379841..1fef557 100644
--- a/adenosine-pds/src/bin/adenosine-pds.rs
+++ b/adenosine-pds/src/bin/adenosine-pds.rs
@@ -208,14 +208,16 @@ fn main() -> Result<()> {
did_plc,
} => {
let req = AccountRequest {
- email: email,
+ email,
handle: handle.clone(),
- password: password,
+ password,
inviteCode: None,
recoveryKey: recovery_key,
};
- let mut config = AtpServiceConfig::default();
- config.public_url = public_url.unwrap_or(format!("https://{}", handle));
+ let config = AtpServiceConfig {
+ public_url: public_url.unwrap_or(format!("https://{}", handle)),
+ ..Default::default()
+ };
let keypair = KeyPair::from_hex(&pds_secret_key)?;
let mut srv =
AtpService::new(&opt.blockstore_db_path, &opt.atp_db_path, keypair, config)?;
diff --git a/adenosine-pds/src/bsky.rs b/adenosine-pds/src/bsky.rs
index 958c2ae..89978fb 100644
--- a/adenosine-pds/src/bsky.rs
+++ b/adenosine-pds/src/bsky.rs
@@ -63,7 +63,7 @@ pub fn bsky_mutate_db(db: &mut AtpDatabase, did: &Did, mutations: Vec<Mutation>)
pub fn bsky_get_profile(srv: &mut AtpService, did: &Did) -> Result<Profile> {
// first get the profile record
let mut profile_cid: Option<Cid> = None;
- let commit_cid = &srv.repo.lookup_commit(&did)?.unwrap();
+ let commit_cid = &srv.repo.lookup_commit(did)?.unwrap();
let last_commit = srv.repo.get_commit(commit_cid)?;
let full_map = srv.repo.mst_to_map(&last_commit.mst_cid)?;
let prefix = "/app.bsky.actor.profile/";
@@ -102,9 +102,9 @@ pub fn bsky_get_profile(srv: &mut AtpService, did: &Did) -> Result<Profile> {
let followers_count: u64 = stmt.query_row(params!(did.to_string()), |row| row.get(0))?;
Ok(Profile {
did: did.to_string(),
- handle: handle,
+ handle,
displayName: display_name,
- description: description,
+ description,
followersCount: followers_count,
followsCount: follows_count,
postsCount: post_count,
@@ -115,7 +115,7 @@ pub fn bsky_get_profile(srv: &mut AtpService, did: &Did) -> Result<Profile> {
pub fn bsky_update_profile(srv: &mut AtpService, did: &Did, profile: ProfileRecord) -> Result<()> {
// get the profile record
let mut profile_tid: Option<Tid> = None;
- let commit_cid = &srv.repo.lookup_commit(&did)?.unwrap();
+ let commit_cid = &srv.repo.lookup_commit(did)?.unwrap();
let last_commit = srv.repo.get_commit(commit_cid)?;
let full_map = srv.repo.mst_to_map(&last_commit.mst_cid)?;
let prefix = "/app.bsky.actor.profile/";
@@ -131,7 +131,7 @@ pub fn bsky_update_profile(srv: &mut AtpService, did: &Did, profile: ProfileReco
json_value_into_ipld(serde_json::to_value(profile)?),
)];
let keypair = srv.pds_keypair.clone();
- srv.repo.mutate_repo(&did, &mutations, &keypair)?;
+ srv.repo.mutate_repo(did, &mutations, &keypair)?;
Ok(())
}
@@ -185,7 +185,7 @@ fn feed_row_to_item(srv: &mut AtpService, row: FeedRow) -> Result<FeedItem> {
let reply_count: u64 = stmt.query_row(params!(uri), |row| row.get(0))?;
let feed_item = FeedItem {
- uri: uri,
+ uri,
cid: Some(row.item_post_cid.to_string()),
author: User {
did: row.item_did.to_string(),
@@ -264,7 +264,7 @@ pub fn bsky_get_thread(
Err(anyhow!("expected a post collection in uri: {}", uri))?;
};
let tid = match uri.record {
- Some(ref tid) => Tid::from_str(&tid)?,
+ Some(ref tid) => Tid::from_str(tid)?,
_ => Err(anyhow!("expected a record in uri: {}", uri))?,
};
@@ -284,7 +284,7 @@ pub fn bsky_get_thread(
if post_items.is_empty() {
Err(XrpcError::NotFound("post not found".to_string()))?;
};
- let post_item = feed_row_to_item(srv, post_items.into_iter().nth(0).unwrap())?;
+ let post_item = feed_row_to_item(srv, post_items.into_iter().next().unwrap())?;
// TODO: any parent
let parent = None;
@@ -329,7 +329,7 @@ pub fn bsky_get_thread(
author: post_item.author,
record: post_item.record,
embed: post_item.embed,
- parent: parent,
+ parent,
replyCount: post_item.replyCount,
replies: Some(children),
likeCount: post_item.likeCount,
diff --git a/adenosine-pds/src/car.rs b/adenosine-pds/src/car.rs
index 832c87e..22f83bc 100644
--- a/adenosine-pds/src/car.rs
+++ b/adenosine-pds/src/car.rs
@@ -87,7 +87,7 @@ async fn inner_car_bytes_reader(
db: &mut BlockStore<libipld::DefaultParams>,
root: &Cid,
) -> Result<Vec<u8>> {
- let car_header = CarHeader::new_v1(vec![root.clone()]);
+ let car_header = CarHeader::new_v1(vec![*root]);
let buf: Vec<u8> = Default::default();
let mut car_writer = CarWriter::new(car_header, buf);
diff --git a/adenosine-pds/src/crypto.rs b/adenosine-pds/src/crypto.rs
index d1a864e..e10401a 100644
--- a/adenosine-pds/src/crypto.rs
+++ b/adenosine-pds/src/crypto.rs
@@ -76,16 +76,14 @@ impl KeyPair {
}
pub fn from_hex(hex: &str) -> Result<Self> {
- Ok(Self::from_bytes(
- &data_encoding::HEXUPPER.decode(hex.as_bytes())?,
- )?)
+ Self::from_bytes(&data_encoding::HEXUPPER.decode(hex.as_bytes())?)
}
}
async fn build_ucan(key_material: P256KeyMaterial, did: &Did) -> Result<String> {
let token_string = UcanBuilder::default()
.issued_by(&key_material)
- .for_audience(&did.to_string())
+ .for_audience(did)
.with_nonce()
.with_lifetime(60 * 60 * 24 * 90)
.build()?
@@ -136,7 +134,7 @@ impl PubKey {
bytes.extend_from_slice(&key.to_bytes());
}
}
- format!("{}", multibase::encode(multibase::Base::Base58Btc, &bytes))
+ multibase::encode(multibase::Base::Base58Btc, &bytes)
}
/// Serializes as a 'did:key' string.
diff --git a/adenosine-pds/src/db.rs b/adenosine-pds/src/db.rs
index b94689a..b694bb5 100644
--- a/adenosine-pds/src/db.rs
+++ b/adenosine-pds/src/db.rs
@@ -207,7 +207,7 @@ impl AtpDatabase {
reply_to_parent_uri,
reply_to_root_uri,
serde_json::to_string(&post)?,
- post.createdAt.unwrap_or_else(|| created_at_now())
+ post.createdAt.unwrap_or_else(created_at_now)
))?;
} else {
let mut stmt = self
diff --git a/adenosine-pds/src/did.rs b/adenosine-pds/src/did.rs
index 74e4f68..88fa5b8 100644
--- a/adenosine-pds/src/did.rs
+++ b/adenosine-pds/src/did.rs
@@ -41,7 +41,7 @@ impl UnsignedCreateOp {
CreateOp {
op_type: self.op_type,
prev: self.prev,
- sig: sig,
+ sig,
signingKey: self.signingKey,
recoveryKey: self.recoveryKey,
username: self.username,
@@ -64,7 +64,7 @@ impl CreateOp {
prev: None,
signingKey: signing_key,
recoveryKey: recovery_key,
- username: username,
+ username,
service: atp_pds,
};
let block = Block::<DefaultParams>::encode(DagCborCodec, Code::Sha2_256, &unsigned)
diff --git a/adenosine-pds/src/lib.rs b/adenosine-pds/src/lib.rs
index a7cb4ae..6a3a8cb 100644
--- a/adenosine-pds/src/lib.rs
+++ b/adenosine-pds/src/lib.rs
@@ -433,7 +433,7 @@ fn xrpc_get_handler(
name: did.to_string(), // TODO: handle?
did: did.to_string(),
didDoc: did_doc,
- collections: collections,
+ collections,
nameIsCorrect: true,
};
Ok(json!(desc))
@@ -454,7 +454,7 @@ fn xrpc_get_handler(
"app.bsky.feed.getTimeline" => {
let mut srv = srv.lock().unwrap();
let auth_did = &xrpc_check_auth_header(&mut srv, request, None)?;
- Ok(json!(bsky_get_timeline(&mut srv, &auth_did)?))
+ Ok(json!(bsky_get_timeline(&mut srv, auth_did)?))
}
"app.bsky.feed.getPostThread" => {
let uri = AtUri::from_str(&xrpc_required_param(request, "uri")?)?;
@@ -473,7 +473,7 @@ fn xrpc_get_repo_handler(srv: &Mutex<AtpService>, request: &Request) -> Result<V
let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?;
// TODO: don't unwrap here
let commit_cid = srv.repo.lookup_commit(&did)?.unwrap();
- Ok(srv.repo.export_car(&commit_cid, None)?)
+ srv.repo.export_car(&commit_cid, None)
}
pub fn create_account(
@@ -704,7 +704,7 @@ fn xrpc_post_handler(
let profile: ProfileRecord = rouille::input::json_input(request)?;
let mut srv = srv.lock().unwrap();
let auth_did = &xrpc_check_auth_header(&mut srv, request, None)?;
- bsky_update_profile(&mut srv, &auth_did, profile)?;
+ bsky_update_profile(&mut srv, auth_did, profile)?;
Ok(json!({}))
}
_ => Err(anyhow!(XrpcError::NotFound(format!(
@@ -724,7 +724,7 @@ fn home_view_handler(srv: &Mutex<AtpService>, request: &Request) -> Result<Strin
srv.atp_db.resolve_handle(host)?
};
if did.is_some() {
- account_view_handler(&srv, &host, request)
+ account_view_handler(srv, host, request)
} else {
let view = GenericHomeView {
domain: host.to_string(),
@@ -810,14 +810,14 @@ fn repo_view_handler(srv: &Mutex<AtpService>, did: &str, request: &Request) -> R
name: did.to_string(), // TODO
did: did.to_string(),
didDoc: did_doc,
- collections: collections,
+ collections,
nameIsCorrect: true,
};
Ok(RepoView {
domain: host.to_string(),
- did: did,
- commit: commit,
+ did,
+ commit,
describe: desc,
}
.render()?)
@@ -854,8 +854,8 @@ fn collection_view_handler(
Ok(CollectionView {
domain: host.to_string(),
- did: did,
- collection: collection,
+ did,
+ collection,
records: record_list,
}
.render()?)
diff --git a/adenosine-pds/src/mst.rs b/adenosine-pds/src/mst.rs
index 969f584..9c4fe69 100644
--- a/adenosine-pds/src/mst.rs
+++ b/adenosine-pds/src/mst.rs
@@ -162,8 +162,8 @@ pub fn collect_mst_keys(
fn leading_zeros(key: &str) -> u8 {
let digest = sha256::digest(key);
let digest = digest.as_bytes();
- for i in 0..digest.len() {
- if digest[i] != b'0' {
+ for (i, c) in digest.iter().enumerate() {
+ if *c != b'0' {
return i as u8;
}
}
diff --git a/adenosine-pds/src/repo.rs b/adenosine-pds/src/repo.rs
index fd75432..56c068f 100644
--- a/adenosine-pds/src/repo.rs
+++ b/adenosine-pds/src/repo.rs
@@ -76,7 +76,7 @@ impl RepoStore {
pub fn get_ipld(&mut self, cid: &Cid) -> Result<Ipld> {
if let Some(b) = self.db.get_block(cid)? {
- let block: Block<DefaultParams> = Block::new(cid.clone(), b)?;
+ let block: Block<DefaultParams> = Block::new(*cid, b)?;
block.ipld()
} else {
Err(anyhow!("missing IPLD CID: {}", cid))
@@ -150,8 +150,8 @@ impl RepoStore {
);
Ok(RepoCommit {
sig: commit_node.sig,
- commit_cid: commit_cid.clone(),
- root_cid: commit_node.root.clone(),
+ commit_cid: *commit_cid,
+ root_cid: commit_node.root,
meta_cid: root_node.meta,
did: Did::from_str(&metadata_node.did)?,
prev: root_node.prev,
@@ -162,7 +162,7 @@ impl RepoStore {
pub fn get_mst_record_by_key(&mut self, mst_cid: &Cid, key: &str) -> Result<Option<Ipld>> {
let map = self.mst_to_map(mst_cid)?;
if let Some(cid) = map.get(key) {
- self.get_ipld(&cid).map(|v| Some(v))
+ self.get_ipld(cid).map(Some)
} else {
Ok(None)
}
@@ -269,7 +269,7 @@ impl RepoStore {
let commit_cid = self.lookup_commit(did)?.unwrap();
let last_commit = self.get_commit(&commit_cid)?;
let new_mst_cid = self
- .update_mst(&last_commit.mst_cid, &mutations)
+ .update_mst(&last_commit.mst_cid, mutations)
.context("updating MST in repo")?;
let new_root_cid = self.write_root(
last_commit.meta_cid,
@@ -278,7 +278,7 @@ impl RepoStore {
)?;
// TODO: is this how signatures are supposed to work?
let sig = signing_key.sign_bytes(new_root_cid.to_string().as_bytes());
- self.write_commit(&did, new_root_cid, &sig)
+ self.write_commit(did, new_root_cid, &sig)
}
/// Reads in a full MST tree starting at a repo commit, then re-builds and re-writes the tree
@@ -347,7 +347,7 @@ impl RepoStore {
_from_commit_cid: Option<&Cid>,
) -> Result<Vec<u8>> {
// TODO: from_commit_cid
- read_car_bytes_from_blockstore(&mut self.db, &commit_cid)
+ read_car_bytes_from_blockstore(&mut self.db, commit_cid)
}
}
diff --git a/adenosine-pds/src/web.rs b/adenosine-pds/src/web.rs
index 98af87e..66ea4ce 100644
--- a/adenosine-pds/src/web.rs
+++ b/adenosine-pds/src/web.rs
@@ -2,7 +2,6 @@ use crate::models::*;
use crate::repo::RepoCommit;
use adenosine_cli::identifiers::{Did, Nsid, Tid};
use askama::Template;
-use serde_json;
#[derive(Template)]
#[template(path = "error.html")]