deleteData: DELETE DATA with ACL

Deletign data with ACL (access control).

API

Z.com Cloud Block Chain

Processing Sequence

DeleteData SomeContract

  • 1 AltExecCnsContract#deleteData

    We call AltExecCnsContract from client's logic.

    When calling, calls are made including the "name", "function name", "parameter", "data to be saved" etc. of the contract to be ultimately called.

  • 1.1 API DELETE data

    The client module provided by this service signs the hash value derived from all the arguments and calls the API.

  • 1.1.1 ContractNameService#getLatestcontract

    The API server queries the CNS for the address of the latest version of Contract.

  • 1.1.2 checkExistance

    The API server checks the existence of the specified object ID.

    (Error (400 BadRequest) when the data of the object ID DOES NOT exists.)

  • 1.1.3 SomeContract#someMethod

    The API server calls the contract as instructed by the end user.
    The second parameter is bytes 32: objectId.

    In the contract method, the DataObject is removed based on the specified object ID.

    With the contract of the service provider alone, the removal of the DataObject is not yet complete. The removal is completed by the API after verification of the data.

    For details, please refer to DataObjectLogic.

  • 1.1.4 deleteData

    Only contracts which has removal permission for the target data remove the DataObject.

Implementation by the service provider

The flow is somewhat complicated, but the implementation of the service provider is very simple.

  • ClientSide

    • AltExecCnsContract#sendData

      var contract = new AltExecCnsContract(account, '__CNS_ADDRESS__');
      contract.deleteData('__PASSWORD__', 'SomeContract', 'someMethod', '__OBJECT_ID__', ['p0', 1, 'p2'], abi, function(err, txHash) {
          if (err) console.error(err);
          else console.log(txHash);
      }
      
  • Contract

    • SomeContract

      The contract to be implemented is called with parameters as specified by the end user, but the second argument is passed as bytes 32: objectId and the third argument is passed as bytes 32: dataHash.

      contract SomeContract is VersionContract {
      
          mapping(address => bool) allowUsers;
          ContractNameService constant GMO_CNS = ContractNameService (0x9148550103573a730535f95a01323a9fc3dc6aa0);
      
          function SomeContract(ContractNameService _cns) VersionContract(_cns, "SomeContract") {}
      
          function someMethod(
                  bytes _sign, 
                  bytes32 _objectId, 
                  bytes32 _dataHash, 
                  bytes32 _p0, 
                  uint _p1, 
                  bytes32 _p2) {
      
              // create all parameters hash
              bytes32 hash = calcEnvHash('someMethod');
              hash = sha3(hash, _objectId);
              hash = sha3(hash, _dataHash);
              hash = sha3(hash, _p0);
              hash = sha3(hash, _p1);
              hash = sha3(hash, _p2);
              // get end user's addresss
              address endUserAddr = Utils.recoverAddress(hash, _sign);
              if (!allowUsers[endUserAddr]) throw;
      
              // remove dataobject
              DataObject object = DataObject(GMO_CNS.getLatestContract("DataObject"));
              object.remove(_objectId);
          }
      }
      

Note

  • msg.sender

    Calling the Contract function is done with the signature of the account for payment.

    "msg.sender" is an account designated to each service provider for payment and is not the end user.

    The signature of the end user is passed as the first parameter, bytes _sign, from which we verify the signature and get the address of the end user.

  • Simplified implementation

    In the example above, we are implementing logic directly in SomeContract for clarity, but in fact it is necessary to implement it separately as in basic contract configuration.

    For details on how to implement the original Contract, refer to the following sources.

results matching ""

    No results matching ""