forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.rs
122 lines (110 loc) Β· 2.69 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
use {
self::{
arguments::Arguments,
blocktime::Blocktime,
bytes::Bytes,
decimal::Decimal,
degree::Degree,
epoch::Epoch,
height::Height,
index::{Index, List},
options::Options,
ordinal::Ordinal,
rarity::Rarity,
rune::Rune,
sat_point::SatPoint,
subcommand::Subcommand,
tally::Tally,
},
anyhow::{anyhow, bail, Context, Error},
bitcoin::{
blockdata::constants::COIN_VALUE,
consensus::{self, Decodable, Encodable},
hash_types::BlockHash,
hashes::{sha256, Hash},
Address, Block, Network, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid,
},
bitcoincore_rpc::RpcApi,
chrono::{DateTime, NaiveDateTime, Utc},
clap::Parser,
derive_more::{Display, FromStr},
redb::{Database, ReadableTable, Table, TableDefinition, WriteTransaction},
regex::Regex,
serde::{Deserialize, Serialize},
std::{
collections::VecDeque,
env,
fmt::{self, Display, Formatter},
fs, io,
net::ToSocketAddrs,
ops::{Add, AddAssign, Mul, Sub},
path::{Path, PathBuf},
process,
str::FromStr,
sync::{
atomic::{self, AtomicU64},
Arc, Mutex,
},
thread,
time::{Duration, Instant},
},
tokio::{runtime::Runtime, task},
tower_http::cors::{Any, CorsLayer},
};
#[cfg(test)]
#[macro_use]
mod test;
#[cfg(test)]
use self::test::*;
mod arguments;
mod blocktime;
mod bytes;
mod decimal;
mod degree;
mod epoch;
mod height;
mod index;
mod options;
mod ordinal;
mod rarity;
mod rune;
mod sat_point;
mod subcommand;
mod tally;
type Result<T = (), E = Error> = std::result::Result<T, E>;
const DIFFCHANGE_INTERVAL: u64 = bitcoin::blockdata::constants::DIFFCHANGE_INTERVAL as u64;
const SUBSIDY_HALVING_INTERVAL: u64 =
bitcoin::blockdata::constants::SUBSIDY_HALVING_INTERVAL as u64;
const CYCLE_EPOCHS: u64 = 6;
static INTERRUPTS: AtomicU64 = AtomicU64::new(0);
static LISTENERS: Mutex<Vec<axum_server::Handle>> = Mutex::new(Vec::new());
fn main() {
env_logger::init();
ctrlc::set_handler(move || {
LISTENERS
.lock()
.unwrap()
.iter()
.for_each(|handle| handle.graceful_shutdown(Some(Duration::from_millis(100))));
let interrupts = INTERRUPTS.fetch_add(1, atomic::Ordering::Relaxed);
if interrupts > 5 {
process::exit(1);
}
})
.expect("Error setting ctrl-c handler");
if let Err(err) = Arguments::parse().run() {
eprintln!("error: {}", err);
err
.chain()
.skip(1)
.for_each(|cause| eprintln!("because: {}", cause));
if env::var_os("RUST_BACKTRACE")
.map(|val| val == "1")
.unwrap_or_default()
{
eprintln!("{}", err.backtrace());
}
process::exit(1);
}
}