示例#1
0
        // deploys a new Receipt smart contract for the specified file
        // returns the state of the receipt
        public async Task <string> NewReceipt(string registryAddress, string fileId, string fileHash,
                                              string metadataHash, string verifiedBy)
        {
            int state = await NewReceiptPrivate(registryAddress, fileId, fileHash,
                                                metadataHash, verifiedBy);

            // check if it worked
            if (state != 0)
            {
                return(StateConvert.IntToString(state));
            }
            else
            {
                state = await NewReceiptPrivate(registryAddress, fileId, fileHash,
                                                metadataHash, verifiedBy);

                // check if it worked second time
                if (state != 0)
                {
                    return(StateConvert.IntToString(state));
                }
                else
                {
                    throw new Exception("Receipt could not be created");
                }
            }
        }
示例#2
0
        // creates and returns a History object by calling Eth functions GetFileAddressGivenId
        // and GetNumberOfReceipts, which are used to loop a series of calls to
        // GetReceiptAddressAtIndex, GetVerificationDateTime, and GetVerifiedBy
        public async Task <History> GetHistory(string registryAddress, string fileId)
        {
            History history = new History();

            // get address of file contract with corresponding fileid
            string fileAddress = await GetFileAddressGivenId.SendRequestAsync(MyWeb3, registryAddress, fileId);

            // call number of receipts function on file contract
            int numReceipts = await GetNumberOfReceipts.SendRequestAsync(MyWeb3, fileAddress);

            // for each receipt
            for (int i = 0; i < numReceipts; ++i)
            {
                // get receipt address at index
                string receiptAddress = await GetReceiptAddressAtIndex.SendRequestAsync(MyWeb3, fileAddress, i);

                // get datetime
                string dateTime = await GetVerificationDateTime.SendRequestAsync(MyWeb3, receiptAddress);

                // get state of receipt
                string state = StateConvert.IntToString(await GetState.SendRequestAsync(MyWeb3, receiptAddress));

                // get user that created receipt
                string verifiedBy = await GetVerifiedBy.SendRequestAsync(MyWeb3, receiptAddress);

                // add values to History object
                history.AddLine(dateTime, state, verifiedBy);
            }

            return(history);
        }