Skip to content

Commit

Permalink
51: use address for resolveDid parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Feb 15, 2024
1 parent 05b7e66 commit c7f7452
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 29 deletions.
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.

33 changes: 13 additions & 20 deletions lib/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,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);

Check warning on line 55 in lib/src/resolver.rs

View check run for this annotation

Codecov / codecov/patch

lib/src/resolver.rs#L55

Added line #L55 was not covered by tests

let mut history = Vec::new();

Expand All @@ -73,7 +66,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 @@ -93,7 +86,7 @@ impl<M: Middleware + 'static> Resolver<M> {
fn dispatch_event(
&self,
doc: &mut EthrBuilder,
public_key: H160,
address: H160,
event: DIDRegistryEvents,
meta: LogMeta,
) {
Expand All @@ -120,19 +113,19 @@ 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,
);
};
}

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 @@ -157,7 +150,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);
// 2. set latest version
if current_version_id < block_number {
current_version_id = block_number;
Expand All @@ -169,7 +162,7 @@ impl<M: Middleware + 'static> Resolver<M> {
}
} else {
// 1. delegate events
Resolver::dispatch_event(self, &mut base_document, public_key, event, meta);
Resolver::dispatch_event(self, &mut base_document, address, event, meta);
// 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>;
}
4 changes: 2 additions & 2 deletions lib/src/rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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");
Expand All @@ -40,7 +40,7 @@ impl<M: Middleware + 'static> DidRegistryServer for DidRegistryMethods<M> {
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
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 c7f7452

Please sign in to comment.