public new static WalletData ot_dynamic_cast(Storable pObject)
    {
        IntPtr     cPtr = otapiPINVOKE.WalletData_ot_dynamic_cast(Storable.getCPtr(pObject));
        WalletData ret  = (cPtr == IntPtr.Zero) ? null : new WalletData(cPtr, false);

        return(ret);
    }
        public async Task SetWalletInfo(WalletId walletId, WalletBlobInfo blob)
        {
            if (walletId == null)
            {
                throw new ArgumentNullException(nameof(walletId));
            }
            using (var ctx = _ContextFactory.CreateContext())
            {
                var walletData = new WalletData()
                {
                    Id = walletId.ToString()
                };
                walletData.SetBlobInfo(blob);
                var entity = await ctx.Wallets.AddAsync(walletData);

                entity.State = EntityState.Modified;
                try
                {
                    await ctx.SaveChangesAsync();
                }
                catch (DbUpdateException) // Does not exists
                {
                    entity.State = EntityState.Added;
                    await ctx.SaveChangesAsync();
                }
            }
        }
Exemple #3
0
    public IEnumerator getMyRoom()
    {
        var wait = 0;

        yield return(new WaitForSeconds(wait));

        wait = 2;
        WalletData wd             = WalletManager.Instance.GetSelectedWalletData();
        var        getOpenRequest = new EthCallUnityRequest(WalletManager.Instance.networkUrl);

        if (wd.address != null)
        {
            var getOpenInput = contract.createGetMyRoomCallInput();
            yield return(getOpenRequest.SendRequest(getOpenInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest()));

            if (getOpenRequest.Exception == null)
            {
                var topScoreUser = contract.decodeGetOpen(getOpenRequest.Result);
                Debug.Log("No error");
                foreach (int i in topScoreUser)
                {
                }
                wait = 3;
            }
            else
            {
                Debug.Log("error");
                Debug.Log(getOpenRequest.Exception.ToString());
            }
        }
    }
Exemple #4
0
        public void DeleteWallet(WalletModel wallet)
        {
            WalletData data   = new WalletData(_config);
            string     userid = User.FindFirstValue(ClaimTypes.NameIdentifier);

            data.DeleteWallet(wallet, userid);
        }
 public void AddOrUpdateWallet(WalletData entity, Action <ResponseBase> callback)
 {
     Task.Factory.StartNew(() => {
         Guid messageId = Guid.NewGuid();
         try {
             entity.ModifiedOn = DateTime.Now;
             AddOrUpdateWalletRequest request = new AddOrUpdateWalletRequest {
                 LoginName = LoginName,
                 MessageId = messageId,
                 Timestamp = DateTime.Now,
                 Data      = entity
             };
             request.SignIt(Password);
             using (var service = CreateService()) {
                 ResponseBase response = service.AddOrUpdateWallet(request);
                 callback?.Invoke(response);
             }
         }
         catch (CommunicationException e) {
             Global.DebugLine(e.Message, ConsoleColor.Red);
             callback?.Invoke(ResponseBase.ClientError(messageId, e.Message));
         }
         catch (Exception e) {
             Global.Logger.Error(e.Message, e);
             callback?.Invoke(ResponseBase.ClientError(messageId, e.Message));
         }
     });
 }
Exemple #6
0
        public static (Features.Wallet.Types.Wallet wallet, ExtKey key) GenerateBlankWalletWithExtKey(string name, string password)
        {
            var    mnemonic    = new Mnemonic("grass industry beef stereo soap employ million leader frequent salmon crumble banana");
            ExtKey extendedKey = mnemonic.DeriveExtKey(password);

            var walletFile = new Features.Wallet.Types.Wallet
            {
                Name          = name,
                EncryptedSeed = extendedKey.PrivateKey.GetEncryptedBitcoinSecret(password, KnownNetworks.Main).ToWif(),
                ChainCode     = extendedKey.ChainCode,
                CreationTime  = DateTimeOffset.Now,
                Network       = KnownNetworks.Main,
                walletStore   = new WalletMemoryStore(),
                BlockLocator  = new List <uint256>()
                {
                    KnownNetworks.Main.GenesisHash
                },
                AccountsRoot = new List <IAccountRoot> {
                    new AccountRoot()
                    {
                        Accounts = new List <IHdAccount>(), CoinType = KnownNetworks.Main.Consensus.CoinType, LastBlockSyncedHash = KnownNetworks.Main.GenesisHash, LastBlockSyncedHeight = 0
                    }
                },
            };

            WalletData data = walletFile.walletStore.GetData();

            data.BlockLocator = walletFile.BlockLocator;
            data.WalletName   = walletFile.Name;
            data.WalletTip    = new Utilities.HashHeightPair(KnownNetworks.Main.GenesisHash, 0);
            walletFile.walletStore.SetData(data);

            return(walletFile, extendedKey);
        }
