From 82b7f76205c7b4e85cf545fb17dab6755b9f529b Mon Sep 17 00:00:00 2001 From: Eloc <42568538+elocremarc@users.noreply.github.com> Date: Wed, 4 Sep 2024 02:00:55 -0700 Subject: [PATCH 01/11] Delegator content --- docs/src/inscriptions/delegate.md | 7 +- docs/src/inscriptions/recursion.md | 12 ++++ src/subcommand/server.rs | 103 +++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) diff --git a/docs/src/inscriptions/delegate.md b/docs/src/inscriptions/delegate.md index 545d7a3448..c896db7400 100644 --- a/docs/src/inscriptions/delegate.md +++ b/docs/src/inscriptions/delegate.md @@ -4,7 +4,12 @@ Delegate Inscriptions may nominate a delegate inscription. Requests for the content of an inscription with a delegate will instead return the content, content type and content encoding of the delegate. This can be used to cheaply create copies -of an inscription. +of an inscription. + +Delegator +======== + +A delegated inscription known as a delegator can access its own inscribed content at `/r/delegator/:id`. This allows for a delegate to have access to any unique data inscribed by the delegator. ### Specification diff --git a/docs/src/inscriptions/recursion.md b/docs/src/inscriptions/recursion.md index bde18fc6e7..25a40d76e3 100644 --- a/docs/src/inscriptions/recursion.md +++ b/docs/src/inscriptions/recursion.md @@ -42,6 +42,7 @@ The recursive endpoints are: - `/r/children//`: the set of 100 child inscription ids on ``. - `/r/children//inscriptions`: details of the first 100 child inscriptions. - `/r/children//inscriptions/`: details of the set of 100 child inscriptions on ``. +- `/r/delegator/`: inscription content of the delegator. - `/r/inscription/`: information about an inscription - `/r/metadata/`: JSON string containing the hex-encoded CBOR metadata. - `/r/parents/`: the first 100 parent inscription ids. @@ -63,6 +64,17 @@ plain-text responses. - `/blockhash/`: block hash at given block height. - `/blocktime`: UNIX time stamp of latest block. +Delegated inscriptions: + +An inscription with delegated content "foo" and original content "bar" will return the following: + +| Endpoint | Response | +|--------------------|----------| +| `/content/:id` | foo | +| `/r/delegator/:id` | bar | + +This allows delegated inscriptions to access both the content they delegate to and their own original content. + Examples -------- diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 104c65717c..a8b595e630 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -243,6 +243,7 @@ impl Server { "/r/children/:inscription_id/inscriptions/:page", get(Self::child_inscriptions_recursive_paginated), ) + .route("/r/delegator/:inscription_id", get(Self::content_delegator)) .route("/r/metadata/:inscription_id", get(Self::metadata)) .route("/r/parents/:inscription_id", get(Self::parents_recursive)) .route( @@ -1467,6 +1468,36 @@ impl Server { }) } + async fn content_delegator( + Extension(index): Extension>, + Extension(settings): Extension>, + Extension(server_config): Extension>, + Path(inscription_id): Path, + accept_encoding: AcceptEncoding, + ) -> ServerResult { + task::block_in_place(|| { + if settings.is_hidden(inscription_id) { + return Ok(PreviewUnknownHtml.into_response()); + } + + let inscription = index + .get_inscription_by_id(inscription_id)? + .ok_or_not_found(|| format!("inscription {inscription_id}"))?; + + if inscription.delegate().is_some() { + Ok( + Self::content_response(inscription, accept_encoding, &server_config)? + .ok_or_not_found(|| format!("inscription {inscription_id} content"))? + .into_response(), + ) + } else { + Err(ServerError::NotFound( + "inscription is not delegated".to_string(), + )) + } + }) + } + fn content_response( inscription: Inscription, accept_encoding: AcceptEncoding, @@ -6509,6 +6540,78 @@ next ); } + #[test] + fn delegator_content() { + let server = TestServer::builder().chain(Chain::Regtest).build(); + + server.mine_blocks(1); + + let delegate = Inscription { + content_type: Some("text/plain".into()), + body: Some("foo".into()), + ..default() + }; + + let delegate_txid = server.core.broadcast_tx(TransactionTemplate { + inputs: &[(1, 0, 0, delegate.to_witness())], + ..default() + }); + + let delegate_id = InscriptionId { + txid: delegate_txid, + index: 0, + }; + + server.mine_blocks(1); + + let inscription = Inscription { + content_type: Some("text/plain".into()), + body: Some("bar".into()), + delegate: Some(delegate_id.value()), + ..default() + }; + + let txid = server.core.broadcast_tx(TransactionTemplate { + inputs: &[(2, 0, 0, inscription.to_witness())], + ..default() + }); + + server.mine_blocks(1); + + let id = InscriptionId { txid, index: 0 }; + + server.assert_response(format!("/r/delegator/{id}"), StatusCode::OK, "bar"); + + server.assert_response(format!("/content/{id}"), StatusCode::OK, "foo"); + + // Test normal inscription without delegate + let normal_inscription = Inscription { + content_type: Some("text/plain".into()), + body: Some("baz".into()), + ..default() + }; + + let normal_txid = server.core.broadcast_tx(TransactionTemplate { + inputs: &[(3, 0, 0, normal_inscription.to_witness())], + ..default() + }); + + server.mine_blocks(1); + + let normal_id = InscriptionId { + txid: normal_txid, + index: 0, + }; + + server.assert_response( + format!("/r/delegator/{normal_id}"), + StatusCode::NOT_FOUND, + "inscription is not delegated", + ); + + server.assert_response(format!("/content/{normal_id}"), StatusCode::OK, "baz"); + } + #[test] fn content_proxy() { let server = TestServer::builder().chain(Chain::Regtest).build(); From eecd541737da76b4c970b10b73574f8a8d904c34 Mon Sep 17 00:00:00 2001 From: Eloc <42568538+elocremarc@users.noreply.github.com> Date: Wed, 4 Sep 2024 02:14:47 -0700 Subject: [PATCH 02/11] update docs --- docs/src/inscriptions/delegate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/inscriptions/delegate.md b/docs/src/inscriptions/delegate.md index c896db7400..34470f24c0 100644 --- a/docs/src/inscriptions/delegate.md +++ b/docs/src/inscriptions/delegate.md @@ -9,7 +9,7 @@ of an inscription. Delegator ======== -A delegated inscription known as a delegator can access its own inscribed content at `/r/delegator/:id`. This allows for a delegate to have access to any unique data inscribed by the delegator. +A delegated inscription known as a delegator can access its own inscribed content at `/r/delegator/:id`. This allows for a delegate to have access to itw own unique inscription data. ### Specification From 41090a2b66a8f27d020677474023f2af40c30d65 Mon Sep 17 00:00:00 2001 From: Eloc <42568538+elocremarc@users.noreply.github.com> Date: Wed, 4 Sep 2024 02:28:34 -0700 Subject: [PATCH 03/11] update docs --- docs/src/inscriptions/delegate.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/docs/src/inscriptions/delegate.md b/docs/src/inscriptions/delegate.md index 34470f24c0..a0be535bd8 100644 --- a/docs/src/inscriptions/delegate.md +++ b/docs/src/inscriptions/delegate.md @@ -4,12 +4,7 @@ Delegate Inscriptions may nominate a delegate inscription. Requests for the content of an inscription with a delegate will instead return the content, content type and content encoding of the delegate. This can be used to cheaply create copies -of an inscription. - -Delegator -======== - -A delegated inscription known as a delegator can access its own inscribed content at `/r/delegator/:id`. This allows for a delegate to have access to itw own unique inscription data. +of an inscription. ### Specification @@ -42,4 +37,4 @@ OP_ENDIF Note that the value of tag `11` is decimal, not hex. The delegate field value uses the same encoding as the parent field. See -[provenance](provenance.md) for more examples of inscription ID encodings; +[provenance](provenance.md) for more examples of inscription ID encodings; \ No newline at end of file From da5632a8a8798fee59fe214ef4957c3700781b1f Mon Sep 17 00:00:00 2001 From: Eloc <42568538+elocremarc@users.noreply.github.com> Date: Wed, 4 Sep 2024 02:31:10 -0700 Subject: [PATCH 04/11] update docs --- docs/src/inscriptions/delegate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/inscriptions/delegate.md b/docs/src/inscriptions/delegate.md index a0be535bd8..545d7a3448 100644 --- a/docs/src/inscriptions/delegate.md +++ b/docs/src/inscriptions/delegate.md @@ -37,4 +37,4 @@ OP_ENDIF Note that the value of tag `11` is decimal, not hex. The delegate field value uses the same encoding as the parent field. See -[provenance](provenance.md) for more examples of inscription ID encodings; \ No newline at end of file +[provenance](provenance.md) for more examples of inscription ID encodings; From fcce3d63e947d2cd1febe1fc6ec9dd5d81f94b97 Mon Sep 17 00:00:00 2001 From: Eloc <42568538+elocremarc@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:04:19 -0700 Subject: [PATCH 05/11] Pr update always return content. --- src/subcommand/server.rs | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 7c07756cc2..d095ad9d60 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -1510,17 +1510,11 @@ impl Server { .get_inscription_by_id(inscription_id)? .ok_or_not_found(|| format!("inscription {inscription_id}"))?; - if inscription.delegate().is_some() { - Ok( - Self::content_response(inscription, accept_encoding, &server_config)? - .ok_or_not_found(|| format!("inscription {inscription_id} content"))? - .into_response(), - ) - } else { - Err(ServerError::NotFound( - "inscription is not delegated".to_string(), - )) - } + Ok( + Self::content_response(inscription, accept_encoding, &server_config)? + .ok_or_not_found(|| format!("inscription {inscription_id} content"))? + .into_response(), + ) }) } @@ -6704,12 +6698,7 @@ next index: 0, }; - server.assert_response( - format!("/r/delegator/{normal_id}"), - StatusCode::NOT_FOUND, - "inscription is not delegated", - ); - + server.assert_response(format!("/r/delegator/{normal_id}"), StatusCode::OK, "baz"); server.assert_response(format!("/content/{normal_id}"), StatusCode::OK, "baz"); } From 4b72f1b5dc1b3b666645fe5282ccb76449568048 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 25 Oct 2024 18:06:32 -0700 Subject: [PATCH 06/11] Amend --- docs/src/inscriptions/recursion.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/inscriptions/recursion.md b/docs/src/inscriptions/recursion.md index 8c34ce40af..9ecf334318 100644 --- a/docs/src/inscriptions/recursion.md +++ b/docs/src/inscriptions/recursion.md @@ -56,7 +56,7 @@ curl -s -H "Accept: application/json" \ ### Description -Latest block hash in JSON. +Latest block hash. ### Example ```bash @@ -2275,6 +2275,7 @@ curl -s -H "Accept: application/json" \ "id": "b205c9d1dc054f24c13aeb886fba42d9dd0aac3cd9bdc4f034affc90f3a0bf3ci95", "number": 75750381, "output": "4b8472a729f7b73feaf1de84895641e62a8b1103818c1878e4da18a585cb1047:1", + "sat": null, "satpoint": "4b8472a729f7b73feaf1de84895641e62a8b1103818c1878e4da18a585cb1047:1:0", "timestamp": 1726292222 }, From fb90ac3d91604f0258f03ec3782a0550625962bc Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 25 Oct 2024 18:14:16 -0700 Subject: [PATCH 07/11] Amend --- docs/src/inscriptions/recursion.md | 19 +++++++++++++++++++ src/subcommand/server.rs | 21 ++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/docs/src/inscriptions/recursion.md b/docs/src/inscriptions/recursion.md index 9ecf334318..fcd673cc46 100644 --- a/docs/src/inscriptions/recursion.md +++ b/docs/src/inscriptions/recursion.md @@ -3118,6 +3118,25 @@ curl -s -H "Accept: application/json" \ ``` +
+ + GET + /r/undelegated-content/<INSCRIPTION_ID> + + +### Description +Content of the undelegated inscription. + +### Example +```bash +curl -s -H "Accept: application/json" \ + http://0.0.0.0:80/r/undelegated-content/ +``` +```json +``` +
+ +
GET diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 5dbee943e0..d711bd7761 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -236,7 +236,10 @@ impl Server { "/r/children/:inscription_id/inscriptions/:page", get(Self::child_inscriptions_recursive_paginated), ) - .route("/r/delegator/:inscription_id", get(Self::content_delegator)) + .route( + "/r/undelegated-content/:inscription_id", + get(Self::undelegated_content), + ) .route("/r/metadata/:inscription_id", get(Self::metadata)) .route("/r/parents/:inscription_id", get(Self::parents_recursive)) .route( @@ -1468,7 +1471,7 @@ impl Server { }) } - async fn content_delegator( + async fn undelegated_content( Extension(index): Extension>, Extension(settings): Extension>, Extension(server_config): Extension>, @@ -6602,7 +6605,7 @@ next } #[test] - fn delegator_content() { + fn undelegated_content() { let server = TestServer::builder().chain(Chain::Regtest).build(); server.mine_blocks(1); @@ -6641,7 +6644,11 @@ next let id = InscriptionId { txid, index: 0 }; - server.assert_response(format!("/r/delegator/{id}"), StatusCode::OK, "bar"); + server.assert_response( + format!("/r/undelegated-content/{id}"), + StatusCode::OK, + "bar", + ); server.assert_response(format!("/content/{id}"), StatusCode::OK, "foo"); @@ -6664,7 +6671,11 @@ next index: 0, }; - server.assert_response(format!("/r/delegator/{normal_id}"), StatusCode::OK, "baz"); + server.assert_response( + format!("/r/undelegated-content/{normal_id}"), + StatusCode::OK, + "baz", + ); server.assert_response(format!("/content/{normal_id}"), StatusCode::OK, "baz"); } From 33d03e232645e7dcae75c1bfc711de7b2be1cb11 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 25 Oct 2024 18:20:57 -0700 Subject: [PATCH 08/11] Amend --- docs/src/inscriptions/recursion.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/docs/src/inscriptions/recursion.md b/docs/src/inscriptions/recursion.md index fcd673cc46..665d47c103 100644 --- a/docs/src/inscriptions/recursion.md +++ b/docs/src/inscriptions/recursion.md @@ -3125,15 +3125,8 @@ curl -s -H "Accept: application/json" \ ### Description -Content of the undelegated inscription. +Undelegated content of an inscription. -### Example -```bash -curl -s -H "Accept: application/json" \ - http://0.0.0.0:80/r/undelegated-content/ -``` -```json -```
From 5348c218051bda2c3646f77fa161fc3bda82e5fa Mon Sep 17 00:00:00 2001 From: raphjaph Date: Fri, 25 Oct 2024 18:23:22 -0700 Subject: [PATCH 09/11] Amend --- docs/src/inscriptions/recursion.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/inscriptions/recursion.md b/docs/src/inscriptions/recursion.md index 665d47c103..83871c0921 100644 --- a/docs/src/inscriptions/recursion.md +++ b/docs/src/inscriptions/recursion.md @@ -3131,10 +3131,10 @@ Undelegated content of an inscription.
- + GET /r/inscription/<INSCRIPTION_ID> - + ### Description Information about an inscription. From 70f8558e4c3cf4fc8f4111ff6187e2dfe776bc20 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 25 Oct 2024 18:26:17 -0700 Subject: [PATCH 10/11] Modify --- docs/src/inscriptions/recursion.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/inscriptions/recursion.md b/docs/src/inscriptions/recursion.md index 83871c0921..af85488faa 100644 --- a/docs/src/inscriptions/recursion.md +++ b/docs/src/inscriptions/recursion.md @@ -33,10 +33,10 @@ Recursion has a number of interesting use-cases: ## Endpoints
- + GET /content/<INSCRIPTION_ID> - + ### Description The content of the inscription with `` From 65fcf4ff2907fde832304f0c17bcfecf0a3818b7 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 25 Oct 2024 18:27:27 -0700 Subject: [PATCH 11/11] Adjust --- docs/src/inscriptions/recursion.md | 64 +++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/docs/src/inscriptions/recursion.md b/docs/src/inscriptions/recursion.md index af85488faa..37f8e80e2e 100644 --- a/docs/src/inscriptions/recursion.md +++ b/docs/src/inscriptions/recursion.md @@ -50,10 +50,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/blockhash - + ### Description Latest block hash. @@ -69,10 +69,10 @@ curl -s \
- + GET /r/blockhash/<HEIGHT> - + ### Description Block hash at given block height as JSON string. @@ -88,10 +88,10 @@ curl -s \
- + GET /r/blockheight - + ### Description Latest block height. @@ -107,10 +107,10 @@ curl -s \
- + GET /r/blockinfo/<QUERY> - + ### Description Block info. `` may be a block height or block hash. @@ -207,10 +207,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/blocktime - + ### Description UNIX time stamp of latest block. @@ -226,10 +226,10 @@ curl -s \
- + GET /r/children/<INSCRIPTION_ID> - + ### Description The first 100 child inscription ids. @@ -350,10 +350,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/children/<INSCRIPTION_ID>/<PAGE> - + ### Description The set of 100 child inscription ids on ``. @@ -474,10 +474,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/children/<INSCRIPTION_ID>/inscriptions - + ### Description Details of the first 100 child inscriptions. @@ -1796,10 +1796,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/children/<INSCRIPTION_ID>/inscriptions/<PAGE> - + ### Description Details of the set of 100 child inscriptions on <PAGE>. @@ -3119,10 +3119,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/undelegated-content/<INSCRIPTION_ID> - + ### Description Undelegated content of an inscription. @@ -3167,10 +3167,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/metadata/<INSCRIPTION_ID> - + ### Description JSON string containing the hex-encoded CBOR metadata. @@ -3186,10 +3186,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/parents/<INSCRIPTION_ID> - + ### Description The first 100 parent inscription ids. @@ -3211,10 +3211,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/parents/<INSCRIPTION_ID>/<PAGE> - + ### Description The set of 100 parent inscription ids on ``. @@ -3234,10 +3234,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/sat/<SAT_NUMBER> - + ### Description The first 100 inscription ids on a sat. Requires index with `--index-sats` flag. @@ -3262,10 +3262,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/sat/<SAT_NUMBER>/<PAGE> - + ### Description The set of 100 inscription ids on ``. Requires index with `--index-sats` flag. @@ -3297,10 +3297,10 @@ curl -s -H "Accept: application/json" \
- + GET /r/sat/<SAT_NUMBER>/at/<INDEX> - + ### Description The inscription id at `` of all inscriptions on a sat. `` may be a negative number to index from the back. `0` being the first and `-1` being the most recent for example. Requires index with `--index-sats` flag.