コード例 #1
0
        public static ICurrencyAccount Create(
            Currency currency,
            IHdWallet wallet,
            IAccountDataRepository dataRepository)
        {
            switch (currency)
            {
            case BitcoinBasedCurrency _:
                return(new BitcoinBasedCurrencyAccount(
                           currency,
                           wallet,
                           dataRepository));

            case Atomix.Ethereum _:
                return(new EthereumCurrencyAccount(
                           currency,
                           wallet,
                           dataRepository));

            case Atomix.Tezos _:
                return(new TezosCurrencyAccount(
                           currency,
                           wallet,
                           dataRepository));

            default:
                throw new NotSupportedException($"Not supported currency {currency.Name}");
            }
        }
コード例 #2
0
 public TezosCurrencyAccount(
     Currency currency,
     IHdWallet wallet,
     IAccountDataRepository dataRepository)
     : base(currency, wallet, dataRepository)
 {
 }
コード例 #3
0
        public Account(
            IHdWallet wallet,
            SecureString password,
            ICurrenciesProvider currenciesProvider,
            ClientType clientType,
            Action <MigrationActionType> migrationCompleteCallback = null)
        {
            Wallet = wallet ?? throw new ArgumentNullException(nameof(wallet));

            Currencies = currenciesProvider.GetCurrencies(Network);

            DataRepository = new LiteDbAccountDataRepository(
                pathToDb: Path.Combine(Path.GetDirectoryName(Wallet.PathToWallet), DefaultDataFileName),
                password: password,
                currencies: Currencies,
                network: wallet.Network,
                migrationCompleteCallback);

            CurrencyAccounts = CurrencyAccountCreator.Create(Currencies, wallet, DataRepository);

            UserSettings = UserSettings.TryLoadFromFile(
                pathToFile: $"{Path.GetDirectoryName(Wallet.PathToWallet)}/{DefaultUserSettingsFileName}",
                password: password) ?? UserSettings.DefaultSettings;

            _clientType = clientType;
        }
コード例 #4
0
ファイル: Account.cs プロジェクト: aph5nt/atomex.client.core
        public Account(
            IHdWallet wallet,
            SecureString password,
            ICurrenciesProvider currenciesProvider,
            ISymbolsProvider symbolsProvider)
        {
            Wallet = wallet ?? throw new ArgumentNullException(nameof(wallet));

            Currencies = currenciesProvider.GetCurrencies(Network);
            Symbols    = symbolsProvider.GetSymbols(Network);

            DataRepository = new LiteDbAccountDataRepository(
                pathToDb: $"{Path.GetDirectoryName(Wallet.PathToWallet)}/{DefaultDataFileName}",
                password: password,
                currencies: Currencies,
                network: wallet.Network);

            CurrencyAccounts = Currencies
                               .ToDictionary(
                c => c.Name,
                c => CurrencyAccountCreator.Create(
                    currency: c.Name,
                    wallet: Wallet,
                    dataRepository: DataRepository,
                    currencies: Currencies));

            UserSettings = UserSettings.TryLoadFromFile(
                pathToFile: $"{Path.GetDirectoryName(Wallet.PathToWallet)}/{DefaultUserSettingsFileName}",
                password: password) ?? UserSettings.DefaultSettings;
        }
コード例 #5
0
 public BitcoinBasedCurrencyAccount(
     Currency currency,
     IHdWallet wallet,
     IAccountDataRepository dataRepository)
     : base(currency, wallet, dataRepository)
 {
 }
コード例 #6
0
 public EthereumAccount(
     string currency,
     ICurrencies currencies,
     IHdWallet wallet,
     IAccountDataRepository dataRepository)
     : base(currency, currencies, wallet, dataRepository)
 {
 }
コード例 #7
0
 public BitcoinBasedAccount(
     string currency,
     ICurrencies currencies,
     IHdWallet wallet,
     IAccountDataRepository dataRepository)
     : base(currency, currencies, wallet, dataRepository)
 {
 }
