Skip to content

Commit

Permalink
refactor: clean up NST exits related code (#206)
Browse files Browse the repository at this point in the history
* refactor: clean up NST exits related code

- drop ExitStartedV2 event in favour of ExitStarted
- put token data into Exit struct

* do not emit token data with ExitStarted event
  • Loading branch information
troggy authored Jun 19, 2019
1 parent 7bae67c commit 0aa613d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 36 deletions.
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;
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

0 comments on commit 0aa613d

Please sign in to comment.