Skip to content

Commit

Permalink
Merge branch 'master' into clean-up-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Dec 31, 2023
2 parents f546470 + d791800 commit 747e441
Show file tree
Hide file tree
Showing 41 changed files with 533 additions and 449 deletions.
2 changes: 1 addition & 1 deletion deploy/ord.service
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ExecStart=/usr/local/bin/ord \
--index-transactions \
server \
--acme-contact mailto:[email protected] \
--csp-origin https://ordinals.com \
--csp-origin https://${CSP_ORIGIN} \
--http \
--https
Group=ord
Expand Down
21 changes: 20 additions & 1 deletion deploy/setup
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ BRANCH=$3
COMMIT=$4
REVISION="ord-$BRANCH-$COMMIT"

case $CHAIN in
main)
CSP_ORIGIN=ordinals.com
;;
regtest)
CSP_ORIGIN=regtest.ordinals.com
;;
signet)
CSP_ORIGIN=signet.ordinals.com
;;
test)
CSP_ORIGIN=testnet.ordinals.com
;;
*)
echo "Unknown chain: $CHAIN"
exit 1
;;
esac

touch ~/.hushlogin

sed -i -E 's/#?PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
Expand All @@ -18,7 +37,7 @@ mkdir -p \
/etc/systemd/system/bitcoind.service.d \
/etc/systemd/system/ord.service.d

printf "[Service]\nEnvironment=CHAIN=%s\n" $CHAIN \
printf "[Service]\nEnvironment=CHAIN=%s\nEnvironment=CSP_ORIGIN=%s\n" $CHAIN $CSP_ORIGIN \
| tee /etc/systemd/system/bitcoind.service.d/override.conf \
> /etc/systemd/system/ord.service.d/override.conf

