You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create a new project through which a user will be able to track his/her expenses, this is the initial contract i came up with,
I wanted to know some opinions/views on this project, am I doing it the right way?
contract ExpenseTracker{
enum TransactionType{ INCOME, EXPENSE }
struct Transaction{
TransactionType t_type;
string t_disc;
uint256 t_amount;
}
mapping(address => Transaction[]) private transactions;
function addExpense(uint amount, string memory desc) public {
transactions[msg.sender].push(Transaction(
TransactionType.EXPENSE,
desc,
amount
));
}
function addIncome(uint amount, string memory desc) public {
transactions[msg.sender].push(Transaction(
TransactionType.INCOME,
desc,
amount
));
}
function getUserTransactions() public view returns (Transaction[] memory){
return transactions[msg.sender];
}
function getUserTransactionsLen() public view returns (uint){
return transactions[msg.sender].length;
}
}
addExpense() - adds user expense addIncome() - adds user income getUserTransactions() - get all transactions done by the user. getUserTransactionsLen() - get the length of all transactions done by the user.
Imp points:
I want to keep the contract specifically for a single user, so can I do something by using the constructor?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to create a new project through which a user will be able to track his/her expenses, this is the initial contract i came up with,
I wanted to know some opinions/views on this project, am I doing it the right way?
addExpense()
- adds user expenseaddIncome()
- adds user incomegetUserTransactions()
- get all transactions done by the user.getUserTransactionsLen()
- get the length of all transactions done by the user.Imp points:
Beta Was this translation helpful? Give feedback.
All reactions