2017-09-13 15:47:34 +09:00
|
|
|
|
using NBitcoin;
|
2017-10-05 00:05:38 +09:00
|
|
|
|
using NBXplorer.DerivationStrategy;
|
2017-09-13 15:47:34 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Validations
|
|
|
|
|
{
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public class DerivationStrategyValidatorAttribute : ValidationAttribute
|
|
|
|
|
{
|
|
|
|
|
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
{
|
|
|
|
|
return ValidationResult.Success;
|
|
|
|
|
}
|
|
|
|
|
var network = (Network)validationContext.GetService(typeof(Network));
|
|
|
|
|
if (network == null)
|
|
|
|
|
return new ValidationResult("No Network specified");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
new DerivationStrategyFactory(network).Parse((string)value);
|
|
|
|
|
return ValidationResult.Success;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return new ValidationResult(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
}
|