diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 89d8ef3..26dfcb2 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -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 diff --git a/.github/workflows/ghcr-image.yml b/.github/workflows/ghcr-image.yml index d95cc2d..2f4ba8c 100644 --- a/.github/workflows/ghcr-image.yml +++ b/.github/workflows/ghcr-image.yml @@ -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: . @@ -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 }} diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index c245849..2e8eb49 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -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: | diff --git a/.github/workflows/prod-ci-image.yml b/.github/workflows/prod-ci-image.yml index e838484..d3b2d4a 100644 --- a/.github/workflows/prod-ci-image.yml +++ b/.github/workflows/prod-ci-image.yml @@ -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: | diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..90537fe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "rust-analyzer.cargo.buildScripts.overrideCommand": null, + "rust-analyzer.cargo.features": "all" +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 32d3bdc..5897625 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 \ No newline at end of file +* url parser diff --git a/Cargo.lock b/Cargo.lock index 8613d23..2eef657 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3537,7 +3537,7 @@ dependencies = [ [[package]] name = "resolver" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "async-trait", diff --git a/Dockerfile b/Dockerfile index f84123f..5030976 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/lib/src/resolver.rs b/lib/src/resolver.rs index 44cec3c..aff92cf 100644 --- a/lib/src/resolver.rs +++ b/lib/src/resolver.rs @@ -65,27 +65,20 @@ impl Resolver { /// Resolve a did:ethr identifier pub async fn resolve_did( &self, - public_key: H160, + address: H160, version_id: Option, ) -> Result> { - 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, ResolverError> { - 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(); @@ -99,7 +92,7 @@ impl Resolver { .events() .from_block(previous_change) .to_block(previous_change) - .topic1(H256::from(public_key)) + .topic1(H256::from(address)) .query_with_meta() .await?; @@ -119,7 +112,7 @@ impl Resolver { async fn dispatch_event( &self, doc: &mut EthrBuilder, - public_key: H160, + address: H160, event: DIDRegistryEvents, meta: LogMeta, ) -> Result<(), ResolverError> { @@ -147,7 +140,7 @@ impl Resolver { 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(()) @@ -155,12 +148,12 @@ impl Resolver { async fn wrap_did_resolution( &self, - public_key: H160, + address: H160, version_id: Option, history: Vec<(DIDRegistryEvents, LogMeta)>, ) -> Result> { let mut base_document = DidDocument::ethr_builder(); - base_document.account_address(&public_key)?; + base_document.account_address(&address)?; let current_block = self .signer() @@ -185,7 +178,7 @@ impl Resolver { 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 { @@ -198,7 +191,7 @@ impl Resolver { } } 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; diff --git a/lib/src/rpc/api.rs b/lib/src/rpc/api.rs index abc27ab..18578fa 100644 --- a/lib/src/rpc/api.rs +++ b/lib/src/rpc/api.rs @@ -11,7 +11,7 @@ pub trait DidRegistry { #[method(name = "resolveDid")] async fn resolve_did( &self, - public_key: String, + address: String, version_id: Option, ) -> Result; } @@ -23,7 +23,7 @@ pub trait DidRegistry { #[method(name = "resolveDid")] async fn resolve_did( &self, - public_key: String, + address: String, version_id: Option, ) -> Result; } diff --git a/lib/src/rpc/methods.rs b/lib/src/rpc/methods.rs index af626d2..ea2a727 100644 --- a/lib/src/rpc/methods.rs +++ b/lib/src/rpc/methods.rs @@ -29,12 +29,12 @@ impl DidRegistryMethods { impl DidRegistryServer for DidRegistryMethods { async fn resolve_did( &self, - public_key: String, + address: String, version_id: Option, ) -> Result { 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())); @@ -42,7 +42,7 @@ impl DidRegistryServer for DidRegistryMethods { 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; diff --git a/resolver/Cargo.toml b/resolver/Cargo.toml index b2e3338..2269e74 100644 --- a/resolver/Cargo.toml +++ b/resolver/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "resolver" -version = "0.1.0" +version = "0.1.1" authors = ["XMTP Labs "] description = "Standalone did:ethr Resolution JSON-RPC Gateway" homepage = "https://github.com/xmtp/didethresolver" diff --git a/resolver/src/main.rs b/resolver/src/main.rs index b269de5..c316f04 100644 --- a/resolver/src/main.rs +++ b/resolver/src/main.rs @@ -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..." //! } //! ``` //! @@ -61,7 +61,7 @@ //! Example Error Response: //! ```json //! { -//! "error": "Invalid public key format" +//! "error": "Invalid address format" //! } //! ``` //!