Skip to content

Commit

Permalink
query_registration_detail method (#162)
Browse files Browse the repository at this point in the history
This PR implements the method taken from Go SDK repo:
``` go
        func (r *ChainReader) QueryRegistrationDetail(
        opts *bind.CallOpts,
        operatorAddress common.Address,
        ) ([]bool, error) {
            operatorId, err := r.GetOperatorId(opts, operatorAddress)
            if err != nil {
                return nil, err
            }
            value, err := r.registryCoordinator.GetCurrentQuorumBitmap(opts, operatorId)
            if err != nil {
                return nil, err
            }
            numBits := value.BitLen()
            var quorums []bool
            for i := 0; i < numBits; i++ {
                quorums = append(quorums, value.Int64()&(1<<i) != 0)
            }
            return quorums, nil
        }
```

---------

Co-authored-by: supernovahs <[email protected]>
  • Loading branch information
pablodeymo and supernovahs authored Dec 17, 2024
1 parent 535670c commit 070d76d
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions crates/chainio/clients/avsregistry/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,43 @@ impl AvsRegistryChainReader {
Ok(quorum_stakes)
}

/// Query registration detail
///
/// # Arguments
///
/// * `operator_address` - The operator address.
///
/// # Returns
///
/// A vector of booleans, where each boolean represents if the operator
/// is registered for a quorum.
///
/// # Errors
///
/// Returns an error if the operator id cannot be fetched or if the quorum bitmap
pub async fn query_registration_detail(
&self,
operator_address: Address,
) -> Result<[bool; 64], AvsRegistryError> {
let operator_id = self.get_operator_id(operator_address).await?;

let provider = get_provider(&self.provider);
let registry_coordinator =
RegistryCoordinator::new(self.registry_coordinator_addr, &provider);
let quorum_bitmap = registry_coordinator
.getCurrentQuorumBitmap(operator_id)
.call()
.await?;

let inner_value = quorum_bitmap._0.into_limbs()[0];
let mut quorums: [bool; 64] = [false; 64];
for i in 0..64_u64 {
let other = inner_value & (1 << i) != 0;
quorums[i as usize] = other;
}
Ok(quorums)
}

/// Get operator id
///
/// # Arguments
Expand Down Expand Up @@ -727,4 +764,40 @@ mod tests {
.await
.unwrap();
}

#[tokio::test]
async fn test_query_registration_detail() {
let avs_reader = build_avs_registry_chain_reader().await;

let operator_id = U256::from_str(
"35344093966194310405039483339636912150346494903629410125452342281826147822033",
)
.unwrap();

let operator_id_b256: B256 = operator_id.into();

let operator_address = avs_reader
.get_operator_from_id(operator_id_b256.into())
.await
.unwrap();

let ret_query_registration_detail = avs_reader
.query_registration_detail(operator_address)
.await
.unwrap();

println!("{:?}", ret_query_registration_detail);

// all the value are false
for ret_value in ret_query_registration_detail.iter() {
assert!(!ret_value);
}

// register an operator
let is_registered = avs_reader
.is_operator_registered(operator_address)
.await
.unwrap();
assert!(!is_registered);
}
}

0 comments on commit 070d76d

Please sign in to comment.