예제 #1
0
 public static async Task <WithdrawResponse> WithdrawAllAsync(SessionInfo session, string address, int totp, Currencies currency)
 {
     return(await WithdrawAsync(session, 0, address, totp, currency));
 }
예제 #2
0
        internal override void SetRawResponse(IDictionary<string, object> resp)
        {
            base.SetRawResponse(resp);
            if (resp.ContainsKey("InvalidApiKey"))
            {
                InvalidApiKey = true;
                return;
            }
            if (resp.ContainsKey("LoginRequired"))
            {
                LoginRequired = true;
                return;
            }
            if (resp.ContainsKey("LoginInvalid"))
            {
                WrongUsernameOrPassword = true;
                return;
            }

            if (resp.ContainsKey("SessionCookie") &&
                resp.ContainsKey("AccountId") &&
                resp.ContainsKey("MaxBetBatchSize"))
            {
                Success = true;
                Session = new SessionInfo(
                    (string)resp["SessionCookie"],
                    Convert.ToInt64(resp["AccountId"]),
                    Convert.ToInt32(resp["MaxBetBatchSize"]));
                if (resp.ContainsKey("AccountCookie"))
                    Session.AccountCookie = (string)resp["AccountCookie"];
                if (resp.ContainsKey("ClientSeed"))
                    Session.ClientSeed = Convert.ToInt64(resp["ClientSeed"]);
                if (resp.ContainsKey("BetCount"))
                    Session.BetCount = Convert.ToInt64(resp["BetCount"]);
                if (resp.ContainsKey("BetPayIn"))
                    Session.BetPayIn = Convert.ToDecimal(resp["BetPayIn"]) / 100000000M;
                if (resp.ContainsKey("BetPayOut"))
                    Session.BetPayOut = Convert.ToDecimal(resp["BetPayOut"]) / 100000000M;
                if (resp.ContainsKey("BetWinCount"))
                    Session.BetWinCount = Convert.ToInt64(resp["BetWinCount"]);
                if (resp.ContainsKey("Balance"))
                    Session.Balance = Convert.ToDecimal(resp["Balance"]) / 100000000M;
                if (resp.ContainsKey("Email"))
                    Session.Email = (string)resp["Email"];
                if (resp.ContainsKey("EmergencyAddress"))
                    Session.EmergencyAddress = (string)resp["EmergencyAddress"];
                if (resp.ContainsKey("DepositAddress"))
                    Session.DepositAddress = (string)resp["DepositAddress"];
            }
        }
예제 #3
0
 public static IAsyncResult BeginGetServerSeedHash(SessionInfo session, AsyncCallback complete, object state)
 {
     return(QueueWork(complete, state, () => GetServerSeedHash(session)));
 }
예제 #4
0
 public static IAsyncResult BeginCreateUser(SessionInfo session, string username, string password, AsyncCallback complete, object state)
 {
     return(QueueWork(complete, state, () => CreateUser(session, username, password)));
 }
예제 #5
0
 public static IAsyncResult BeginWithdrawAll(SessionInfo session, string address, Currencies currency, AsyncCallback complete, object state)
 {
     return(QueueWork(complete, state, () => WithdrawAll(session, address, currency)));
 }
예제 #6
0
 public static async Task <GetServerSeedHashResponse> GetServerSeedHashAsync(SessionInfo session)
 {
     Validate(session);
     return(await RequestAsync <GetServerSeedHashResponse>(GetFormDataGetServerSeedHash(session.SessionCookie)));
 }
예제 #7
0
 public static async Task <GetDepositAddressResponse> GetDepositAddressAsync(SessionInfo session, Currencies currency)
 {
     Validate(session);
     return(Process(session, await RequestAsync <GetDepositAddressResponse>(GetFormDataGetDepositAddress(session.SessionCookie, currency)), currency));
 }
예제 #8
0
 public static CreateUserResponse CreateUser(SessionInfo session, string username, string password)
 {
     Validate(session, username, password);
     username = username.Trim();
     return(Process(session, Request <CreateUserResponse>(GetFormDataCreateUser(session.SessionCookie, username, password)), username));
 }
