-
Notifications
You must be signed in to change notification settings - Fork 45
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
Use ABI V2 to shorten settle arg list #1392
Changes from 1 commit
adbcbde
67cf44e
4deabfd
65a977e
ad0a198
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pragma solidity 0.6.4; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "lib/ECVerify.sol"; | ||
import "raiden/Token.sol"; | ||
|
@@ -124,6 +125,13 @@ contract TokenNetwork is Utils { | |
uint256 locked_amount; | ||
} | ||
|
||
struct ParticipantSettleInput { | ||
address participant; | ||
uint256 transferred_amount; | ||
uint256 locked_amount; | ||
bytes32 locksroot; | ||
} | ||
|
||
event ChannelOpened( | ||
uint256 indexed channel_identifier, | ||
address indexed participant1, | ||
|
@@ -692,6 +700,30 @@ contract TokenNetwork is Utils { | |
bytes32 participant2_locksroot | ||
) | ||
public | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why wouldn't we change the signature for
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, expand-contract pattern...I see. |
||
{ | ||
settleChannel2( | ||
channel_identifier, | ||
ParticipantSettleInput({ | ||
participant: participant1, | ||
transferred_amount: participant1_transferred_amount, | ||
locked_amount: participant1_locked_amount, | ||
locksroot: participant1_locksroot | ||
}), | ||
ParticipantSettleInput({ | ||
participant: participant2, | ||
transferred_amount: participant2_transferred_amount, | ||
locked_amount: participant2_locked_amount, | ||
locksroot: participant2_locksroot | ||
}) | ||
); | ||
} | ||
|
||
function settleChannel2( | ||
uint256 channel_identifier, | ||
ParticipantSettleInput memory participant1_settlement, | ||
ParticipantSettleInput memory participant2_settlement | ||
) | ||
public | ||
{ | ||
// There are several requirements that this function MUST enforce: | ||
// - it MUST never fail; therefore, any overflows or underflows must be | ||
|
@@ -708,6 +740,8 @@ contract TokenNetwork is Utils { | |
// therefore it cannot ensure correctness. Users MUST use the official | ||
// Raiden clients for signing balance proofs. | ||
|
||
address participant1 = participant1_settlement.participant; | ||
address participant2 = participant2_settlement.participant; | ||
require(channel_identifier == getChannelIdentifier(participant1, participant2)); | ||
|
||
bytes32 pair_hash; | ||
|
@@ -725,16 +759,16 @@ contract TokenNetwork is Utils { | |
|
||
require(verifyBalanceHashData( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
participant1_state, | ||
participant1_transferred_amount, | ||
participant1_locked_amount, | ||
participant1_locksroot | ||
participant1_settlement.transferred_amount, | ||
participant1_settlement.locked_amount, | ||
participant1_settlement.locksroot | ||
)); | ||
|
||
require(verifyBalanceHashData( | ||
participant2_state, | ||
participant2_transferred_amount, | ||
participant2_locked_amount, | ||
participant2_locksroot | ||
participant2_settlement.transferred_amount, | ||
participant2_settlement.locked_amount, | ||
participant2_settlement.locksroot | ||
)); | ||
|
||
// We are calculating the final token amounts that need to be | ||
|
@@ -752,17 +786,17 @@ contract TokenNetwork is Utils { | |
// We are reusing variables due to the local variables number limit. | ||
// For better readability this can be refactored further. | ||
( | ||
participant1_transferred_amount, | ||
participant2_transferred_amount, | ||
participant1_locked_amount, | ||
participant2_locked_amount | ||
participant1_settlement.transferred_amount, | ||
participant2_settlement.transferred_amount, | ||
participant1_settlement.locked_amount, | ||
participant2_settlement.locked_amount | ||
) = getSettleTransferAmounts( | ||
participant1_state, | ||
participant1_transferred_amount, | ||
participant1_locked_amount, | ||
participant1_settlement.transferred_amount, | ||
participant1_settlement.locked_amount, | ||
participant2_state, | ||
participant2_transferred_amount, | ||
participant2_locked_amount | ||
participant2_settlement.transferred_amount, | ||
participant2_settlement.locked_amount | ||
); | ||
|
||
// Remove the channel data from storage | ||
|
@@ -779,32 +813,32 @@ contract TokenNetwork is Utils { | |
channel_identifier, | ||
participant1, | ||
participant2, | ||
participant1_locked_amount, | ||
participant1_locksroot | ||
participant1_settlement.locked_amount, | ||
participant1_settlement.locksroot | ||
); | ||
storeUnlockData( | ||
channel_identifier, | ||
participant2, | ||
participant1, | ||
participant2_locked_amount, | ||
participant2_locksroot | ||
participant2_settlement.locked_amount, | ||
participant2_settlement.locksroot | ||
); | ||
|
||
emit ChannelSettled( | ||
channel_identifier, | ||
participant1_transferred_amount, | ||
participant1_locksroot, | ||
participant2_transferred_amount, | ||
participant2_locksroot | ||
participant1_settlement.transferred_amount, | ||
participant1_settlement.locksroot, | ||
participant2_settlement.transferred_amount, | ||
participant2_settlement.locksroot | ||
); | ||
|
||
// Do the actual token transfers | ||
if (participant1_transferred_amount > 0) { | ||
require(token.transfer(participant1, participant1_transferred_amount)); | ||
if (participant1_settlement.transferred_amount > 0) { | ||
require(token.transfer(participant1, participant1_settlement.transferred_amount)); | ||
} | ||
|
||
if (participant2_transferred_amount > 0) { | ||
require(token.transfer(participant2, participant2_transferred_amount)); | ||
if (participant2_settlement.transferred_amount > 0) { | ||
require(token.transfer(participant2, participant2_settlement.transferred_amount)); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pragma solidity 0.6.4; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "raiden/TokenNetwork.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.
imho we could go with a shorter name here:
SettleInput
(having a mandatoryparticipant
argument) should be completely self-explanatory :)