forked from apezord/ord-dogecoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
173 lines (155 loc) Β· 3.73 KB
/
lib.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#![allow(
clippy::too_many_arguments,
clippy::type_complexity,
clippy::result_large_err
)]
#![deny(
clippy::cast_lossless,
clippy::cast_possible_truncation,
clippy::cast_possible_wrap,
clippy::cast_sign_loss
)]
use {
self::{
arguments::Arguments,
blocktime::Blocktime,
config::Config,
decimal::Decimal,
deserialize_from_str::DeserializeFromStr,
epoch::Epoch,
height::Height,
index::{Index, List},
inscription::Inscription,
inscription_id::InscriptionId,
media::Media,
options::Options,
outgoing::Outgoing,
representation::Representation,
subcommand::Subcommand,
tally::Tally,
},
anyhow::{anyhow, bail, Context, Error},
bip39::Mnemonic,
bitcoin::{
blockdata::constants::COIN_VALUE,
consensus::{self, Decodable, Encodable},
hash_types::BlockHash,
hashes::Hash,
Address, Amount, Block, Network, OutPoint, Script, Sequence, Transaction, TxIn, TxOut, Txid,
},
bitcoincore_rpc::{Client, RpcApi},
chain::Chain,
chrono::{DateTime, TimeZone, Utc},
clap::{ArgGroup, Parser},
derive_more::{Display, FromStr},
html_escaper::{Escape, Trusted},
lazy_static::lazy_static,
regex::Regex,
serde::{Deserialize, Deserializer, Serialize, Serializer},
std::{
cmp,
collections::{BTreeMap, HashSet, VecDeque},
env,
ffi::OsString,
fmt::{self, Display, Formatter},
fs::{self, File},
io,
net::{TcpListener, ToSocketAddrs},
ops::{Add, AddAssign, Sub},
path::{Path, PathBuf},
process::{self, Command},
str::FromStr,
sync::{
atomic::{self, AtomicU64},
Arc, Mutex,
},
thread,
time::{Duration, Instant, SystemTime},
},
tempfile::TempDir,
tokio::{runtime::Runtime, task},
};
pub use crate::{
fee_rate::FeeRate, object::Object, rarity::Rarity, sat::Sat, sat_point::SatPoint,
subcommand::wallet::transaction_builder::TransactionBuilder,
};
#[cfg(test)]
#[macro_use]
mod test;
#[cfg(test)]
use self::test::*;
macro_rules! tprintln {
($($arg:tt)*) => {
if cfg!(test) {
eprint!("==> ");
eprintln!($($arg)*);
}
};
}
mod arguments;
mod blocktime;
mod chain;
mod config;
mod decimal;
mod deserialize_from_str;
mod epoch;
mod fee_rate;
mod height;
mod index;
mod inscription;
mod inscription_id;
mod media;
mod object;
mod options;
mod outgoing;
mod page_config;
mod rarity;
mod representation;
mod sat;
mod sat_point;
pub mod subcommand;
mod tally;
mod templates;
mod wallet;
type Result<T = (), E = Error> = std::result::Result<T, E>;
static INTERRUPTS: AtomicU64 = AtomicU64::new(0);
static LISTENERS: Mutex<Vec<axum_server::Handle>> = Mutex::new(Vec::new());
fn integration_test() -> bool {
env::var_os("ORD_INTEGRATION_TEST")
.map(|value| value.len() > 0)
.unwrap_or(false)
}
fn timestamp(seconds: u32) -> DateTime<Utc> {
Utc.timestamp_opt(seconds.into(), 0).unwrap()
}
const INTERRUPT_LIMIT: u64 = 5;
pub fn main() {
env_logger::init();
ctrlc::set_handler(move || {
LISTENERS
.lock()
.unwrap()
.iter()
.for_each(|handle| handle.graceful_shutdown(Some(Duration::from_millis(100))));
println!("Detected Ctrl-C, attempting to shut down ord gracefully. Press Ctrl-C {INTERRUPT_LIMIT} times to force shutdown.");
let interrupts = INTERRUPTS.fetch_add(1, atomic::Ordering::Relaxed);
if interrupts > INTERRUPT_LIMIT {
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);
}
}