Add some comments

This commit is contained in:
nicolas.dorier
2018-02-19 11:31:34 +09:00
parent 35f669aa15
commit af94de93d1
4 changed files with 22 additions and 17 deletions

View File

@@ -21,27 +21,29 @@ namespace BTCPayServer.Data
#pragma warning disable CS0618
public ScriptId GetHash()
public string GetAddress()
{
if (Address == null)
return null;
var index = Address.IndexOf("#", StringComparison.InvariantCulture);
var index = Address.LastIndexOf("#", StringComparison.InvariantCulture);
if (index == -1)
return new ScriptId(Address);
return new ScriptId(Address.Substring(0, index));
return Address;
return Address.Substring(0, index);
}
public AddressInvoiceData SetHash(ScriptId scriptId, CryptoDataId cryptoDataId)
public AddressInvoiceData Set(string address, CryptoDataId cryptoDataId)
{
Address = scriptId + "#" + cryptoDataId?.ToString();
Address = address + "#" + cryptoDataId?.ToString();
return this;
}
public CryptoDataId GetCryptoDataId()
{
if (Address == null)
return null;
var index = Address.IndexOf("#", StringComparison.InvariantCulture);
var index = Address.LastIndexOf("#", StringComparison.InvariantCulture);
// Legacy AddressInvoiceData does not have the CryptoDataId attached to the Address
if (index == -1)
return CryptoDataId.Parse("BTC");
/////////////////////////
return CryptoDataId.Parse(Address.Substring(index + 1));
}
#pragma warning restore CS0618

View File

@@ -33,11 +33,13 @@ namespace BTCPayServer.Payments.Bitcoin
DepositAddress = BitcoinAddress.Create(newPaymentDestination, DepositAddress.Network);
}
// Those properties are JsonIgnore because their data is inside CryptoData class for legacy reason
[JsonIgnore]
public FeeRate FeeRate { get; set; }
[JsonIgnore]
public Money TxFee { get; set; }
[JsonIgnore]
public BitcoinAddress DepositAddress { get; set; }
///////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@@ -130,12 +130,12 @@ namespace BTCPayServer.Services.Invoices
throw new InvalidOperationException("CryptoCode unsupported");
var paymentDestination = cryptoData.GetPaymentMethod().GetPaymentDestination();
ScriptId hash = GetAddressInvoiceHash(cryptoData);
string address = GetDestination(cryptoData);
context.AddressInvoices.Add(new AddressInvoiceData()
{
InvoiceDataId = invoice.Id,
CreatedTime = DateTimeOffset.UtcNow,
}.SetHash(hash, cryptoData.GetId()));
}.Set(address, cryptoData.GetId()));
context.HistoricalAddressInvoices.Add(new HistoricalAddressInvoiceData()
{
@@ -162,14 +162,15 @@ namespace BTCPayServer.Services.Invoices
return invoice;
}
private static ScriptId GetAddressInvoiceHash(CryptoData cryptoData)
private static string GetDestination(CryptoData cryptoData)
{
ScriptId hash = null;
// For legacy reason, BitcoinLikeOnChain is putting the hashes of addresses in database
if (cryptoData.GetId().PaymentType == Payments.PaymentTypes.BTCLike)
{
hash = ((Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod)cryptoData.GetPaymentMethod()).DepositAddress.ScriptPubKey.Hash;
return ((Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod)cryptoData.GetPaymentMethod()).DepositAddress.ScriptPubKey.Hash.ToString();
}
return hash;
///////////////
return cryptoData.GetPaymentMethod().GetPaymentDestination();
}
public async Task<bool> NewAddress(string invoiceId, IPaymentMethod paymentMethod, BTCPayNetwork network)
@@ -208,7 +209,7 @@ namespace BTCPayServer.Services.Invoices
InvoiceDataId = invoiceId,
CreatedTime = DateTimeOffset.UtcNow
}
.SetHash(GetAddressInvoiceHash(currencyData), currencyData.GetId()));
.Set(GetDestination(currencyData), currencyData.GetId()));
context.HistoricalAddressInvoices.Add(new HistoricalAddressInvoiceData()
{
InvoiceDataId = invoiceId,
@@ -360,7 +361,7 @@ namespace BTCPayServer.Services.Invoices
}
if (invoice.AddressInvoices != null)
{
entity.AvailableAddressHashes = invoice.AddressInvoices.Select(a => a.GetHash() + a.GetCryptoDataId().ToString()).ToHashSet();
entity.AvailableAddressHashes = invoice.AddressInvoices.Select(a => a.GetAddress() + a.GetCryptoDataId().ToString()).ToHashSet();
}
if(invoice.Events != null)
{