Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Impl PartialOrd for ContractAddress Type #3464

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions corelib/src/starknet/contract_address.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use zeroable::Zeroable;
use serde::Serde;
use traits::Into;

#[derive(Copy, Drop)]
extern type ContractAddress;
Expand Down Expand Up @@ -60,3 +61,33 @@ impl ContractAddressPartialEq of PartialEq<ContractAddress> {
!(lhs == rhs)
}
}

impl ContractAddressPartialOrd of PartialOrd<ContractAddress> {
#[inline(always)]
fn le(lhs: ContractAddress, rhs: ContractAddress) -> bool {
let lhs_u256: u256 = contract_address_to_felt252(lhs).into();
let rhs_u256: u256 = contract_address_to_felt252(rhs).into();
lhs_u256 <= rhs_u256
}

#[inline(always)]
fn ge(lhs: ContractAddress, rhs: ContractAddress) -> bool {
let lhs_u256: u256 = contract_address_to_felt252(lhs).into();
let rhs_u256: u256 = contract_address_to_felt252(rhs).into();
lhs_u256 >= rhs_u256
}

#[inline(always)]
fn lt(lhs: ContractAddress, rhs: ContractAddress) -> bool {
let lhs_u256: u256 = contract_address_to_felt252(lhs).into();
let rhs_u256: u256 = contract_address_to_felt252(rhs).into();
lhs_u256 < rhs_u256
}

#[inline(always)]
fn gt(lhs: ContractAddress, rhs: ContractAddress) -> bool {
let lhs_u256: u256 = contract_address_to_felt252(lhs).into();
let rhs_u256: u256 = contract_address_to_felt252(rhs).into();
lhs_u256 > rhs_u256
}
}