2020-07-29 18:55:28 +09:00
|
|
|
#if ALTCOINS
|
2019-12-24 08:20:44 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2021-07-30 18:47:02 +09:00
|
|
|
using BTCPayServer.Common;
|
2019-12-24 08:20:44 +01:00
|
|
|
using NBitcoin;
|
|
|
|
using NBXplorer;
|
|
|
|
using NBXplorer.Models;
|
|
|
|
|
|
|
|
namespace BTCPayServer
|
|
|
|
{
|
2020-01-21 14:28:13 +01:00
|
|
|
public class ElementsBTCPayNetwork : BTCPayNetwork
|
2019-12-24 08:20:44 +01:00
|
|
|
{
|
|
|
|
public string NetworkCryptoCode { get; set; }
|
|
|
|
public uint256 AssetId { get; set; }
|
2019-12-29 17:08:30 +01:00
|
|
|
public override bool ReadonlyWallet { get; set; } = true;
|
2019-12-24 08:20:44 +01:00
|
|
|
|
2020-01-21 14:28:13 +01:00
|
|
|
public override IEnumerable<(MatchedOutput matchedOutput, OutPoint outPoint)> GetValidOutputs(
|
|
|
|
NewTransactionEvent evtOutputs)
|
2019-12-24 08:20:44 +01:00
|
|
|
{
|
2020-01-21 14:28:13 +01:00
|
|
|
return evtOutputs.Outputs.Where(output =>
|
2019-12-24 08:20:44 +01:00
|
|
|
output.Value is AssetMoney assetMoney && assetMoney.AssetId == AssetId).Select(output =>
|
|
|
|
{
|
|
|
|
var outpoint = new OutPoint(evtOutputs.TransactionData.TransactionHash, output.Index);
|
|
|
|
return (output, outpoint);
|
|
|
|
});
|
|
|
|
}
|
2020-01-16 07:01:01 +01:00
|
|
|
|
2021-03-11 13:34:52 +01:00
|
|
|
public override List<TransactionInformation> FilterValidTransactions(List<TransactionInformation> transactionInformationSet)
|
2020-05-03 18:04:34 +02:00
|
|
|
{
|
2021-03-11 13:34:52 +01:00
|
|
|
return transactionInformationSet.FindAll(information =>
|
|
|
|
information.Outputs.Any(output =>
|
|
|
|
output.Value is AssetMoney assetMoney && assetMoney.AssetId == AssetId) ||
|
|
|
|
information.Inputs.Any(output =>
|
|
|
|
output.Value is AssetMoney assetMoney && assetMoney.AssetId == AssetId));
|
2020-05-03 18:04:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-30 18:47:02 +09:00
|
|
|
public override PaymentUrlBuilder GenerateBIP21(string cryptoInfoAddress, Money cryptoInfoDue)
|
2020-01-16 07:01:01 +01:00
|
|
|
{
|
2020-03-20 09:31:22 +01:00
|
|
|
//precision 0: 10 = 0.00000010
|
|
|
|
//precision 2: 10 = 0.00001000
|
|
|
|
//precision 8: 10 = 10
|
2021-07-30 18:47:02 +09:00
|
|
|
var money = cryptoInfoDue is null ? null : new Money(cryptoInfoDue.ToDecimal(MoneyUnit.BTC) / decimal.Parse("1".PadRight(1 + 8 - Divisibility, '0')), MoneyUnit.BTC);
|
|
|
|
var builder = base.GenerateBIP21(cryptoInfoAddress, money);
|
|
|
|
builder.QueryParams.Add("assetid", AssetId.ToString());
|
|
|
|
return builder;
|
2020-01-16 07:01:01 +01:00
|
|
|
}
|
2019-12-24 08:20:44 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-28 22:48:51 +02:00
|
|
|
#endif
|