updateFile: Update FILE with ACL

Updating file with ACL (access control).


Z.com Cloud Block Chain**

Processing Sequence

The basic processing sequence is the same as Register FILE Process.

In the case of registration, an error (400 Bad Request) occurs when data of the target key 'IS' registered, and in the case of updating, an error (400 Bad Response) occurs when the data of the key 'IS NOT' registered.

In this update process, only the data content is updated. For changing the file name, it is necessary to change it by Update DataObject.

SendData SomeContract

  • 1 AltExecCnsContract#updateFile

    We call AltExecCnsContract from client's logic.

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

  • 1.1 API PUT 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 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, and the third parameter is bytes 32: dataHash.

    In the contract method, the FileObject is created based on the specified object ID hash value and the data hash value is set.

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

    For details, please refer to FileObjectLogic.

  • 1.1.4 canWrite

    Within the API server, check the data on Ethereum as to whether the end user (address of) has write permission for the target data.

  • 1.1.5 put

    The API server writes the target data to the data storage area.

  • 1.1.6 fixData

    The API server performs Fix processing of Hash value using the key of this service.

    The Hash value of FileObject can not be changed unless both Hash value writing (1.1.3) by the user with write permission to FileObject and Hash value writing by key of this service are made.

    This prevents the writing of unilateral Hash value by service provider or this service.

Implementation by the service provider

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

  • ClientSide

    • AltExecCnsContract#updateFile

      var contract = new AltExecCnsContract(account, '__CNS_ADDRESS__');
      contract.updateData('__PASSWORD__', 'SomeContract', 'someMethod', '__OBJECT_ID__', file, ['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 parameter is bytes 32: fileNameHash, and the fourth parameter is 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;
              // fileobject creation
              FileObject object = FileObject(GMO_CNS.getLatestContract("FileObject"));
              object.setHashByWriter(_objectId, msg.sender, _dataHash);


  • 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 ""