Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
3af268a
copy Felipe PR 9 to new branch off master
ericatallah Mar 20, 2023
dbeb372
fix block hash logging
ericatallah Mar 22, 2023
0d54a53
Miscellaneous design improvements (#1968)
raphjaph Mar 24, 2023
a7d403f
insignificant change
ericatallah Mar 24, 2023
2ac705b
Merge pull request #12 from metagood/index-logger-master
ericatallah Mar 24, 2023
936ae98
add `witness` cli command
felipelincoln Mar 24, 2023
8e2d5c7
change logic to use inscription id
felipelincoln Mar 25, 2023
3a367ef
update witness cli about
felipelincoln Mar 25, 2023
162b18f
format
felipelincoln Mar 25, 2023
66db0bf
run cargo fmt
ericatallah Mar 25, 2023
6d1d5d8
improve code readability
felipelincoln Mar 25, 2023
91b8041
Merge pull request #11 from metagood/witness-parser-cli
huuep Mar 25, 2023
e00c5c0
print file size
felipelincoln Mar 27, 2023
936ca6f
skip write if file is empty
felipelincoln Mar 27, 2023
a314534
Label change and receive addresses correctly (#1847)
gmart7t2 Mar 27, 2023
92157e5
Mandatory fee rate for inscribe (#1897)
gmart7t2 Mar 27, 2023
ab2f178
Add `ord wallet cardinals` command to list the cardinal outputs (#1904)
gmart7t2 Mar 27, 2023
d407b27
Merge pull request #14 from metagood/file-size
huuep Mar 28, 2023
ccd10bd
fix inscription_satpoint.txt format, use localhost by default
ericatallah Apr 5, 2023
da64c03
fix indexer to look for inscriptions in all tx inputs
ericatallah Apr 5, 2023
6f03ec1
copy Felipe PR 9 to new branch off master
ericatallah Mar 20, 2023
484afcd
fix block hash logging
ericatallah Mar 22, 2023
4fbb880
insignificant change
ericatallah Mar 24, 2023
aebf051
add `witness` cli command
felipelincoln Mar 24, 2023
052bb96
change logic to use inscription id
felipelincoln Mar 25, 2023
5ad357b
update witness cli about
felipelincoln Mar 25, 2023
a6df036
format
felipelincoln Mar 25, 2023
36e009e
run cargo fmt
ericatallah Mar 25, 2023
2b3c7f5
improve code readability
felipelincoln Mar 25, 2023
21fed5d
print file size
felipelincoln Mar 27, 2023
a808347
skip write if file is empty
felipelincoln Mar 27, 2023
a67e864
fix inscription_satpoint.txt format, use localhost by default
ericatallah Apr 5, 2023
816519a
fix indexer to look for inscriptions in all tx inputs
ericatallah Apr 5, 2023
df62dfc
include content_type, body, and file size in log file for new inscrip…
ericatallah Apr 7, 2023
2d661ac
remove body data from log file
ericatallah Apr 7, 2023
0b6c338
fix log file to handle empty inscriptions, add test
ericatallah Apr 7, 2023
9fb0d60
Merge branch 'ord6' into ord6-rebased-casey-master
ericatallah Apr 7, 2023
896205b
Merge pull request #16 from metagood/ord6-rebased-casey-master
ericatallah Apr 7, 2023
2569624
add inscription number to log
felipelincoln Apr 11, 2023
15b11db
Merge pull request #18 from metagood/log-inscription-number
ericatallah Apr 11, 2023
86b8181
add block height to inscription_satpoint.txt log
ericatallah Apr 13, 2023
5f68337
fix off by 1 bug for height, clean up prev hash
ericatallah Apr 13, 2023
c2f2d7e
Merge pull request #19 from metagood/add-block-height-to-log
ericatallah Apr 13, 2023
711553e
create inscription-data endpoint
felipelincoln Apr 14, 2023
63dcb38
cargo fmt
felipelincoln Apr 14, 2023
7f47614
add inscription number
felipelincoln Apr 14, 2023
c65fd22
fix creator address
felipelincoln Apr 14, 2023
e4cfb12
fix inscription number on log
felipelincoln Apr 14, 2023
3a8d334
Merge pull request #20 from metagood/integrity-check-api
felipelincoln Apr 17, 2023
d30c857
update inscriptions data endpoint
felipelincoln Apr 19, 2023
96585ea
Merge pull request #21 from metagood/bulk-inscription-data-endpoint
felipelincoln Apr 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/target
/test-times.txt
/tmp
inscription_satpoint.txt
2 changes: 1 addition & 1 deletion docs/src/guides/inscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Creating Inscriptions
To create an inscription with the contents of `FILE`, run:

```
ord wallet inscribe FILE
ord wallet inscribe --fee-rate FEE_RATE FILE
```

Ord will output two transactions IDs, one for the commit transaction, and one
Expand Down
1 change: 0 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ impl Index {
.open_table(SATPOINT_TO_INSCRIPTION_ID)?,
outpoint,
)?
.into_iter()
.map(|(_satpoint, inscription_id)| inscription_id)
.collect(),
)
Expand Down
16 changes: 14 additions & 2 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl Updater {

let mut uncommitted = 0;
let mut value_cache = HashMap::new();

loop {
let block = match rx.recv() {
Ok(block) => block,
Expand All @@ -113,10 +114,21 @@ impl Updater {
&mut outpoint_sender,
&mut value_receiver,
&mut wtx,
block,
&block,
&mut value_cache,
)?;

if self.height.checked_sub(1).is_some() {
log::info!(
target: "new_inscription_satpoint",
"{{\"height\":{},\"block_hash\":\"{}\",\"prev_block_hash\":\"{}\",\"tx_count\":{}}}",
&self.height - 1,
&block.header.block_hash(),
&block.header.prev_blockhash,
&block.txdata.len(),
);
}

if let Some(progress_bar) = &mut progress_bar {
progress_bar.inc(1);

Expand Down Expand Up @@ -333,7 +345,7 @@ impl Updater {
outpoint_sender: &mut Sender<OutPoint>,
value_receiver: &mut Receiver<u64>,
wtx: &mut WriteTransaction,
block: BlockData,
block: &BlockData,
value_cache: &mut HashMap<OutPoint, u64>,
) -> Result<()> {
// If value_receiver still has values something went wrong with the last block
Expand Down
34 changes: 34 additions & 0 deletions src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub(super) struct Flotsam {
inscription_id: InscriptionId,
offset: u64,
origin: Origin,
tx_in: Option<TxIn>,
}

enum Origin {
Expand Down Expand Up @@ -87,6 +88,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
offset: input_value + old_satpoint.offset,
inscription_id,
origin: Origin::Old(old_satpoint),
tx_in: None,
});
}

Expand Down Expand Up @@ -115,6 +117,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
inscription_id: txid.into(),
offset: 0,
origin: Origin::New(input_value - tx.output.iter().map(|txout| txout.value).sum::<u64>()),
tx_in: tx.input.get(0).cloned(),
});
};

Expand Down Expand Up @@ -239,6 +242,37 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
self.satpoint_to_id.insert(&new_satpoint, &inscription_id)?;
self.id_to_satpoint.insert(&inscription_id, &new_satpoint)?;

let inscription_id = InscriptionId::load(inscription_id);
let satpoint = SatPoint::load(new_satpoint);
let inscription_entry = self.id_to_entry.get(&inscription_id.store())?.unwrap();
let inscription_number = InscriptionEntry::load(inscription_entry.value()).number;

if let Some(tx_in) = flotsam.tx_in {
let inscription = Inscription::from_tx_input(&tx_in).unwrap();
let content_type = inscription.content_type().unwrap_or("");
let content_len = inscription.body().map_or(0, |body| body.len());

log::info!(
target: "new_inscription_satpoint",
"{},{},{},{},{},{}",
self.height,
satpoint,
inscription_id,
inscription_number,
content_type,
content_len,
);
} else {
log::info!(
target: "new_inscription_satpoint",
"{},{},{},{}",
self.height,
satpoint,
inscription_id,
inscription_number,
);
}

Ok(())
}
}
22 changes: 22 additions & 0 deletions src/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ impl Inscription {

pub(crate) fn from_transaction(tx: &Transaction) -> Option<Inscription> {
InscriptionParser::parse(&tx.input.get(0)?.witness).ok()
// for input in &tx.input {
// if let Some(inscription) = Inscription::from_tx_input(input) {
// return Some(inscription);
// }
// }

// None
}

pub(crate) fn from_tx_input(tx_in: &TxIn) -> Option<Inscription> {
InscriptionParser::parse(&tx_in.witness).ok()
}

pub(crate) fn from_file(chain: Chain, path: impl AsRef<Path>) -> Result<Self, Error> {
Expand Down Expand Up @@ -389,6 +400,17 @@ mod tests {
);
}

#[test]
fn no_content_type_and_no_body() {
assert_eq!(
InscriptionParser::parse(&envelope(&[b"ord"])),
Ok(Inscription {
content_type: None,
body: None,
}),
);
}

#[test]
fn valid_body_in_multiple_pushes() {
assert_eq!(
Expand Down
19 changes: 16 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ use {
env,
ffi::OsString,
fmt::{self, Display, Formatter},
fs::{self, File},
io,
fs::{self, File, OpenOptions},
io::{self, Write},
net::{TcpListener, ToSocketAddrs},
ops::{Add, AddAssign, Sub},
path::{Path, PathBuf},
Expand Down Expand Up @@ -144,7 +144,20 @@ fn timestamp(seconds: u32) -> DateTime<Utc> {
const INTERRUPT_LIMIT: u64 = 5;

pub fn main() {
env_logger::init();
let inscription_satpoint_logs_file = OpenOptions::new()
.write(true)
.append(true)
.create(true)
.open("inscription_satpoint.txt")
.unwrap();

env_logger::builder()
.filter(Some("new_inscription_satpoint"), log::LevelFilter::Info)
.target(env_logger::Target::Pipe(Box::new(
inscription_satpoint_logs_file,
)))
.format(|buf, record| writeln!(buf, "{}", record.args()))
.init();

ctrlc::set_handler(move || {
LISTENERS
Expand Down
4 changes: 4 additions & 0 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod subsidy;
pub mod supply;
pub mod traits;
pub mod wallet;
pub mod witness;

fn print_json(output: impl Serialize) -> Result {
serde_json::to_writer_pretty(io::stdout(), &output)?;
Expand Down Expand Up @@ -45,6 +46,8 @@ pub(crate) enum Subcommand {
Traits(traits::Traits),
#[clap(subcommand, about = "Wallet commands")]
Wallet(wallet::Wallet),
#[clap(subcommand, about = "Extract witness content from inscription")]
Witness(witness::Witness),
}

impl Subcommand {
Expand All @@ -67,6 +70,7 @@ impl Subcommand {
Self::Supply => supply::run(),
Self::Traits(traits) => traits.run(),
Self::Wallet(wallet) => wallet.run(options),
Self::Witness(witness) => witness.run(options),
}
}
}
130 changes: 124 additions & 6 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use {
},
axum::{
body,
extract::{Extension, Path, Query},
extract::{Extension, Path, Query, RawBody},
headers::UserAgent,
http::{header, HeaderMap, HeaderValue, StatusCode, Uri},
response::{IntoResponse, Redirect, Response},
routing::get,
Router, TypedHeader,
routing::{get, post},
Json, Router, TypedHeader,
},
axum_server::Handle,
rust_embed::RustEmbed,
Expand All @@ -27,7 +27,7 @@ use {
caches::DirCache,
AcmeConfig,
},
std::{cmp::Ordering, str},
std::{cmp::Ordering, str, collections::HashMap},
tokio_stream::StreamExt,
tower_http::{
compression::CompressionLayer,
Expand Down Expand Up @@ -87,11 +87,34 @@ impl Display for StaticHtml {
}
}

#[derive(Serialize, Deserialize, Clone)]
struct InscriptionData {
number: u64,
id: InscriptionId,
owner_address: Address,
location: SatPoint,
genesis_height: u64,
genesis_transaction: Txid,
creator_address: Address,
content_length: usize,
content_type: String,
}

#[derive(Serialize)]
struct InscriptionsDataResult {
inscriptions: HashMap<InscriptionId, InscriptionData>,
}

#[derive(Serialize, Deserialize, Debug)]
struct InscriptionsDataRequest {
ids: Vec<InscriptionId>,
}

#[derive(Debug, Parser)]
pub(crate) struct Server {
#[clap(
long,
default_value = "0.0.0.0",
default_value = "127.0.0.1",
help = "Listen on <ADDRESS> for incoming requests."
)]
address: String,
Expand Down Expand Up @@ -154,6 +177,7 @@ impl Server {
.route("/feed.xml", get(Self::feed))
.route("/input/:block/:transaction/:input", get(Self::input))
.route("/inscription/:inscription_id", get(Self::inscription))
.route("/inscriptions-data/", post(Self::inscriptions_data))
.route("/inscriptions", get(Self::inscriptions))
.route("/inscriptions/:from", get(Self::inscriptions_from))
.route("/install.sh", get(Self::install_script))
Expand Down Expand Up @@ -768,7 +792,7 @@ impl Server {
.get_inscription_by_id(inscription_id)?
.ok_or_not_found(|| format!("inscription {inscription_id}"))?;

return match inscription.media() {
match inscription.media() {
Media::Audio => Ok(PreviewAudioHtml { inscription_id }.into_response()),
Media::Iframe => Ok(
Self::content_response(inscription)
Expand Down Expand Up @@ -809,7 +833,101 @@ impl Server {
}
Media::Unknown => Ok(PreviewUnknownHtml.into_response()),
Media::Video => Ok(PreviewVideoHtml { inscription_id }.into_response()),
}
}

async fn inscriptions_data(
Extension(page_config): Extension<Arc<PageConfig>>,
Extension(index): Extension<Arc<Index>>,
RawBody(body): RawBody,
) -> ServerResult<Json<InscriptionsDataResult>> {
let body_bytes = hyper::body::to_bytes(body).await.unwrap().to_vec();
let body_string = String::from_utf8(body_bytes).unwrap();
let request_body = serde_json::from_str::<InscriptionsDataRequest>(&body_string).unwrap();

let inscriptions = request_body.ids;
let mut data_map: HashMap<InscriptionId, InscriptionData> = HashMap::new();

for inscription_id in inscriptions.into_iter() {
match Server::get_inscription_data(&index, page_config.chain, inscription_id).await {
Ok(inscription_data) => {
data_map.insert(inscription_id, inscription_data);
}
Err(_) => {
// skip broken inscriptions
continue;
}
}
}

let inscription_data_result = InscriptionsDataResult {
inscriptions: data_map,
};

Ok(Json(inscription_data_result))
}

async fn get_inscription_data(
index: &Arc<Index>,
chain: Chain,
inscription_id: InscriptionId,
) -> Result<InscriptionData> {
let entry = index.get_inscription_entry(inscription_id)?.unwrap();

let inscription = index.get_inscription_by_id(inscription_id)?.unwrap();

let satpoint = index
.get_inscription_satpoint_by_id(inscription_id)?
.unwrap();

let output = index
.get_transaction(satpoint.outpoint.txid)?
.unwrap()
.output
.into_iter()
.nth(satpoint.outpoint.vout.try_into().unwrap())
.unwrap();

let previous_outpoint = index
.get_transaction(inscription_id.txid)?
.unwrap()
.input
.into_iter()
.nth(inscription_id.index.try_into().unwrap())
.unwrap()
.previous_output;

let previous_output = index
.get_transaction(previous_outpoint.txid)?
.unwrap()
.output
.into_iter()
.nth(previous_outpoint.vout.try_into().unwrap())
.unwrap();

let owner_address = chain
.address_from_script(&output.script_pubkey)
.ok()
.unwrap();

let creator_address = chain
.address_from_script(&previous_output.script_pubkey)
.ok()
.unwrap();

let inscription_data = InscriptionData {
number: entry.number,
id: inscription_id,
owner_address,
genesis_height: entry.height,
genesis_transaction: inscription_id.txid,
creator_address,
location: satpoint,
content_length: inscription.content_length().unwrap_or(0),
content_type: inscription.content_type().unwrap_or("").to_string(),
};

Ok(inscription_data)
}

async fn inscription(
Expand Down
Loading