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

fix: add default connection setter #87

Merged
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
15 changes: 10 additions & 5 deletions contracts/evm/xcall/contracts/CallService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ contract CallService is IBSH, ICallService, IFeeManage, Initializable {
return networkAddress;
}

function getNetworkId(
function getNetworkId(
) external view override returns (
string memory
) {
Expand Down Expand Up @@ -138,6 +138,7 @@ contract CallService is IBSH, ICallService, IFeeManage, Initializable {

if (sources.length == 0) {
address conn = defaultConnections[netTo];
require(conn != address(0), "NoDefaultConnection");
uint256 requiredFee = IConnection(conn).getFee(netTo, needResponse);
sendBTPMessage(conn, requiredFee, netTo, Types.CS_REQUEST, msgSn, _msg);
} else {
Expand Down Expand Up @@ -346,9 +347,9 @@ contract CallService is IBSH, ICallService, IFeeManage, Initializable {
delete pendingReqs[dataHash][req.protocols[i]];
}
} else if (req.protocols.length == 1) {
require(msg.sender == req.protocols[0].parseAddress("IllegalArgument"));
require(msg.sender == req.protocols[0].parseAddress("IllegalArgument"), "NotAuthorized");
} else {
require(msg.sender == defaultConnections[fromNID]);
require(msg.sender == defaultConnections[fromNID], "NotAuthorized");
}

uint256 reqId = getNextReqId();
Expand Down Expand Up @@ -384,9 +385,9 @@ contract CallService is IBSH, ICallService, IFeeManage, Initializable {
delete pendingResponses[res.sn][req.sources[i]];
}
} else if (req.sources.length == 1) {
require(msg.sender == req.sources[0].parseAddress("IllegalArgument"));
require(msg.sender == req.sources[0].parseAddress("IllegalArgument"), "NotAuthorized");
} else {
require(msg.sender == defaultConnections[req.to]);
require(msg.sender == defaultConnections[req.to], "NotAuthorized");
}

emit ResponseMessage(res.sn, res.code);
Expand Down Expand Up @@ -446,6 +447,10 @@ contract CallService is IBSH, ICallService, IFeeManage, Initializable {
return feeHandler;
}

function setDefaultConnection(string memory nid, address connection) external onlyAdmin {
defaultConnections[nid] = connection;
}

function setProtocolFee(
uint256 _value
) external override onlyAdmin {
Expand Down