Exemple #7
0
        public bool Login(LoginRequest _loginRequest)
        {
            WalletData ret = null;

            if (_loginRequest.CreateNewWallet &&
                _loginRequest.PassCode != "" &&
                _loginRequest.WalletName != "" &&
                !FileBinIO.Exists(_loginRequest.WalletName))
            {
                ret = GenerateWallet(_loginRequest.PassCode, _loginRequest.WalletName);
            }
            else if (_loginRequest.CreateNewWallet)
            {
                Console.WriteLine("Missing wallet name or password, or password requirements do not match, or wallet already exists");
                return(false);    //Todo: add exception error
            }
            else
            {
                ret = LoginWallet(_loginRequest);
            }

            Data = ret;

            return(Data == null ? false : true);
        }
    // We create the function which will check the balance of the address and return a callback with a decimal variable
    public IEnumerator CreateAccountCoroutine(string password, string accountName)
    {
        yield return(0); // allow UI to update

        //transictionScripts _transictionScripts = new transictionScripts();
        //var name = StartCoroutine(_transictionScripts.createUsers(accountName));

        CreateAccount(password, (address, encryptedJson, privateKey) =>
        {
            // We just print the address and the encrypted json we just created
            Debug.Log(address);
            Debug.Log(encryptedJson);

            WalletData w     = new WalletData();
            w.name           = accountName;
            w.address        = address;
            w.cachedPassword = password;
            w.encryptedJson  = encryptedJson;
            w.privateKey     = privateKey;

            walletList.Add(w);

            newAccountAdded.Invoke();
            loadingFinished.Invoke();
            Debug.Log(accountName);
            getScripts.Instance.B_openRooms();
            RefreshTopPanelView();
        });
    }
Exemple #9
0
        public List <WalletModel> GetWallets()
        {
            string             id     = User.FindFirstValue(ClaimTypes.NameIdentifier);
            WalletData         data   = new WalletData(_config);
            List <WalletModel> output = data.GetCurrentUsersWallets(id);

            return(output);
        }
Exemple #10
0
        public void AddOrUpdateWalletAsync(WalletData entity, Action <ResponseBase, Exception> callback)
        {
            DataRequest <WalletData> request = new DataRequest <WalletData>()
            {
                Data = entity
            };

            RpcRoot.PostAsync(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IWalletController.AddOrUpdateWallet), request, request, callback);
        }
Exemple #11
0
            public void AddOrUpdateWalletAsync(WalletData entity, Action <ResponseBase, Exception> callback)
            {
                DataRequest <WalletData> request = new DataRequest <WalletData>()
                {
                    Data = entity
                };

                PostAsync(SControllerName, nameof(IWalletController.AddOrUpdateWallet), request.ToQuery(SingleUser.LoginName, SingleUser.PasswordSha1), request, callback);
            }
Exemple #12
0
 public void LogOut()
 {
     //Only do something if we're actually logged in
     if (Data != null)
     {
         WriteWalletData(Data, Data.WalletName);
         Data = null;    //Remove data
     }
 }
Exemple #13
0
        /// <summary>
        /// Create a Recent wallet
        /// </summary>
        /// <returns>Wallet data</returns>
        public WalletData createWallet()
        {
            var ecKey = EthECKey.GenerateKey();

            _wallet = new WalletData {
                address = ecKey.GetPublicAddress(), PK = ecKey.GetPrivateKey()
            };
            _web3 = new Web3(new Nethereum.Web3.Accounts.Account(_wallet.PK), NodeUrl);
            return(_wallet);
        }
