Skip to content

Commit

Permalink
fix: disable methods and add withdraw method
Browse files Browse the repository at this point in the history
  • Loading branch information
gcranju committed Jan 24, 2025
1 parent 71b8210 commit 347993d
Show file tree
Hide file tree
Showing 2 changed files with 391 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ public Map<String, BigInteger> getAccumulatedFees() {
*/
@External
public void tokenFallback(Address _from, BigInteger _value, byte[] _data) {
Context.revert("Not supported");
require(_value.compareTo(BigInteger.ZERO) >= 0, "value should be positive");
checkUintLimit(_value);
String _coinName = coinAddressName.get(Context.getCaller());
Expand Down Expand Up @@ -526,6 +527,7 @@ public void tokenFallback(Address _from, BigInteger _value, byte[] _data) {
*/
@External
public void reclaim(String _coinName, BigInteger _value) {
Context.revert("Not supported");
require(_value.compareTo(BigInteger.ZERO) > 0, "_value must be positive");
checkUintLimit(_value);

Expand Down Expand Up @@ -555,6 +557,34 @@ public void reclaim(String _coinName, BigInteger _value) {
}
}

@External
public void withdrawAllTokens() {
requireOwnerAccess();
Address _to = Context.getCaller();
for (String coinName : coinNames()) {
if (name.equals(coinName)) {
Context.transfer(_to, Context.getBalance(Context.getAddress()));
} else {
BigInteger balance = Context.call(BigInteger.class, this.getCoinAddress(coinName), "balanceOf", Context.getAddress());
if(balance.compareTo(BigInteger.ZERO) == 0) continue;
transfer(_to, coinName, balance);
}
}
}

@External
public void withdrawToken(String _coinName) {
requireOwnerAccess();
Address _to = Context.getCaller();
if(name.equals(_coinName)) {
Context.transfer(_to, Context.getBalance(Context.getAddress()));
return;
}
BigInteger balance = Context.call(BigInteger.class, this.getCoinAddress(_coinName), "balanceOf", Context.getAddress());
if(balance.compareTo(BigInteger.ZERO) == 0) return;
transfer(_to, _coinName, balance);
}

/**
* To transfer nativecoin |ICX| to destination chains
* Checks for blacklist and token limit
Expand Down Expand Up @@ -598,6 +628,7 @@ public void transferNativeCoin(String _to) {
*/
@External
public void transfer(String _coinName, BigInteger _value, String _to) {
Context.revert("Not supported");
require(!_coinName.equals(name), "Only for IRC2 Token");
require(_value != null && _value.compareTo(BigInteger.ZERO) > 0, "Invalid amount");
checkUintLimit(_value);
Expand Down Expand Up @@ -631,6 +662,7 @@ public void transfer(String _coinName, BigInteger _value, String _to) {
@Payable
@External
public void transferBatch(String[] _coinNames, BigInteger[] _values, String _to) {
Context.revert("Not supported");
Context.require(_to.length() < 100, "Length Check");
int len = _coinNames.length;
require(len > 0, "Zero length arguments");
Expand Down
Loading

0 comments on commit 347993d

Please sign in to comment.