## 5 System Implementation
### Data-Processing Phase
#### 5.2.1 Wine Record Creation Process  
Once a registered node of winemaker role is added to the consortium with its blockchain node as part of the blockchain network, the wine-record creation process will be started after the physical bottled wine is produced, packaged and ready to be shipped at the winemaker point, as the wine record creation process could only be performed by registered nodes of the winemaker role, such as the one performed by the Registered Node A, as described in Figure 12.  
The wine-record creation process starts with the app-backend service, as described in the proposed dNAS system architecture of the Registered Node A. First, a request is sent to its blockchain service instance, by invoking the endpoint of _\"/peer/validate\"_, to confirm if Registered Node A is indeed a part of the consortium based on the on-chain validation with a public key, stored in its own instance of key vault service, compared to the version stored in the on-chain registry. Once it is ascertained that a requesting node is part of the consortium, its app-backend service instance would then be notified, and the off-chain creation process of a wine record would commence, including the processes of creating the actual wine record and storing the full wine record to the database of the app-backend service. Invoking an endpoint of signing operations in the blockchain service would produce and return a signature on a _byte-array_ of the wine identifier, tagging the identifier and device identifier involved in the process. In order to write the required data to an NFC tag, Register Node A will then utilize the NFC-enabled _TagWINE_ mobile application, which only the registered nodes of winemaker role could access, according to the use cases' analysis, to write the wine identifier, signature and the value of write counter on the tag itself. The \"_wine_status_\" and \"_supply_chain_data_\" are then updated: the former will have updated data fields with latest values, while new entries would be created for the latter whenever there is a new activity of any interaction with the tag. The protection mode, with a randomly predefined password automatically injected by the app-backend service, is also applied to NTAG 216 Ferrite NFC tag once the tag-writing process is completed. After completing all the required processes of the off-chain creation operation, the on-chain creation process of a wine record is initiated. The app-backend service will invoke the _create_ endpoint of the blockchain service, with the subset version of the wine record, instead of the full wine record, as the payload of the API call, and perform operations required on both the IPFS network and the blockchain network. Once such a wine record subset is uploaded to the IPFS network via a designated IPFS node, a _46-byte content hash_ based on _SHA256 hash algorithm_ is then returned to the blockchain service. The content hash of IPFS, alongside the public address of the registered node and the unique identifiers of the wine product, tag and device, are all included in the payload when invoking the \"_create_wine_record_\" method of a deployed smart contract with transactions sent to the blockchain network. The state of the on-chain storage of all these payload fields is updated when the transaction is validated and packaged in the block. The new block is mined by one of the blockchain nodes running on the network, with the respective block number and  
Figure 12: The Wine Record Creation Process. transaction hash, and the event of \"_create_wine_record_\" is emitted on-chain and returned to the blockchain service. Both block number and transaction hash are then returned to the app-backend service, and the supply chain data and transaction data of the full wine record stored in the dedicated database of the app-backend service are updated.