首页 > 解决方案 > 已过时的“改用 GetAddress(ScriptPubKeyType.Legacy)”

问题描述

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() };
        }
    }
}

我得到了这种警告,请任何人帮助如何解决它?

在此处输入图像描述

标签: asp.net-coreasp.net-core-mvcnbitcoin

解决方案


如前所述Progman,您可以改用GetAddress(ScriptPublicKeyType.Legacy)to BitcoinSecret.getAddress()

下面是 GetAddress(ScriptPublicKeyType.Legacy) 的用法:

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

此外,如果您不想更改方法。您可以使用[Obsolete].

这是一个演示:Program.cs:</p>

[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() };
    }
}

结果:

在此处输入图像描述


推荐阅读