예제 #1
0
        public static async Task DeployContract()
        {
            // 1. Unclock Account
            var unlockTime = new HexBigInteger(120);

            WriteLog($"Unlock account for {unlockTime.Value}s\n" +
                     $"  address: {EV.WalletAddress}\n" +
                     $"  pass: {EV.WalletPassword}\n\n");
            var unlockRes = await _web3.Personal.UnlockAccount.SendRequestAsync(
                EV.WalletAddress, EV.WalletPassword, unlockTime);

            // 2. Deploy contract
            // Get contract receipt & contractAddress, save contractAdress to file
            WriteLog("\nCreate transaction to deploy contract\n" +
                     $"  gas: {_gas.Value}\n" +
                     $"  library address: {EV.LibraryAddress}");

            var adminBytes = new
            {
                login     = CastHelper.StringToBytes32(admin[0]),
                password  = CastHelper.StringToBytes32(admin[1]),
                firstName = CastHelper.ToUserNameType(admin[2]),
                lastName  = CastHelper.ToUserNameType(admin[3]),
                info      = CastHelper.ToDescriptionType(admin[4]),
            };

            WriteLog("\n  Admin:\n" +
                     $"    login:    {admin[0]}\n" +
                     $"    password: {admin[1]}\n" +
                     $"    name:     {admin[2]} {admin[3]}\n" +
                     $"    info:     {admin[4]}");
            WriteLog("\n  . . . Getting hash . . .");

            var transactionHash =
                await UsersAndFilesService.DeployContractAsync(_web3,
                                                               EV.LibraryAddress,
                                                               EV.WalletAddress,
                                                               adminBytes.login,
                                                               adminBytes.password,
                                                               adminBytes.firstName,
                                                               adminBytes.lastName,
                                                               adminBytes.info,
                                                               _gas);

            WriteLog($"  hash: {transactionHash}");

            // 3. Mine transaction
            WriteLog("\nMine transaction\n" +
                     "  . . . Getting receipt . . .");
            var receipt = await UsersAndFilesService.MineAndGetReceiptAsync(_web3, transactionHash);

            WriteLog($"  gas used: {receipt.GasUsed.Value}");

            EV.ContractAddress = receipt.ContractAddress;
            File.WriteAllText(_output, receipt.ContractAddress);

            WriteLog("\n>>>\n" +
                     $">>> Contract Address: {receipt.ContractAddress}\n" +
                     ">>>");
        }
예제 #2
0
        public async Task T2_DeployContract()
        {
            // 1. Unclock Account
            var unlockRes = await _web3.Personal.UnlockAccount.SendRequestAsync(
                SenderAddress, Password, new HexBigInteger(120));

            Assert.True(unlockRes);

            // 2. Deploy contract
            // Get contract receipt & contractAddress, save contractAdress to file
            var transactionHash =
                await UsersAndFilesService.DeployContractAsync(_web3,
                                                               LibraryAddress,
                                                               SenderAddress,
                                                               Stub.AdminLogin,
                                                               Stub.AdminPassword,
                                                               Stub.FirstName1,
                                                               Stub.LastName1,
                                                               Stub.Info1,
                                                               Gas);

            var receipt = await UsersAndFilesService.MineAndGetReceiptAsync(_web3, transactionHash);

            ContractAddress = receipt.ContractAddress;

            Assert.True(!string.IsNullOrEmpty(transactionHash));
            Assert.NotNull(receipt);
        }