Skip to content

Commit

Permalink
Merge branch 'main' of github.com:xmtp/didethresolver into insipx/xps…
Browse files Browse the repository at this point in the history
…-timestamp
  • Loading branch information
insipx committed Feb 15, 2024
2 parents e821cda + c7f7452 commit 5ffe023
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: true
22 changes: 6 additions & 16 deletions .github/workflows/ghcr-image.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
name: Docker Image Build Push

on:
push:
tags:
- "*"

concurrency:
group: "docker-image"
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Generate repository name
run: |
echo "REPOSITORY_PATH=$( echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]' )" >> ${GITHUB_ENV}
echo "REPOSITORY_SHA=$( echo ${GITHUB_SHA} | cut -c 1-8 )" >> ${GITHUB_ENV}
-
name: Login to GitHub Container Registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and Push
- name: Build and Push
uses: docker/build-push-action@v3
with:
context: .
Expand All @@ -49,8 +40,7 @@ jobs:
ghcr.io/${{ env.REPOSITORY_PATH }}:v${{ github.ref_name }}
ghcr.io/${{ env.REPOSITORY_PATH }}:${{ env.REPOSITORY_SHA }}
ghcr.io/${{ env.REPOSITORY_PATH }}:latest
-
name: GitHub Release
- name: GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
profile: minimal
override: true
- name: Run tests
run: |
cargo test --tests tests -p lib-didethresolver --all-features
env:
CARGO_INCREMENTAL: 0
run: |
cargo test --workspace --all-features --tests tests
id: test
- name: Invoke cargo doc
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prod-ci-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: docker/build-push-action@v3
with:
context: .
file: prod/Dockerfile
file: prod/Dockerfile
platforms: linux/amd64
push: false
build-args: |
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rust-analyzer.cargo.buildScripts.overrideCommand": null,
"rust-analyzer.cargo.features": "all"
}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# 0.1.1 (2024-02-09)

* parsing improvements

# 0.1.0 (2024-01-24)

* inital production support
* light refactor
* command line and environment variables
* url parser
* url parser
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ COPY --from=ghcr.io/xmtp/foundry:latest /usr/local/bin/anvil /usr/local/bin/anvi

COPY --chown=xmtp:xmtp . .