Exemple #14
0
        /// <summary>
        /// Create a Recent wallet given a Private Key
        /// </summary>
        /// <param name="PK">The Private key</param>
        /// <returns>Wallet data</returns>
        public WalletData importWalletFromPK(string PK)
        {
            var address = EthECKey.GetPublicAddress(PK);

            _wallet = new WalletData {
                address = address, PK = PK
            };
            _web3 = new Web3(new Nethereum.Web3.Accounts.Account(_wallet.PK), NodeUrl);
            return(_wallet);
        }
Exemple #15
0
        public static void issue_burn_tx(
            WalletConfig config,
            Keychain keychain,
            ulong amount,
            ulong minimumConfirmations,
            uint maxOutputs
            )
        {
            keychain = Keychain.Burn_enabled(keychain, Identifier.Zero());

            var chainTip      = Checker.get_tip_from_node(config);
            var currentHeight = chainTip.Height;

            var _ = Checker.refresh_outputs(config, keychain);

            var keyId = keychain.Root_key_id();

// select some spendable coins from the walvar
            var coins = WalletData.Read_wallet(
                config.DataFileDir, walletData => walletData.Select(
                    keyId.Clone(),
                    amount,
                    currentHeight,
                    minimumConfirmations,
                    maxOutputs,
                    false));


            Log.Debug("selected some coins - {}", coins.Length);

            var(partsArray, _) = inputs_and_change(coins, config, keychain, amount);

            var parts = partsArray.ToList();

            // add burn output and fees
            var fee = Types.tx_fee((uint)coins.Length, 2, null);

            parts.Add(c => c.Output(amount - fee, Identifier.Zero()));

            // finalize the burn transaction and send
            var(txBurn, _) = Build.Transaction(parts.ToArray(), keychain);
            txBurn.Validate(keychain.Secp);

            var txHex = HexUtil.to_hex(Ser.Ser_vec(txBurn));

            var url = $"{config.CheckNodeApiHttpAddr}/v1/pool/push";

            var json = JsonConvert.SerializeObject(new TxWrapper {
                TxHex = txHex
            });

            var res = ApiClient.PostContentAsync(url, new StringContent(json, Encoding.UTF8, "application/json")).Result;

            Log.Debug("{StatusCode}", res.StatusCode);
        }
Exemple #16
0
    public IEnumerator GetName(int id, BigInteger bet, int prn, string selection = "JoinRoom")
    {
        var wait = 0;

        wait = 2;
        WalletData wd             = WalletManager.Instance.GetSelectedWalletData();
        var        getOpenRequest = new EthCallUnityRequest(WalletManager.Instance.networkUrl);

        if (wd.address != null)
        {
            var getNameInput = contract.createGetNameCallInput(wd.address);
            yield return(getOpenRequest.SendRequest(getNameInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest()));

            if (getOpenRequest.Exception == null)
            {
                var topScoreUser = contract.decodeGetName(getOpenRequest.Result);
                Debug.Log("No error");
                if (topScoreUser == "")
                {
                    Debug.Log(topScoreUser);
                    yield return(transictionScripts.Instance.createUsers(wd.name));

                    switch (selection)
                    {
                    case "JoinRoom":
                        transictionScripts.Instance._JoinRoom(id, bet, prn);
                        break;

                    case "CreateRoom":
                        transictionScripts.Instance._CreateRoom();
                        break;
                    }
                }
                else
                {
                    switch (selection)
                    {
                    case "JoinRoom":
                        transictionScripts.Instance._JoinRoom(id, bet, prn);
                        break;

                    case "CreateRoom":
                        transictionScripts.Instance._CreateRoom();
                        break;
                    }
                }
            }
            else
            {
                Debug.Log("error");
                Debug.Log(getOpenRequest.Exception.ToString());
            }
        }
    }
Exemple #17
0
        public static void WriteWalletData(WalletData _WalletDataToBlob, string _walletName)
        {
            //TODO: Move serialization to FileBinIO to avoid duplicating code on multiple objects
            MemoryStream    memorystream = new MemoryStream();
            BinaryFormatter bf           = new BinaryFormatter();

            bf.Serialize(memorystream, _WalletDataToBlob);
            byte[] BlobData = memorystream.ToArray();

            FileBinIO.WriteBin(BlobData, _walletName);
        }
