2021-10-18 05:37:59 +02:00
|
|
|
#nullable enable
|
2021-04-13 10:36:49 +02:00
|
|
|
using System;
|
|
|
|
using NBitcoin;
|
|
|
|
using NBitcoin.Payment;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Data
|
|
|
|
{
|
|
|
|
public class UriClaimDestination : IBitcoinLikeClaimDestination
|
|
|
|
{
|
|
|
|
private readonly BitcoinUrlBuilder _bitcoinUrl;
|
|
|
|
|
|
|
|
public UriClaimDestination(BitcoinUrlBuilder bitcoinUrl)
|
|
|
|
{
|
|
|
|
if (bitcoinUrl == null)
|
|
|
|
throw new ArgumentNullException(nameof(bitcoinUrl));
|
|
|
|
if (bitcoinUrl.Address is null)
|
|
|
|
throw new ArgumentException(nameof(bitcoinUrl));
|
|
|
|
_bitcoinUrl = bitcoinUrl;
|
2021-10-23 14:47:15 +09:00
|
|
|
Address = bitcoinUrl.Address ?? throw new FormatException("the bip21 doesn't contain an address");
|
2021-04-13 10:36:49 +02:00
|
|
|
}
|
|
|
|
public BitcoinUrlBuilder BitcoinUrl => _bitcoinUrl;
|
2021-10-23 14:47:15 +09:00
|
|
|
public BitcoinAddress Address { get; }
|
2021-04-13 10:36:49 +02:00
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return _bitcoinUrl.ToString();
|
|
|
|
}
|
2021-10-18 05:37:59 +02:00
|
|
|
|
2021-10-21 17:43:02 +02:00
|
|
|
public string Id => Address.ToString();
|
2021-10-18 05:37:59 +02:00
|
|
|
public decimal? Amount => _bitcoinUrl.Amount?.ToDecimal(MoneyUnit.BTC);
|
2021-04-13 10:36:49 +02:00
|
|
|
}
|
|
|
|
}
|