已过时 "Use GetAddress(ScriptPubKeyType.Legacy) instead"

Obsolete "Use GetAddress(ScriptPubKeyType.Legacy) instead"

using System;
using NBitcoin;

namespace RSA
{
    public class RSA
    {
        public static Wallet KeyGenerate()
        {
            Key  privateKey = new Key();

            var v = privateKey.GetBitcoinSecret(Network.Main).GetAddress();
            var address = BitcoinAddress.Create(v.ToString(), Network.Main);

            return new Wallet { PublicKey = v.ToString(), PrivateKey = privateKey.GetBitcoinSecret(Network.Main).ToString() };
        }
    }
}

我收到了这种警告,请问有人帮忙解决吗?

Progman所说,您可以使用GetAddress(ScriptPublicKeyType.Legacy)代替BitcoinSecret.getAddress()

这里是GetAddress(ScriptPublicKeyType.Legacy)的用法:

var v = privateKey.PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.Main);

此外,如果你不想改变method.You可以使用[Obsolete]

这是一个有效的演示: Program.cs:

[Obsolete]
class Program
{
    static void Main(string[] args) {
        KeyGenerate();
    }

    public static Wallet KeyGenerate()
    {
        Key privateKey = new Key();

        var v = privateKey.GetBitcoinSecret(Network.Main).GetAddress();
        Console.WriteLine(v);
        var v1 = privateKey.PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.Main);
        Console.WriteLine(v1);
        var address = BitcoinAddress.Create(v.ToString(), Network.Main);

        return new Wallet { PublicKey = v.ToString(), PrivateKey = privateKey.GetBitcoinSecret(Network.Main).ToString() };
    }
}

结果: