Skip to content

Commit 63499a9

Browse files
committed
parent and exists methods and endpoints
1 parent 4c9bf7f commit 63499a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3762
-94
lines changed

README.md

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ Redbit reads struct annotations and derives code necessary for persisting and qu
22
[Redb](https://github.com/cberner/redb) using secondary indexes and dictionaries, served by [axum](https://github.com/tokio-rs/axum)
33
through auto-generated REST API.
44

5-
### Main motivations
6-
- ✅ Achieving more advanced querying capabilities with embedded KV stores is non-trivial
7-
- ✅ Absence of any existing db & http higher-level layer for structured data in embedded KV stores
8-
- ✅ Handwriting custom codecs on byte-level is tedious and painful
5+
### Main motivation is a research
6+
7+
- ✅ Rust type and macro system and db engines at the byte level
8+
- ✅ decentralized persistence options to maximize indexing speed and minimize data size
9+
- ✅ meta space : self-tested and self-documented db & http layers of code derived from annotated structs
910

1011
### Major Out-of-the-Box Features
1112

@@ -183,7 +184,7 @@ And R/W entire instances efficiently using indexes and dictionaries `examples/ut
183184

184185
println!("Persisting blocks:");
185186
for block in blocks.iter() {
186-
Block::store_and_commit(&db, block)?
187+
Block::store_unsafe_and_commit(&db, block)?
187188
}
188189

189190
let read_tx = db.begin_read()?;
@@ -302,3 +303,66 @@ Block__get_header 277993
302303
BlockHeader__get 280582
303304
```
304305
<!-- END_BENCH -->
306+
307+
### Http Endpoints generated
308+
```
309+
Endpoint /block/id/{value}
310+
Endpoint /block?take=
311+
Endpoint /block?first=
312+
Endpoint /block?last=
313+
Endpoint /block/id/{value}
314+
Endpoint /block/id?from=&until=
315+
Endpoint /block/{value}/header
316+
Endpoint /block/{value}/transactions
317+
318+
Endpoint /blockheader/id/{value}
319+
Endpoint /blockheader?take=
320+
Endpoint /blockheader?first=
321+
Endpoint /blockheader?last=
322+
Endpoint /blockheader/id/{value}
323+
Endpoint /blockheader/id?from=&until=
324+
Endpoint /blockheader/hash/{value}
325+
Endpoint /blockheader/timestamp/{value}
326+
Endpoint /blockheader/timestamp?from=&until=
327+
Endpoint /blockheader/merkle_root/{value}
328+
329+
Endpoint /transaction/id/{value}
330+
Endpoint /transaction?take=
331+
Endpoint /transaction?first=
332+
Endpoint /transaction?last=
333+
Endpoint /transaction/id/{value}
334+
Endpoint /transaction/id/{value}/parent_pk
335+
Endpoint /transaction/id?from=&until=
336+
Endpoint /transaction/hash/{value}
337+
Endpoint /transaction/{value}/utxos
338+
Endpoint /transaction/{value}/inputs
339+
340+
Endpoint /utxo/id/{value}
341+
Endpoint /utxo?take=
342+
Endpoint /utxo?first=
343+
Endpoint /utxo?last=
344+
Endpoint /utxo/id/{value}
345+
Endpoint /utxo/id/{value}/parent_pk
346+
Endpoint /utxo/id?from=&until=
347+
Endpoint /utxo/datum/{value}
348+
Endpoint /utxo/address/{value}
349+
Endpoint /utxo/{value}/assets
350+
351+
Endpoint /inputref/id/{value}
352+
Endpoint /inputref?take=
353+
Endpoint /inputref?first=
354+
Endpoint /inputref?last=
355+
Endpoint /inputref/id/{value}
356+
Endpoint /inputref/id/{value}/parent_pk
357+
Endpoint /inputref/id?from=&until=
358+
359+
Endpoint /asset/id/{value}
360+
Endpoint /asset?take=
361+
Endpoint /asset?first=
362+
Endpoint /asset?last=
363+
Endpoint /asset/id/{value}
364+
Endpoint /asset/id/{value}/parent_pk
365+
Endpoint /asset/id?from=&until=
366+
Endpoint /asset/name/{value}
367+
Endpoint /asset/policy_id/{value}
368+
```

examples/utxo/benches/utxo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn benchmark_persistence(c: &mut Criterion) {
1919
group.bench_function("Block::store_and_commit", |b| {
2020
b.iter(|| {
2121
for block in blocks.iter() {
22-
Block::store_and_commit(&db, block).unwrap();
22+
Block::store_unsafe_and_commit(&db, block).unwrap();
2323
}
2424
})
2525
});

examples/utxo/src/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn empty_temp_db(name: &str) -> Database {
2424
pub fn init_temp_db(name: &str) -> (Vec<Block>, Database) {
2525
let db = empty_temp_db(name);
2626
let blocks = get_blocks(Height(4), 4, 4, 4);
27-
blocks.iter().for_each(|block| Block::store_and_commit(&db, &block).expect("Failed to persist blocks"));
27+
blocks.iter().for_each(|block| Block::store_unsafe_and_commit(&db, &block).expect("Failed to persist blocks"));
2828
(blocks, db)
2929
}
3030

examples/utxo/src/demo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub fn run(db: Arc<Database>) -> Result<(), AppError> {
88

99
println!("Persisting blocks:");
1010
for block in blocks.iter() {
11-
Block::store_and_commit(&db, block)?
11+
Block::store_unsafe_and_commit(&db, block)?
1212
}
1313

1414
let read_tx = db.begin_read()?;

examples/utxo/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Block {
2020

2121
#[derive(Entity, Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
2222
pub struct BlockHeader {
23-
#[pk(range)]
23+
#[fk(one2one, range)]
2424
pub id: BlockPointer,
2525
#[column(index)]
2626
pub hash: Hash,
@@ -34,7 +34,7 @@ pub struct BlockHeader {
3434

3535
#[derive(Entity, Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
3636
pub struct Transaction {
37-
#[pk(range)]
37+
#[fk(one2many, range)]
3838
pub id: TxPointer,
3939
#[column(index)]
4040
pub hash: Hash,
@@ -46,7 +46,7 @@ pub struct Transaction {
4646

4747
#[derive(Entity, Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
4848
pub struct Utxo {
49-
#[pk(range)]
49+
#[fk(one2many, range)]
5050
pub id: UtxoPointer,
5151
#[column]
5252
pub amount: Amount,
@@ -58,9 +58,15 @@ pub struct Utxo {
5858
pub assets: Vec<Asset>,
5959
}
6060

61+
#[derive(Entity, Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
62+
pub struct InputRef {
63+
#[fk(one2many, range)]
64+
pub id: InputPointer,
65+
}
66+
6167
#[derive(Entity, Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
6268
pub struct Asset {
63-
#[pk(range)]
69+
#[fk(one2many, range)]
6470
pub id: AssetPointer,
6571
#[column]
6672
pub amount: Amount,
@@ -96,12 +102,6 @@ pub struct InputPointer {
96102
pub utxo_index: UtxoIndex,
97103
}
98104

99-
#[derive(Entity, Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
100-
pub struct InputRef {
101-
#[pk(range)]
102-
pub id: InputPointer,
103-
}
104-
105105
#[derive(PK, Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
106106
pub struct AssetPointer {
107107
#[parent]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| Endpoint | GET:/asset/id/{value} asset_get
2+
| Endpoint | GET:/asset?take= asset_take
3+
| Endpoint | GET:/asset?first= asset_first
4+
| Endpoint | GET:/asset?last= asset_last
5+
| Endpoint | HEAD:/asset/id/{value} asset_exists
6+
| Endpoint | GET:/asset/id/{value}/parent_pk asset_parent_pk
7+
| Endpoint | GET:/asset/id?from=&until= asset_range
8+
| Endpoint | GET:/asset/name/{value} asset_get_by_name
9+
| Endpoint | GET:/asset/policy_id/{value} asset_get_by_policy_id
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
| Endpoint | GET:/block/id/{value} block_get
2+
| Endpoint | GET:/block?take= block_take
3+
| Endpoint | GET:/block?first= block_first
4+
| Endpoint | GET:/block?last= block_last
5+
| Endpoint | HEAD:/block/id/{value} block_exists
6+
| Endpoint | GET:/block/id?from=&until= block_range
7+
| Endpoint | GET:/block/{value}/header block_get_header
8+
| Endpoint | GET:/block/{value}/transactions block_get_transactions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| Endpoint | GET:/blockheader/id/{value} blockheader_get
2+
| Endpoint | GET:/blockheader?take= blockheader_take
3+
| Endpoint | GET:/blockheader?first= blockheader_first
4+
| Endpoint | GET:/blockheader?last= blockheader_last
5+
| Endpoint | HEAD:/blockheader/id/{value} blockheader_exists
6+
| Endpoint | GET:/blockheader/id?from=&until= blockheader_range
7+
| Endpoint | GET:/blockheader/hash/{value} blockheader_get_by_hash
8+
| Endpoint | GET:/blockheader/timestamp/{value} blockheader_get_by_timestamp
9+
| Endpoint | GET:/blockheader/timestamp?from=&until= blockheader_range_by_timestamp
10+
| Endpoint | GET:/blockheader/merkle_root/{value} blockheader_get_by_merkle_root
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| Endpoint | GET:/inputref/id/{value} inputref_get
2+
| Endpoint | GET:/inputref?take= inputref_take
3+
| Endpoint | GET:/inputref?first= inputref_first
4+
| Endpoint | GET:/inputref?last= inputref_last
5+
| Endpoint | HEAD:/inputref/id/{value} inputref_exists
6+
| Endpoint | GET:/inputref/id/{value}/parent_pk inputref_parent_pk
7+
| Endpoint | GET:/inputref/id?from=&until= inputref_range
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| Endpoint | GET:/transaction/id/{value} transaction_get
2+
| Endpoint | GET:/transaction?take= transaction_take
3+
| Endpoint | GET:/transaction?first= transaction_first
4+
| Endpoint | GET:/transaction?last= transaction_last
5+
| Endpoint | HEAD:/transaction/id/{value} transaction_exists
6+
| Endpoint | GET:/transaction/id/{value}/parent_pk transaction_parent_pk
7+
| Endpoint | GET:/transaction/id?from=&until= transaction_range
8+
| Endpoint | GET:/transaction/hash/{value} transaction_get_by_hash
9+
| Endpoint | GET:/transaction/{value}/utxos transaction_get_utxos
10+
| Endpoint | GET:/transaction/{value}/inputs transaction_get_inputs

0 commit comments

Comments
 (0)