Expand Down
95 changes: 20 additions & 75 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use {
crate::{
subcommand::{find::FindRangeOutput, server::InscriptionQuery},
templates::{RuneHtml, StatusHtml},
wallet::Wallet,
},
bitcoin::block::Header,
bitcoincore_rpc::{json::GetBlockHeaderResult, Client},
Expand Down Expand Up @@ -207,13 +206,12 @@ pub struct Index {

impl Index {
pub fn open(options: &Options) -> Result<Self> {
let client = options.bitcoin_rpc_client()?;
let client = options.bitcoin_rpc_client(None)?;

let path = if let Some(path) = &options.index {
path.clone()
} else {
options.data_dir()?.join("index.redb")
};
let path = options
.index
.clone()
.unwrap_or(options.data_dir().clone().join("index.redb"));

if let Err(err) = fs::create_dir_all(path.parent().unwrap()) {
bail!(
Expand Down Expand Up @@ -378,56 +376,12 @@ impl Index {
})
}

pub(crate) fn get_locked_outputs(&self, _wallet: Wallet) -> Result<BTreeSet<OutPoint>> {
#[derive(Deserialize)]
pub(crate) struct JsonOutPoint {
txid: bitcoin::Txid,
vout: u32,
}

Ok(
self
.client
.call::<Vec<JsonOutPoint>>("listlockunspent", &[])?
.into_iter()
.map(|outpoint| OutPoint::new(outpoint.txid, outpoint.vout))
.collect(),
)
}
#[cfg(test)]
fn set_durability(&mut self, durability: redb::Durability) {
self.durability = durability;
}

pub(crate) fn get_unspent_outputs(&self, wallet: Wallet) -> Result<BTreeMap<OutPoint, Amount>> {
let mut utxos = BTreeMap::new();
utxos.extend(
self
.client
.list_unspent(None, None, None, None, None)?
.into_iter()
.map(|utxo| {
let outpoint = OutPoint::new(utxo.txid, utxo.vout);
let amount = utxo.amount;

(outpoint, amount)
}),
);

let locked_utxos: BTreeSet<OutPoint> = self.get_locked_outputs(wallet)?;

for outpoint in locked_utxos {
utxos.insert(
outpoint,
Amount::from_sat(
self
.client
.get_raw_transaction(&outpoint.txid, None)?
.output[TryInto::<usize>::try_into(outpoint.vout).unwrap()]
.value,
),
);
}
pub(crate) fn check_sync(&self, utxos: &BTreeMap<OutPoint, Amount>) -> Result<bool> {
let rtx = self.database.begin_read()?;
let outpoint_to_value = rtx.open_table(OUTPOINT_TO_VALUE)?;
for outpoint in utxos.keys() {
Expand All @@ -438,22 +392,7 @@ impl Index {
}
}

Ok(utxos)
}

pub(crate) fn get_unspent_output_ranges(
&self,
wallet: Wallet,
) -> Result<Vec<(OutPoint, Vec<(u64, u64)>)>> {
self
.get_unspent_outputs(wallet)?
.into_keys()
.map(|outpoint| match self.list(outpoint)? {
Some(List::Unspent(sat_ranges)) => Ok((outpoint, sat_ranges)),
Some(List::Spent) => bail!("output {outpoint} in wallet but is spent according to index"),
None => bail!("index has not seen {outpoint}"),
})
.collect()
Ok(true)
}

pub(crate) fn has_rune_index(&self) -> bool {
Expand Down Expand Up @@ -1709,7 +1648,7 @@ impl Index {
Utc::now()
.round_subsecs(0)
.checked_add_signed(chrono::Duration::seconds(
10 * 60 * i64::try_from(expected_blocks)?,
10 * 60 * i64::from(expected_blocks),
))
.ok_or_else(|| anyhow!("block timestamp out of range"))?,
))
Expand Down Expand Up @@ -3455,14 +3394,20 @@ mod tests {
let mut entropy = [0; 16];
rand::thread_rng().fill_bytes(&mut entropy);
let mnemonic = Mnemonic::from_entropy(&entropy).unwrap();
crate::subcommand::wallet::initialize_wallet(&context.options, mnemonic.to_seed("")).unwrap();
crate::subcommand::wallet::initialize("ord".into(), &context.options, mnemonic.to_seed(""))
.unwrap();
context.rpc_server.mine_blocks(1);
assert_regex_match!(
context
.index
.get_unspent_outputs(Wallet::load(&context.options).unwrap())
.unwrap_err()
.to_string(),
crate::subcommand::wallet::get_unspent_outputs(
&crate::subcommand::wallet::bitcoin_rpc_client_for_wallet_command(
"ord".to_string(),
&context.options,
)
.unwrap(),
&context.index
)
.unwrap_err()
.to_string(),
r"output in Bitcoin Core wallet but not in ord index: [[:xdigit:]]{64}:\d+"
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/index/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ impl Fetcher {
pub(crate) fn new(options: &Options) -> Result<Self> {
let client = Client::new();

let url = if options.rpc_url().starts_with("http:https://") {
options.rpc_url()
let url = if options.rpc_url(None).starts_with("http:https://") {
options.rpc_url(None)
} else {
"http:https://".to_string() + &options.rpc_url()
"http:https://".to_string() + &options.rpc_url(None)
};

let url = Uri::try_from(&url).map_err(|e| anyhow!("Invalid rpc url {url}: {e}"))?;
Expand Down
2 changes: 1 addition & 1 deletion src/index/reorg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Reorg {
&& u32::try_from(
index
.options
.bitcoin_rpc_client()?
.bitcoin_rpc_client(None)?
.get_blockchain_info()?
.headers,
)
Expand Down
4 changes: 2 additions & 2 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<'index> Updater<'_> {

let height_limit = index.height_limit;

let client = index.options.bitcoin_rpc_client()?;
let client = index.options.bitcoin_rpc_client(None)?;

let first_inscription_height = index.first_inscription_height;

Expand Down Expand Up @@ -498,7 +498,7 @@ impl<'index> Updater<'_> {
coinbase_inputs.extend(input_sat_ranges);
}

if let Some((tx, txid)) = block.txdata.get(0) {
if let Some((tx, txid)) = block.txdata.first() {
self.index_transaction_sats(
tx,
*txid,
Expand Down
15 changes: 15 additions & 0 deletions src/inscriptions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use super::*;

use tag::Tag;

pub(crate) use self::{charm::Charm, envelope::ParsedEnvelope, media::Media};

pub use self::{envelope::Envelope, inscription::Inscription, inscription_id::InscriptionId};

mod charm;
mod envelope;
mod inscription;
mod inscription_id;
pub(crate) mod media;
mod tag;
pub(crate) mod teleburn;
File renamed without changes.
Loading

0 comments on commit 747e441

Please sign in to comment.