Ejemplo n.º 1
0
        public async Task <IEthereumUser> AddAsyncCall(string login, string password, string firstName, string lastName,
                                                       string info)
        {
            var param = new
            {
                Login     = CastHelper.StringToBytes32(login),
                Password  = CastHelper.StringToBytes32(password),
                FirstName = CastHelper.ToUserNameType(firstName),
                LastName  = CastHelper.ToUserNameType(lastName),
                Info      = CastHelper.ToDescriptionType(info ?? ""),
            };

            // send call to get output value
            var result = await _contractService.AddAsyncCall(
                param.Login, param.Password, param.FirstName, param.LastName, param.Info);

            // send transaction & wait it to be mined
            var transactionHash = await _contractService.AddAsync(_walletAddress,
                                                                  param.Login, param.Password, param.FirstName, param.LastName, param.Info,
                                                                  _gas
                                                                  );

            var receipt = await _contractService.MineAndGetReceiptAsync(transactionHash);

            var user = await _contractService.GetAsyncCall(param.Login);

            return(user.ToReadable());
        }
Ejemplo n.º 2
0
        public async Task <IEthereumFile> AddAsync(
            string login, string password,
            string type, string hash, long size, string name, string description, DateTime created)
        {
            var param = new
            {
                Login       = CastHelper.StringToBytes32(login),
                Password    = CastHelper.StringToBytes32(password),
                Mime        = CastHelper.StringToBytes32(type),
                Hash        = CastHelper.ToDescriptionType(hash),
                Size        = CastHelper.StringToBytes32(size.ToString()),
                Name        = CastHelper.ToFileNameType(name),
                Description = CastHelper.ToDescriptionType(description),
                Timestamp   = (int)((DateTimeOffset)created).ToUnixTimeSeconds()
            };

            // send call to get output value
            var response = await _contractService.AddFileAsyncCall(
                param.Login, param.Password,
                param.Mime, param.Hash, param.Size, param.Name, param.Description, param.Timestamp);

            // send transaction & wait it to be mined
            var transactionHash = await _contractService.AddFileAsync(
                _walletAddress,
                param.Login, param.Password,
                param.Mime, param.Hash, param.Size, param.Name, param.Description, param.Timestamp,
                _gas);

            var receipt = await _contractService.MineAndGetReceiptAsync(transactionHash);

            return(await GetAsyncCall(login, password, response.Fileindex));
        }
Ejemplo n.º 3
0
        public static async Task DeployLibrary()
        {
            // 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 library
            WriteLog("Create transaction to deploy library\n" +
                     $"  gas: {_gas.Value}\n" +
                     $"  . . . Getting hash . . .");
            var transactionHash =
                await UsersAndFilesService.DeployLibraryAsync(_web3, EV.WalletAddress, _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.LibraryAddress = receipt.ContractAddress;
            WriteLog($"\n>>> Library Address: {receipt.ContractAddress}");
        }
Ejemplo n.º 4
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" +
                     ">>>");
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public async Task T1_DeployLibrary()
        {
            // 1. Unclock Account
            var unlockRes = await _web3.Personal.UnlockAccount.SendRequestAsync(
                SenderAddress, Password, new HexBigInteger(120));

            Assert.True(unlockRes);

            // 2. Deploy library
            var transactionHash =
                await UsersAndFilesService.DeployLibraryAsync(_web3,
                                                              SenderAddress, Gas);

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

            LibraryAddress = receipt.ContractAddress;

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