-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
build this neo cli plugin and you will have the ability to sign the transaction generated by neooffline
<PackageReference Include="Neo.ConsoleService" Version="1.2.0" />
using Neo.Network.P2P.Payloads;
using Neo.Wallets;
using Neo.ConsoleService;
using Neo.IO;
namespace Neo.Plugins;
public class OfflineSigner : Plugin
{
public override string Description => "Offline Transaction Signer";
private IWalletProvider? walletProvider;
private Wallets.Wallet? w;
public NeoSystem? neoSystem;
protected override void OnSystemLoaded(NeoSystem system)
{
neoSystem = system;
neoSystem.ServiceAdded += NeoSystem_ServiceAdded!;
}
private void NeoSystem_ServiceAdded(object sender, object service)
{
if (service is IWalletProvider)
{
walletProvider = service as IWalletProvider;
neoSystem!.ServiceAdded -= NeoSystem_ServiceAdded!;
walletProvider!.WalletChanged += WalletProvider_WalletChanged!;
}
}
private void WalletProvider_WalletChanged(object sender, Wallet wallet)
{
walletProvider!.WalletChanged -= WalletProvider_WalletChanged!;
w = wallet;
}
[ConsoleCommand("offsign", Category = "Lazynode", Description = "sign the hex encoded transaction")]
private void OnOffSign(string txhex)
{
if (w == null)
{
ConsoleHelper.Error("You have to open the wallet first.");
return;
}
byte[] data = Convert.FromHexString(txhex);
Transaction tx = new();
MemoryReader reader = new(data);
tx.DeserializeUnsigned(ref reader);
tx.Witnesses = tx.Signers.Select(v => new Witness { }).ToArray();
Console.WriteLine(tx.ToJson(neoSystem.Settings).ToString(true));
w.GetAccounts().Where(v => tx.Signers.Any(w => w.Account == v.ScriptHash)).Select(account =>
{
var signature = tx.Sign(account.GetKey(), neoSystem!.Settings.Network);
Console.WriteLine($"{account.Address}: {signature.ToHexString()}");
return 0;
}).ToArray().ToString();
}
}
Metadata
Metadata
Assignees
Labels
No labels