예제 #9
0
 public static WithdrawResponse WithdrawAll(SessionInfo session, string address, int totp, Currencies currency)
 {
     return(Withdraw(session, 0, address, totp, currency));
 }
예제 #10
0
 public static IAsyncResult BeginPlaceAutomatedBets(SessionInfo session, AutomatedBetsSettings settings, AsyncCallback complete, object state)
 {
     return(QueueWork(complete, state, () => PlaceAutomatedBets(session, settings)));
 }
예제 #11
0
        static PlaceAutomatedBetsResponse Process(SessionInfo session, PlaceAutomatedBetsResponse res, AutomatedBetsSettings settings)
        {
            res.Currency = settings.Currency;
            if (res.Success)
            {
                byte[] seed = new byte[res.ServerSeed.Length / 2];
                for (int x = 0; x < seed.Length; ++x)
                {
                    seed[x] = byte.Parse(res.ServerSeed.Substring(x * 2, 2), System.Globalization.NumberStyles.HexNumber);
                }
                byte[]  client = BitConverter.GetBytes(settings.ClientSeed).Reverse().ToArray();
                decimal payin  = settings.StartingPayIn;
                decimal bal    = res.StartingBalance;
                for (int x = 0; x < res.BetCount; ++x)
                {
                    byte[] data = seed.Concat(client).Concat(BitConverter.GetBytes(x).Reverse()).ToArray();
                    using (SHA512 sha512 = CreateSHA512())
                    {
                        byte[] hash  = sha512.ComputeHash(sha512.ComputeHash(data));
                        bool   found = false;
                        while (!found)
                        {
                            for (int y = 0; y <= 61; y += 3)
                            {
                                long result = (hash[y] << 16) | (hash[y + 1] << 8) | hash[y + 2];
                                if (result < 16000000)
                                {
                                    res.Secrets[x] = result % 1000000;
                                    found          = true;
                                    break;
                                }
                            }
                        }
                    }
                    res.PayIns[x] = payin;
                    bal          += payin;
                    bool win = res.Secrets[x] >= settings.GuessLow && res.Secrets[x] <= settings.GuessHigh;
                    if (win)
                    {
                        res.PayOuts[x] = CalculateWinPayout(payin, settings.GuessLow, settings.GuessHigh);
                        bal           += res.PayOuts[x];
                        if (settings.ResetOnWin)
                        {
                            payin = settings.BasePayIn;
                        }
                        else
                        {
                            payin = TruncateSatoshis(payin * (1 + settings.IncreaseOnWinPercent));
                        }
                    }
                    else
                    {
                        if (settings.ResetOnLose || (settings.ResetOnLoseMaxBet && payin == settings.MaxAllowedPayIn))
                        {
                            payin = settings.BasePayIn;
                        }
                        else
                        {
                            payin = TruncateSatoshis(payin * (1 + settings.IncreaseOnLosePercent));
                        }
                    }
                    if (payin < settings.MaxAllowedPayIn && settings.MaxAllowedPayIn != 0)
                    {
                        payin = settings.MaxAllowedPayIn;
                    }
                    if (payin < -bal)
                    {
                        payin = -bal;
                    }
                }
                Debug.Assert(res.TotalPayIn == res.PayIns.Sum());
                Debug.Assert(res.TotalPayOut == res.PayOuts.Sum());

                session[settings.Currency].PauseUpdates();
                try
                {
                    for (int x = 0; x < res.BetCount; ++x)
                    {
                        if (res.Secrets[x] >= settings.GuessLow && res.Secrets[x] <= settings.GuessHigh)
                        {
                            ++session[settings.Currency].BetWinCount;
                        }
                    }
                    session[settings.Currency].BetCount  += res.BetCount;
                    session[settings.Currency].Balance    = res.StartingBalance + res.TotalPayIn + res.TotalPayOut;
                    session[settings.Currency].BetPayIn  += res.TotalPayIn;
                    session[settings.Currency].BetPayOut += res.TotalPayOut;
                }
                finally
                {
                    session[settings.Currency].UnpauseUpdates();
                }
            }
            return(res);
        }
