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

Finance App #99

Closed
wants to merge 22 commits into from
Closed

Finance App #99

wants to merge 22 commits into from

Conversation

readevalprint
Copy link
Contributor

@readevalprint readevalprint commented Sep 13, 2017

  • update Accounting with recurring payments/invoices
  • deposit function should record transactions
  • Add natspec
  • More tests

@readevalprint readevalprint changed the title Finance App Finance App WIP Sep 13, 2017
@readevalprint readevalprint changed the title Finance App WIP Finance App Sep 14, 2017
@readevalprint readevalprint self-assigned this Sep 14, 2017
Copy link
Contributor

@izqui izqui left a 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";


Copy link
Contributor

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 {
Copy link
Contributor

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 {

Copy link
Contributor

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];
Copy link
Contributor

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)'));
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

@izqui izqui Sep 18, 2017

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;
Copy link
Contributor

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
Copy link
Contributor

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 ...
*/

@onbjerg onbjerg added the apps label Sep 22, 2017
@izqui
Copy link
Contributor

izqui commented Sep 25, 2017

Closed in favor of #118

@izqui izqui closed this Sep 25, 2017
@facuspagnuolo facuspagnuolo deleted the accountingapp branch May 27, 2020 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants