dump approvals functions and binary

This commit is contained in:
Mike Dilger 2024-03-22 09:39:25 +13:00
parent 69e2e1be37
commit f5043cf50d
3 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,50 @@
use chorus_lib::config::{Config, FriendlyConfig};
use chorus_lib::error::Error;
use chorus_lib::store::Store;
use std::env;
use std::fs::OpenOptions;
use std::io::Read;
fn main() -> Result<(), Error> {
// Get args (config path)
let mut args = env::args();
if args.len() <= 1 {
panic!("USAGE: chorus_moderate <config_path>");
}
let _ = args.next(); // ignore program name
let config_path = args.next().unwrap();
// Read config file
let mut file = OpenOptions::new().read(true).open(config_path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let friendly_config: FriendlyConfig = toml::from_str(&contents)?;
let mut config: Config = friendly_config.into_config()?;
env_logger::Builder::new()
.filter_level(config.library_log_level)
.filter(Some("Server"), config.server_log_level)
.filter(Some("Client"), config.client_log_level)
.format_target(true)
.format_module_path(false)
.format_timestamp_millis()
.init();
log::debug!(target: "Server", "Loaded config file.");
// Force allow of scraping (this program is a scraper)
config.allow_scraping = true;
// Setup store
let store = Store::new(&config)?;
for (id, approved) in store.dump_event_approvals()? {
println!("ID {} = {}", id, approved);
}
for (pubkey, approved) in store.dump_pubkey_approvals()? {
println!("PUBKEY {} = {}", pubkey, approved);
}
Ok(())
}

View File

@ -981,6 +981,18 @@ impl Store {
.map(|u| u != 0))
}
pub fn dump_event_approvals(&self) -> Result<Vec<(Id, bool)>, Error> {
let mut output: Vec<(Id, bool)> = Vec::new();
let txn = self.env.read_txn()?;
for i in self.approved_events.iter(&txn)? {
let (key, val) = i?;
let id = Id(key.try_into().unwrap());
let approval: bool = val != 0;
output.push((id, approval));
}
Ok(output)
}
pub fn mark_pubkey_approval(&self, pubkey: Pubkey, approval: bool) -> Result<(), Error> {
let mut txn = self.env.write_txn()?;
self.approved_pubkeys
@ -1005,6 +1017,18 @@ impl Store {
.map(|u| u != 0))
}
pub fn dump_pubkey_approvals(&self) -> Result<Vec<(Pubkey, bool)>, Error> {
let mut output: Vec<(Pubkey, bool)> = Vec::new();
let txn = self.env.read_txn()?;
for i in self.approved_pubkeys.iter(&txn)? {
let (key, val) = i?;
let pubkey = Pubkey(key.try_into().unwrap());
let approval: bool = val != 0;
output.push((pubkey, approval));
}
Ok(output)
}
fn key_ci_index(created_at: Time, id: Id) -> Vec<u8> {
let mut key: Vec<u8> =
Vec::with_capacity(std::mem::size_of::<Time>() + std::mem::size_of::<Id>());

View File

@ -70,6 +70,7 @@ Ok now let's install that (along with the utility binaries):
```bash
sudo install --mode=0700 --owner=chorus ./target/release/chorus /opt/chorus/sbin/chorus
sudo install --mode=0700 --owner=chorus ./target/release/chorus_dump /opt/chorus/sbin/chorus_dump
sudo install --mode=0700 --owner=chorus ./target/release/chorus_dump_approvals /opt/chorus/sbin/chorus_dump_approvals
sudo install --mode=0700 --owner=chorus ./target/release/chorus_moderate /opt/chorus/sbin/chorus_moderate
```
@ -182,6 +183,7 @@ git pull
cargo build --release
sudo install --mode=0700 --owner=chorus ./target/release/chorus /opt/chorus/sbin/chorus
sudo install --mode=0700 --owner=chorus ./target/release/chorus_dump /opt/chorus/sbin/chorus_dump
sudo install --mode=0700 --owner=chorus ./target/release/chorus_dump_approvals /opt/chorus/sbin/chorus_dump_approvals
sudo install --mode=0700 --owner=chorus ./target/release/chorus_moderate /opt/chorus/sbin/chorus_moderate
sudo systemctl restart chorus.service
````