public void TestCaseThree()
        {
            MasterCard person1MasterCard1 = new MasterCard(100m);
            MasterCard person1MasterCard2 = new MasterCard(100m);

            WalletType person1Wallet = new WalletType();

            person1Wallet.AddCard(person1MasterCard1)
            .AddCard(person1MasterCard2);

            WalletPerson person1 = new WalletPerson();

            person1.AddWallet(person1Wallet);

            MasterCard person2MasterCard = new MasterCard(100m);
            Visa       person2Visa       = new Visa(100m);

            WalletType person2Wallet = new WalletType();

            person2Wallet.AddCard(person2MasterCard)
            .AddCard(person2Visa);

            WalletPerson person2 = new WalletPerson();

            person2.AddWallet(person2Wallet);

            Assert.Equal(10m, person1.CalculateTotalInterest());
            Assert.Equal(10m, person1Wallet.CalculateTotalInterest());
            Assert.Equal(15m, person2.CalculateTotalInterest());
            Assert.Equal(15m, person2Wallet.CalculateTotalInterest());
        }
Exemplo n.º 2
0
        private IWallet SetupWallet(WalletType walletType)
        {
            switch (walletType)
            {
            case WalletType.KeyStore:
            {
                IKeyStoreConfig config = new KeyStoreConfig();
                config.KeyStoreDirectory = _keyStorePath;
                ISymmetricEncrypter encrypter = new AesEncrypter(config, LimboLogs.Instance);
                return(new DevKeyStoreWallet(
                           new FileKeyStore(config, new EthereumJsonSerializer(), encrypter, new CryptoRandom(), LimboLogs.Instance),
                           LimboLogs.Instance));
            }

            case WalletType.Memory:
                return(new DevWallet(new WalletConfig(), LimboLogs.Instance));

            case WalletType.ProtectedKeyStore:
            {
                IKeyStoreConfig config = new KeyStoreConfig();
                config.KeyStoreDirectory = _keyStorePath;
                ISymmetricEncrypter encrypter = new AesEncrypter(config, LimboLogs.Instance);
                var wallet = new ProtectedKeyStoreWallet(
                    new FileKeyStore(config, new EthereumJsonSerializer(), encrypter, new CryptoRandom(), LimboLogs.Instance),
                    new ProtectedPrivateKeyFactory(new CryptoRandom(), Timestamper.Default),
                    Timestamper.Default,
                    LimboLogs.Instance);
                wallet.SetupTestAccounts(3);
                return(wallet);
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(walletType), walletType, null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="wallet"></param>
        /// <param name="wType"></param>
        private static void SetWallet(string wallet, WalletType wType)
        {
            string sWallet = string.Empty;

            switch (wType)
            {
            case WalletType.Private:
                sWallet = "PrivateWallet";
                break;

            case WalletType.Public:
                sWallet = "PublicWallet";
                break;
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(_filename);

            if (doc.DocumentElement.Attributes[sWallet] == null)
            {
                doc.DocumentElement.Attributes.Append(doc.CreateAttribute(sWallet));
            }
            doc.DocumentElement.SetAttribute(sWallet, wallet);
            doc.Save(_filename);
        }
Exemplo n.º 4
0
 public string CreateWallet(WalletType Wallet, string ID, TickerSymbol Symbol = TickerSymbol.BTC)
 {
     if (walletDat.Exists(ID, Wallet, Symbol))
     {
         return(GetAddress(Wallet, ID, Symbol)); // if wallet already exists get current address
     }
     else
     {
         if (Wallet == WalletType.HotWallet)
         {
             return(string.Empty); // will add code later
         }
         else if (Wallet == WalletType.VaultWallet)
         {
             return(VaultWalletCreate(ID, Symbol));
         }
         else if (Wallet == WalletType.ExchangeWallet)
         {
             return(string.Empty); // will add code later
         }
         else
         {
             return(string.Empty);
         }
     }
 }
Exemplo n.º 5
0
 public string CreateAddress(WalletType Wallet, string ID, TickerSymbol Symbol = TickerSymbol.BTC)
 {
     if (walletDat.Exists(ID, Wallet))
     {
         return(GetAddress(Wallet, ID, Symbol));
     }
     else
     {
         //create wallets if there is no existing wallet
         if (Wallet == WalletType.ExchangeWallet)
         {
             return(ExchangeWalletCreate(ID, Symbol));
         }
         else if (Wallet == WalletType.HotWallet)
         {
             return(HotWalletCreate(ID, Symbol));
         }
         else if (Wallet == WalletType.VaultWallet)
         {
             return(VaultWalletCreate(ID, Symbol));
         }
         else
         {
             return("NO WALLET CREATED"); // probably add error codes later
         }
     }
 }
Exemplo n.º 6
0
        public IActionResult PayCheck(WalletType walletType, decimal amount)
        {
            //Single 有,且僅有一個.
            var walletService = _walletService.Single(x => x.WalletType == walletType);

            return(Ok());
        }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (WalletType != null)
         {
             hashCode = hashCode * 59 + WalletType.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (SupportsInputToUniqueAddress != null)
         {
             hashCode = hashCode * 59 + SupportsInputToUniqueAddress.GetHashCode();
         }
         if (SupportsInputToSharedAddressWithMemo != null)
         {
             hashCode = hashCode * 59 + SupportsInputToSharedAddressWithMemo.GetHashCode();
         }
         if (DefaultInputAddressType != null)
         {
             hashCode = hashCode * 59 + DefaultInputAddressType.GetHashCode();
         }
         if (ExtraData != null)
         {
             hashCode = hashCode * 59 + ExtraData.GetHashCode();
         }
         return(hashCode);
     }
 }
    private static Bitmap GetBitmap(WalletType type)
    {
        Uri uri = new($"avares://WalletWasabi.Fluent/Assets/WalletIcons/{ThemeHelper.CurrentTheme}/generic.png");

        switch (type)
        {
        case WalletType.Coldcard:
            uri = new($"avares://WalletWasabi.Fluent/Assets/WalletIcons/{ThemeHelper.CurrentTheme}/coldcard.png");
            break;

        case WalletType.Trezor:
            uri = new($"avares://WalletWasabi.Fluent/Assets/WalletIcons/{ThemeHelper.CurrentTheme}/trezor.png");
            break;

        case WalletType.Ledger:
            uri = new($"avares://WalletWasabi.Fluent/Assets/WalletIcons/{ThemeHelper.CurrentTheme}/ledger.png");
            break;

        case WalletType.Normal:
        case WalletType.Unknown:
            uri = new($"avares://WalletWasabi.Fluent/Assets/WalletIcons/{ThemeHelper.CurrentTheme}/normal.png");
            break;
        }

        return(AssetHelpers.GetBitmapAsset(uri));
    }
Exemplo n.º 9
0
        /// <summary>
        /// Returns true if OutputAddressesModel1 instances are equal
        /// </summary>
        /// <param name="other">Instance of OutputAddressesModel1 to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(OutputAddressesModel1 other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;

            return 
                (
                    Address == other.Address ||
                    Address != null &&
                    Address.Equals(other.Address)
                ) && 
                (
                    Memo == other.Memo ||
                    Memo != null &&
                    Memo.Equals(other.Memo)
                ) && 
                (
                    Nickname == other.Nickname ||
                    Nickname != null &&
                    Nickname.Equals(other.Nickname)
                ) && 
                (
                    WalletType == other.WalletType ||
                    WalletType != null &&
                    WalletType.Equals(other.WalletType)
                ) && 
                (
                    SessionToken == other.SessionToken ||
                    SessionToken != null &&
                    SessionToken.Equals(other.SessionToken)
                );
        }
Exemplo n.º 10
0
        /// <summary>
        /// Makes ScriptSig based on wallet type.
        /// </summary>
        /// <param name="hash">Hes string to put inside of ScriptSig.</param>
        /// <param name="type">Type of wallet that is supposed to sign this transaction.</param>
        /// <returns>ScriptSig</returns>
        public static string BuildScript(string hash, WalletType type)
        {
            string result = "";

            if (type == WalletType.Normal)
            {
                //76 a9 14 - 88 ac
                result =
                    NumberConversions.IntToHex((int)OPCodes.opcodetype.OP_DUP, 1) +
                    NumberConversions.IntToHex((int)OPCodes.opcodetype.OP_HASH160, 1) +
                    NumberConversions.IntToHex((UInt64)hash.Length / 2, 1) +
                    hash +
                    NumberConversions.IntToHex((int)OPCodes.opcodetype.OP_EQUALVERIFY, 1) +
                    NumberConversions.IntToHex((int)OPCodes.opcodetype.OP_CHECKSIG, 1);
            }
            else if (type == WalletType.Electrum)
            {
                //01 ff 16 fd 00
                result =
                    NumberConversions.IntToHex(0x01, 1) +
                    NumberConversions.IntToHex((int)OPCodes.opcodetype.OP_INVALIDOPCODE, 1) +
                    NumberConversions.IntToHex(0x16, 1) +
                    NumberConversions.IntToHex((int)OPCodes.opcodetype.OP_PUBKEYHASH, 1) +
                    NumberConversions.IntToHex((int)OPCodes.opcodetype.OP_0, 1) +
                    hash;
            }
            else if (type == WalletType.Core)
            {
                result = "";
            }
            return(result);
        }
 /// <summary>
 /// Initializes a new instance of the CreateWalletRequest class.
 /// </summary>
 /// <param name="type">Possible values include: 'Trusted',
 /// 'Trading'</param>
 public CreateWalletRequest(WalletType type, string name, string description)
 {
     Type        = type;
     Name        = name;
     Description = description;
     CustomInit();
 }
Exemplo n.º 12
0
        public bool Thaw(string memberId, WalletType walletType, decimal money, string remark, out string error)
        {
            error = string.Empty;
            if (money == 0)
            {
                return(true);
            }
            using (var dbContext = new WalletDbContext())
            {
                var wallet =
                    dbContext.Set <Models.Wallet>()
                    .FirstOrDefault(w => w.WalletType == walletType && w.MemberId.Equals(memberId, StringComparison.OrdinalIgnoreCase));
                if (wallet == null)
                {
                    error = "冻结金额不足";
                    return(false);
                }
                else
                {
                    if (wallet.Frozen < money)
                    {
                        error = "冻结金额不足";
                        return(false);
                    }
                    wallet.Available += money;
                    wallet.Frozen    -= money;
                    dbContext.Set <Models.Wallet>().Attach(wallet);
                    dbContext.Entry(wallet).State = EntityState.Modified;
                }

                dbContext.SaveChanges();
                return(true);
            }
        }
Exemplo n.º 13
0
        //
        public async Task <string> TransferWallets(decimal amount, string currency, string walletfrom, string walletto)
        {
            WalletType formatedWalletfrom = (WalletType)Enum.Parse(typeof(WalletType), walletfrom);
            WalletType formatedWalletto   = (WalletType)Enum.Parse(typeof(WalletType), walletto);
            var        result             = await Bitfinex.TransferWallets(amount, currency, formatedWalletfrom, formatedWalletto);

            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the CreateWalletRequest class.
 /// </summary>
 /// <param name="type">Possible values include: 'Trusted',
 /// 'Trading'</param>
 public CreateWalletRequest(WalletType type, string clientId = default(string), string name = default(string), string description = default(string))
 {
     ClientId    = clientId;
     Type        = type;
     Name        = name;
     Description = description;
     CustomInit();
 }
Exemplo n.º 15
0
        public async Task SavePaymentAddress(string address, WalletType walletType, int id)
        {
            var entry = await Get(s => s.Id == id);

            entry.Address    = address;
            entry.WalletType = walletType;

            await Update(entry);
        }
Exemplo n.º 16
0
 public Wallet(byte[] w_id, IxiNumber w_balance)
 {
     id             = w_id;
     balance        = w_balance;
     type           = WalletType.Normal;
     requiredSigs   = 1;
     allowedSigners = null;
     data           = null;
     publicKey      = null;
 }
Exemplo n.º 17
0
 public WalletModel(string name, WalletType type, bool @default, double balance, List <DateOffsetBalance> dateOffsetBalance, WalletColor color, DateTime lastUpdated)
 {
     Name              = name;
     Type              = type;
     Default           = @default;
     Balance           = balance;
     DateOffsetBalance = dateOffsetBalance;
     Color             = color;
     LastUpdated       = lastUpdated;
 }
Exemplo n.º 18
0
 public Wallet()
 {
     id             = null;
     balance        = new IxiNumber();
     type           = WalletType.Normal;
     requiredSigs   = 1;
     allowedSigners = null;
     data           = null;
     publicKey      = null;
 }
Exemplo n.º 19
0
        public AddedWalletPageViewModel(string walletName, WalletType type)
        {
            WalletName = walletName;
            Type       = type;

            NextCommand = ReactiveCommand.Create(() =>
            {
                Navigate().Clear();
            });
        }
Exemplo n.º 20
0
        /// <summary>
        /// Create new wallet on user account. For use, must authorize User
        /// </summary>
        /// <param name="currencyCode">Currency code.</param>
        /// <param name="name">Wallet name</param>
        /// <param name="walletType">Wallet type: crypto/fiat.</param>
        /// <returns>Created wallet data.</returns>
        public WalletItem CreateNewWallet(string currencyCode, string name, WalletType walletType)
        {
            RestClient rc = new RestClient(config.ApiDoubleBalancesUrl);

            NewWalletRequest nw = new NewWalletRequest(currencyCode, walletType.ToString(), name);

            rc.AddOwnHeaderToRequest(new AutorizeData(config));
            rc.SendPOST(nw);

            return(Tools.TryGetResponse <WalletList>(rc).Balances[0]);
        }
Exemplo n.º 21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="walletType"></param>
        /// /// <param name="ownerId"></param>
        /// <returns></returns>
        public static Wallet FindByOwnerId(WalletType walletType, long ownerId)
        {
            if (ownerId < 1)
            {
                return(null);
            }

            var repository = RepositoryManager.GetRepository <IWalletRepository>(ModuleEnvironment.ModuleName);
            var model      = repository.FindByOwnerId(walletType, ownerId);

            return(model);
        }
Exemplo n.º 22
0
        internal static string ToSerializedValue(this WalletType value)
        {
            switch (value)
            {
            case WalletType.Trusted:
                return("Trusted");

            case WalletType.Trading:
                return("Trading");
            }
            return(null);
        }
Exemplo n.º 23
0
        public ActionResult List(WalletType walletType, string memberId)
        {
            ViewBag.WalletType = walletType;
            ViewBag.MemberId   = memberId;

            var wallet = _walletService.GetWalletByMemberId(memberId, walletType) ??
                         new Models.Wallet {
                WalletType = walletType, MemberId = memberId
            };

            return(View(wallet));
        }
        internal static string ToSerializedValue(this WalletType value)
        {
            switch (value)
            {
            case WalletType.Deposit:
                return("Deposit");

            case WalletType.Withdrawal:
                return("Withdrawal");
            }
            return(null);
        }
Exemplo n.º 25
0
        public bool Draw(string memberId, WalletType walletType, decimal money, string remark, out string error, string tag = null, string toMemberId = null, bool drawFrozen = false)
        {
            error = string.Empty;
            if (money == 0)
            {
                return(true);
            }

            using (var dbContext = new WalletDbContext())
            {
                var wallet =
                    dbContext.Set <Models.Wallet>()
                    .FirstOrDefault(w => w.WalletType == walletType && w.MemberId == memberId);

                if (drawFrozen)
                {
                    if (wallet == null || wallet.Frozen < money)
                    {
                        error = "冻结余额不足";
                        return(false);
                    }

                    wallet.Frozen -= money;
                }
                else
                {
                    if (wallet == null || wallet.Available < money)
                    {
                        error = "余额不足";
                        return(false);
                    }

                    wallet.Available -= money;
                }
                dbContext.Set <Models.Wallet>().Attach(wallet);
                dbContext.Entry(wallet).State = EntityState.Modified;

                WalletBill walletBill = new WalletBill();
                walletBill.Id           = KeyGenerator.GetGuidKey();
                walletBill.MemberId     = memberId;
                walletBill.BillType     = BillType.TakeOut;
                walletBill.WalletType   = walletType;
                walletBill.Money        = money;
                walletBill.Remark       = remark;
                walletBill.BillTag      = tag;
                walletBill.CreateTime   = DateTime.Now;
                walletBill.FromMemberId = toMemberId;
                dbContext.WalletBills.Add(walletBill);
                dbContext.SaveChanges();
                return(true);
            }
        }
Exemplo n.º 26
0
        public ApiResult Get(WalletType walletType = WalletType.Cash, int pageNo = 1, int limit = 10)
        {
            var result = new ApiResult();
            int totalCount;
            var listWalletBill = _walletService.GetWalletBillByMemberId(AuthorizedUser.Id, pageNo, limit, out totalCount, walletType);
            var data           = new
            {
                TotalCount = totalCount,
                Bills      = listWalletBill
            };

            result.SetData(data);
            return(result);
        }
Exemplo n.º 27
0
        public async Task <List <BaseInfo> > TransferWallets(
            decimal amount,
            string currency,
            WalletType walletfrom,
            WalletType walletto)
        {
            var args = GeneratePayload("TransferWallets");

            args.Add("amount", amount.ToString());
            args.Add("currency", currency.ToUpper());
            args.Add("walletfrom", ConvertHelper.ObtainEnumValue(walletfrom));
            args.Add("walletto", ConvertHelper.ObtainEnumValue(walletto));

            return(await ProcessAuthenticated <List <BaseInfo> >(args));
        }
Exemplo n.º 28
0
        public Wallet(byte[] bytes)
        {
            using (MemoryStream m = new MemoryStream(bytes))
            {
                using (BinaryReader reader = new BinaryReader(m))
                {
                    try
                    {
                        int idLen = reader.ReadInt32();
                        id = reader.ReadBytes(idLen);
                        string balance_str = reader.ReadString();
                        balance = new IxiNumber(balance_str);

                        int dataLen = reader.ReadInt32();
                        if (dataLen > 0)
                        {
                            data = reader.ReadBytes(dataLen);
                        }

                        type         = (WalletType)reader.ReadByte();
                        requiredSigs = reader.ReadByte();
                        byte num_allowed_sigs = reader.ReadByte();
                        if (num_allowed_sigs > 0)
                        {
                            allowedSigners = new byte[num_allowed_sigs][];
                            for (int i = 0; i < num_allowed_sigs; i++)
                            {
                                int signerLen = reader.ReadInt32();
                                allowedSigners[i] = reader.ReadBytes(signerLen);
                            }
                        }
                        else
                        {
                            allowedSigners = null;
                        }

                        int pkLen = reader.ReadInt32();
                        if (pkLen > 0)
                        {
                            publicKey = reader.ReadBytes(pkLen);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="walletType"></param>
        /// <param name="ownerId"></param>
        /// <returns></returns>
        public Wallet FindByOwnerId(WalletType walletType, long ownerId)
        {
            var sqlName   = this.FormatSqlName("SelectByOwnerId");
            var sqlParams = new Dictionary <string, object>(1);

            sqlParams.Add("WalletType", walletType);
            sqlParams.Add("OwnerId", ownerId);
            var    dataTable = SqlHelper.ExecuteDataSet(sqlName, sqlParams).Tables[0];
            Wallet model     = null;

            if (dataTable.Rows.Count > 0)
            {
                model = this.Convert(dataTable.Rows[0]);
            }
            return(model);
        }
Exemplo n.º 30
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (WalletType != null)
         {
             hashCode = hashCode * 59 + WalletType.GetHashCode();
         }
         if (SessionToken != null)
         {
             hashCode = hashCode * 59 + SessionToken.GetHashCode();
         }
         return(hashCode);
     }
 }