Exemple #18
0
        private static void AddWallet(string accountName, string address, string encryptedJson, string privateKey)
        {
            WalletData wallet = new WalletData(accountName, address, encryptedJson, privateKey);

            walletList.Add(wallet);

            SaveWallets();

            _currentWalletIndex = walletList.Count - 1;             // Use this wallet as current
            walletCreated?.Invoke();
        }
Exemple #19
0
        /// <summary>
        /// Create a seed phrase and a Recent wallet
        /// </summary>
        /// <returns>The seed phrase</returns>
        public string createAndRetrieveSeedPhrase()
        {
            Wallet wallet  = new Wallet(Wordlist.English, WordCount.Twelve);
            var    account = wallet.GetAccount(0);

            _wallet = new WalletData {
                address = account.Address, PK = account.PrivateKey
            };
            _web3 = new Web3(account, NodeUrl);
            return(string.Join(" ", wallet.Words));
        }
Exemple #20
0
            public void AddOrUpdateWalletAsync(WalletData entity, Action <ResponseBase, Exception> callback)
            {
                DataRequest <WalletData> request = new DataRequest <WalletData>()
                {
                    LoginName = SingleUser.LoginName,
                    Data      = entity
                };

                request.SignIt(SingleUser.PasswordSha1);
                PostAsync(SControllerName, nameof(IControlCenterController.AddOrUpdateWallet), null, request, callback);
            }
Exemple #21
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            Login loginForm = new Login();

            WalletData = null;  //Clear data

            // Show the settings form
            loginForm.Show();

            this.Close();
        }
Exemple #22
0
        /// <summary>
        /// Create a Recent wallet
        /// </summary>
        /// <returns>Wallet data</returns>
        public WalletData createWallet()
        {
            var ecKey = EthECKey.GenerateKey();

            _wallet = new WalletData {
                address = ecKey.GetPublicAddress(), PK = ecKey.GetPrivateKey()
            };
            _web3 = new Web3(new Nethereum.Web3.Accounts.Account(_wallet.PK), _nodeUrl);
            _paymentChannelsContract = _web3.Eth.GetContract(PaymentChannelsABI, _paymentChannelsContractAddress);
            _validatorsContract      = _web3.Eth.GetContract(ValidatorsABI, _validatorsContractAddress);
            return(_wallet);
        }
Exemple #23
0
 private void UpdateWallet(WalletData entity)
 {
     if (VirtualRoot.IsMinerStudio)
     {
         RpcRoot.Server.WalletService.AddOrUpdateWalletAsync(entity, null);
     }
     else
     {
         var repository = NTMinerRoot.CreateLocalRepository <WalletData>();
         repository.Update(entity);
     }
 }
Exemple #24
0
 private void AddWallet(WalletData entity)
 {
     if (VirtualRoot.IsMinerStudio)
     {
         Server.ControlCenterService.AddOrUpdateWalletAsync(entity, null);
     }
     else
     {
         var repository = NTMinerRoot.CreateLocalRepository <WalletData>();
         repository.Add(entity);
     }
 }
Exemple #25
0
 public void RefreshWalletData()
 {
     try
     {
         WalletData = JsonSerializer.ReadFromJsonFile <WalletData>(WalletDataFileName);
     }
     catch (FileNotFoundException ex)
     {
         // File does not exist yet do just create an empty data file
         WalletData = new WalletData();
     }
 }
Exemple #26
0
 private void UpdateWallet(WalletData entity)
 {
     if (UseRemoteWalletList)
     {
         Server.ControlCenterService.AddOrUpdateWallet(entity, null);
     }
     else
     {
         var repository = NTMinerRoot.CreateLocalRepository <WalletData>();
         repository.Update(entity);
     }
 }
Exemple #27
0
        private WalletData GenerateWallet(string _passCode, string _walletName)
        {
            WalletData ret = null;

            if (PasswordManager.CheckPassRequirements(_passCode))
            {
                ret = makeWallet(_passCode, _walletName);
                WriteWalletData(ret, _walletName);
            }

            return(ret);
        }
