Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
lugondev committed Feb 21, 2024
2 parents de88064 + 3964b99 commit 024e4b8
Show file tree
Hide file tree
Showing 49 changed files with 1,188 additions and 436 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/.vagrant
/.vscode
/docs/build
/env
/fuzz/artifacts
/fuzz/corpus
/fuzz/coverage
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ brotli = "3.4.0"
chrono = { version = "0.4.19", features = ["serde"] }
ciborium = "0.2.1"
clap = { version = "4.4.2", features = ["derive"] }
colored = "2.0.4"
ctrlc = { version = "3.2.1", features = ["termination"] }
dirs = "5.0.0"
env_logger = "0.10.0"
Expand Down Expand Up @@ -65,7 +66,7 @@ tempfile = "3.2.0"
tokio = { version = "1.17.0", features = ["rt-multi-thread"] }
tokio-stream = "0.1.9"
tokio-util = {version = "0.7.3", features = ["compat"] }
tower-http = { version = "0.4.0", features = ["compression-br", "compression-gzip", "cors", "set-header"] }
tower-http = { version = "0.4.0", features = ["auth", "compression-br", "compression-gzip", "cors", "set-header"] }

[dev-dependencies]
criterion = "0.5.1"
Expand Down
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Summary
- [Pointer](inscriptions/pointer.md)
- [Provenance](inscriptions/provenance.md)
- [Recursion](inscriptions/recursion.md)
- [Rendering](inscriptions/rendering.md)
- [FAQ](faq.md)
- [Contributing](contributing.md)
- [Donate](donate.md)
Expand Down
83 changes: 59 additions & 24 deletions docs/src/inscriptions/recursion.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The recursive endpoints are:
- `/r/blocktime`: UNIX time stamp of latest block.
- `/r/children/<INSCRIPTION_ID>`: the first 100 child inscription ids.
- `/r/children/<INSCRIPTION_ID>/<PAGE>`: the set of 100 child inscription ids on `<PAGE>`.
- `/r/inscription/:inscription_id`: information about an inscription
- `/r/metadata/<INSCRIPTION_ID>`: JSON string containing the hex-encoded CBOR metadata.
- `/r/sat/<SAT_NUMBER>`: the first 100 inscription ids on a sat.
- `/r/sat/<SAT_NUMBER>/<PAGE>`: the set of 100 inscription ids on `<PAGE>`.
Expand All @@ -50,16 +51,38 @@ plain-text responses.
Examples
--------

- `/r/blockhash/0`:

```json
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
```

- `/r/blockheight`:

```json
777000
```

- `/r/blockhash/0`:
- `/r/blockinfo/0`:

```json
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
{
"bits": 486604799,
"chainwork": 0,
"confirmations": 0,
"difficulty": 0.0,
"hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
"height": 0,
"median_time": null,
"merkle_root": "0000000000000000000000000000000000000000000000000000000000000000",
"next_block": null,
"nonce": 0,
"previous_block": null,
"target": "00000000ffff0000000000000000000000000000000000000000000000000000",
"timestamp": 0,
"transaction_count": 0,
"version": 1
}
```