예제 #12
0
 public static IAsyncResult BeginPlaceBet(SessionInfo session, decimal payIn, long guessLow, long guessHigh, int clientSeed, Currencies currency, AsyncCallback complete, object state)
 {
     return(QueueWork(complete, state, () => PlaceBet(session, payIn, guessLow, guessHigh, clientSeed, currency)));
 }
예제 #13
0
 public static IAsyncResult BeginUpdateEmergencyAddress(SessionInfo session, string emergencyAddress, AsyncCallback complete, object state)
 {
     return(QueueWork(complete, state, () => UpdateEmergencyAddress(session, emergencyAddress)));
 }
예제 #14
0
 public static IAsyncResult BeginUpdateEmail(SessionInfo session, string email, AsyncCallback complete, object state)
 {
     return(QueueWork(complete, state, () => UpdateEmail(session, email)));
 }
예제 #15
0
 public static async Task <WithdrawResponse> WithdrawAsync(SessionInfo session, decimal amount, string address, int totp, Currencies currency)
 {
     Validate(session, address);
     return(Process(session, await RequestAsync <WithdrawResponse>(GetFormDataWithdraw(session.SessionCookie, amount, address, totp, currency)), currency));
 }
예제 #16
0
 public static WithdrawResponse Withdraw(SessionInfo session, decimal amount, string address, int totp, Currencies currency)
 {
     Validate(session, address);
     Validate(currency);
     return(Process(session, Request <WithdrawResponse>(GetFormDataWithdraw(session.SessionCookie, amount, address, totp, currency)), currency));
 }
예제 #17
0
 public static async Task <ChangePasswordResponse> ChangePasswordAsync(SessionInfo session, string oldPassword, string newPassword)
 {
     Validate(session);
     return(await RequestAsync <ChangePasswordResponse>(GetFormDataChangePassword(session.SessionCookie, oldPassword, newPassword)));
 }
예제 #18
0
 public static ChangePasswordResponse ChangePassword(SessionInfo session, string oldPassword, string newPassword)
 {
     Validate(session);
     return(Request <ChangePasswordResponse>(GetFormDataChangePassword(session.SessionCookie, oldPassword, newPassword)));
 }
예제 #19
0
 public static async Task <UpdateEmergencyAddressResponse> UpdateEmergencyAddressAsync(SessionInfo session, string emergencyAddress)
 {
     Validate(session);
     if (emergencyAddress != null)
     {
         emergencyAddress = emergencyAddress.Trim();
     }
     return(Process(session, await RequestAsync <UpdateEmergencyAddressResponse>(GetFormDataUpdateEmergencyAddress(session.SessionCookie, emergencyAddress)), emergencyAddress));
 }
예제 #20
0
 public static GetServerSeedHashResponse GetServerSeedHash(SessionInfo session)
 {
     Validate(session);
     return(Request <GetServerSeedHashResponse>(GetFormDataGetServerSeedHash(session.SessionCookie)));
 }
예제 #21
0
 public static async Task <PlaceAutomatedBetsResponse> PlaceAutomatedBetsAsync(SessionInfo session, AutomatedBetsSettings settings)
 {
     Validate(session, settings);
     return(Process(session, await RequestAsync <PlaceAutomatedBetsResponse>(
                        GetFormDataPlaceAutomatedBets(session.SessionCookie, settings)), settings));
 }
예제 #22
0
 public static GetDepositAddressResponse GetDepositAddress(SessionInfo session, Currencies currency)
 {
     Validate(session);
     Validate(currency);
     return(Process(session, Request <GetDepositAddressResponse>(GetFormDataGetDepositAddress(session.SessionCookie, currency)), currency));
 }
예제 #23
0
 public static IAsyncResult BeginGetBalance(SessionInfo session, Currencies currency, AsyncCallback complete, object state)
 {
     return(QueueWork(complete, state, () => GetBalance(session, currency)));
 }
