From 75275f395d439662468b1d443e759a389cdc379e Mon Sep 17 00:00:00 2001 From: Christopher Schuchardt Date: Mon, 10 Jun 2024 22:37:16 -0400 Subject: [PATCH 1/3] Fixed Props paths --- src/Directory.Build.props | 4 +- src/Neo.SDK/JsonWalletDefaults.cs | 22 +++++++++++ src/Neo.SDK/Neo.SDK.csproj | 22 +++++++++++ src/Neo.SDK/Wallet/NEP6Wallet.cs | 42 +++++++++++++++++++++ src/Neo.SDK/Wallet/ScryptParameters.cs | 32 ++++++++++++++++ src/Plugins/Directory.Build.props | 6 +-- tests/Neo.SDK.Tests/Neo.SDK.Tests.csproj | 25 ++++++++++++ tests/Neo.SDK.Tests/Wallet/UT_NEP6Wallet.cs | 36 ++++++++++++++++++ tests/Neo.SDK.Tests/wallet1.json | 30 +++++++++++++++ 9 files changed, 214 insertions(+), 5 deletions(-) create mode 100644 src/Neo.SDK/JsonWalletDefaults.cs create mode 100644 src/Neo.SDK/Neo.SDK.csproj create mode 100644 src/Neo.SDK/Wallet/NEP6Wallet.cs create mode 100644 src/Neo.SDK/Wallet/ScryptParameters.cs create mode 100644 tests/Neo.SDK.Tests/Neo.SDK.Tests.csproj create mode 100644 tests/Neo.SDK.Tests/Wallet/UT_NEP6Wallet.cs create mode 100644 tests/Neo.SDK.Tests/wallet1.json diff --git a/src/Directory.Build.props b/src/Directory.Build.props index c211ee34aa..ba6b9f24c2 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -19,8 +19,8 @@ - - + + diff --git a/src/Neo.SDK/JsonWalletDefaults.cs b/src/Neo.SDK/JsonWalletDefaults.cs new file mode 100644 index 0000000000..9dc2b38a54 --- /dev/null +++ b/src/Neo.SDK/JsonWalletDefaults.cs @@ -0,0 +1,22 @@ +// Copyright (C) 2015-2024 The Neo Project. +// +// JsonWalletDefaults.cs file belongs to the neo project and is free +// software distributed under the MIT software license, see the +// accompanying file LICENSE in the main directory of the +// repository or http://www.opensource.org/licenses/mit-license.php +// for more details. +// +// Redistribution and use in source and binary forms with or without +// modifications are permitted. + +namespace Neo.SDK +{ + internal class JsonWalletDefaults + { + public static readonly string Version = "version"; + public static readonly string Name = "name"; + public static readonly string Scrypt = "scrypt"; + public static readonly string Accounts = "accounts"; + public static readonly string Extra = "extra"; + } +} diff --git a/src/Neo.SDK/Neo.SDK.csproj b/src/Neo.SDK/Neo.SDK.csproj new file mode 100644 index 0000000000..d6f6dab6d0 --- /dev/null +++ b/src/Neo.SDK/Neo.SDK.csproj @@ -0,0 +1,22 @@ + + + + netstandard2.1;net8.0 + true + enable + Neo.SDK + NEO;AntShares;Blockchain;Smart Contract;SDK;Software Development Kit + ../../bin/$(PackageId) + + + + + + + + + + + + + diff --git a/src/Neo.SDK/Wallet/NEP6Wallet.cs b/src/Neo.SDK/Wallet/NEP6Wallet.cs new file mode 100644 index 0000000000..b8d4050f24 --- /dev/null +++ b/src/Neo.SDK/Wallet/NEP6Wallet.cs @@ -0,0 +1,42 @@ +// Copyright (C) 2015-2024 The Neo Project. +// +// NEP6Wallet.cs file belongs to the neo project and is free +// software distributed under the MIT software license, see the +// accompanying file LICENSE in the main directory of the +// repository or http://www.opensource.org/licenses/mit-license.php +// for more details. +// +// Redistribution and use in source and binary forms with or without +// modifications are permitted. + +using Microsoft.Extensions.Configuration; +using System; +using System.IO; +using System.Security; + +namespace Neo.SDK.Wallet +{ + public class NEP6Wallet + { + public string? Name { get; internal set; } + public Version Version { get; internal set; } = new Version("1.0"); + public SecureString? Password { get; internal set; } + public ScryptParameters Scrypt { get; internal set; } = ScryptParameters.Default; + public IConfigurationSection? Extra { get; internal set; } + + public static NEP6Wallet Load(IConfigurationRoot section) + { + var wallet = new NEP6Wallet(); + var version = section.GetValue(JsonWalletDefaults.Version, Version.Parse("1.0")); + + if (version != wallet.Version) + throw new InvalidDataException(JsonWalletDefaults.Version); + + wallet.Name = section.GetValue(JsonWalletDefaults.Name, string.Empty); + wallet.Scrypt = section.GetValue(JsonWalletDefaults.Scrypt, ScryptParameters.Default)!; + wallet.Extra = section.GetSection(JsonWalletDefaults.Extra); + + return wallet; + } + } +} diff --git a/src/Neo.SDK/Wallet/ScryptParameters.cs b/src/Neo.SDK/Wallet/ScryptParameters.cs new file mode 100644 index 0000000000..777082e1e0 --- /dev/null +++ b/src/Neo.SDK/Wallet/ScryptParameters.cs @@ -0,0 +1,32 @@ +// Copyright (C) 2015-2024 The Neo Project. +// +// ScryptParameters.cs file belongs to the neo project and is free +// software distributed under the MIT software license, see the +// accompanying file LICENSE in the main directory of the +// repository or http://www.opensource.org/licenses/mit-license.php +// for more details. +// +// Redistribution and use in source and binary forms with or without +// modifications are permitted. + +using Microsoft.Extensions.Configuration; + +namespace Neo.SDK.Wallet +{ + public class ScryptParameters + { + public static ScryptParameters Default => new() { N = 16384, R = 8, P = 8 }; + + public int N { get; set; } + public int R { get; set; } + public int P { get; set; } + + public static ScryptParameters Load(IConfigurationSection section) => + new() + { + N = section.GetValue("n"), + R = section.GetValue("r"), + P = section.GetValue("p") + }; + } +} diff --git a/src/Plugins/Directory.Build.props b/src/Plugins/Directory.Build.props index 72e96f0300..e7cfbdeb1e 100644 --- a/src/Plugins/Directory.Build.props +++ b/src/Plugins/Directory.Build.props @@ -4,12 +4,12 @@ - - + + - + diff --git a/tests/Neo.SDK.Tests/Neo.SDK.Tests.csproj b/tests/Neo.SDK.Tests/Neo.SDK.Tests.csproj new file mode 100644 index 0000000000..40a31b35f9 --- /dev/null +++ b/tests/Neo.SDK.Tests/Neo.SDK.Tests.csproj @@ -0,0 +1,25 @@ + + + + net8.0 + enable + + + + + + + + + + + + + + + + Always + + + + diff --git a/tests/Neo.SDK.Tests/Wallet/UT_NEP6Wallet.cs b/tests/Neo.SDK.Tests/Wallet/UT_NEP6Wallet.cs new file mode 100644 index 0000000000..aeae794a0b --- /dev/null +++ b/tests/Neo.SDK.Tests/Wallet/UT_NEP6Wallet.cs @@ -0,0 +1,36 @@ +// Copyright (C) 2015-2024 The Neo Project. +// +// UnitTest1.cs file belongs to the neo project and is free +// software distributed under the MIT software license, see the +// accompanying file LICENSE in the main directory of the +// repository or http://www.opensource.org/licenses/mit-license.php +// for more details. +// +// Redistribution and use in source and binary forms with or without +// modifications are permitted. + + +using Microsoft.Extensions.Configuration; +using Neo.SDK.Wallet; +using Xunit; + +namespace Neo.SDK.Tests.Wallet +{ + public class UT_NEP6Wallet + { + [Fact] + public void Test_Static_Load() + { + var root = new ConfigurationBuilder().AddJsonFile("wallet1.json", optional: false).Build(); + var wallet = NEP6Wallet.Load(root); + + Assert.NotNull(wallet); + + Assert.NotNull(wallet.Name); + Assert.Equal("wallet1", wallet.Name); + + Assert.NotNull(wallet.Scrypt); + Assert.Equal(ScryptParameters.Default, wallet.Scrypt); + } + } +} diff --git a/tests/Neo.SDK.Tests/wallet1.json b/tests/Neo.SDK.Tests/wallet1.json new file mode 100644 index 0000000000..235b4d6f9b --- /dev/null +++ b/tests/Neo.SDK.Tests/wallet1.json @@ -0,0 +1,30 @@ +{ + "name": "wallet1", + "version": "1.0", + "scrypt": { + "n": 16384, + "r": 8, + "p": 8 + }, + "accounts": [ + { + "address": "NM2ZMTS83QAunnxQd91UbgZZtVDG2YsdAJ", + "label": null, + "isDefault": false, + "lock": false, + "key": "6PYMtjw28NGAJbMmMWA7oT3yHukLNt4yFSb5Z5D5MFn51DXeB3Pjz8qAYy", + "contract": { + "script": "DCED9Q7CjUQd3eqyBCQZx/H0lqDOEGnzxkcQbHxI7k8N1c9BVuezJw==", + "parameters": [ + { + "name": "signature", + "type": "Signature" + } + ], + "deployed": false + }, + "extra": null + } + ], + "extra": null +} From c6636a141e913d1b1caaad20f337cda6f2c4544d Mon Sep 17 00:00:00 2001 From: Christopher Schuchardt Date: Mon, 10 Jun 2024 22:41:04 -0400 Subject: [PATCH 2/3] Removed unwanted files --- tests/Neo.SDK.Tests/Neo.SDK.Tests.csproj | 25 -------------- tests/Neo.SDK.Tests/Wallet/UT_NEP6Wallet.cs | 36 --------------------- tests/Neo.SDK.Tests/wallet1.json | 30 ----------------- 3 files changed, 91 deletions(-) delete mode 100644 tests/Neo.SDK.Tests/Neo.SDK.Tests.csproj delete mode 100644 tests/Neo.SDK.Tests/Wallet/UT_NEP6Wallet.cs delete mode 100644 tests/Neo.SDK.Tests/wallet1.json diff --git a/tests/Neo.SDK.Tests/Neo.SDK.Tests.csproj b/tests/Neo.SDK.Tests/Neo.SDK.Tests.csproj deleted file mode 100644 index 40a31b35f9..0000000000 --- a/tests/Neo.SDK.Tests/Neo.SDK.Tests.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - net8.0 - enable - - - - - - - - - - - - - - - - Always - - - - diff --git a/tests/Neo.SDK.Tests/Wallet/UT_NEP6Wallet.cs b/tests/Neo.SDK.Tests/Wallet/UT_NEP6Wallet.cs deleted file mode 100644 index aeae794a0b..0000000000 --- a/tests/Neo.SDK.Tests/Wallet/UT_NEP6Wallet.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2015-2024 The Neo Project. -// -// UnitTest1.cs file belongs to the neo project and is free -// software distributed under the MIT software license, see the -// accompanying file LICENSE in the main directory of the -// repository or http://www.opensource.org/licenses/mit-license.php -// for more details. -// -// Redistribution and use in source and binary forms with or without -// modifications are permitted. - - -using Microsoft.Extensions.Configuration; -using Neo.SDK.Wallet; -using Xunit; - -namespace Neo.SDK.Tests.Wallet -{ - public class UT_NEP6Wallet - { - [Fact] - public void Test_Static_Load() - { - var root = new ConfigurationBuilder().AddJsonFile("wallet1.json", optional: false).Build(); - var wallet = NEP6Wallet.Load(root); - - Assert.NotNull(wallet); - - Assert.NotNull(wallet.Name); - Assert.Equal("wallet1", wallet.Name); - - Assert.NotNull(wallet.Scrypt); - Assert.Equal(ScryptParameters.Default, wallet.Scrypt); - } - } -} diff --git a/tests/Neo.SDK.Tests/wallet1.json b/tests/Neo.SDK.Tests/wallet1.json deleted file mode 100644 index 235b4d6f9b..0000000000 --- a/tests/Neo.SDK.Tests/wallet1.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "wallet1", - "version": "1.0", - "scrypt": { - "n": 16384, - "r": 8, - "p": 8 - }, - "accounts": [ - { - "address": "NM2ZMTS83QAunnxQd91UbgZZtVDG2YsdAJ", - "label": null, - "isDefault": false, - "lock": false, - "key": "6PYMtjw28NGAJbMmMWA7oT3yHukLNt4yFSb5Z5D5MFn51DXeB3Pjz8qAYy", - "contract": { - "script": "DCED9Q7CjUQd3eqyBCQZx/H0lqDOEGnzxkcQbHxI7k8N1c9BVuezJw==", - "parameters": [ - { - "name": "signature", - "type": "Signature" - } - ], - "deployed": false - }, - "extra": null - } - ], - "extra": null -} From bbf0f16fa09cbb1b9e198777d4467203b7452aae Mon Sep 17 00:00:00 2001 From: Christopher Schuchardt Date: Mon, 10 Jun 2024 22:41:49 -0400 Subject: [PATCH 3/3] Removed unwanted project files --- src/Neo.SDK/JsonWalletDefaults.cs | 22 -------------- src/Neo.SDK/Neo.SDK.csproj | 22 -------------- src/Neo.SDK/Wallet/NEP6Wallet.cs | 42 -------------------------- src/Neo.SDK/Wallet/ScryptParameters.cs | 32 -------------------- 4 files changed, 118 deletions(-) delete mode 100644 src/Neo.SDK/JsonWalletDefaults.cs delete mode 100644 src/Neo.SDK/Neo.SDK.csproj delete mode 100644 src/Neo.SDK/Wallet/NEP6Wallet.cs delete mode 100644 src/Neo.SDK/Wallet/ScryptParameters.cs diff --git a/src/Neo.SDK/JsonWalletDefaults.cs b/src/Neo.SDK/JsonWalletDefaults.cs deleted file mode 100644 index 9dc2b38a54..0000000000 --- a/src/Neo.SDK/JsonWalletDefaults.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2015-2024 The Neo Project. -// -// JsonWalletDefaults.cs file belongs to the neo project and is free -// software distributed under the MIT software license, see the -// accompanying file LICENSE in the main directory of the -// repository or http://www.opensource.org/licenses/mit-license.php -// for more details. -// -// Redistribution and use in source and binary forms with or without -// modifications are permitted. - -namespace Neo.SDK -{ - internal class JsonWalletDefaults - { - public static readonly string Version = "version"; - public static readonly string Name = "name"; - public static readonly string Scrypt = "scrypt"; - public static readonly string Accounts = "accounts"; - public static readonly string Extra = "extra"; - } -} diff --git a/src/Neo.SDK/Neo.SDK.csproj b/src/Neo.SDK/Neo.SDK.csproj deleted file mode 100644 index d6f6dab6d0..0000000000 --- a/src/Neo.SDK/Neo.SDK.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - netstandard2.1;net8.0 - true - enable - Neo.SDK - NEO;AntShares;Blockchain;Smart Contract;SDK;Software Development Kit - ../../bin/$(PackageId) - - - - - - - - - - - - - diff --git a/src/Neo.SDK/Wallet/NEP6Wallet.cs b/src/Neo.SDK/Wallet/NEP6Wallet.cs deleted file mode 100644 index b8d4050f24..0000000000 --- a/src/Neo.SDK/Wallet/NEP6Wallet.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2015-2024 The Neo Project. -// -// NEP6Wallet.cs file belongs to the neo project and is free -// software distributed under the MIT software license, see the -// accompanying file LICENSE in the main directory of the -// repository or http://www.opensource.org/licenses/mit-license.php -// for more details. -// -// Redistribution and use in source and binary forms with or without -// modifications are permitted. - -using Microsoft.Extensions.Configuration; -using System; -using System.IO; -using System.Security; - -namespace Neo.SDK.Wallet -{ - public class NEP6Wallet - { - public string? Name { get; internal set; } - public Version Version { get; internal set; } = new Version("1.0"); - public SecureString? Password { get; internal set; } - public ScryptParameters Scrypt { get; internal set; } = ScryptParameters.Default; - public IConfigurationSection? Extra { get; internal set; } - - public static NEP6Wallet Load(IConfigurationRoot section) - { - var wallet = new NEP6Wallet(); - var version = section.GetValue(JsonWalletDefaults.Version, Version.Parse("1.0")); - - if (version != wallet.Version) - throw new InvalidDataException(JsonWalletDefaults.Version); - - wallet.Name = section.GetValue(JsonWalletDefaults.Name, string.Empty); - wallet.Scrypt = section.GetValue(JsonWalletDefaults.Scrypt, ScryptParameters.Default)!; - wallet.Extra = section.GetSection(JsonWalletDefaults.Extra); - - return wallet; - } - } -} diff --git a/src/Neo.SDK/Wallet/ScryptParameters.cs b/src/Neo.SDK/Wallet/ScryptParameters.cs deleted file mode 100644 index 777082e1e0..0000000000 --- a/src/Neo.SDK/Wallet/ScryptParameters.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015-2024 The Neo Project. -// -// ScryptParameters.cs file belongs to the neo project and is free -// software distributed under the MIT software license, see the -// accompanying file LICENSE in the main directory of the -// repository or http://www.opensource.org/licenses/mit-license.php -// for more details. -// -// Redistribution and use in source and binary forms with or without -// modifications are permitted. - -using Microsoft.Extensions.Configuration; - -namespace Neo.SDK.Wallet -{ - public class ScryptParameters - { - public static ScryptParameters Default => new() { N = 16384, R = 8, P = 8 }; - - public int N { get; set; } - public int R { get; set; } - public int P { get; set; } - - public static ScryptParameters Load(IConfigurationSection section) => - new() - { - N = section.GetValue("n"), - R = section.GetValue("r"), - P = section.GetValue("p") - }; - } -}