-
Notifications
You must be signed in to change notification settings - Fork 245
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
Finance App #99
Finance App #99
Conversation
readevalprint
commented
Sep 13, 2017
•
edited
Loading
edited
- update Accounting with recurring payments/invoices
- deposit function should record transactions
- Add natspec
- More tests
Add aesthetically pleasing space in README
65b2fdb
to
1011d3f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the introduction of Payments, now all the logic regarding transaction states is no longer relevant as _newOutgoingTransaction
is only called when withdrawing a payment. All state handling functions (approveTransaction, denyTransaction) don't have any real effect (but spend a lot in storage) as transactions can only go from creation to execution.
When you test the code it is possible that you will run into issues because of using the memory
keyword in instances where you need to modify storage.
Also code is hard to follow as functions are weirdly ordered. Following the style guide or a more logical approach would go a long way in terms of readability.
Support for wrapping and unwrapping ether in an EtherToken is missing.
import "../vault/Vault.sol"; | ||
import "../../misc/Crontab.sol"; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too much whitespace
|
||
|
||
|
||
contract FinanceApp is App, Initializable, Crontab { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rename dir 'apps/accounting/FinanceApp.sol' to 'apps/finance/FinanceApp.sol'
Vault vault; | ||
|
||
struct AccountingPeriod { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no newline needed before first struct member (the Transaction struct is perfect)
@dev Set the schedual of payments | ||
*/ | ||
function _setPaymentSchedual(uint pid, uint repeat, bytes2 ct_sec, bytes2 ct_min, bytes2 ct_hour, bytes2 ct_day, bytes2 ct_month, bytes2 ct_weekday, bytes2 ct_year) internal { | ||
Payment memory p = payments[pid]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Payment should be in storage
here or modifications won't be saved to storage
require(state == TransactionState.PendingApproval); | ||
_updateTransaction(transactionId, TransactionState.Denied, reason); | ||
} | ||
bytes4 constant TRANSFER_SIG = bytes4(sha3('transfer(address,address,uint256)')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused constant
// TODO: store endBlock of last accountingPeriod? | ||
ap.startBlock = block.number; | ||
accountingPeriods.push(ap); | ||
//vault.requestAllowances(ap.budgetTokens, ap.budgetAmounts); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't pulled from your branch when I added this initially so the function didn't exist
/** | ||
@dev External authenticated function to start the next accounting period | ||
*/ | ||
function startNextAccountingPeriod() external auth { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
startNewAccountingPeriod should not only not be protected behind the ACL but it should be tried to be executed in every write function, as if the accounting period has ended, to ensure transactions are in the correct accounting period.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good point
Transaction memory t = transactions[transactionId]; | ||
var (state, r) = getTransactionState(transactionId); | ||
require(state == TransactionState.Approved); | ||
bool succeeded = ERC20(t.token).transfer(t.externalAddress, t.amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be a transferFrom. The FinanceApp doesn't have a balance in the tokens, just whatever it was allowed.
function newPayment(ERC20 token, uint amount, address to, uint repeat, uint startTimestamp, bytes2 ct_sec, bytes2 ct_min, bytes2 ct_hour, bytes2 ct_day, bytes2 ct_month, bytes2 ct_weekday, bytes2 ct_year) auth external { | ||
require(repeat > 0); | ||
uint pid = _newPayment(token, amount, to, startTimestamp); | ||
_setPaymentSchedual(pid, repeat, ct_sec, ct_min, ct_hour, ct_day, ct_month, ct_weekday, ct_year); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a payment can be withdrawn on creation, we should make it happen so only one transaction is needed for individual payments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you mean if repeat=1
then do the token.transfer()
immediately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually if a transaction can happen at the moment of payment creation, we should execute the withdrawal.
bytes2 ct_year; | ||
uint startBlock; | ||
uint startTimestamp; | ||
uint endTimestamp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By not specifying the uint size the compiler will default to using uint256
for timestamps and block numbers that could be stored in uint64
.
} | ||
|
||
/** | ||
@param vaultAddress The vault app to use with this FinanceApp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a *
before the comment line for conformance with the spec.
/**
* @param ...
*/
Closed in favor of #118 |