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

refactor: clean up NST exits related code #206

Merged
merged 2 commits into from
Jun 19, 2019
Merged
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
52 changes: 17 additions & 35 deletions contracts/ExitHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,17 @@ contract ExitHandler is IExitHandler, DepositHandler {
uint256 amount
);

event ExitStartedV2(
bytes32 indexed txHash,
uint8 indexed outIndex,
uint256 indexed color,
address exitor,
uint256 amount,
bytes32 data
);

/**
- tokenData — (optional) NST data
*/
struct Exit {
uint256 amount;
uint16 color;
address owner;
bool finalized;
uint32 priorityTimestamp;
uint256 stake;
Copy link
Member

Choose a reason for hiding this comment

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

if you make stake a uint32 (for example multiple of 0.1 ETH), then you save one storage slot.

Copy link
Member

Choose a reason for hiding this comment

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

out of scope, but noted here: #207

bytes32 tokenData;
}

uint256 public exitDuration;
Expand All @@ -54,11 +49,9 @@ contract ExitHandler is IExitHandler, DepositHandler {
uint256 public nstExitCounter;

/**
* UTXO → Exit mapping. Contains exits for both NFT and ERC20 colors
* UTXO → Exit mapping
*/
mapping(bytes32 => Exit) public exits;
// mapping for NST data
mapping(bytes32 => bytes32) public exitsTokenData;

function initializeWithExit(
Bridge _bridge,
Expand Down Expand Up @@ -158,29 +151,17 @@ contract ExitHandler is IExitHandler, DepositHandler {
amount: out.value,
finalized: false,
stake: exitStake,
priorityTimestamp: timestamp
priorityTimestamp: timestamp,
tokenData: out.stateRoot
});

if (isNST(out.color)) {
exitsTokenData[utxoId] = out.stateRoot;

emit ExitStartedV2(
txHash,
_outputIndex,
out.color,
out.owner,
out.value,
out.stateRoot
);
} else {
emit ExitStarted(
txHash,
_outputIndex,
out.color,
out.owner,
out.value
);
}
emit ExitStarted(
txHash,
_outputIndex,
out.color,
out.owner,
out.value
);
}

function startDepositExit(uint256 _depositId) public payable {
Expand Down Expand Up @@ -211,7 +192,8 @@ contract ExitHandler is IExitHandler, DepositHandler {
amount: deposit.amount,
finalized: false,
stake: exitStake,
priorityTimestamp: uint32(now)
priorityTimestamp: uint32(now),
tokenData: "0x"
});

// no need to emit ExitStartedV2
Expand Down Expand Up @@ -248,7 +230,7 @@ contract ExitHandler is IExitHandler, DepositHandler {
if (isNft(currentExit.color)) {
tokens[currentExit.color].addr.transferFrom(address(this), currentExit.owner, currentExit.amount);
} else if (isNST(currentExit.color)) {
bytes32 tokenData = exitsTokenData[utxoId];
bytes32 tokenData = currentExit.tokenData;
address tokenAddr = address(tokens[currentExit.color].addr);

bool success;
Expand Down
3 changes: 2 additions & 1 deletion contracts/FastExitHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ contract FastExitHandler is ExitHandler {
amount: out.value,
finalized: false,
stake: exitStake,
priorityTimestamp: data.timestamp
priorityTimestamp: data.timestamp,
tokenData: out.stateRoot
});
emit ExitStarted(
data.txHash,
Expand Down