0

If there is "FreezeToken" in the wallet, freeze the wallet. And if there is "ThawToken" in the wallet, it cancels the freeze. This code is an example of failure.

let FreezeToken = base58'GwmXnsF3Z5tANgHwmDW7Lf4SwyYNEp4S3QZM3aBFLHwS'
let ThawToken = base58'GK7ZV8xFbh1Qz14Cnr6mLkV93svaZGrurVuaBZocwLZZ'
match tx {
     case m : ExchangeTransaction. =>
         if (assetBalance(e.sender,ThawToken) >= 1 ) then{true}
         else if (assetBalance(e.sender,ThawToken) >= 1 ) then{false}
         else true
     case _ => false
}

TransferTransaction succeeded but ExchangeTransaction failed. How do I change this code? please tell me.

marchin
  • 21
  • 2

1 Answers1

1

I am guessing you are creating a smart account? From what I see in the code, is that you used 2 times ThawToken, one time this results to true and another time to false. My guess is that you want one from the 2 be replaced by FreezeToken

Also in your example you have "ExchangeTransaction.", this dot doesn't seem needed here from what I can understand from your code.

Also according to the examples it seems that your whole second if structure should be included into {}. Example: https://github.com/wavesplatform/ride-examples/blob/bc8db2342f53fe1554a10dc5aaa211b1542a5ca1/smart-assets/HotPotatoToken.ride#L41

However I think this issue could be solved with a && statement, and as following the second if-then-else is not needed anymore. What I propose is a check that does following:

Check if ThawToken not in wallet and if that is the case, check if freezetoken is in wallet.

If ThawToken is and FreezeToken is also => wallet free since ThawToken frees it.

If ThawToken is not and FreezeToken is 1 or more => wallet locked since only FreezeToken.

If ThawToken is not and FreezeToken is not => wallet free since no FreezeToken

    if (assetBalance(e.sender,ThawToken) == 0 &&
 assetBalance(e.sender,FreezeToken) >= 1 ) then{
      false
    }else{
      true
    }

Also to block all transactions and indeed freeze the wallet, you would need to filter on another type, for all types use: Transaction, be careful this also disables the option to change the script in case you locked your account. To block transfer transaction use: TransferTransaction.

All types can be found here: https://docs.wavesplatform.com/en/smart-contracts/ride-language/standard-library.html