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

feat: add ownership && channel status #21

Open
wants to merge 1 commit into
base: master
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
21 changes: 19 additions & 2 deletions bridge-eth/contracts/Vault.Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ struct Channel {
uint256 maxValue;
IERC20 erc20;
IKeeper keeper;
bool status; // 0: abandoned 1: in use
}

contract Vault is IVault {
address private owner;
Channel[] public channels;
mapping(bytes32 => bool) public spentHashes;

Expand All @@ -41,16 +43,23 @@ contract Vault is IVault {
);

constructor(IKeeper _keeper, int8 _decimalDiff, uint256 _minValue, uint256 _maxValue) {
owner = msg.sender;
newChannel(IERC20(0x00), _keeper, _decimalDiff, _minValue, _maxValue);
}

modifier ownerOnly() {
require(owner == msg.sender, "Caller is not owner");
_;
}

function spent(bytes32 _hash) public view override returns (bool) {
return spentHashes[_hash];
}

function newChannel(IERC20 _erc20, IKeeper _keeper, int8 _decimalDiff, uint256 _minValue, uint256 _maxValue)
public
override
ownerOnly
returns (uint256)
{
bytes32 _inputHash = keccak256(
Expand All @@ -71,7 +80,7 @@ contract Vault is IVault {
int8 _decimalDiff,
uint256 _minValue,
uint256 _maxValue
) public returns (uint256) {
) public ownerOnly returns (uint256) {
channels.push(
Channel({
inputId: 0,
Expand All @@ -82,7 +91,8 @@ contract Vault is IVault {
minValue: _minValue,
maxValue: _maxValue,
erc20: _erc20,
keeper: _keeper
keeper: _keeper,
status: true
})
);
requireAndUpdateSpentHashes(_inputHash);
Expand All @@ -98,6 +108,8 @@ contract Vault is IVault {
uint256 value
) public payable override {
Channel memory channel = channels[id];

require(channel.status, "the channel is abandoned!");

require(value >= channel.minValue && value <= channel.maxValue, "value is illegal");

Expand Down Expand Up @@ -179,5 +191,10 @@ contract Vault is IVault {
return channels.length;
}

function abandonChannel(uint256 id) public {
Channel storage channel = channels[id];
channel.status = false;
}

receive() external payable {}
}
22 changes: 19 additions & 3 deletions bridge-vite/contracts/Vault.solpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct Channel {
uint256 maxValue;
vitetoken erc20;
uint256 keeperId;
bool status; // 0: abandoned 1: in use
}

struct MultiSigKeeper {
Expand All @@ -48,6 +49,7 @@ struct MultiSigKeeper {
}

contract Vault is IVault {
address private owner;
Channel[] public channels;

uint256 public numKeepers;
Expand All @@ -66,7 +68,13 @@ contract Vault is IVault {
);
event Output(uint256 channelId, uint256 index, bytes32 outputHash, address dest, uint256 value);

modifier ownerOnly() {
require(owner == msg.sender, "Caller is not owner");
_;
}

constructor() {
owner = msg.sender;
}

function numChannels() public view returns (uint256){
Expand All @@ -84,6 +92,7 @@ contract Vault is IVault {
function newChannel(vitetoken _erc20, address[] memory _keepers, uint8 _threshold, int8 _decimalDiff, uint256 _minValue, uint256 _maxValue)
public
override
ownerOnly
returns (uint256)
{
bytes32 _inputHash = keccak256(
Expand All @@ -98,7 +107,7 @@ contract Vault is IVault {
return newChannelWithHash(_erc20, _inputHash, _outputHash, keeperId, _decimalDiff, _minValue, _maxValue);
}

function newKeepers(address[] memory _keepers, uint8 _threshold) public returns(uint256) {
function newKeepers(address[] memory _keepers, uint8 _threshold) public ownerOnly returns(uint256) {
MultiSigKeeper storage r = keepers[numKeepers];
r.threshold = _threshold;
uint256 len = _keepers.length;
Expand All @@ -119,7 +128,7 @@ contract Vault is IVault {
int8 _decimalDiff,
uint256 _minValue,
uint256 _maxValue
) public returns (uint256) {
) public ownerOnly returns (uint256) {
channels.push(
Channel({
inputId: 0,
Expand All @@ -130,7 +139,8 @@ contract Vault is IVault {
minValue: _minValue,
maxValue: _maxValue,
erc20: _erc20,
keeperId:_keeperId
keeperId:_keeperId,
status: true
})
);
requireAndUpdateSpentHashes(_inputHash);
Expand All @@ -148,6 +158,7 @@ contract Vault is IVault {
) public payable override {
Channel memory channel = channels[id];

require(channel.status, "the channel is abandoned!");
require(msg.value == value, "Transfer Value Require Failed.");
require(msg.token == channel.erc20, "Transfer Token Require Failed");
require(value >= channel.minValue && value <= channel.maxValue, "value is illegal");
Expand Down Expand Up @@ -254,6 +265,11 @@ contract Vault is IVault {
return keepers[keeperId].approvedKeepers[outputHash][keeper];
}

function abandonChannel(uint256 id) public {
Channel storage channel = channels[id];
channel.status = false;
}


// ------------------------

Expand Down