Exemple #28
0
        /// <summary>
        /// Create a Recent wallet given a Private Key
        /// </summary>
        /// <param name="PK">The Private key</param>
        /// <returns>Wallet data</returns>
        public WalletData importWalletFromPK(string PK)
        {
            var address = EthECKey.GetPublicAddress(PK);

            _wallet = new WalletData {
                address = address, PK = PK
            };
            _web3 = new Web3(new Nethereum.Web3.Accounts.Account(_wallet.PK, _chainId), _nodeUrl);
            _paymentChannelsContract = _web3.Eth.GetContract(PaymentChannelsABI, _paymentChannelsContractAddress);
            _validatorsContract      = _web3.Eth.GetContract(ValidatorsABI, _validatorsContractAddress);
            return(_wallet);
        }
Exemple #29
0
        public PlayerDataHelper(SpilUnityImplementationBase Instance)
        {
            string walletString    = Instance.GetWalletFromSdk();
            string inventoryString = Instance.GetInvetoryFromSdk();

            if (walletString != null && inventoryString != null)
            {
                WalletData    walletData    = JsonHelper.getObjectFromJson <WalletData>(walletString);
                InventoryData inventoryData = JsonHelper.getObjectFromJson <InventoryData>(inventoryString);

                AddDataToHelper(walletData != null ? walletData.currencies : null, inventoryData != null ? inventoryData.items : null);
            }
        }
