asp.net-coreasp.net-core-mvcnbitcoin

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

I got this kind of warning, anyone please help how to fix it?

enter image description here


Solution

  • As Progman says,you can use GetAddress(ScriptPublicKeyType.Legacy) to instead BitcoinSecret.getAddress().

    Here is the usage of GetAddress(ScriptPublicKeyType.Legacy):

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

    In addition,if you don't want to change the method.You can use [Obsolete].

    Here is a demo worked: 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() };
        }
    }
    

    Result:

    enter image description here