Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
e9a8f81a
Commit
e9a8f81a
authored
Oct 27, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add C header
rustdoc
parent
51da1fcf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
1 deletion
+66
-1
README.md
op-service/rethdb-reader/README.md
+36
-1
lib.rs
op-service/rethdb-reader/src/lib.rs
+14
-0
reth_db_test.go
op-service/sources/reth_db_test.go
+16
-0
No files found.
op-service/rethdb-reader/README.md
View file @
e9a8f81a
# `rethdb-reader`
# `rethdb-reader`
Exported Rust code to be u
sed via FFI in
`op-service`
's
`sources`
package for reading information
A dylib to be acces
sed via FFI in
`op-service`
's
`sources`
package for reading information
directly from the
`reth`
database.
directly from the
`reth`
database.
### C Header
```
c
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>
struct
ReceiptsResult
{
uint32_t
*
data
;
uintptr_t
data_len
;
bool
error
;
};
extern
"C"
{
/// Read the receipts for a blockhash from the RETH database directly.
///
/// # Safety
/// - All possible nil pointer dereferences are checked, and the function will return a
/// failing [ReceiptsResult] if any are found.
ReceiptsResult
read_receipts
(
const
uint8_t
*
block_hash
,
uintptr_t
block_hash_len
,
const
char
*
db_path
);
/// Free a string that was allocated in Rust and passed to C.
///
/// # Safety
/// - All possible nil pointer dereferences are checked.
void
free_string
(
char
*
string
);
}
```
op-service/rethdb-reader/src/lib.rs
View file @
e9a8f81a
#![doc
=
include_str
!
(
"../README.md"
)]
use
reth
::{
use
reth
::{
blockchain_tree
::
noop
::
NoopBlockchainTree
,
blockchain_tree
::
noop
::
NoopBlockchainTree
,
primitives
::{
primitives
::{
...
@@ -10,6 +12,12 @@ use reth::{
...
@@ -10,6 +12,12 @@ use reth::{
};
};
use
std
::{
os
::
raw
::
c_char
,
path
::
Path
};
use
std
::{
os
::
raw
::
c_char
,
path
::
Path
};
/// A [ReceiptsResult] is a wrapper around a JSON string containing serialized [TransactionReceipt]s
/// as well as an error status that is compatible with FFI.
///
/// # Safety
/// - When the `error` field is false, the `data` pointer is guaranteed to be valid.
/// - When the `error` field is true, the `data` pointer is guaranteed to be null.
#[repr(C)]
#[repr(C)]
pub
struct
ReceiptsResult
{
pub
struct
ReceiptsResult
{
data
:
*
mut
char
,
data
:
*
mut
char
,
...
@@ -18,6 +26,7 @@ pub struct ReceiptsResult {
...
@@ -18,6 +26,7 @@ pub struct ReceiptsResult {
}
}
impl
ReceiptsResult
{
impl
ReceiptsResult
{
/// Constructs a successful [ReceiptsResult] from a JSON string.
pub
fn
success
(
data
:
*
mut
char
,
data_len
:
usize
)
->
Self
{
pub
fn
success
(
data
:
*
mut
char
,
data_len
:
usize
)
->
Self
{
Self
{
Self
{
data
,
data
,
...
@@ -26,6 +35,7 @@ impl ReceiptsResult {
...
@@ -26,6 +35,7 @@ impl ReceiptsResult {
}
}
}
}
/// Constructs a failing [ReceiptsResult] with a null pointer to the data.
pub
fn
fail
()
->
Self
{
pub
fn
fail
()
->
Self
{
Self
{
Self
{
data
:
std
::
ptr
::
null_mut
(),
data
:
std
::
ptr
::
null_mut
(),
...
@@ -143,6 +153,10 @@ pub unsafe extern "C" fn free_string(string: *mut c_char) {
...
@@ -143,6 +153,10 @@ pub unsafe extern "C" fn free_string(string: *mut c_char) {
}
}
}
}
/// Builds a hydrated [TransactionReceipt] from information in the passed transaction,
/// receipt, and block receipts.
///
/// Returns [None] if the transaction's sender could not be recovered from the signature.
#[inline(always)]
#[inline(always)]
fn
build_transaction_receipt_with_block_receipts
(
fn
build_transaction_receipt_with_block_receipts
(
tx
:
TransactionSigned
,
tx
:
TransactionSigned
,
...
...
op-service/sources/reth_db_test.go
0 → 100644
View file @
e9a8f81a
package
sources
import
(
"testing"
"github.com/ethereum/go-ethereum/common"
)
func
TestRethDBRead
(
t
*
testing
.
T
)
{
t
.
Parallel
()
_
,
err
:=
FetchRethReceipts
(
"/test"
,
&
common
.
Hash
{})
if
err
!=
nil
{
panic
(
"test"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment