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

update workflow #229

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
- name: Run Scarb commands
working-directory: ./land_registry
run: |
scarb fmt --check
scarb build

test:
Expand All @@ -46,7 +45,7 @@ jobs:
- name: Set up SNForge
uses: foundry-rs/setup-snfoundry@v3
with:
starknet-foundry-version: "0.33.0"
starknet-foundry-version: "0.31.0"

- name: Run tests
run: snforge test
Expand Down
8 changes: 4 additions & 4 deletions land_registry/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba

[[package]]
name = "snforge_scarb_plugin"
version = "0.33.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.33.0#221b1dbff42d650e9855afd4283508da8f8cacba"
version = "0.31.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.31.0#72ea785ca354e9e506de3e5d687da9fb2c1b3c67"

[[package]]
name = "snforge_std"
version = "0.33.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.33.0#221b1dbff42d650e9855afd4283508da8f8cacba"
version = "0.31.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.31.0#72ea785ca354e9e506de3e5d687da9fb2c1b3c67"
dependencies = [
"snforge_scarb_plugin",
]
5 changes: 3 additions & 2 deletions land_registry/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "land_registry"
version = "0.1.0"
cairo-version = "2.8.2"
edition = "2023_11"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

Expand All @@ -12,11 +13,11 @@ openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", ta

[dev-dependencies]
assert_macros = "2.8.2"
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.33.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.31.0" }

[[target.starknet-contract]]
casm = true
sierra = true

