Skip to content

Commit

Permalink
feat: implement batch_get_name_price() fn (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
realnimish authored Jul 24, 2024
1 parent 9b199a3 commit 5164793
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/azns_registry/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,17 @@ mod azns_registry {
Ok((base_price, premium, discount, referrer_addr))
}

#[ink(message)]
pub fn batch_get_name_price(
&self,
input: Vec<(String, AccountId, u8, Option<String>)>,
) -> Vec<Result<(Balance, Balance, Balance, Option<AccountId>)>> {
input
.into_iter()
.map(|item| self.get_name_price(item.0, item.1, item.2, item.3))
.collect()
}

#[ink(message)]
pub fn validate_referrer(&self, recipient: AccountId, referrer_name: String) -> bool {
self.get_address_dict_ref(&referrer_name)
Expand Down Expand Up @@ -2796,6 +2807,20 @@ mod tests {
);
}

#[ink::test]
fn batch_get_name_price_works() {
let contract = get_test_name_service();
let inp = vec![
("alice".to_string(), default_accounts().alice, 1, None),
("bob".to_string(), default_accounts().bob, 2, None),
];

assert_eq!(
contract.batch_get_name_price(inp),
vec![Ok((1000, 0, 0, None)), Ok((1000, 0, 0, None))]
)
}

#[ink::test]
fn referral_system_works() {
let default_accounts = default_accounts();
Expand Down

0 comments on commit 5164793

Please sign in to comment.