Example #1
0
 public void OpenWallet(Wallet wallet, string password, bool isAutoLock)
 {
     if (rpcServer == null)
     {
         rpcServer = new RpcServer(this, wallet, password, isAutoLock, Fixed8.Zero);
     }
     rpcServer.SetWallet(wallet, password, isAutoLock);
 }
Example #2
0
        /// <summary>
        /// 将钱包解锁指定时长,单位秒
        /// </summary>
        /// <param name="_params[0]">钱包密码</param>
        /// <param name="_params[1]">解锁钱包的秒数,600=10分钟</param>
        /// <returns>解锁结果</returns>
        private JObject Unlock(JArray _params)
        {
            if (ExtensionSettings.Default.WalletConfig.Path.Trim().Length < 1)
            {
                throw new RpcException(-500, "Wallet file is exists.");
            }

            if (_params.Count < 2)
            {
                throw new RpcException(-501, "parameter is error.");
            }

            string password = _params[0].AsString();

            if (!VerifyPW(password))
            {
                throw new RpcException(-501, $"password max length {MaxPWLength}");
            }

            int duration = (int)_params[1].AsNumber();

            if (Unlocking)
            {
                throw new RpcException(-502, "wallet is unlocking....");
            }

            Unlocking = true;
            try
            {
                if (wallet == null)
                {
                    wallet = OpenWallet(ExtensionSettings.Default.WalletConfig.Indexer, ExtensionSettings.Default.WalletConfig.Path, password);
                    walletTimeLock.SetDuration(wallet == null ? 0 : duration);
                    rpcServer.SetWallet(wallet);
                    return($"success");
                }
                else
                {
                    bool ok = walletTimeLock.UnLock(wallet, password, duration);
                    return(ok ? "success" : "failure");
                }
            }
            finally
            {
                Unlocking = false;
            }
        }
Example #3
0
        // 设置钱包
        public void SetWallet(Wallet wallet)
        {
            rpcserver?.SetWallet(wallet);

            eventHandler.SetWallet(wallet);
        }