[scripts]
test = "snforge test"
test = "snforge test"
73 changes: 37 additions & 36 deletions land_registry/src/custom_error.cairo
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
/////////////////
//CUSTOM ERRORS
/////////////////
mod Errors {
const MINT_NFT: felt252 = 'Only land registry can mint';
const TRANSFER_NFT: felt252 = 'Only land registry can transfer';
const UPDATE_BY_LAND: felt252 = 'Only owner can update land';
const ONLY_OWNER_TRNF: felt252 = 'Only owner can transfer';
const LAND_APPROVAL: felt252 = 'Land must be approved';
const NO_LAND: felt252 = 'Land not found';
const INSPECTOR_APPROVE: felt252 = 'Only inspector can approve';
const INSPECTOR_REJECT: felt252 = 'Only inspector can reject';
const PENDING_LAND: felt252 = 'Land must be in Pending status';
const INSPECTOR_OWNER_APPR: felt252 = 'Only inspector/owner can reject';
const OWNER_MK_INSPECTOR: felt252 = 'Only owner can set an inspector';
const INSPECTOR_ADDR: felt252 = 'Invalid inspector address';
const REGISTERED_INSPECTOR: felt252 = 'Inspector already registered';
const NOT_REGISTERED_INSP: felt252 = 'Inspector not registered';
const ACTIVE_INSPECTOR: felt252 = 'Inspector is active';
const NOT_AUTHORIZED: felt252 = 'Not authorized';
const ADDRESS_ZERO: felt252 = 'ADDRESS_ZERO';
const LAND_NOT_LISTED: felt252 = 'Land not listed';
const INVALID_PRICE: felt252 = 'Invalid price';
const ONLY_OWNER_LIST: felt252 = 'Only owner can list';
const LAND_NOT_APPROVED: felt252 = 'Land not approved';
const CANNOT_BUY_OWN_LAND: felt252 = 'Cannot buy own land';
const AREA_NOT_ZERO: felt252 = 'Area must be greater than 0';
const INVALID_ADDRESS: felt252 = 'Invalid address';
const LOCKED: felt252 = 'Locked';
const NOT_LOCKED: felt252 = 'Not locked';
const SET_URI_ONLY_LAND_REGISTRY: felt252 = 'Only land registry can update';
const LOCK_NFT_ONLY_LAND_REGISTRY: felt252 = 'Only land registry can lock';
const UNLOCK_NFT_ONLY_LAND_REGISTRY: felt252 = 'Only land registry can unlock';
pub mod Errors {
pub const MINT_NFT: felt252 = 'Only land registry can mint';
pub const TRANSFER_NFT: felt252 = 'Only land registry can transfer';
pub const UPDATE_BY_LAND: felt252 = 'Only owner can update land';
pub const ONLY_OWNER_TRNF: felt252 = 'Only owner can transfer';
pub const LAND_APPROVAL: felt252 = 'Land must be approved';

pub const NO_LAND: felt252 = 'Land not found';
pub const INSPECTOR_APPROVE: felt252 = 'Only inspector can approve';
pub const INSPECTOR_REJECT: felt252 = 'Only inspector can reject';
pub const PENDING_LAND: felt252 = 'Land must be in Pending status';
pub const INSPECTOR_OWNER_APPR: felt252 = 'Only inspector/owner can reject';
pub const OWNER_MK_INSPECTOR: felt252 = 'Only owner can set an inspector';
pub const INSPECTOR_ADDR: felt252 = 'Invalid inspector address';
pub const REGISTERED_INSPECTOR: felt252 = 'Inspector already registered';
pub const NOT_REGISTERED_INSP: felt252 = 'Inspector not registered';
pub const ACTIVE_INSPECTOR: felt252 = 'Inspector is active';
pub const NOT_AUTHORIZED: felt252 = 'Not authorized';
pub const ADDRESS_ZERO: felt252 = 'ADDRESS_ZERO';
pub const LAND_NOT_LISTED: felt252 = 'Land not listed';
pub const INVALID_PRICE: felt252 = 'Invalid price';
pub const ONLY_OWNER_LIST: felt252 = 'Only owner can list';
pub const LAND_NOT_APPROVED: felt252 = 'Land not approved';
pub const CANNOT_BUY_OWN_LAND: felt252 = 'Cannot buy own land';
pub const AREA_NOT_ZERO: felt252 = 'Area must be greater than 0';
pub const INVALID_ADDRESS: felt252 = 'Invalid address';
pub const LOCKED: felt252 = 'Locked';
pub const NOT_LOCKED: felt252 = 'Not locked';
pub const SET_URI_ONLY_LAND_REGISTRY: felt252 = 'Only land registry can update';
pub const LOCK_NFT_ONLY_LAND_REGISTRY: felt252 = 'Only land registry can lock';
pub const UNLOCK_NFT_ONLY_LAND_REGISTRY: felt252 = 'Only land registry can unlock';

// Listing only
const ONLY_OWNER_CAN_LIST: felt252 = 'Only owner can list land';
const ONLY_SELLER_CAN_CANCEL_LIST: felt252 = 'Only seller can cancel';
const ONLY_SELLER_CAN_UPDATE_LIST: felt252 = 'Only seller can update';
const SELLER_CANT_BUY_OWN: felt252 = 'Cannot buy own listing';
const LISTING_NOT_ACTIVE: felt252 = 'Listing not active';
const INSUFFICIENT_PAYMENT_TO_BUY_LAND: felt252 = 'Insufficient payment';
pub const ONLY_OWNER_CAN_LIST: felt252 = 'Only owner can list land';
pub const ONLY_SELLER_CAN_CANCEL_LIST: felt252 = 'Only seller can cancel';
pub const ONLY_SELLER_CAN_UPDATE_LIST: felt252 = 'Only seller can update';
pub const SELLER_CANT_BUY_OWN: felt252 = 'Cannot buy own listing';
pub const LISTING_NOT_ACTIVE: felt252 = 'Listing not active';
pub const INSUFFICIENT_PAYMENT_TO_BUY_LAND: felt252 = 'Insufficient payment';
}
10 changes: 5 additions & 5 deletions land_registry/src/interface/land_nft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ pub trait ILandNFT<TContractState> {

// Events
#[derive(Drop, starknet::Event)]
struct BaseURIUpdated {
caller: ContractAddress,
new_base_uri: ByteArray
pub struct BaseURIUpdated {
pub caller: ContractAddress,
pub new_base_uri: ByteArray
}

#[derive(Drop, starknet::Event)]
pub struct Locked {
token_id: u256
pub token_id: u256
}

#[derive(Drop, starknet::Event)]
pub struct Unlocked {
token_id: u256
pub token_id: u256
}
92 changes: 46 additions & 46 deletions land_registry/src/interface/land_register.cairo
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use starknet::ContractAddress;
use land_registry::utils::utils::{create_land_id};
// use land_registry::utils::utils::{create_land_id};

// Core data structures and interfaces for the Land Registry system

// Represents a land parcel with its properties and metadata
#[derive(Drop, Copy, Serde, starknet::Store)]
pub struct Land {
land_id: u256, // Land id
owner: ContractAddress, // Address of the current land owner
location: Location, // Geographic coordinates of the land
area: u256, // Size of the land parcel
land_use: LandUse, // Designated purpose/usage of the land
status: LandStatus, // Current verification status
last_transaction_timestamp: u64, // Timestamp of the most recent transaction
inspector: ContractAddress, // Address of assigned inspector
pub land_id: u256, // Land id
pub owner: ContractAddress, // Address of the current land owner
pub location: Location, // Geographic coordinates of the land
pub area: u256, // Size of the land parcel
pub land_use: LandUse, // Designated purpose/usage of the land
pub status: LandStatus, // Current verification status
pub last_transaction_timestamp: u64, // Timestamp of the most recent transaction
pub inspector: ContractAddress, // Address of assigned inspector
}

// Represents the verification status of a land parcel
Expand All @@ -27,8 +27,8 @@ pub enum LandStatus {
// Geographic coordinates of a land parcel
#[derive(Drop, Copy, Serde, starknet::Store, PartialEq)]
pub struct Location {
latitude: felt252, // Latitude coordinate
longitude: felt252, // Longitude coordinate
pub latitude: felt252, // Latitude coordinate
pub longitude: felt252, // Longitude coordinate
}

// Classification of land usage types
Expand All @@ -47,12 +47,12 @@ pub enum LandUse {
// Represents a land listing in the marketplace
#[derive(Drop, Copy, Serde, starknet::Store)]
pub struct Listing {
land_id: u256,
seller: ContractAddress,
price: u256,
status: ListingStatus,
created_at: u64,
updated_at: u64
pub land_id: u256,
pub seller: ContractAddress,
pub price: u256,
pub status: ListingStatus,
pub created_at: u64,
pub updated_at: u64
}

#[derive(Drop, Debug, Copy, Serde, Clone, starknet::Store, PartialEq)]
Expand Down Expand Up @@ -110,74 +110,74 @@ pub trait ILandRegistry<TContractState> {
// Events
#[derive(Drop, starknet::Event)]
pub struct LandRegistered {
land_id: u256,
owner: ContractAddress,
location: Location,
area: u256,
land_use: Option<felt252>,
pub land_id: u256,
pub owner: ContractAddress,
pub location: Location,
pub area: u256,
pub land_use: Option<felt252>,
}

#[derive(Drop, starknet::Event)]
pub struct LandTransferred {
land_id: u256,
from_owner: ContractAddress,
to_owner: ContractAddress,
pub land_id: u256,
pub from_owner: ContractAddress,
pub to_owner: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct LandVerified {
land_id: u256,
pub land_id: u256,
}

#[derive(Drop, Copy, starknet::Event)]
pub struct LandUpdated {
land_id: u256,
land_use: Option<felt252>,
area: u256
pub land_id: u256,
pub land_use: Option<felt252>,
pub area: u256
}


#[derive(Drop, Copy, starknet::Event)]
pub struct LandInspectorSet {
land_id: u256,
inspector: ContractAddress,
pub land_id: u256,
pub inspector: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct InspectorAdded {
inspector: ContractAddress,
pub inspector: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct InspectorRemoved {
inspector: ContractAddress,
pub inspector: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct ListingCreated {
listing_id: u256,
land_id: u256,
seller: ContractAddress,
price: u256
pub listing_id: u256,
pub land_id: u256,
pub seller: ContractAddress,
pub price: u256
}

#[derive(Drop, starknet::Event)]
pub struct ListingCancelled {
listing_id: u256
pub listing_id: u256
}

#[derive(Drop, starknet::Event)]
pub struct ListingPriceUpdated {
listing_id: u256,
old_price: u256,
new_price: u256
pub listing_id: u256,
pub old_price: u256,
pub new_price: u256
}

#[derive(Drop, starknet::Event)]
pub struct LandSold {
listing_id: u256,
land_id: u256,
seller: ContractAddress,
buyer: ContractAddress,
price: u256
pub listing_id: u256,
pub land_id: u256,
pub seller: ContractAddress,
pub buyer: ContractAddress,
pub price: u256
}
12 changes: 6 additions & 6 deletions land_registry/src/land_nft.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Implementation of NFT functionality for land parcels using ERC721 standard

use starknet::ContractAddress;
use openzeppelin::token::erc721::ERC721Component;
use openzeppelin::introspection::src5::SRC5Component;
use land_registry::custom_error::Errors;
// use starknet::ContractAddress;
// use openzeppelin::token::erc721::ERC721Component;
// use openzeppelin::introspection::src5::SRC5Component;
// use land_registry::custom_error::Errors;

use land_registry::interface::land_nft::{ILandNFT};

Expand All @@ -20,7 +20,7 @@ pub mod LandNFT {
use openzeppelin::token::erc721::ERC721HooksEmptyImpl;
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::upgrades::UpgradeableComponent;
use openzeppelin::upgrades::interface::IUpgradeable;
// use openzeppelin::upgrades::interface::IUpgradeable;
use land_registry::custom_error;
use land_registry::interface::land_nft::{BaseURIUpdated, Locked, Unlocked};

Expand Down Expand Up @@ -60,7 +60,7 @@ pub mod LandNFT {

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
pub enum Event {
#[flat]
ERC721Event: ERC721Component::Event,
#[flat]
Expand Down
9 changes: 5 additions & 4 deletions land_registry/src/land_register.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pub mod LandRegistryContract {
use OwnableComponent::InternalTrait;
use starknet::SyscallResultTrait;
use starknet::{
get_caller_address, get_contract_address, get_block_timestamp, ContractAddress, syscalls
get_caller_address, get_contract_address, get_block_timestamp, ContractAddress, syscalls,
get_tx_info
};
use land_registry::interface::land_register::{
ILandRegistry, Land, LandUse, Location, LandStatus, Listing, ListingStatus
Expand All @@ -13,7 +14,7 @@ pub mod LandRegistryContract {
InspectorAdded, InspectorRemoved, ListingCreated, ListingCancelled, ListingPriceUpdated,
LandSold
};
use land_registry::land_nft::{LandNFT};
// use land_registry::land_nft::{LandNFT};
use land_registry::interface::land_nft::{ILandNFTDispatcher, ILandNFTDispatcherTrait};
use land_registry::utils::utils::{create_land_id, LandUseIntoOptionFelt252};
use core::array::ArrayTrait;
Expand All @@ -22,7 +23,7 @@ pub mod LandRegistryContract {

use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::upgrades::UpgradeableComponent;
use openzeppelin::upgrades::interface::IUpgradeable;
// use openzeppelin::upgrades::interface::IUpgradeable;

// open zeppellin commponents
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
Expand Down Expand Up @@ -528,7 +529,7 @@ pub mod LandRegistryContract {
assert(buyer != listing.seller, Errors::SELLER_CANT_BUY_OWN);

// Verify payment
let payment = starknet::info::get_tx_info().unbox().max_fee.into();
let payment = get_tx_info().unbox().max_fee.into();
assert(payment >= listing.price, Errors::INSUFFICIENT_PAYMENT_TO_BUY_LAND);

// Get land details
Expand Down
2 changes: 1 addition & 1 deletion land_registry/src/utils.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod utils {
use starknet::{get_caller_address, get_block_timestamp, ContractAddress};
use starknet::ContractAddress;
use core::poseidon::PoseidonTrait;
use core::hash::{HashStateTrait, HashStateExTrait};
use land_registry::interface::land_register::{Location, LandUse};
Expand Down
Loading
Loading