Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Martin committed Mar 8, 2023
2 parents 0e2a7e6 + a4ee361 commit a95f976
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bip.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ sats in the main chain are maintained [https://github.com/casey/ord here].
A variation of this scheme was independently invented a decade ago by jl2012
[https://bitcointalk.org/index.php?topic=117224.0 on the Bitcoin Forum].

For other colored coin proposals see [https://en.bitcoin.it/wiki/Colored_Coins
the Bitcoin Wiki entry].
For other colored coin proposals see [https://en.bitcoin.it/wiki/Colored_Coins the
Bitcoin Wiki entry].

For aliases, an implementation of short on-chain identifiers, see
[https://github.com/bitcoin/bips/blob/master/bip-0015.mediawiki BIP 15].
11 changes: 9 additions & 2 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ impl Updater {

let mut outpoint_to_value = wtx.open_table(OUTPOINT_TO_VALUE)?;

if !self.index_sats {
let index_inscriptions = self.height >= index.first_inscription_height;

if index_inscriptions {
// Send all missing input outpoints to be fetched right away
let txids = block
.txdata
Expand Down Expand Up @@ -476,6 +478,7 @@ impl Updater {
&mut sat_ranges_written,
&mut outputs_in_block,
&mut inscription_updater,
index_inscriptions,
)?;

coinbase_inputs.extend(input_sat_ranges);
Expand All @@ -490,6 +493,7 @@ impl Updater {
&mut sat_ranges_written,
&mut outputs_in_block,
&mut inscription_updater,
index_inscriptions,
)?;
}

Expand Down Expand Up @@ -548,8 +552,11 @@ impl Updater {
sat_ranges_written: &mut u64,
outputs_traversed: &mut u64,
inscription_updater: &mut InscriptionUpdater,
index_inscriptions: bool,
) -> Result {
inscription_updater.index_transaction_inscriptions(tx, txid, Some(input_sat_ranges))?;
if index_inscriptions {
inscription_updater.index_transaction_inscriptions(tx, txid, Some(input_sat_ranges))?;
}

for (vout, output) in tx.output.iter().enumerate() {
let outpoint = OutPoint {
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ fn timestamp(seconds: u32) -> DateTime<Utc> {
Utc.timestamp_opt(seconds.into(), 0).unwrap()
}

const INTERRUPT_LIMIT: u64 = 5;

pub fn main() {
env_logger::init();

Expand All @@ -151,9 +153,11 @@ pub fn main() {
.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 > 5 {
if interrupts > INTERRUPT_LIMIT {
process::exit(1);
}
})
Expand Down
4 changes: 3 additions & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ impl Inscribe {

utxos.insert(
reveal_tx.input[0].previous_output,
Amount::from_sat(unsigned_commit_tx.output[0].value),
Amount::from_sat(
unsigned_commit_tx.output[reveal_tx.input[0].previous_output.vout as usize].value,
),
);

let fees =
Expand Down
6 changes: 6 additions & 0 deletions src/subcommand/wallet/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub enum Error {
},
NotEnoughCardinalUtxos,
NotInWallet(SatPoint),
OutOfRange(SatPoint, u64),
UtxoContainsAdditionalInscription {
outgoing_satpoint: SatPoint,
inscribed_satpoint: SatPoint,
Expand All @@ -72,6 +73,7 @@ impl fmt::Display for Error {
dust_value,
} => write!(f, "output value is below dust value: {output_value} < {dust_value}"),
Error::NotInWallet(outgoing_satpoint) => write!(f, "outgoing satpoint {outgoing_satpoint} not in wallet"),
Error::OutOfRange(outgoing_satpoint, maximum) => write!(f, "outgoing satpoint {outgoing_satpoint} offset higher than maximum {maximum}"),
Error::NotEnoughCardinalUtxos => write!(
f,
"wallet does not contain enough cardinal UTXOs, please add additional funds to wallet."
Expand Down Expand Up @@ -227,6 +229,10 @@ impl TransactionBuilder {
.get(&self.outgoing.outpoint)
.ok_or(Error::NotInWallet(self.outgoing))?;

if self.outgoing.offset >= amount.to_sat() {
return Err(Error::OutOfRange(self.outgoing, amount.to_sat() - 1));
}

self.utxos.remove(&self.outgoing.outpoint);
self.inputs.push(self.outgoing.outpoint);
self.outputs.push((self.recipient.clone(), amount));
Expand Down

0 comments on commit a95f976

Please sign in to comment.