コード例 #1
0
        public async Task SetChronoBankContract(Guid clientId, string contract)
        {
            var walletCredentials = await GetAsync(clientId);

            if (string.IsNullOrEmpty(walletCredentials.ChronoBankContract))
            {
                var changedRecord = WalletCredentials.Create(walletCredentials);
                changedRecord.ChronoBankContract = contract;
                await MergeAsync(changedRecord);
            }
        }
コード例 #2
0
        public async Task SetEncodedPrivateKey(string clientId, string encodedPrivateKey)
        {
            var partitionKeyByClient = WalletCredentialsEntity.ByClientId.GeneratePartitionKey();
            var rowKeyByClient       = WalletCredentialsEntity.ByClientId.GenerateRowKey(clientId);

            var currentRecord = await _tableStorage.GetDataAsync(partitionKeyByClient, rowKeyByClient);

            var changedRecord = WalletCredentials.Create(currentRecord);

            changedRecord.EncodedPrivateKey = encodedPrivateKey;

            await MergeAsync(changedRecord);
        }
コード例 #3
0
        public async Task SetPreventTxDetection(string clientId, bool value)
        {
            var partitionKeyByClient = WalletCredentialsEntity.ByClientId.GeneratePartitionKey();
            var rowKeyByClient       = WalletCredentialsEntity.ByClientId.GenerateRowKey(clientId);

            var currentRecord = await _tableStorage.GetDataAsync(partitionKeyByClient, rowKeyByClient);

            var changedRecord = WalletCredentials.Create(currentRecord);

            changedRecord.PreventTxDetection = value;

            await MergeAsync(changedRecord);
        }
コード例 #4
0
        public async Task SetQuantaContract(string clientId, string contract)
        {
            var partitionKeyByClient = WalletCredentialsEntity.ByClientId.GeneratePartitionKey();
            var rowKeyByClient       = WalletCredentialsEntity.ByClientId.GenerateRowKey(clientId);

            var currentRecord = await _tableStorage.GetDataAsync(partitionKeyByClient, rowKeyByClient);

            if (string.IsNullOrEmpty(currentRecord.QuantaContract))
            {
                var changedRecord = WalletCredentials.Create(currentRecord);
                changedRecord.QuantaContract = contract;
                await MergeAsync(changedRecord);
            }
        }
コード例 #5
0
        public async Task SetSolarCoinWallet(string clientId, string address)
        {
            var partitionKeyByClient = WalletCredentialsEntity.ByClientId.GeneratePartitionKey();
            var rowKeyByClient       = WalletCredentialsEntity.ByClientId.GenerateRowKey(clientId);

            var currentRecord = await _tableStorage.GetDataAsync(partitionKeyByClient, rowKeyByClient);

            if (string.IsNullOrEmpty(currentRecord.SolarCoinWalletAddress))
            {
                var changedRecord = WalletCredentials.Create(currentRecord);
                changedRecord.SolarCoinWalletAddress = address;
                await MergeAsync(changedRecord);
            }
        }
コード例 #6
0
        public async Task SetEthConversionWallet(string clientId, string contract)
        {
            var partitionKeyByClient = WalletCredentialsEntity.ByClientId.GeneratePartitionKey();
            var rowKeyByClient       = WalletCredentialsEntity.ByClientId.GenerateRowKey(clientId);

            var currentRecord = await _tableStorage.GetDataAsync(partitionKeyByClient, rowKeyByClient);

            if (string.IsNullOrEmpty(currentRecord.EthConversionWalletAddress))
            {
                var changedRecord = WalletCredentials.Create(currentRecord);
                changedRecord.EthConversionWalletAddress = contract;

                var newByEthWalletEntity = WalletCredentialsEntity.ByEthContract.CreateNew(changedRecord);
                await _tableStorage.InsertOrReplaceAsync(newByEthWalletEntity);

                await MergeAsync(changedRecord);
            }
        }
