Пример #1
0
        public async Task <string[]> GenerateSeed(string aezeedPassphrase = default(string))
        {
            var genSeedResponse = new GenSeedResponse();

            try
            {
                walletRpcChannel = new Grpc.Core.Channel(HostName, new SslCredentials(Cert));
                walletUnlocker   = new WalletUnlocker.WalletUnlockerClient(walletRpcChannel);
                await walletRpcChannel.ConnectAsync();

                var genSeedRequest = new GenSeedRequest();
                if (!string.IsNullOrEmpty(aezeedPassphrase))
                {
                    genSeedRequest.AezeedPassphrase = ByteString.CopyFromUtf8(aezeedPassphrase);
                }
                genSeedResponse = await walletUnlocker.GenSeedAsync(genSeedRequest);

                walletRpcChannel.ShutdownAsync().Wait();
            } catch (RpcException e)
            {
                walletRpcChannel.ShutdownAsync().Wait();
                return(new string[] { e.Status.Detail });
            }
            return(genSeedResponse.CipherSeedMnemonic.ToArray());;
        }
Пример #2
0
        public async Task <string> UnlockWallet(string walletPassword, string[] mnemonic)
        {
            walletRpcChannel = new Grpc.Core.Channel(HostName, new SslCredentials(Cert));
            walletUnlocker   = new WalletUnlocker.WalletUnlockerClient(walletRpcChannel);
            await walletRpcChannel.ConnectAsync();

            var initWalletRequest = new InitWalletRequest();

            initWalletRequest.WalletPassword = ByteString.CopyFromUtf8(walletPassword);
            initWalletRequest.CipherSeedMnemonic.AddRange(mnemonic);
            try
            {
                var initWalletResponse = await walletUnlocker.InitWalletAsync(initWalletRequest);

                walletRpcChannel.ShutdownAsync().Wait();


                return("unlocked");
            } catch (RpcException e)
            {
                if (e.Status.Detail == "wallet already exists")
                {
                    var unlockWalletRequest = new UnlockWalletRequest()
                    {
                        WalletPassword = ByteString.CopyFromUtf8(walletPassword)
                    };
                    var unlockWalletResponse = await walletUnlocker.UnlockWalletAsync(unlockWalletRequest);

                    walletRpcChannel.ShutdownAsync().Wait();


                    return("unlocked");
                }
                Debug.Log(e);
            }
            walletRpcChannel.ShutdownAsync().Wait();

            return("not unlocked");
        }