-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.cairo
More file actions
166 lines (145 loc) · 4.21 KB
/
Copy pathlib.cairo
File metadata and controls
166 lines (145 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use core::starknet::ContractAddress;
#[starknet::interface]
pub trait IBookstore<TContractState> {
fn add_books(
ref self: TContractState,
book_id: felt252,
title: felt252,
name_of_author: felt252,
publisher: felt252,
publication_date: felt252,
isbn: u64,
edition: u64,
genre: felt252,
quantity: u32
);
fn remove_books(ref self: TContractState, book_id: felt252);
fn borrow_books(ref self: TContractState, book_id: felt252);
fn order_books(ref self: TContractState, book_id: felt252, order_details: felt252);
fn get_total_number_of_books(self: @TContractState) -> u128;
fn get_orders(self: @TContractState, order_details: felt252) -> u256;
fn get_book(self: @TContractState, book_details: felt252) -> u256;
}
#[starknet::contract]
mod Bookstore {
use starknet::get_caller_address;
use core::starknet::Storage::{Map, StorageMapReadAccess, StorageMapWriteAccess};
}
#[storage]
struct Storage {
bookstore: Map::<felt252, Book>, //which u64...meant to be the book_id
book_count: felt252,
bookstore_owner: ContractAddress,
total_number_of_books: felt252,
order_details: felt252,
book_details: felt252,
}
#[constructor]
fn constructor(ref self: ContractState, bookstore_owner: ContractAddress) {
self.bookstore_owner.write(bookstore_owner);
}
#[derive(Drop, Serde, starknet::Store)]
struct Book {
book_id: felt252,
title: felt252,
name_of_author: felt252,
publisher: felt252,
publication_date: felt252,
isbn: u64,
edition: u64,
genre: felt252,
quantity: u32,
}
#[event]
#[derive(Drop, starknet::Event)]
enum event {
TransactionDetails: TransactionDetails,
OrderConfirmation: OrderConfirmation,
DeliveryUpdates: DeliveryUpdates,
BookBorrowed: BookBorrowed,
}
#[derive(Drop, starknet::Event)]
struct TransactionDetails {
#[key]
transaction_id: felt252,
amount: u256,
timestamp: u64,
}
#[derive(Drop, starknet::Event)]
struct OrderConfirmation {
#[key]
order_id: felt252,
customer: ContractAddress,
total_amount: u256,
}
#[derive(Drop, starknet::Event)]
struct DeliveryUpdates {
#[key]
tracking_number: felt252,
status: felt252,
estimated_delivery: u64,
}
#[derive(Drop, starknet::Event)]
struct BookBorrowed {
#[key]
book_id: felt252,
borrower: ContractAddress,
due_date: u64,
}
#[abi(embed_V0)]
impl BookstoreImpl of super::IBookstore<ContractState> {
fn add_books(
ref self: TContractState,
book_id: felt252,
title: felt252,
name_of_author: felt252,
publisher: felt252,
publication_date: felt252,
isbn: u64,
edition: u64,
genre: felt252,
quantity: u32
) {
let new_book = Book {
book_id,
title,
name_of_author,
publisher,
publication_date,
isbn,
edition,
genre,
quantity
};
self.bookstore.write(book_id, new_book);
}
fn remove_books(ref self: TContractState, book_id: felt252) {
let mut bookstore = self.bookstore.read();
bookstore.remove(book_id);
self.bookstore.write(books);
}
fn borrow_books(ref self: TContractState, book_id: felt252) {
let mut bookstore = self.bookstore.read();
bookstore.borrow(book_id);
self.bookstore.write(books);
self.emit(BookBorrowed { book_id: book_id, borrower: starknet::get_caller_address(), });
}
fn order_books(ref self: TContractState, book_id: felt252, order_details: felt252) {
assert(book_exists(book_id), 'Book does not exist');
process_order(book_id, order_details);
// self.emit
}
fn get_total_number_of_books(self: @TContractState, total_number_of_books: felt252) -> felt252 {
let total_books = self.total_number_of_books.read();
total
books
}
fn get_orders(self: @TContractState, order_details: felt252) -> felt252 {
let orders = self.order_details.read();
orders
}
fn get_book(self: @TContractState, book_details: felt252) -> felt252 {
let book = self.book_details.read();
book
}
}