コード例 #7
0
        public async Task <IWalletCredentials> GenerateWallets(string clientId, string clientPubKeyHex, string encodedPrivateKey, string privateKey, NetworkType networkType)
        {
            var network = networkType == NetworkType.Main ? Network.Main : Network.TestNet;

            PubKey clientPubKey  = new PubKey(clientPubKeyHex);
            var    clientAddress = clientPubKey.GetAddress(network).ToWif();

            var wallets = await GetWalletsForPubKey(clientPubKeyHex);

            var currentWalletCreds = await _walletCredentialsRepository.GetAsync(clientId);

            IWalletCredentials walletCreds;

            if (currentWalletCreds == null)
            {
                var btcConvertionWallet = GetNewAddressAndPrivateKey(network);

                walletCreds = WalletCredentials.Create(
                    clientId, clientAddress, /*todo: remove*/ privateKey, wallets.MultiSigAddress,
                    wallets.ColoredMultiSigAddress,
                    btcConvertionWallet.PrivateKey, btcConvertionWallet.Address, encodedPk: encodedPrivateKey,
                    pubKey: clientPubKeyHex);

                await _walletCredentialsRepository.SaveAsync(walletCreds);
            }
            else
            {
                walletCreds = WalletCredentials.Create(
                    clientId, clientAddress, /*todo: remove*/ privateKey, wallets.MultiSigAddress,
                    wallets.ColoredMultiSigAddress, null, null, encodedPk: encodedPrivateKey,
                    pubKey: clientPubKeyHex);

                await _walletCredentialsHistoryRepository.InsertHistoryRecord(currentWalletCreds);

                await _walletCredentialsRepository.MergeAsync(walletCreds);
            }

            return(walletCreds);
        }
コード例 #8
0
        public async Task <IBcnCredentialsRecord> GenerateWallets(Guid clientId)
        {
            var network = _btcSettings.NetworkType == NetworkType.Main ? Network.Main : Network.TestNet;

            var wallets = await GetWalletsForPubKey();

            IBcnCredentialsRecord bcnCreds;
            var currentWalletCreds = await _walletCredentialsRepository.GetAsync(clientId);

            if (currentWalletCreds == null)
            {
                var btcConvertionWallet = GetNewAddressAndPrivateKey(network);

                IWalletCredentials walletCreds = WalletCredentials.Create(
                    clientId.ToString(),
                    null,
                    null,
                    null,
                    wallets.ColoredMultiSigAddress,
                    btcConvertionWallet.PrivateKey,
                    btcConvertionWallet.Address,
                    encodedPk: "",
                    pubKey: "");

                bcnCreds = BcnCredentialsRecord.Create(SpecialAssetIds.BitcoinAssetId,
                                                       clientId.ToString(),
                                                       null,
                                                       wallets.SegwitAddress,
                                                       "");

                await Task.WhenAll(
                    _walletCredentialsRepository.SaveAsync(walletCreds),
                    _walletCredentialsRepository.SaveAsync(bcnCreds)
                    );
            }
            else
            {
                //walletCreds = WalletCredentials.Create(
                //    clientId.ToString(),
                //    null,
                //    null,
                //    null,
                //    wallets.ColoredMultiSigAddress,
                //    null,
                //    null,
                //    encodedPk: "",
                //    pubKey: "");

                bcnCreds = await _walletCredentialsRepository.GetBcnCredsAsync(SpecialAssetIds.BitcoinAssetId,
                                                                               clientId);

                if (bcnCreds == null)
                {
                    bcnCreds = BcnCredentialsRecord.Create(
                        SpecialAssetIds.BitcoinAssetId,
                        clientId.ToString(),
                        null,
                        wallets.SegwitAddress,
                        ""
                        );

                    await _walletCredentialsRepository.SaveAsync(bcnCreds);
                }

                //await _walletCredentialsHistoryRepository.InsertHistoryRecord(currentWalletCreds);
                //await _walletCredentialsRepository.Merge(walletCreds);
            }

            return(bcnCreds);
        }