using System; using System.Threading.Tasks; using Nethereum.Hex.HexConvertors.Extensions; using Nethereum.Hex.HexTypes; using Nethereum.JsonRpc.Client; using Nethereum.RPC.Eth; namespace Nethereum.RPC.Personal { /// /// personal_unlockAccount /// Unlock an account /// Parameters /// string, address of the account to unlock /// string, passphrase of the account to unlock (optional in console, user will be prompted) /// integer, unlock account for duration seconds (optional) /// Return /// boolean indication if the account was unlocked /// Example /// personal.unlockAccount(eth.coinbase, "mypasswd", 300) /// public class PersonalUnlockAccount : RpcRequestResponseHandler, IPersonalUnlockAccount { public PersonalUnlockAccount(IClient client) : base(client, ApiMethods.personal_unlockAccount.ToString()) { } /// /// This is compatible with newer versions of Geth /// public Task SendRequestAsync(string address, string passPhrase, ulong? durationInSeconds, object id = null) { if (address == null) throw new ArgumentNullException(nameof(address)); if (passPhrase == null) throw new ArgumentNullException(nameof(passPhrase)); return base.SendRequestAsync(id, address.EnsureHexPrefix(), passPhrase, durationInSeconds); } /// /// This is compatible with older versions of Geth and Parity /// public Task SendRequestAsync(string address, string passPhrase, HexBigInteger durationInSeconds, object id = null) { if (address == null) throw new ArgumentNullException(nameof(address)); if (passPhrase == null) throw new ArgumentNullException(nameof(passPhrase)); return base.SendRequestAsync(id, address.EnsureHexPrefix(), passPhrase, durationInSeconds); } #if !DOTNET35 public async Task SendRequestAsync(EthCoinBase coinbaseRequest, string passPhrase, object id = null) { if (coinbaseRequest == null) throw new ArgumentNullException(nameof(coinbaseRequest)); if (passPhrase == null) throw new ArgumentNullException(nameof(passPhrase)); return await base.SendRequestAsync(id, await coinbaseRequest.SendRequestAsync(), passPhrase) .ConfigureAwait(false); } #endif public RpcRequest BuildRequest(string address, string passPhrase, int? durationInSeconds, object id = null) { if (address == null) throw new ArgumentNullException(nameof(address)); if (passPhrase == null) throw new ArgumentNullException(nameof(passPhrase)); return base.BuildRequest(id, address.EnsureHexPrefix(), passPhrase, durationInSeconds); } } }