Exemple #1
0
        private async void btnKMSSetItem_Click(object sender, EventArgs e)
        {
            if (ValidateKMSSet() == false)
            {
                return;
            }

            if (contractHandler == null &&
                !string.IsNullOrEmpty(txtKMSContractAddress.Text.Trim()))
            {
                Web3 web3 = GetWeb3();
                contractHandler = web3.Eth.GetContractHandler(txtKMSContractAddress.Text.Trim());
            }

            if (contractHandler == null)
            {
                MessageBox.Show("Problem in getting an instance of the Contract Handler. " +
                                "Please try specifying a valid Contract Address", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            StartProgressBar();

            btnKMSSetItem.Enabled = false;
            var encryptedText = RSAEncryptionHelper.Encrypt(txtValue.Text.Trim(), filteredCert);
            var account       = new Nethereum.Web3.Accounts.Account(privateKey);

            var setItemRequest = new SetItemFunction
            {
                Key         = txtKeyName.Text.Trim(),
                Value       = encryptedText,
                FromAddress = account.Address
            };

            // Set the Gas value
            var estimate = await contractHandler
                           .EstimateGasAsync(setItemRequest);

            setItemRequest.Gas = estimate.Value;

            var setItemFunctionTxnReceipt = await contractHandler
                                            .SendRequestAndWaitForReceiptAsync(setItemRequest);

            if (setItemFunctionTxnReceipt != null &&
                setItemFunctionTxnReceipt.BlockNumber.Value > 0)
            {
                string[]     keyCollection = new string[3];
                ListViewItem listItem;
                keyCollection[0] = txtKeyName.Text.Trim();
                keyCollection[1] = encryptedText;
                keyCollection[2] = "";
                listItem         = new ListViewItem(keyCollection);
                listView1.Items.Add(listItem);
            }

            btnKMSSetItem.Enabled = true;

            StopProgressBar();
        }
Exemple #2
0
        protected TransactionResult GivenATransaction <TTransactionMessage>(TTransactionMessage transactionMessage) where TTransactionMessage : FunctionMessage, new()
        {
            TestLogger.LogGivenSendTransaction(transactionMessage);
            var transactionReceipt = ContractHandler.SendRequestAndWaitForReceiptAsync <TTransactionMessage>(transactionMessage).Result;

            return(new TransactionResult(ContractHandler, transactionReceipt, TestLogger, Stateprinter));
        }
Exemple #3
0
        public void ShouldCheckForNewupdate()
        {
            string lookupContractAddress = "0xa454963c7a6dcbdcd0d3fb281f4e67262fb71586";
            string ncContractAddress     = "0x5f51f49e25b2ba1acc779066a2614eb70a9093a0";
            string rpc = Environment.GetEnvironmentVariable("TEST_RPC") ?? "http://localhost:8545";
            string validatorAddress      = "0xc3681dfe99730eb45154208cba7b0df7e705f305";
            string fileToPersistBlockNum = Path.GetTempFileName();

            ResetToSnapshot(rpc);

            // no new update should be seen
            ContractWrapper cw        = new ContractWrapper(lookupContractAddress, rpc, validatorAddress, new MockLogger(), "test", _keyjson, fileToPersistBlockNum);
            bool            hasUpdate = cw.HasNewUpdate().Result;

            hasUpdate.Should().Be(false);


            // Send an update
            // prepare RPC connection to play some tx

            string  contractOwnerPk = "ae29ab491cf53d8b63f281cc5eecdbbac4a992b2a4bf483bacae66dfff0740f0";
            Account account         = new Account(contractOwnerPk);

            // create a web 3 instance
            Web3 web3 = new Web3(account, rpc);

            // hook up to the contract and event
            ContractHandler contractHandler = web3.Eth.GetContractHandler(ncContractAddress);

            // contract gets primed with by ganache start
            // const valAddr = "0xc3681dfe99730eb45154208cba7b0df7e705f305"; // first addr in ganache
            // contract.updateValidator(valAddr, '0x123456', 'parity/parity:v2.3.3', '0x123456', 'https://chainspec', true);

            TransactionReceipt confirmResponse = contractHandler.SendRequestAndWaitForReceiptAsync(new UpdateValidatorFunction
            {
                DockerSha        = new byte[] { 0x0, 0x1, 0x2, 0x3, 0x23 },
                DockerName       = "parity/parity:v2.3.4",
                ChainspecSha     = new byte[] { 0x0, 0x1, 0x2, 0x3, 0x23 },
                ChainspecUrl     = "https://example.com" + new Random().Next(),
                IsSigning        = true,
                ValidatorAddress = validatorAddress
            }).Result;


            bool?hasErrors = confirmResponse.HasErrors();

            if (hasErrors.HasValue && hasErrors.Value)
            {
                throw new ContractException("Unable to confirm update");
            }

            // now an update should be seen
            bool hasUpdate2Nd = cw.HasNewUpdate().Result;

            hasUpdate2Nd.Should().Be(true);
        }
Exemple #4
0
        public Task <TransactionReceipt> SetPoItemAcceptedRequestAndWaitForReceiptAsync(string eShopIdString, BigInteger poNumber, byte poItemNumber, string soNumber, string soItemNumber, CancellationTokenSource cancellationToken = null)
        {
            var setPoItemAcceptedFunction = new SetPoItemAcceptedFunction();

            setPoItemAcceptedFunction.EShopIdString = eShopIdString;
            setPoItemAcceptedFunction.PoNumber      = poNumber;
            setPoItemAcceptedFunction.PoItemNumber  = poItemNumber;
            setPoItemAcceptedFunction.SoNumber      = soNumber.ConvertToBytes32();
            setPoItemAcceptedFunction.SoItemNumber  = soItemNumber.ConvertToBytes32();

            return(ContractHandler.SendRequestAndWaitForReceiptAsync(setPoItemAcceptedFunction, cancellationToken));
        }
 public Task <TransactionReceipt> ApproveRequestAndWaitForReceiptAsync(ApproveFunction ApproveFunction, CancellationTokenSource CancellationToken = null)
 {
     return(ContractHandler.SendRequestAndWaitForReceiptAsync(ApproveFunction, CancellationToken));
 }