- `/r/blocktime`:
Expand All @@ -68,6 +91,40 @@ Examples
1700770905
```

- `/r/children/60bcf821240064a9c55225c4f01711b0ebbcab39aa3fafeefe4299ab158536fai0/49`:

```json
{
"ids":[
"7cd66b8e3a63dcd2fada917119830286bca0637267709d6df1ca78d98a1b4487i4900",
"7cd66b8e3a63dcd2fada917119830286bca0637267709d6df1ca78d98a1b4487i4901",
...
"7cd66b8e3a63dcd2fada917119830286bca0637267709d6df1ca78d98a1b4487i4935",
"7cd66b8e3a63dcd2fada917119830286bca0637267709d6df1ca78d98a1b4487i4936"
],
"more":false,
"page":49
}
```

- `r/inscription/3bd72a7ef68776c9429961e43043ff65efa7fb2d8bb407386a9e3b19f149bc36i0`

```json
{
"charms": [],
"content_type": "image/png",
"content_length": 144037,
"fee": 36352,
"height": 209,
"number": 2,
"output": "3bd72a7ef68776c9429961e43043ff65efa7fb2d8bb407386a9e3b19f149bc36:0",
"sat": null,
"satpoint": "3bd72a7ef68776c9429961e43043ff65efa7fb2d8bb407386a9e3b19f149bc36:0:0",
"timestamp": 1708312562,
"value": 10000
}
```

- `/r/metadata/35b66389b44535861c44b2b18ed602997ee11db9a30d384ae89630c9fc6f011fi3`:

```json
Expand Down Expand Up @@ -109,25 +166,3 @@ Examples
"page":49
}
```

- `/r/blockinfo/0`:

```json
{
"bits": 486604799,
"chainwork": 0,
"confirmations": 0,
"difficulty": 0.0,
"hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
"height": 0,
"median_time": null,
"merkle_root": "0000000000000000000000000000000000000000000000000000000000000000",
"next_block": null,
"nonce": 0,
"previous_block": null,
"target": "00000000ffff0000000000000000000000000000000000000000000000000000",
"timestamp": 0,
"transaction_count": 0,
"version": 1
}
```
35 changes: 35 additions & 0 deletions docs/src/inscriptions/rendering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Rendering
=========

Aspect Ratio
------------

Inscriptions should be rendered with a square aspect ratio. Non-square aspect
ratio inscriptions should not be cropped, and should instead be centered and
resized to fit within their container.

Maximum Size
------------

The `ord` explorer, used by [ordinals.com](https://ordinals.com/), displays
inscription previews with a maximum size of 576 by 576 pixels, making it a
reasonable choice when choosing a maximum display size.

Image Rendering
---------------

The CSS `image-rendering` property controls how images are resampled when
upscaled and downscaled.

When downscaling image inscriptions, `image-rendering: auto`, should be used.
This is desirable even when downscaling pixel art.

When upscaling image inscriptions other than AVIF, `image-rendering: pixelated`
should be used. This is desriable when upscaling pixel art, since it preserves
the sharp edges of pixels. It is undesirable when upscaling non-pixel art, but
should still be used for visual compatibility with the `ord` explorer.

When upscaling AVIF and JPEG XL inscriptions, `image-rendering: auto` should be
used. This allows inscribers to opt-in to non-pixelated upscaling for non-pixel
art inscriptions. Until such time as JPEG XL is widely supported by browsers,
it is not a recommended image format.
15 changes: 14 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod updater;
#[cfg(test)]
pub(crate) mod testing;

const SCHEMA_VERSION: u64 = 17;
const SCHEMA_VERSION: u64 = 18;

macro_rules! define_table {
($name:ident, $key:ty, $value:ty) => {
Expand All @@ -61,6 +61,7 @@ macro_rules! define_multimap_table {
define_multimap_table! { SATPOINT_TO_SEQUENCE_NUMBER, &SatPointValue, u32 }
define_multimap_table! { SAT_TO_SEQUENCE_NUMBER, u64, u32 }
define_multimap_table! { SEQUENCE_NUMBER_TO_CHILDREN, u32, u32 }
define_table! { CONTENT_TYPE_TO_COUNT, Option<&[u8]>, u64 }
define_table! { HEIGHT_TO_BLOCK_HEADER, u32, &HeaderValue }
define_table! { HEIGHT_TO_LAST_SEQUENCE_NUMBER, u32, u32 }
define_table! { HOME_INSCRIPTIONS, u32, InscriptionIdValue }
Expand Down Expand Up @@ -327,6 +328,7 @@ impl Index {
tx.open_multimap_table(SATPOINT_TO_SEQUENCE_NUMBER)?;
tx.open_multimap_table(SAT_TO_SEQUENCE_NUMBER)?;
tx.open_multimap_table(SEQUENCE_NUMBER_TO_CHILDREN)?;
tx.open_table(CONTENT_TYPE_TO_COUNT)?;
tx.open_table(HEIGHT_TO_BLOCK_HEADER)?;
tx.open_table(HEIGHT_TO_LAST_SEQUENCE_NUMBER)?;
tx.open_table(HOME_INSCRIPTIONS)?;
Expand Down Expand Up @@ -472,9 +474,20 @@ impl Index {
let blessed_inscriptions = statistic(Statistic::BlessedInscriptions)?;
let cursed_inscriptions = statistic(Statistic::CursedInscriptions)?;

let mut content_type_counts = rtx
.open_table(CONTENT_TYPE_TO_COUNT)?
.iter()?
.map(|result| {
result.map(|(key, value)| (key.value().map(|slice| slice.into()), value.value()))
})
.collect::<Result<Vec<(Option<Vec<u8>>, u64)>, StorageError>>()?;

content_type_counts.sort_by_key(|(_content_type, count)| Reverse(*count));

Ok(StatusHtml {
blessed_inscriptions,
chain: self.options.chain(),
content_type_counts,
cursed_inscriptions,
height,
inscriptions: blessed_inscriptions + cursed_inscriptions,
Expand Down
2 changes: 2 additions & 0 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ impl<'index> Updater<'_> {
}
}

let mut content_type_to_count = wtx.open_table(CONTENT_TYPE_TO_COUNT)?;
let mut height_to_block_header = wtx.open_table(HEIGHT_TO_BLOCK_HEADER)?;
let mut height_to_last_sequence_number = wtx.open_table(HEIGHT_TO_LAST_SEQUENCE_NUMBER)?;
let mut home_inscriptions = wtx.open_table(HOME_INSCRIPTIONS)?;
Expand Down Expand Up @@ -423,6 +424,7 @@ impl<'index> Updater<'_> {
let mut inscription_updater = InscriptionUpdater {
blessed_inscription_count,
chain: self.index.options.chain(),
content_type_to_count: &mut content_type_to_count,
cursed_inscription_count,
event_sender: self.index.event_sender.as_ref(),
flotsam: Vec::new(),
Expand Down
13 changes: 13 additions & 0 deletions src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum Origin {
pub(super) struct InscriptionUpdater<'a, 'db, 'tx> {
pub(super) blessed_inscription_count: u64,
pub(super) chain: Chain,
pub(super) content_type_to_count: &'a mut Table<'db, 'tx, Option<&'static [u8]>, u64>,
pub(super) cursed_inscription_count: u64,
pub(super) event_sender: Option<&'a Sender<Event>>,
pub(super) flotsam: Vec<Flotsam>,
Expand Down Expand Up @@ -195,6 +196,18 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
.filter(|&pointer| pointer < total_output_value)
.unwrap_or(offset);

let content_type = inscription.payload.content_type.as_deref();

let content_type_count = self
.content_type_to_count
.get(content_type)?
.map(|entry| entry.value())
.unwrap_or_default();

self
.content_type_to_count
.insert(content_type, content_type_count + 1)?;

floating_inscriptions.push(Flotsam {
inscription_id,
offset,
Expand Down
2 changes: 1 addition & 1 deletion src/inscriptions/inscription_id.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

#[derive(Debug, PartialEq, Copy, Clone, Hash, Eq)]
#[derive(Debug, PartialEq, Copy, Clone, Hash, Eq, PartialOrd, Ord)]
pub struct InscriptionId {
pub txid: Txid,
pub index: u32,
Expand Down
Loading

0 comments on commit 024e4b8

Please sign in to comment.