예제 #24
0
 public static PlaceAutomatedBetsResponse PlaceAutomatedBets(SessionInfo session, AutomatedBetsSettings settings)
 {
     Validate(session, settings);
     return(Process(session, Request <PlaceAutomatedBetsResponse>(
                        GetFormDataPlaceAutomatedBets(session.SessionCookie, settings)), settings));
 }
예제 #25
0
 public static IAsyncResult BeginWithdraw(SessionInfo session, decimal amount, string address, int totp, Currencies currency, AsyncCallback complete, object state)
 {
     return(QueueWork(complete, state, () => Withdraw(session, amount, address, totp, currency)));
 }
예제 #26
0
 public static async Task <CreateUserResponse> CreateUserAsync(SessionInfo session, string username, string password)
 {
     Validate(session, username, password);
     username = username.Trim();
     return(Process(session, await RequestAsync <CreateUserResponse>(GetFormDataCreateUser(session.SessionCookie, username, password)), username));
 }
예제 #27
0
        internal override void SetRawResponse(IDictionary<string, object> resp)
        {
            base.SetRawResponse(resp);
            if (resp.ContainsKey("InvalidApiKey"))
            {
                InvalidApiKey = true;
                return;
            }
            if (resp.ContainsKey("LoginRequired"))
            {
                LoginRequired = true;
                return;
            }
            if (resp.ContainsKey("LoginInvalid"))
            {
                WrongUsernameOrPassword = true;
                return;
            }

            if (resp.ContainsKey("SessionCookie") &&
                resp.ContainsKey("AccountId") &&
                resp.ContainsKey("MaxBetBatchSize"))
            {
                Success = true;
                Session = new SessionInfo(
                    (string)resp["SessionCookie"],
                    Convert.ToInt64(resp["AccountId"]),
                    Convert.ToInt32(resp["MaxBetBatchSize"]));
                if (resp.ContainsKey("AccountCookie"))
                    Session.AccountCookie = (string)resp["AccountCookie"];
                if (resp.ContainsKey("Email"))
                    Session.Email = (string)resp["Email"];
                if (resp.ContainsKey("EmergencyAddress"))
                    Session.EmergencyAddress = (string)resp["EmergencyAddress"];

                for (int x = 0; ; ++x)
                {
                    IDictionary<string, object> c = null;
                    SessionInfo.CurrencyInfo ci = null;
                    switch (x)
                    {
                        case 0:
                            c = resp;
                            ci = Session[Currencies.BTC];
                            break;
                        case 1:
                            c = resp.ContainsKey("Doge") ? resp["Doge"] as IDictionary<string, object> : null;
                            ci = Session[Currencies.Doge];
                            break;
                        default:
                            break;
                    }
                    if (ci == null)
                        break;
                    if (c == null)
                        continue;
                    if (c.ContainsKey("BetCount"))
                        ci.BetCount = Convert.ToInt64(c["BetCount"]);
                    if (c.ContainsKey("BetPayIn"))
                        ci.BetPayIn = Convert.ToDecimal(c["BetPayIn"]) / 100000000M;
                    if (c.ContainsKey("BetPayOut"))
                        ci.BetPayOut = Convert.ToDecimal(c["BetPayOut"]) / 100000000M;
                    if (c.ContainsKey("BetWinCount"))
                        ci.BetWinCount = Convert.ToInt64(c["BetWinCount"]);
                    if (c.ContainsKey("Balance"))
                        ci.Balance = Convert.ToDecimal(c["Balance"]) / 100000000M;
                    if (c.ContainsKey("DepositAddress"))
                        ci.DepositAddress = (string)c["DepositAddress"];
                }
            }
        }
예제 #28
0
 public static IAsyncResult BeginChangePassword(SessionInfo session, string oldPassword, string newPassword, AsyncCallback complete, object state)
 {
     return(QueueWork(complete, state, () => ChangePassword(session, oldPassword, newPassword)));
 }