コード例 #8
0
 public static ICurrencyAccount Create(
     string currency,
     IHdWallet wallet,
     IAccountDataRepository dataRepository,
     ICurrencies currencies)
 {
     return(currency switch
     {
         "BTC" => (ICurrencyAccount) new BitcoinBasedAccount(
             currency,
             currencies,
             wallet,
             dataRepository),
         "LTC" => (ICurrencyAccount) new BitcoinBasedAccount(
             currency,
             currencies,
             wallet,
             dataRepository),
         "USDT" => (ICurrencyAccount) new ERC20Account(
             currency,
             currencies,
             wallet,
             dataRepository),
         "USDC" => (ICurrencyAccount) new ERC20Account(
             currency,
             currencies,
             wallet,
             dataRepository),
         "ETH" => (ICurrencyAccount) new EthereumAccount(
             currency,
             currencies,
             wallet,
             dataRepository),
         "NYX" => (ICurrencyAccount) new NYXAccount(
             currency,
             currencies,
             wallet,
             dataRepository),
         "FA2" => (ICurrencyAccount) new FA2Account(
             currency,
             currencies,
             wallet,
             dataRepository),
         "TZBTC" => (ICurrencyAccount) new FA12Account(
             currency,
             currencies,
             wallet,
             dataRepository),
         "XTZ" => (ICurrencyAccount) new TezosAccount(
             currency,
             currencies,
             wallet,
             dataRepository),
         _ => throw new NotSupportedException($"Not supported currency {currency}"),
     });
コード例 #9
0
        protected CurrencyAccount(
            Currency currency,
            IHdWallet wallet,
            IAccountDataRepository dataRepository)
        {
            Currency       = currency;
            Wallet         = wallet;
            DataRepository = dataRepository;

            PreloadBalances();
        }
コード例 #10
0
        public TezosAccount(
            string currency,
            ICurrencies currencies,
            IHdWallet wallet,
            IAccountDataRepository dataRepository)
            : base(currency, currencies, wallet, dataRepository)
        {
            var xtz = Xtz;

            _tezosRevealChecker     = new TezosRevealChecker(xtz);
            _tezosAllocationChecker = new TezosAllocationChecker(xtz);
        }
コード例 #11
0
        public static IList <WalletAddress> ResolvePublicKeys(
            this IList <WalletAddress> addresses,
            ICurrencies currencies,
            IHdWallet wallet)
        {
            foreach (var address in addresses)
            {
                ResolvePublicKey(address, currencies, wallet);
            }

            return(addresses);
        }
コード例 #12
0
        protected CurrencyAccount(
            string currency,
            ICurrencies currencies,
            IHdWallet wallet,
            IAccountDataRepository dataRepository)
        {
            Currency       = currency ?? throw new ArgumentNullException(nameof(currency));
            Currencies     = currencies ?? throw new ArgumentNullException(nameof(currencies));
            Wallet         = wallet ?? throw new ArgumentNullException(nameof(wallet));
            DataRepository = dataRepository ?? throw new ArgumentNullException(nameof(dataRepository));

            LoadBalances();
        }
コード例 #13
0
        public TezosAccount(
            ICurrencies currencies,
            IHdWallet wallet,
            IAccountDataRepository dataRepository)
            : base(TezosConfig.Xtz, currencies, wallet, dataRepository)
        {
            var xtz = Config;

            _tezosRevealChecker     = new TezosRevealChecker(xtz);
            _tezosAllocationChecker = new TezosAllocationChecker(xtz);

            AddressLocker = new ResourceLocker <string>();
        }
コード例 #14
0
        public static WalletAddress ResolvePublicKey(
            this WalletAddress address,
            ICurrencies currencies,
            IHdWallet wallet)
        {
            var currency = currencies.GetByName(address.Currency);

            address.PublicKey = wallet
                                .GetAddress(
                currency: currency,
                keyIndex: address.KeyIndex,
                keyType: address.KeyType)
                                .PublicKey;

            return(address);
        }
コード例 #15
0
        public static ICurrencyAccount CreateCurrencyAccount(
            string currency,
            IHdWallet wallet,
            IAccountDataRepository dataRepository,
            ICurrencies currencies,
            ICurrencyAccount baseChainAccount = null)
        {
            return(currency switch
            {
                "BTC" or "LTC" => (ICurrencyAccount) new BitcoinBasedAccount(
                    currency,
                    currencies,
                    wallet,
                    dataRepository),

                "USDT" or "USDC" or "TBTC" or "WBTC" => new Erc20Account(
                    currency,
                    currencies,
                    wallet,
                    dataRepository),

                "ETH" => new EthereumAccount(
                    currency,
                    currencies,
                    wallet,
                    dataRepository),

                "TZBTC" or "KUSD" => new Fa12Account(
                    currency: currency,
                    tokenContract: currencies
                    .Get <Fa12Config>(currency)
                    .TokenContractAddress,
                    tokenId: 0,
                    currencies: currencies,
                    wallet: wallet,
                    dataRepository: dataRepository,
                    tezosAccount: baseChainAccount as TezosAccount),

                "XTZ" => new TezosAccount(
                    currencies,
                    wallet,
                    dataRepository),

                _ => throw new NotSupportedException($"Not supported currency {currency}."),
            });
コード例 #16
0
 public Fa2Account(
     string currency,
     string tokenContract,
     decimal tokenId,
     ICurrencies currencies,
     IHdWallet wallet,
     IAccountDataRepository dataRepository,
     TezosAccount tezosAccount)
     : base(currency,
            "FA2",
            tokenContract,
            tokenId,
            currencies,
            wallet,
            dataRepository,
            tezosAccount)
 {
 }
コード例 #17
0
        public Account(
            IHdWallet wallet,
            SecureString password,
            IAccountDataRepository dataRepository,
            ICurrenciesProvider currenciesProvider,
            ClientType clientType)
        {
            Wallet         = wallet ?? throw new ArgumentNullException(nameof(wallet));
            DataRepository = dataRepository ?? throw new ArgumentNullException(nameof(dataRepository));

            Currencies       = currenciesProvider.GetCurrencies(Network);
            CurrencyAccounts = CurrencyAccountCreator.Create(Currencies, wallet, DataRepository);

            UserSettings = UserSettings.TryLoadFromFile(
                pathToFile: $"{Path.GetDirectoryName(Wallet.PathToWallet)}/{DefaultUserSettingsFileName}",
                password: password) ?? UserSettings.DefaultSettings;

            _clientType = clientType;
        }
コード例 #18
0
        public static IDictionary <string, ICurrencyAccount> Create(
            ICurrencies currencies,
            IHdWallet wallet,
            IAccountDataRepository dataRepository)
        {
            var accounts = new Dictionary <string, ICurrencyAccount>();

            foreach (var currency in currencies)
            {
                if (Currencies.IsTezosToken(currency.Name))
                {
                    if (!accounts.TryGetValue(TezosConfig.Xtz, out var tezosAccount))
                    {
                        tezosAccount = CreateCurrencyAccount(
                            currency: TezosConfig.Xtz,
                            wallet: wallet,
                            dataRepository: dataRepository,
                            currencies: currencies);

                        accounts.Add(TezosConfig.Xtz, tezosAccount);
                    }

                    accounts.Add(currency.Name, CreateCurrencyAccount(
                                     currency: currency.Name,
                                     wallet: wallet,
                                     dataRepository: dataRepository,
                                     currencies: currencies,
                                     baseChainAccount: tezosAccount));
                }
                else
                {
                    accounts.Add(currency.Name, CreateCurrencyAccount(
                                     currency: currency.Name,
                                     wallet: wallet,
                                     dataRepository: dataRepository,
                                     currencies: currencies));
                }
            }

            return(accounts);
        }
コード例 #19
0
        public TezosTokenAccount(
            string currency,
            string tokenType,
            string tokenContract,
            decimal tokenId,
            ICurrencies currencies,
            IHdWallet wallet,
            IAccountDataRepository dataRepository,
            TezosAccount tezosAccount)
        {
            Currency       = currency ?? throw new ArgumentNullException(nameof(currency));
            TokenType      = tokenType ?? throw new ArgumentNullException(nameof(tokenType));
            Currencies     = currencies ?? throw new ArgumentNullException(nameof(currencies));
            Wallet         = wallet ?? throw new ArgumentNullException(nameof(wallet));
            DataRepository = dataRepository ?? throw new ArgumentNullException(nameof(dataRepository));

            _tokenContract = tokenContract ?? throw new ArgumentNullException(nameof(tokenContract));
            _tokenId       = tokenId;
            _tezosAccount  = tezosAccount ?? throw new ArgumentNullException(nameof(tezosAccount));

            ReloadBalances();
        }