Exemple #30
0
        /// <summary>
        /// Create a seed phrase and a Recent wallet
        /// </summary>
        /// <returns>The seed phrase</returns>
        public string createAndRetrieveSeedPhrase()
        {
            Wallet wallet  = new Wallet(Wordlist.English, WordCount.Twelve);
            var    account = wallet.GetAccount(0);

            _wallet = new WalletData {
                address = account.Address, PK = account.PrivateKey
            };
            _web3 = new Web3(new Nethereum.Web3.Accounts.Account(_wallet.PK, _chainId), _nodeUrl);
            _paymentChannelsContract = _web3.Eth.GetContract(PaymentChannelsABI, _paymentChannelsContractAddress);
            _validatorsContract      = _web3.Eth.GetContract(ValidatorsABI, _validatorsContractAddress);
            return(string.Join(" ", wallet.Words));
        }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WalletData obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
        public void ProcessPlayerDataResponse(ResponseEvent response)
        {
            WalletData receivedWallet = null;
            InventoryData receivedInventory = null;

            if (response.data.HasField ("wallet")) {

                JSONObject walletJSON = response.data.GetField ("wallet");

                receivedWallet = new WalletData ();

                if (walletJSON.HasField ("currencies")) {
                    receivedWallet.currencies = new List<PlayerCurrencyData> ();

                    JSONObject currenciesJSON = walletJSON.GetField ("currencies");

                    for (int i = 0; i < currenciesJSON.Count; i++) {
                        PlayerCurrencyData currency = new PlayerCurrencyData ();

                        currency.id = (int)currenciesJSON.list [i].GetField ("id").n;
                        currency.currentBalance = (int)currenciesJSON.list [i].GetField ("currentBalance").n;
                        currency.delta = (int)currenciesJSON.list [i].GetField ("delta").n;

                        receivedWallet.currencies.Add (currency);
                    }
                }

                receivedWallet.offset = (int)walletJSON.GetField ("offset").n;
                receivedWallet.logic = walletJSON.GetField ("logic").str;

            }

            if (response.data.HasField ("inventory")) {

                JSONObject inventoryJSON = response.data.GetField ("inventory");

                receivedInventory = new InventoryData ();

                if (inventoryJSON.HasField ("items")) {
                    receivedInventory.items = new List<PlayerItemData> ();

                    JSONObject itemsJSON = inventoryJSON.GetField ("items");

                    for (int i = 0; i < itemsJSON.Count; i++) {
                        PlayerItemData item = new PlayerItemData ();

                        item.id = (int)itemsJSON.list [i].GetField ("id").n;
                        item.amount = (int)itemsJSON.list [i].GetField ("amount").n;
                        item.delta = (int)itemsJSON.list [i].GetField ("delta").n;

                        receivedInventory.items.Add (item);
                    }
                }

                receivedInventory.offset = (int)inventoryJSON.GetField ("offset").n;
                receivedInventory.logic = inventoryJSON.GetField ("logic").str;

            }

            CalculatePlayerDataResponse (receivedWallet, receivedInventory);
        }
 internal static HandleRef getCPtr(WalletData obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
        private void CalculatePlayerDataResponse(WalletData receivedWallet, InventoryData receivedInventory)
        {
            bool updated = false;
            PlayerDataUpdatedData updatedData = new PlayerDataUpdatedData ();

            if (receivedWallet != null) {

                for (int i = 0; i < Wallet.currencies.Count; i++) {
                    Wallet.currencies[i].delta = 0;
                }

                if (Wallet.offset < receivedWallet.offset && receivedWallet.currencies.Count > 0) {

                    for (int i = 0; i < receivedWallet.currencies.Count; i++) {
                        for (int j = 0; j < Wallet.currencies.Count; j++) {
                            if (receivedWallet.logic.Equals ("CLIENT")) {
                                if (Wallet.currencies [j].id == receivedWallet.currencies [i].id && receivedWallet.currencies [i].delta != 0) {
                                    int updatedBalance = 0;

                                    if (Wallet.offset == 0 && receivedWallet.offset != 0) {
                                        updatedBalance = receivedWallet.currencies [i].currentBalance;
                                    } else {
                                        updatedBalance = Wallet.currencies [j].currentBalance + receivedWallet.currencies [i].delta;

                                        if (updatedBalance < 0) {
                                            updatedBalance = 0;
                                        }
                                    }

                                    Wallet.currencies [j].currentBalance = updatedBalance;

                                    updated = true;
                                    updatedData.currencies.Add (Wallet.currencies [j]);
                                }
                            } else if (receivedWallet.logic.Equals ("SERVER")) {

                            }
                        }
                    }

                }

                Wallet.offset = receivedWallet.offset;
                Wallet.logic = receivedWallet.logic;

            }

            if (receivedInventory != null) {
                for (int i = 0; i < Inventory.items.Count; i++) {
                    Inventory.items[i].delta = 0;
                }

                if(Inventory.offset < receivedInventory.offset && receivedInventory.items.Count > 0){
                    List<PlayerItemData> itemsToBeAdded = new List<PlayerItemData>();

                    for(int i = 0; i < receivedInventory.items.Count; i++){
                        for(int j = 0; j < Inventory.items.Count; j++){
                            if(receivedInventory.logic.Equals("CLIENT")){
                                if(Inventory.items[j].id == receivedInventory.items[i].id && receivedInventory.items[i].delta != 0){
                                    int updatedAmount = Inventory.items[j].amount + receivedInventory.items[i].delta;

                                    Inventory.items[j].amount = updatedAmount;
                                } else {
                                    itemsToBeAdded.Add(receivedInventory.items[i]);
                                }

                                updated = true;
                            } else if(receivedInventory.logic.Equals("SERVER")){

                            }
                        }

                        updatedData.items.Add(receivedInventory.items[i]);
                    }

                    for(int i = 0; i < itemsToBeAdded.Count; i++){
                        SpilItemData item = GetItemFromObjects(itemsToBeAdded[i].id);

                        if(item != null && itemsToBeAdded[i].amount > 0){
                            PlayerItemData playerItem = new PlayerItemData();
                            playerItem.id = item.id;
                            playerItem.name = item.name;
                            playerItem.type = item.type;
                            playerItem.amount = itemsToBeAdded[i].amount;
                            playerItem.value = itemsToBeAdded[i].value;
                            playerItem.delta = 0;

                            Inventory.items.Add(playerItem);

                            updated = true;
                        }
                    }
                }

                Inventory.offset = receivedInventory.offset;
                Inventory.logic = receivedInventory.logic;

            }

            if (updated) {
                updatedData.reason = PlayerDataUpdateReasons.ServerUpdate;

                SpilUnityImplementationBase.firePlayerDataUpdated (JsonHelper.getJSONFromObject (updatedData));
            }
        }