public override TrackedTransaction CreateTrackedTransaction(TrackedSource trackedSource, ITrackedTransactionSerializable tx) { var trackedTransaction = (ElementsTrackedTransaction)base.CreateTrackedTransaction(trackedSource, tx); trackedTransaction.Unblind(((ElementsTransactionMatchData)tx).Unblind); return(trackedTransaction); }
public async Task <UTXOChanges> GetUTXOsAsync(TrackedSource trackedSource, Bookmark[] confirmedBookmarks, Bookmark[] unconfirmedBookmarks, bool longPolling = true, CancellationToken cancellation = default) { if (trackedSource == null) { throw new ArgumentNullException(nameof(trackedSource)); } Dictionary <string, string> parameters = new Dictionary <string, string>(); if (confirmedBookmarks != null) { parameters.Add("confirmedBookmarks", String.Join(",", confirmedBookmarks.Select(b => b.ToString()))); } if (unconfirmedBookmarks != null) { parameters.Add("unconfirmedBookmarks", String.Join(",", unconfirmedBookmarks.Select(b => b.ToString()))); } parameters.Add("longPolling", longPolling.ToString()); var query = String.Join("&", parameters.Select(p => p.Key + "=" + p.Value).ToArray()); if (trackedSource is DerivationSchemeTrackedSource dsts) { return(await SendAsync <UTXOChanges>(HttpMethod.Get, null, "v1/cryptos/{0}/derivations/{1}/utxos?" + query, new object[] { CryptoCode, dsts.DerivationStrategy.ToString() }, cancellation).ConfigureAwait(false)); } else if (trackedSource is AddressTrackedSource asts) { return(await SendAsync <UTXOChanges>(HttpMethod.Get, null, "v1/cryptos/{0}/addresses/{1}/utxos?" + query, new object[] { CryptoCode, asts.Address }, cancellation).ConfigureAwait(false)); } else { throw UnSupported(trackedSource); } }
public async Task <IActionResult> TrackWallet( string cryptoCode, [ModelBinder(BinderType = typeof(DerivationStrategyModelBinder))] DerivationStrategyBase derivationScheme, [ModelBinder(BinderType = typeof(BitcoinAddressModelBinder))] BitcoinAddress address) { TrackedSource trackedSource = GetTrackedSource(derivationScheme, address); if (trackedSource == null) { return(NotFound()); } var network = GetNetwork(cryptoCode, false); if (trackedSource is DerivationSchemeTrackedSource dts) { foreach (var feature in Enum.GetValues(typeof(DerivationFeature)).Cast <DerivationFeature>()) { await RepositoryProvider.GetRepository(network).GenerateAddresses(dts.DerivationStrategy, feature, new GenerateAddressQuery(minAddresses: 3, null)); } foreach (var feature in Enum.GetValues(typeof(DerivationFeature)).Cast <DerivationFeature>()) { _ = AddressPoolService.GenerateAddresses(network, dts.DerivationStrategy, feature); } } else if (trackedSource is IDestination ats) { await RepositoryProvider.GetRepository(network).Track(ats); } return(Ok()); }
public TrackedTransaction(TrackedTransactionKey key, TrackedSource trackedSource, IEnumerable <Coin> receivedCoins, Dictionary <Script, KeyPath> knownScriptMapping) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (!key.IsPruned) { throw new ArgumentException("The key should be pruned", nameof(key)); } if (trackedSource == null) { throw new ArgumentNullException(nameof(trackedSource)); } TrackedSource = trackedSource; Key = key; if (knownScriptMapping != null) { KnownKeyPathMapping = knownScriptMapping; } if (receivedCoins != null) { ReceivedCoins.AddRange(receivedCoins); } }
public Task <GetTransactionsResponse> GetTransactionsAsync(TrackedSource trackedSource, GetTransactionsResponse previous, bool longPolling, CancellationToken cancellation = default) { return(GetTransactionsAsync(trackedSource, previous == null ? null : new[] { previous.ConfirmedTransactions.Bookmark }, previous == null ? null : new[] { previous.UnconfirmedTransactions.Bookmark }, previous == null ? null : new[] { previous.ReplacedTransactions.Bookmark }, longPolling, cancellation)); }
public TrackedTransaction(TrackedTransactionKey key, TrackedSource trackedSource, Transaction transaction, Dictionary <Script, KeyPath> knownScriptMapping) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (transaction == null) { throw new ArgumentNullException(nameof(transaction)); } if (knownScriptMapping == null) { throw new ArgumentNullException(nameof(knownScriptMapping)); } if (trackedSource == null) { throw new ArgumentNullException(nameof(trackedSource)); } if (key.IsPruned) { throw new ArgumentException("The key should not be pruned", nameof(key)); } Key = key; TrackedSource = trackedSource; Transaction = transaction; transaction.PrecomputeHash(false, true); KnownKeyPathMapping = knownScriptMapping; KnownKeyPathMappingUpdated(); }
public BitcoinConnector(string oracleAddress, string endpoint, Channel <Deposit> depositStream, Channel <WithdrawInfo> withdrawStream) { this.depositStream = depositStream; this.withdrawStream = withdrawStream; this.oracleAddress = TrackedSource.Create(new BitcoinPubKeyAddress(oracleAddress)); client = new ExplorerClient(new NBXplorerNetworkProvider(NetworkType.Testnet).GetBTC(), new Uri(endpoint)); client.SetNoAuth(); }
private void UpdateTxConfirmations(WalletAddr addr) { var baddr = BitcoinAddress.Create(addr.Address, GetNetwork()); var trackedSource = TrackedSource.Create(baddr); var txs = GetClient().GetTransactions(trackedSource); UpdateTxConfirmations(txs); }
public Task <UTXOChanges> GetUTXOsAsync(DerivationStrategyBase extKey, Bookmark[] confirmedBookmarks, Bookmark[] unconfirmedBookmarks, bool longPolling = true, CancellationToken cancellation = default) { if (extKey == null) { throw new ArgumentNullException(nameof(extKey)); } return(GetUTXOsAsync(TrackedSource.Create(extKey), confirmedBookmarks, unconfirmedBookmarks, longPolling, cancellation)); }
public void RebroadcastPeriodically(NBXplorerNetwork network, TrackedSource trackedSource, params TrackedTransactionKey[] txIds) { if (network == null) { throw new ArgumentNullException(nameof(network)); } _BroadcastedTransactionsByCryptoCode[network].RebroadcastPeriodically(trackedSource, txIds); }
public Task <UTXOChanges> GetUTXOsAsync(DerivationStrategyBase extKey, CancellationToken cancellation = default) { if (extKey == null) { throw new ArgumentNullException(nameof(extKey)); } return(GetUTXOsAsync(TrackedSource.Create(extKey), cancellation)); }
public async Task RebroadcastPeriodically(NBXplorerNetwork network, TrackedSource trackedSource, params uint256[] txIds) { List <TrackedTransactionKey> keys = new List <TrackedTransactionKey>(); foreach (var txId in txIds) { keys.AddRange((await _Repositories.GetRepository(network).GetTransactions(trackedSource, txId)).Select(k => k.Key)); } RebroadcastPeriodically(network, trackedSource, keys.ToArray()); }
public async Task TrackClaim(PaymentMethodId paymentMethodId, IClaimDestination claimDestination) { var network = _btcPayNetworkProvider.GetNetwork <BTCPayNetwork>(paymentMethodId.CryptoCode); var explorerClient = _explorerClientProvider.GetExplorerClient(network); if (claimDestination is IBitcoinLikeClaimDestination bitcoinLikeClaimDestination) { await explorerClient.TrackAsync(TrackedSource.Create(bitcoinLikeClaimDestination.Address)); } }
internal static uint160 GetHash(this TrackedSource trackedSource) { if (trackedSource is DerivationSchemeTrackedSource t) { return(t.DerivationStrategy.GetHash()); } var data = Encoding.UTF8.GetBytes(trackedSource.ToString()); return(new uint160(Hashes.RIPEMD160(data, data.Length))); }
private static TrackedSource GetTrackedSource(DerivationStrategyBase derivationScheme, BitcoinAddress address) { TrackedSource trackedSource = null; if (address != null) { trackedSource = new AddressTrackedSource(address); } if (derivationScheme != null) { trackedSource = new DerivationSchemeTrackedSource(derivationScheme); } return(trackedSource); }
public IEnumerable <MatchedOutput> GetReceivedOutputs(TrackedSource trackedSource) { return(this.ReceivedCoins .Select(o => (Index: (int)o.Outpoint.N, Output: o, KeyPath: KnownKeyPathMapping.TryGet(o.ScriptPubKey))) .Where(o => o.KeyPath != null || o.Output.ScriptPubKey == (trackedSource as IDestination)?.ScriptPubKey) .Select(o => new MatchedOutput() { Index = o.Index, Value = o.Output.Amount, KeyPath = o.KeyPath, ScriptPubKey = o.Output.ScriptPubKey })); }
public void RebroadcastPeriodically(TrackedSource trackedSource, params TrackedTransactionKey[] txIds) { lock (CollectionLock) { if (TransactionsHashSet.TryGetValue(trackedSource, out var v)) { v.AddKeys(txIds); } else { TransactionsHashSet.Add(trackedSource, new RebroadcastedTransaction(txIds) { TrackedSource = trackedSource }); } } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { return(null); } if (reader.TokenType != JsonToken.String) { return(null); } if (TrackedSource.TryParse(reader.Value.ToString(), out var v, Network)) { return(v); } throw new JsonObjectException("Invalid TrackedSource", reader); }
public Task <GetTransactionsResponse> GetTransactionsAsync(TrackedSource trackedSource, CancellationToken cancellation = default) { if (trackedSource == null) { throw new ArgumentNullException(nameof(trackedSource)); } if (trackedSource is DerivationSchemeTrackedSource dsts) { return(SendAsync <GetTransactionsResponse>(HttpMethod.Get, null, $"v1/cryptos/{CryptoCode}/derivations/{dsts.DerivationStrategy}/transactions", null, cancellation)); } else if (trackedSource is AddressTrackedSource asts) { return(SendAsync <GetTransactionsResponse>(HttpMethod.Get, null, $"v1/cryptos/{CryptoCode}/addresses/{asts.Address}/transactions", null, cancellation)); } else { throw UnSupported(trackedSource); } }
public Task TrackAsync(TrackedSource trackedSource, CancellationToken cancellation = default) { if (trackedSource == null) { throw new ArgumentNullException(nameof(trackedSource)); } if (trackedSource is DerivationSchemeTrackedSource dsts) { return(SendAsync <string>(HttpMethod.Post, null, "v1/cryptos/{0}/derivations/{1}", new[] { CryptoCode, dsts.DerivationStrategy.ToString() }, cancellation)); } else if (trackedSource is AddressTrackedSource asts) { return(SendAsync <string>(HttpMethod.Post, null, "v1/cryptos/{0}/addresses/{1}", new[] { CryptoCode, asts.Address.ToString() }, cancellation)); } else { throw UnSupported(trackedSource); } }
public async Task <UTXOChanges> GetUTXOsAsync(TrackedSource trackedSource, CancellationToken cancellation = default) { if (trackedSource == null) { throw new ArgumentNullException(nameof(trackedSource)); } if (trackedSource is DerivationSchemeTrackedSource dsts) { return(await SendAsync <UTXOChanges>(HttpMethod.Get, null, "v1/cryptos/{0}/derivations/{1}/utxos", new object[] { CryptoCode, dsts.DerivationStrategy.ToString() }, cancellation).ConfigureAwait(false)); } else if (trackedSource is AddressTrackedSource asts) { return(await SendAsync <UTXOChanges>(HttpMethod.Get, null, "v1/cryptos/{0}/addresses/{1}/utxos", new object[] { CryptoCode, asts.Address }, cancellation).ConfigureAwait(false)); } else { throw UnSupported(trackedSource); } }
public async Task <IActionResult> TrackWallet( string cryptoCode, [ModelBinder(BinderType = typeof(DerivationStrategyModelBinder))] DerivationStrategyBase derivationScheme, [ModelBinder(BinderType = typeof(BitcoinAddressModelBinder))] BitcoinAddress address, [FromBody] TrackWalletRequest request = null) { request = request ?? new TrackWalletRequest(); TrackedSource trackedSource = GetTrackedSource(derivationScheme, address); if (trackedSource == null) { return(NotFound()); } var network = GetNetwork(cryptoCode, false); if (trackedSource is DerivationSchemeTrackedSource dts) { if (request.Wait) { foreach (var feature in keyPathTemplates.GetSupportedDerivationFeatures()) { await RepositoryProvider.GetRepository(network).GenerateAddresses(dts.DerivationStrategy, feature, GenerateAddressQuery(request, feature)); } } else { foreach (var feature in keyPathTemplates.GetSupportedDerivationFeatures()) { await RepositoryProvider.GetRepository(network).GenerateAddresses(dts.DerivationStrategy, feature, new GenerateAddressQuery(minAddresses: 3, null)); } foreach (var feature in keyPathTemplates.GetSupportedDerivationFeatures()) { _ = AddressPoolService.GenerateAddresses(network, dts.DerivationStrategy, feature, GenerateAddressQuery(request, feature)); } } } else if (trackedSource is IDestination ats) { await RepositoryProvider.GetRepository(network).Track(ats); } return(Ok()); }
public Task <TrackedSource> ConstructTrackedSource() { var data = GetData(); var explorerClient = _nbXplorerClientProvider.GetClient(data.CryptoCode); var factory = explorerClient.Network.DerivationStrategyFactory; if (string.IsNullOrEmpty(data .DerivationStrategy)) { return(Task.FromResult <TrackedSource>(TrackedSource.Create(BitcoinAddress.Create( data.Address, explorerClient.Network.NBitcoinNetwork)))); } else { return(Task.FromResult <TrackedSource>(TrackedSource.Create(_derivationSchemeParser.Parse(factory, data.DerivationStrategy)))); } }
internal static string ToPrettyString(this TrackedSource trackedSource) { if (trackedSource is DerivationSchemeTrackedSource derivation) { var strategy = derivation.DerivationStrategy.ToString(); if (strategy.Length > 35) { strategy = strategy.Substring(0, 10) + "..." + strategy.Substring(strategy.Length - 20); } return(strategy); } else if (trackedSource is AddressTrackedSource addressDerivation) { return(addressDerivation.Address.ToString()); } else { return(trackedSource.ToString()); } }
public Task <GetTransactionsResponse> GetTransactionsAsync(TrackedSource trackedSource, Bookmark[] confirmedBookmarks, Bookmark[] unconfirmedBookmarks, Bookmark[] replacedBookmarks, bool longPolling, CancellationToken cancellation = default) { if (trackedSource == null) { throw new ArgumentNullException(nameof(trackedSource)); } Dictionary <string, string> parameters = new Dictionary <string, string>(); if (confirmedBookmarks != null) { parameters.Add("confirmedBookmarks", String.Join(",", confirmedBookmarks.Select(b => b.ToString()))); } if (unconfirmedBookmarks != null) { parameters.Add("unconfirmedBookmarks", String.Join(",", unconfirmedBookmarks.Select(b => b.ToString()))); } if (replacedBookmarks != null) { parameters.Add("replacedBookmarks", String.Join(",", replacedBookmarks.Select(b => b.ToString()))); } parameters.Add("longPolling", longPolling.ToString()); var query = String.Join("&", parameters.Select(p => p.Key + "=" + p.Value).ToArray()); if (trackedSource is DerivationSchemeTrackedSource dsts) { return(SendAsync <GetTransactionsResponse>(HttpMethod.Get, null, $"v1/cryptos/{CryptoCode}/derivations/{dsts.DerivationStrategy}/transactions?" + query, null, cancellation)); } else if (trackedSource is AddressTrackedSource asts) { return(SendAsync <GetTransactionsResponse>(HttpMethod.Get, null, $"v1/cryptos/{CryptoCode}/addresses/{asts.Address}/transactions?" + query, null, cancellation)); } else { throw UnSupported(trackedSource); } }
List <TransactionInformationMatch> ToMatch(AnnotatedTransactionCollection txs, List <TxOut> outputs, TrackedSource derivation) { var result = new List <TransactionInformationMatch>(); for (int i = 0; i < outputs.Count; i++) { if (outputs[i] == null) { continue; } if (!IsMatching(derivation, outputs[i].ScriptPubKey, txs)) { continue; } var keyPath = txs.GetKeyPath(outputs[i].ScriptPubKey); result.Add(new TransactionInformationMatch() { Index = i, KeyPath = keyPath, Value = outputs[i].Value }); } return(result); }
public TrackedTransaction(TrackedTransactionKey key, TrackedSource trackedSource, IEnumerable <Coin> receivedCoins, IEnumerable <KeyPathInformation> knownScriptMapping) : this(key, trackedSource, receivedCoins, ToDictionary(knownScriptMapping)) { }
public TrackedTransaction(TrackedTransactionKey key, TrackedSource trackedSource) : this(key, trackedSource, null as Coin[], null as Dictionary <Script, KeyPath>) { }
public TransactionInformation GetTransaction(TrackedSource trackedSource, uint256 txId, CancellationToken cancellation = default) { return(this.GetTransactionAsync(trackedSource, txId, cancellation).GetAwaiter().GetResult()); }
public Task <GetTransactionsResponse> GetTransactionsAsync(DerivationStrategyBase strategy, Bookmark[] confirmedBookmarks, Bookmark[] unconfirmedBookmarks, Bookmark[] replacedBookmarks, bool longPolling, CancellationToken cancellation = default) { return(GetTransactionsAsync(TrackedSource.Create(strategy), confirmedBookmarks, unconfirmedBookmarks, replacedBookmarks, longPolling, cancellation)); }