Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
e659dd7a
Commit
e659dd7a
authored
Dec 13, 2021
by
hezhengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add transfer Helper
parent
3ca1f9aa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
11 deletions
+51
-11
BridgeBank.sol
...oss2eth/contracts/contracts4eth/BridgeBank/BridgeBank.sol
+5
-6
EthereumBank.sol
...s2eth/contracts/contracts4eth/BridgeBank/EthereumBank.sol
+5
-5
TransferHelper.sol
...eth/contracts/contracts4eth/BridgeBank/TransferHelper.sol
+41
-0
BridgeBank.go
...cross2eth/contracts/contracts4eth/generated/BridgeBank.go
+0
-0
No files found.
plugin/dapp/cross2eth/contracts/contracts4eth/BridgeBank/BridgeBank.sol
View file @
e659dd7a
...
...
@@ -2,9 +2,11 @@ pragma solidity ^0.5.0;
import "./Chain33Bank.sol";
import "./EthereumBank.sol";
import "./TransferHelper.sol";
import "../Oracle.sol";
import "../Chain33Bridge.sol";
/**
* @title BridgeBank
* @dev Bank contract which coordinates asset-related functionality.
...
...
@@ -257,12 +259,9 @@ contract BridgeBank is Chain33Bank, EthereumBank {
symbol = platformTokenSymbol;
// ERC20 deposit
} else {
require(
BridgeToken(_token).transferFrom(msg.sender, address(this), _amount),
"Contract token allowances insufficient to complete this lock request"
);
// Set symbol to the ERC20 token's symbol
symbol = BridgeToken(_token).symbol();
TransferHelper.safeTransferFrom(_token, msg.sender, address(this), _amount);
symbol = tokenAddrAllow2symbol[_token];
require(
tokenAllow2Lock[keccak256(abi.encodePacked(symbol))] == _token,
...
...
plugin/dapp/cross2eth/contracts/contracts4eth/BridgeBank/EthereumBank.sol
View file @
e659dd7a
...
...
@@ -2,6 +2,7 @@ pragma solidity ^0.5.0;
import "../../openzeppelin-solidity/contracts/math/SafeMath.sol";
import "./BridgeToken.sol";
import "./TransferHelper.sol";
/*
* @title: EthereumBank
...
...
@@ -16,6 +17,7 @@ contract EthereumBank {
address payable public offlineSave;
mapping(address => uint256) public lockedFunds;
mapping(bytes32 => address) public tokenAllow2Lock;
mapping(address => string) public tokenAddrAllow2symbol;
mapping(address => OfflineSaveCfg) public offlineSaveCfgs;
uint8 public lowThreshold = 5;
uint8 public highThreshold = 80;
...
...
@@ -153,7 +155,7 @@ contract EthereumBank {
if (address(0) == _token) {
offlineSave.transfer(amount);
} else {
require(BridgeToken(_token).transfer(offlineSave, amount), "Erc20 Token Transfer to offline Save account failed"
);
TransferHelper.safeTransfer(_token, offlineSave, amount
);
}
return;
}
...
...
@@ -182,10 +184,7 @@ contract EthereumBank {
if (_token == address(0)) {
_recipient.transfer(_amount);
} else {
require(
BridgeToken(_token).transfer(_recipient, _amount),
"Token transfer failed"
);
TransferHelper.safeTransfer(_token, _recipient, _amount);
}
emit LogUnlock(
...
...
@@ -213,6 +212,7 @@ contract EthereumBank {
address tokenQuery = tokenAllow2Lock[symHash];
require(tokenQuery == address(0), 'The token with the same symbol has been added to lock allow list already.');
tokenAllow2Lock[symHash] = _token;
tokenAddrAllow2symbol[_token] = _symbol;
}
/*
...
...
plugin/dapp/cross2eth/contracts/contracts4eth/BridgeBank/TransferHelper.sol
0 → 100644
View file @
e659dd7a
pragma solidity ^0.5.0;
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(address token, address to, uint value) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
}
function safeTransfer(address token, address to, uint value) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
}
function safeTransferFrom(address token, address from, address to, uint value) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
}
// function safeTransferETH(address to, uint value) internal {
// (bool success,) = to.call{value:value}(new bytes(0));
// require(success, 'TransferHelper: ETH_TRANSFER_FAILED');
// }
}
//var ERC20FuncSigs = map[string]string{
//"dd62ed3e": "allowance(address,address)",
//"095ea7b3": "approve(address,uint256)",
//"70a08231": "balanceOf(address)",
//"313ce567": "decimals()",
//"a457c2d7": "decreaseAllowance(address,uint256)",
//"39509351": "increaseAllowance(address,uint256)",
//"06fdde03": "name()",
//"95d89b41": "symbol()",
//"18160ddd": "totalSupply()",
//"a9059cbb": "transfer(address,uint256)",
//"23b872dd": "transferFrom(address,address,uint256)",
//}
plugin/dapp/cross2eth/contracts/contracts4eth/generated/BridgeBank.go
View file @
e659dd7a
This source diff could not be displayed because it is too large. You can
view the blob
instead.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment