Ejemplo n.º 1
0
        /// <summary>
        /// Releases the contract.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="abi">The abi.</param>
        /// <param name="byteCode">The byte code.</param>
        /// <param name="gas">The gas.</param>
        /// <returns></returns>
        /// <exception cref="Exception">Contract {name}</exception>
        public async Task <bool> ReleaseContractAsync(string name, string abi, string byteCode, int gas)
        {
            // check contractName
            var existing = await this.GetContractFromTableStorageAsync(name);

            if (existing != null)
            {
                throw new Exception($"Contract {name} is present in storage");
            }
            try
            {
                var resultUnlocking = await web3.Personal.UnlockAccount.SendRequestAsync(this.accountAddress, password, 60);

                if (resultUnlocking)
                {
                    var transactionHash = await web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, this.accountAddress, new Nethereum.Hex.HexTypes.HexBigInteger(gas), 2);

                    EthereumContract eci = new EthereumContract()
                    {
                        RowKey          = name,
                        Abi             = abi,
                        Bytecode        = byteCode,
                        TransactionHash = transactionHash
                    };
                    return(await SaveContractToTableStorageAsync(eci));
                }
            }
            catch (Exception exc)
            {
                this.logger.LogError(exc, "An error occured on Ethereum service");
                return(false);
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Used to get email hash for display.
        /// </summary>
        /// <param name="ethContract"></param>
        /// <param name="emailId"></param>
        /// <returns></returns>
        protected internal async Task <string> GetEmailHashWithoutTransaction(EthereumContract ethContract, string emailId)
        {
            var contract = web3.Eth.GetContract(ethContract.ContractABI, ethContract.ContractAddress);
            var function = contract.GetFunction("getEmailHash");
            var result   = await function.CallAsync <string>(emailId).ConfigureAwait(false);

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Used to get the email status and current step being executed.
        /// </summary>
        /// <param name="ethContract"></param>
        /// <param name="emailId"></param>
        /// <returns></returns>
        protected internal async Task <int> UpdateEmailStatus(EthereumContract ethContract, string emailId)
        {
            var contract = web3.Eth.GetContract(ethContract.ContractABI, ethContract.ContractAddress);
            var function = contract.GetFunction("updateEmailStatus");
            var result   = await function.CallAsync <int>(emailId).ConfigureAwait(false);

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Used by the sender to get the email hash provided by the recipient.
        /// </summary>
        /// <param name="ethContract"></param>
        /// <param name="sender"></param>
        /// <param name="emailId"></param>
        /// <returns></returns>
        protected internal async Task <string> GetEmailHashWithTransaction(EthereumContract ethContract, EthereumUser sender, string emailId)
        {
            var contract = web3.Eth.GetContract(ethContract.ContractABI, ethContract.ContractAddress);
            var txCount  = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(sender.PublicAddress).ConfigureAwait(false);

            var function = contract.GetFunction("getEmailHash");
            var data     = function.GetData(emailId);
            var encoded  = web3.OfflineTransactionSigning.SignTransaction(sender.PrivateKey, ethContract.ContractAddress, 0, txCount.Value, 1000000000000L, 900000, data);

            return(await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(encoded).ConfigureAwait(false));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Used by the recipient to confirm the email receival. The recipient uses this method to create a transaction on Ethereum with the received email hash and the public encryption key of the public/private generated RSA encryption keypair.
        /// </summary>
        /// <param name="ethContract"></param>
        /// <param name="recipient"></param>
        /// <param name="emailId"></param>
        /// <param name="emailHash"></param>
        /// <param name="encryptionPublicKey"></param>
        /// <returns></returns>
        protected internal async Task <string> ConfirmReceivalAndUploadEmailHash(EthereumContract ethContract, EthereumUser recipient, string emailId, string emailHash, string encryptionPublicKey)
        {
            var contract = web3.Eth.GetContract(ethContract.ContractABI, ethContract.ContractAddress);
            var txCount  = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(recipient.PublicAddress).ConfigureAwait(false);

            var function = contract.GetFunction("confirmReceivalAndUploadEmailHash");
            var data     = function.GetData(emailId, emailHash, encryptionPublicKey);
            var encoded  = web3.OfflineTransactionSigning.SignTransaction(recipient.PrivateKey, ethContract.ContractAddress, 0, txCount.Value, 1000000000000L, 900000, data);

            return(await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(encoded).ConfigureAwait(false));
        }
        private void RegisterEmail_Load(object sender, RibbonUIEventArgs e)
        {
            blockchainHelper = new BlockchainHelper();

            // Ethereum contract details
            ethContract = new EthereumContract();
            ethContract.ContractAddress = Constants.ContractAddress;
            ethContract.ContractABI     = Constants.ContractABI;

            // Get sender's saved Ethereum account details (If exists)
            GetSenderInfo();
        }
Ejemplo n.º 7
0
        public frmEmailStatus(EthereumContract eContract, string eId)
        {
            InitializeComponent();

            blockchainHelper = new BlockchainHelper();

            ethContract                 = new EthereumContract();
            ethContract.ContractABI     = eContract.ContractABI;
            ethContract.ContractAddress = eContract.ContractAddress;

            emailId = eId;
        }
        private void ReadEncryptedEmail_Load(object sender, RibbonUIEventArgs e)
        {
            blockchainHelper = new BlockchainHelper();
            securityHelper   = new SecurityHelper();
            fileHelper       = new FileOperationsHelper();

            ethContract = new EthereumContract();
            ethContract.ContractAddress = Constants.ContractAddress;
            ethContract.ContractABI     = Constants.ContractABI;

            // Get recipient's saved Ethereum account details (If exists)
            GetRecipientInfo();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Saves the contract to table storage.
        /// </summary>
        /// <param name="contract">The contract.</param>
        /// <returns></returns>
        public async Task <bool> SaveContractToTableStorageAsync(EthereumContract contract)
        {
            StorageCredentials  credentials = new StorageCredentials(storageAccount, storageKey);
            CloudStorageAccount account     = new CloudStorageAccount(credentials, true);
            var client = account.CreateCloudTableClient();

            var tableRef = client.GetTableReference("ethtransactions");
            await tableRef.CreateIfNotExistsAsync();

            TableOperation ops = TableOperation.InsertOrMerge(contract);
            await tableRef.ExecuteAsync(ops);

            return(true);
        }
Ejemplo n.º 10
0
 public async Task <IEnumerable <EthereumContract> > CreateContractAsync(EthereumContract contract)
 {
     return(await Post <EthereumContract, IEnumerable <EthereumContract> >($"/v1/{_coinType}/{_network}/newcontract", contract));
 }
Ejemplo n.º 11
0
 public Task <IEnumerable <EthereumContract> > CreateContract([FromBody] EthereumContract contract)
 {
     return(_service.CreateContractAsync(contract));
 }