3

Actually, I am a little bit confused about when we say that we can freeze a deployed smart contract and cannot perform any transaction till it is unfrozen. And we can unfreeze the contract after making changes in the contract by deploying the latest one.

Is my understanding correct and if it is then how can we freeze the contracts?

3

There are at least two more methods to freeze your smart contract:

By Block Producer Voting

This maybe for the case for buggy or malicious smart contracts that maybe affecting the whole EOS blockchain. You would have to make formal process to do so.

Take this part from the whitepaper:

The block producers on all blockchains have the power to select which transactions are included in blocks which gives them the ability to freeze accounts. A blockchain using EOS.IO software formalizes this authority by subjecting the process of freezing an account to a 15/21 vote of active producers.

By including a function in the contract

You could simply update your code like @user167 said or you would use a flag like @damianodamiano suggested. But his implementation is incorrect, because it ignores the fact that you can not store local variables or class attributes. You would have to use a multi_index from the Persistence API.

Assuming you have member table that stores uint64_t values with a key you could use this structure:

mId (unint64_t) | mKey (String) | mValue (unint64_t)
0              | "FROZEN"        | 0

You have to define the coresponding structs and tables in the hpp but this kind of depends on the tools and contract structure you are using.

More general you can use this implementation for your cpp file.

const FROZEN_FLAG = "FROZEN"; // == 1 means frozen, == 0 means unfrozen

// method to make the multi_index changes
void setFrozen(uint64_t pFrozen) {
    memberIndex members(_self, _self); // code, scope
    auto iterator = members.find(FROZEN_FLAG);
    if(iterator != members.end()){ // update the existing flag
       members.modify( itr, _self, [&]( auto& member ) {
          member.mValue = pFrozen;
       });
    }else{ // create new member entry
       auto id = members.available_primary_key();
       members.emplace(_self, [&](auto &member) {
          member.mId = id;
          member.mKey = FROZEN_FLAG;
          member.mValue = pFrozen;
       });
    }
}

// method to search the mulit_index for the frozen flag
boolean getFrozen(){
    memberIndex members(_self, _self); // code, scope
    auto iterator = members.find(FROZEN_FLAG);
    if(iterator != members.end()){
       return (*iterator) == 1; // found so is it frozen (== 1)?
    }else{
       return false; // default not frozen, change as you like
    }
}

// public Action
void freeze() {
    require_auth(_self); // only the contract account can call this
    setFrozen(1);
}

// public Action
void unfreeze() {
    require_auth(_self); // only the contract account can call this
    setFrozen(0);
}

// any public action
void action(...) {
    eosio_assert(getFrozen() == true, "Contract is frozen!");
    ...
}
0

Just updated your smart contract and add freeze code to do that.

For simple just add before every methods in your smart contract like

eosio_assert("This smart contract is under development");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.