Skip to content

Commit b0e3d82

Browse files
committed
modify to u64
1 parent d391b8d commit b0e3d82

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/events.cairo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ use starknet::ContractAddress;
44
pub struct AccountCreated {
55
pub name: ByteArray,
66
pub address: ContractAddress,
7-
pub balance: u128,
7+
pub balance: u64,
88
}
99

1010
#[derive(Clone, Drop, Debug, starknet::Event)]
1111
pub struct DepositMade {
12-
pub amount: u128,
12+
pub amount: u64,
1313
pub address: ContractAddress,
1414
}
1515

1616
#[derive(Clone, Drop, Debug, starknet::Event)]
1717
pub struct WithdrawalMade {
18-
pub amount: u128,
18+
pub amount: u64,
1919
pub address: ContractAddress,
2020
}
2121

2222
#[derive(Clone, Drop, Debug, starknet::Event)]
2323
pub struct TransferMade {
24-
pub amount: u128,
24+
pub amount: u64,
2525
pub from: ContractAddress,
2626
pub to: ContractAddress,
2727
}
@@ -30,5 +30,5 @@ use starknet::ContractAddress;
3030
pub struct AccountClosed {
3131
pub closed: ContractAddress,
3232
pub beneficiary: ContractAddress,
33-
pub amount: u128,
33+
pub amount: u64,
3434
}

src/interface.cairo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use starknet::ContractAddress;
44
#[starknet::interface]
55
pub trait ISimpleBank<TContractState> {
66
fn open_account(ref self: TContractState, name: ByteArray);
7-
fn deposit(ref self: TContractState, amount: u128);
8-
fn withdraw(ref self: TContractState, amount: u128);
9-
fn transfer(ref self: TContractState, amount: u128, recipient: ContractAddress);
7+
fn deposit(ref self: TContractState, amount: u64);
8+
fn withdraw(ref self: TContractState, amount: u64);
9+
fn transfer(ref self: TContractState, amount: u64, recipient: ContractAddress);
1010
fn close_account(ref self: TContractState, beneficiary: ContractAddress);
11-
fn get_balance(self: @TContractState) -> u128;
11+
fn get_balance(self: @TContractState) -> u64;
1212
fn get_account_details(self: @TContractState) -> BankAccount;
1313
}

src/lib.cairo

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub mod interface;
66
pub struct BankAccount {
77
pub name: ByteArray,
88
pub address: ContractAddress,
9-
pub balance: u128,
9+
pub balance: u64,
1010
pub opened: bool,
1111
}
1212

@@ -47,13 +47,13 @@ pub mod SimpleBank {
4747
self.emit(Event::AccountCreated(AccountCreated { name, address, balance: 0 }));
4848
}
4949

50-
fn deposit(ref self: ContractState, amount: u128) {
50+
fn deposit(ref self: ContractState, amount: u64) {
5151
let address = get_caller_address();
5252

5353
let mut bank_account: BankAccount = self.bank_accounts.read(address);
5454
assert(bank_account.opened, 'Nonexistent Account');
5555

56-
let balance: u128 = bank_account.balance;
56+
let balance: u64 = bank_account.balance;
5757

5858
let (new_balance, is_overflow) = balance.overflowing_add(amount);
5959
assert(!is_overflow, 'Balance Overflow');
@@ -63,13 +63,13 @@ pub mod SimpleBank {
6363
self.emit(Event::DepositMade(DepositMade { amount, address }))
6464
}
6565

66-
fn withdraw(ref self: ContractState, amount: u128) {
66+
fn withdraw(ref self: ContractState, amount: u64) {
6767
let address = get_caller_address();
6868

6969
let mut bank_account: BankAccount = self.bank_accounts.read(address);
7070
assert(bank_account.opened, 'Nonexistent Account');
7171

72-
let balance: u128 = bank_account.balance;
72+
let balance: u64 = bank_account.balance;
7373

7474
let (new_balance, is_underflow) = balance.overflowing_sub(amount);
7575
assert(!is_underflow, 'Balance Underflow');
@@ -80,7 +80,7 @@ pub mod SimpleBank {
8080
self.emit(Event::WithdrawalMade(WithdrawalMade { amount, address }))
8181
}
8282

83-
fn transfer(ref self: ContractState, amount: u128, recipient: ContractAddress) {
83+
fn transfer(ref self: ContractState, amount: u64, recipient: ContractAddress) {
8484
let from = get_caller_address();
8585

8686
let mut bank_account_from: BankAccount = self.bank_accounts.read(from);
@@ -89,8 +89,8 @@ pub mod SimpleBank {
8989
assert(bank_account_from.opened, 'Nonexistent Account');
9090
assert(bank_account_to.opened, 'Nonexistent Account');
9191

92-
let balance_from: u128 = bank_account_from.balance;
93-
let balance_to: u128 = bank_account_to.balance;
92+
let balance_from: u64 = bank_account_from.balance;
93+
let balance_to: u64 = bank_account_to.balance;
9494

9595
let (balance_from_new_amount, is_underflow) = balance_from.overflowing_sub(amount);
9696
assert(!is_underflow, 'Insufficient Funds');
@@ -132,7 +132,7 @@ pub mod SimpleBank {
132132
)
133133
}
134134

135-
fn get_balance(self: @ContractState) -> u128 {
135+
fn get_balance(self: @ContractState) -> u64 {
136136
self.get_account_details().balance
137137
}
138138

0 commit comments

Comments
 (0)