RUN yamlfmt -lint .github/workflows/*.yml

ENV CARGO_INCREMENTAL=${CARGO_INCREMENTAL:-1}
RUN cargo check --all-features
RUN cargo fmt --check --all
Expand Down
33 changes: 13 additions & 20 deletions lib/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,20 @@ impl<M: Middleware + 'static> Resolver<M> {
/// Resolve a did:ethr identifier
pub async fn resolve_did(
&self,
public_key: H160,
address: H160,
version_id: Option<U64>,
) -> Result<DidResolutionResult, ResolverError<M>> {
let history = self.changelog(public_key).await?;
self.wrap_did_resolution(public_key, version_id, history)
.await
let history = self.changelog(address).await?;
self.wrap_did_resolution(address, version_id, history).await
}

async fn changelog(
&self,
public_key: H160,
address: H160,
) -> Result<Vec<(DIDRegistryEvents, LogMeta)>, ResolverError<M>> {
let mut previous_change: U64 = self
.registry
.changed(public_key)
.call()
.await?
.as_u64()
.into();
let mut previous_change: U64 = self.registry.changed(address).call().await?.as_u64().into();

log::trace!("Previous Change for {}: {:?}", public_key, previous_change);
log::trace!("Previous Change for {}: {:?}", address, previous_change);

let mut history = Vec::new();

Expand All @@ -99,7 +92,7 @@ impl<M: Middleware + 'static> Resolver<M> {
.events()
.from_block(previous_change)
.to_block(previous_change)
.topic1(H256::from(public_key))
.topic1(H256::from(address))
.query_with_meta()
.await?;

Expand All @@ -119,7 +112,7 @@ impl<M: Middleware + 'static> Resolver<M> {
async fn dispatch_event(
&self,
doc: &mut EthrBuilder,
public_key: H160,
address: H160,
event: DIDRegistryEvents,
meta: LogMeta,
) -> Result<(), ResolverError<M>> {
Expand Down Expand Up @@ -147,20 +140,20 @@ impl<M: Middleware + 'static> Resolver<M> {
if let Err(e) = res {
log::error!(
"Error while resolving for {} at event block={}, log index={}, incorrect format?: {}",
public_key, meta.block_number, meta.log_index, e,
address, meta.block_number, meta.log_index, e,
);
};
Ok(())
}

async fn wrap_did_resolution(
&self,
public_key: H160,
address: H160,
version_id: Option<U64>,
history: Vec<(DIDRegistryEvents, LogMeta)>,
) -> Result<DidResolutionResult, ResolverError<M>> {
let mut base_document = DidDocument::ethr_builder();
base_document.account_address(&public_key)?;
base_document.account_address(&address)?;

let current_block = self
.signer()
Expand All @@ -185,7 +178,7 @@ impl<M: Middleware + 'static> Resolver<M> {
if version_id.unwrap_or_default() > U64::zero() {
if meta.block_number <= version_id.unwrap_or_default() {
// 1. delegate events
Resolver::dispatch_event(self, &mut base_document, public_key, event, meta)
Resolver::dispatch_event(self, &mut base_document, address, event, meta)
.await?;
// 2. set latest version
if current_version_id < block_number {
Expand All @@ -198,7 +191,7 @@ impl<M: Middleware + 'static> Resolver<M> {
}
} else {
// 1. delegate events
Resolver::dispatch_event(self, &mut base_document, public_key, event, meta).await?;
Resolver::dispatch_event(self, &mut base_document, address, event, meta).await?;
// 2. set latest version
if current_version_id < block_number {
current_version_id = block_number;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/rpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait DidRegistry {
#[method(name = "resolveDid")]
async fn resolve_did(
&self,
public_key: String,
address: String,
version_id: Option<String>,
) -> Result<DidResolutionResult, ErrorObjectOwned>;
}
Expand All @@ -23,7 +23,7 @@ pub trait DidRegistry {
#[method(name = "resolveDid")]
async fn resolve_did(
&self,
public_key: String,
address: String,
version_id: Option<String>,
) -> Result<DidResolutionResult, ErrorObjectOwned>;
}
6 changes: 3 additions & 3 deletions lib/src/rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ impl<M: Middleware> DidRegistryMethods<M> {
impl<M: Middleware + 'static> DidRegistryServer for DidRegistryMethods<M> {
async fn resolve_did(
&self,
public_key: String,
address: String,
version_id: Option<String>,
) -> Result<DidResolutionResult, ErrorObjectOwned> {
log::debug!("did_resolveDid called");

log::trace!("Resolving for key {}", public_key);
log::trace!("Resolving for key {}", &address);

// parse the version_id
let parsed_version_id = version_id.map(|str| U64::from(u64::from_str(&str).unwrap()));

let resolution_result = self
.resolver
.resolve_did(
H160::from_str(&public_key).map_err(RpcError::from)?,
H160::from_str(&address).map_err(RpcError::from)?,
parsed_version_id,
)
.await;
Expand Down
2 changes: 1 addition & 1 deletion resolver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "resolver"
version = "0.1.0"
version = "0.1.1"
authors = ["XMTP Labs <[email protected]>"]
description = "Standalone did:ethr Resolution JSON-RPC Gateway"
homepage = "https://github.com/xmtp/didethresolver"
Expand Down
8 changes: 4 additions & 4 deletions resolver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
//!
//! ### Request Format
//!
//! The request should be a JSON object containing one field: `publicKey`.
//! The request should be a JSON object containing one field: `address`.
//!
//! - `publicKey` (string, required): The Ethereum public key (starting with '0x').
//! - `address` (string, required): The Ethereum address (starting with '0x').
//!
//! Example Request:
//! ```json
//! {
//! "publicKey": "0x123abc..."
//! "address": "0x123abc..."
//! }
//! ```
//!
Expand Down Expand Up @@ -61,7 +61,7 @@
//! Example Error Response:
//! ```json
//! {
//! "error": "Invalid public key format"
//! "error": "Invalid address format"
//! }
//! ```
//!
Expand Down

0 comments on commit 5ffe023

Please sign in to comment.