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

added any erc20 support to payments #37

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions contracts/Escapable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract Escapable {
function escapeHatch() onlyEscapeHatchCaller {
uint total = getBalance();
// Send the total balance of this contract to the `escapeHatchDestination`
transfer(escapeHatchDestination, total);
transfer(baseToken, escapeHatchDestination, total);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has it's own function and should not be added to the constructor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has it's own function, see claimTokens which may need to be renamed

EscapeHatchCalled(total);
}
/// @notice Changes the address assigned to call `escapeHatch()`
Expand All @@ -67,13 +67,14 @@ contract Escapable {
return this.balance;
}
}
/// @notice Sends an `_amount` of `baseToken` to `_to` from this contract,
/// @notice Sends an `_amount` of `_token` to `_to` from this contract,
/// and it can only be called by the contract itself
/// @param _token to deposit, 0x0 to send ether.
/// @param _to The address of the recipient
/// @param _amount The amount of `baseToken to be sent
function transfer(address _to, uint _amount) internal {
if (address(baseToken) != 0) {
if (!baseToken.transfer(_to, _amount)) throw;
function transfer(address _token, address _to, uint _amount) internal {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have to ask jordi but i think the better design is to have a second function for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has it's own function, see claimTokens which may need to be renamed... Honestly i dont think this contract needs changes

if (_token != 0) {
if (!Token(_token).transfer(_to, _amount)) throw;
} else {
if (! _to.send(_amount)) throw;
}
Expand Down
8 changes: 6 additions & 2 deletions contracts/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ contract Vault is Escapable, Owned {
struct Payment {
string name; // What is the purpose of this payment
bytes32 reference; // Reference of the payment.
address token; // if 0 payment of ether, else the token being sent
address spender; // Who is sending the funds
uint earliestPayTime; // The earliest a payment can be made (Unix Time)
bool canceled; // If True then the payment has been canceled
Expand Down Expand Up @@ -196,6 +197,7 @@ contract Vault is Escapable, Owned {
/// @param _name Brief description of the payment that is authorized
/// @param _reference Reference hash of the payment shared with the contract
/// requesting the payment.
/// @param _token The token being sent
/// @param _recipient Destination of the payment
/// @param _amount Amount to be paid in wei
/// @param _paymentDelay Number of seconds the payment is to be delayed, if
Expand All @@ -204,6 +206,7 @@ contract Vault is Escapable, Owned {
function authorizePayment(
string _name,
bytes32 _reference,
address _token,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a better strategy to create a second function for non-baseToken transfers... but we need to hear from jordi... it might be a few days

address _recipient,
uint _amount,
uint _paymentDelay
Expand Down Expand Up @@ -233,13 +236,14 @@ contract Vault is Escapable, Owned {
p.amount = _amount;
p.name = _name;
p.reference = _reference;
p.token = (_token == 0) ? baseToken : _token;

totalAuthorizedToBeSpent += p.amount;
PaymentAuthorized(idPayment, p.recipient, p.amount);

if ((now >= p.earliestPayTime) && (getBalance() >= p.amount)) {
p.paid = true; // Set the payment to being paid
transfer(p.recipient, p.amount); // Make the payment
transfer(p.token, p.recipient, p.amount); // Make the payment

totalAuthorizedToBeSpent -= p.amount;
totalSpent += p.amount; // Accounting
Expand Down Expand Up @@ -271,7 +275,7 @@ contract Vault is Escapable, Owned {
if (getBalance() < p.amount) throw;

p.paid = true; // Set the payment to being paid
transfer(p.recipient, p.amount);// Make the payment
transfer(p.token, p.recipient, p.amount);// Make the payment

totalAuthorizedToBeSpent -= p.amount;
totalSpent += p.amount;
Expand Down