updateData: Update FILE with ACL

Updating file with ACL (access control).

API

Z.com Cloud Block Chain

Processing Sequence

SendData SomeContract

  • 1 AltExecCnsContract#deleteFile

    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 DELETE file

    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 file 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.

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

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

    For details, please refer to FileObjectLogic.

  • 1.1.4 deleteFile

    Only contracts which has removal permission for the target file remove the FileObject.

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.deleteFile('__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.

      contract SomeContract is VersionContract {
      
          mapping(address => bool) allowUsers;
          ContractNameService constant GMO_CNS = ContractNameService (0x993e5e0dca2d937a2313db2141d4a5abe51d3ed7);
      
          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 fileobject
              FileObject object = FileObject(GMO_CNS.getLatestContract("FileObject"));
              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 ""