예제 #1
0
        public async Task <AccountInfoOM> GetNewAddress(string tag)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithParameterList("GetNewAddress", new[] { tag }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            AccountInfoOM responseValue = response.GetResult <AccountInfoOM>();

            return(responseValue);
        }
예제 #2
0
        public async Task <AccountInfoOM> GetDefaultAccount()
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithNoParameters("GetDefaultAccount", 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            AccountInfoOM responseValue = response.GetResult <AccountInfoOM>();

            return(responseValue);
        }
예제 #3
0
        public static async Task <ApiResponse> CreateNewPaymentRequest(string tag, long amount, string comment)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                Accounts       accounts    = new Accounts();
                PaymentRequest request     = new PaymentRequest();
                PayRequest     pay         = new PayRequest();
                AccountInfoOM  accountInfo = await accounts.GetNewAddress(tag);

                PayRequestOM result = await request.CreateNewPaymentRequest(accountInfo.Address, tag, amount, comment);

                if (result != null)
                {
                    pay.AccountId   = result.AccountId;
                    pay.Amount      = result.Amount;
                    pay.Comment     = result.Comment;
                    pay.Id          = result.Id;
                    pay.Tag         = result.Tag;
                    pay.Timestamp   = result.Timestamp;
                    response.Result = Newtonsoft.Json.Linq.JToken.FromObject(pay);
                }
                else
                {
                    response.Result = null;
                }
            }
            catch (ApiCustomException ex)
            {
                Logger.Singleton.Error(ex.Message);
                response.Error = new ApiError(ex.ErrorCode, ex.Message);
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error(ex.Message);
                response.Error = new ApiError(ex.HResult, ex.Message);
            }
            return(response);
        }
예제 #4
0
        public static async Task <ApiResponse> GetNewAddress(string tag)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                Accounts      account = new Accounts();
                AccountInfo   info    = new AccountInfo();
                AccountInfoOM result  = await account.GetNewAddress(tag);

                if (result != null)
                {
                    info.Address    = result.Address;
                    info.Balance    = result.Balance;
                    info.IsDefault  = result.IsDefault;
                    info.PublicKey  = result.PublicKey;
                    info.Tag        = result.Tag;
                    info.WatchOnly  = result.WatchOnly;
                    response.Result = Newtonsoft.Json.Linq.JToken.FromObject(info);
                }
                else
                {
                    response.Result = null;
                }
            }
            catch (ApiCustomException ex)
            {
                Logger.Singleton.Error(ex.ToString());
                response.Error = new ApiError(ex.ErrorCode, ex.ToString());
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error(ex.ToString());
                response.Error = new ApiError(ex.HResult, ex.ToString());
            }
            return(response);
        }