diff --git a/Substrate.NetApi.TestNode/BasicTest.cs b/Substrate.NetApi.TestNode/BasicTest.cs index e737be5..f705d03 100644 --- a/Substrate.NetApi.TestNode/BasicTest.cs +++ b/Substrate.NetApi.TestNode/BasicTest.cs @@ -40,7 +40,7 @@ public async Task GetSystemChainTestAsync() { var result = await _substrateClient.System.ChainAsync(CancellationToken.None); - Assert.AreEqual("Bajun Kusama", result); + Assert.AreEqual("Polkadot", result); } [Test] @@ -80,9 +80,9 @@ public async Task GetSystemPropertiesTestAsync() { var result = await _substrateClient.System.PropertiesAsync(CancellationToken.None); - Assert.AreEqual(1337, result.Ss58Format); - Assert.AreEqual(12, result.TokenDecimals); - Assert.AreEqual("BAJU", result.TokenSymbol); + Assert.AreEqual(0, result.Ss58Format); + Assert.AreEqual(10, result.TokenDecimals); + Assert.AreEqual("DOT", result.TokenSymbol); } [Test] @@ -93,7 +93,7 @@ public async Task GetBlockNumberTestAsync() var result = await _substrateClient.Chain.GetBlockHashAsync(blockNumber, CancellationToken.None); - Assert.AreEqual("0x35A06BFEC2EDF0FF4BE89A6428CCD9FF5BD0167D618C5A0D4341F9600A458D14", result.Value); + Assert.AreEqual("0x91B171BB158E2D3848FA23A9F1C25182FB8E20313B2C1EB49219DA7A70CE90C3", result.Value); } [Test] @@ -110,7 +110,7 @@ public async Task GetAccountInfoTestAsync() var result = await _substrateClient.GetStorageAsync(parameters, CancellationToken.None); Assert.IsNotNull(result); - Assert.AreEqual("0x35A06BFEC2EDF0FF4BE89A6428CCD9FF5BD0167D618C5A0D4341F9600A458D14", Utils.Bytes2HexString(result.Value.Select(p => p.Value).ToArray())); + Assert.AreEqual("0x91B171BB158E2D3848FA23A9F1C25182FB8E20313B2C1EB49219DA7A70CE90C3", Utils.Bytes2HexString(result.Value.Select(p => p.Value).ToArray())); blockNumber.Create(999999999); diff --git a/Substrate.NetApi.TestNode/ModuleChainTest.cs b/Substrate.NetApi.TestNode/ModuleChainTest.cs new file mode 100644 index 0000000..7630fde --- /dev/null +++ b/Substrate.NetApi.TestNode/ModuleChainTest.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Metadata; +using System.Threading; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; +using NUnit.Framework; +using StreamJsonRpc; +using Substrate.NetApi.Model.Rpc; +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Primitive; + +namespace Substrate.NetApi.TestNode +{ + public class ModuleChainTest : NodeTest + { + [Test] + public async Task GetBlockAsyncTestAsync() + { + var result = await _substrateClient.Chain.GetBlockAsync(CancellationToken.None); + + Assert.IsNotNull(result); + } + + + } +} \ No newline at end of file diff --git a/Substrate.NetApi.TestNode/ModulePaymentTest.cs b/Substrate.NetApi.TestNode/ModulePaymentTest.cs index 85d97a9..371939d 100644 --- a/Substrate.NetApi.TestNode/ModulePaymentTest.cs +++ b/Substrate.NetApi.TestNode/ModulePaymentTest.cs @@ -11,7 +11,7 @@ namespace Substrate.NetApi.TestNode public class ModulePaymentTest : NodeTest { [Test] - [TestCase("0x5d02840094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c58270128da3e1cd19a10e3bbdd37ef0f24a0424a6febc1a6adeaa46ef0294a0f300e795dc4cfd380345b4fa53e28a8c258bd4ff4b0ed6554b78fc292d3aed0659ac48a45031989000f0700c87277c3912dfe4107ab28c32309c6b10ca6c0ad6ebc540fbfd26674db51b5291f0000005b2c765c5c43be65")] + [TestCase("0x4902840094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c582701b475d9d1d45cc3f372607f3542ba5671a9328303610e4b6274e7e574eeff3064a7d1a2bfb807d7a0577f9fc2b47925db22ffb9ec8c1bf04793c5a3a789edf28245020101000005030094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c58270700e40b5402")] public async Task QueryFeeDetailTestAsync(string extrinsicHex) { await _substrateClient.ConnectAsync(false, CancellationToken.None); @@ -23,7 +23,7 @@ public async Task QueryFeeDetailTestAsync(string extrinsicHex) } [Test] - [TestCase("0x5d02840094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c58270128da3e1cd19a10e3bbdd37ef0f24a0424a6febc1a6adeaa46ef0294a0f300e795dc4cfd380345b4fa53e28a8c258bd4ff4b0ed6554b78fc292d3aed0659ac48a45031989000f0700c87277c3912dfe4107ab28c32309c6b10ca6c0ad6ebc540fbfd26674db51b5291f0000005b2c765c5c43be65")] + [TestCase("0x4902840094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c582701b475d9d1d45cc3f372607f3542ba5671a9328303610e4b6274e7e574eeff3064a7d1a2bfb807d7a0577f9fc2b47925db22ffb9ec8c1bf04793c5a3a789edf28245020101000005030094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c58270700e40b5402")] public async Task QueryInfoTestAsync(string extrinsicHex) { diff --git a/Substrate.NetApi.TestNode/ModuleRuntimeCallTest.cs b/Substrate.NetApi.TestNode/ModuleRuntimeCallTest.cs new file mode 100644 index 0000000..c31cadd --- /dev/null +++ b/Substrate.NetApi.TestNode/ModuleRuntimeCallTest.cs @@ -0,0 +1,47 @@ +using NUnit.Framework; +using Substrate.NetApi.Model.Types.Metadata; +using Substrate.NetApi.Model.Types.Metadata.V14; +using System.Threading; +using System.Threading.Tasks; +using System.Linq; +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Primitive; + +namespace Substrate.NetApi.TestNode +{ + public class ModuleRuntimeCallTest : NodeTest + { + [Test] + public async Task GetMetadataTestAsync() + { + var result14 = await _substrateClient.RuntimeCall.MetadataAsync(CancellationToken.None); + var mdv14 = new RuntimeMetadata(); + mdv14.Create(result14.Value.Select(p => p.Value).ToArray()); + Assert.IsNotNull(mdv14); + } + + [Test] + public async Task GetMetadataAtVersionTestAsync() + { + var result14 = await _substrateClient.RuntimeCall.MetadataAtVersionAsync(14, CancellationToken.None); + var mdv14 = new RuntimeMetadata(); + mdv14.Create(result14.Value.Value.Select(p => p.Value).ToArray()); + Assert.IsNotNull(mdv14); + + var result15 = await _substrateClient.RuntimeCall.MetadataAtVersionAsync(15, CancellationToken.None); + var mdv15 = new RuntimeMetadata(); + mdv15.Create(result15.Value.Value.Select(p => p.Value).ToArray()); + Assert.IsNotNull(mdv15); + } + + [Test] + public async Task GetMetadataVersionsTestAsync() + { + var result = await _substrateClient.RuntimeCall.MetadataVersionsAsync(CancellationToken.None); + + Assert.IsNotNull(result); + Assert.AreEqual(14, result.Value[0].Value); + Assert.AreEqual(15, result.Value[1].Value); + } + } +} \ No newline at end of file diff --git a/Substrate.NetApi.TestNode/ModuleStateTest.cs b/Substrate.NetApi.TestNode/ModuleStateTest.cs index d9ebb43..77d20f9 100644 --- a/Substrate.NetApi.TestNode/ModuleStateTest.cs +++ b/Substrate.NetApi.TestNode/ModuleStateTest.cs @@ -34,12 +34,12 @@ public async Task GetKeysPagedAtTestAsync() } [Test] - [TestCase("0x26aa394eea5630e07c48ae0c9558cef7a44704b568d21667356a5a050c118746b4def25cfda6ef3a00000000")] - public async Task GetQueryStorageAtAsyncTestAsync(string storageKeyHex) + [TestCase("0x26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac", "0xa6aeb4a363120918b0a844e2bb17113d7d96f512c025dacd0fa015b9125669cf")] + public async Task GetQueryStorageAtAsyncTestAsync(string storageKeyHex, string blockHash) { var storageKeys = new List() { Utils.HexToByteArray(storageKeyHex) }; - var results = await _substrateClient.State.GetQueryStorageAtAsync(storageKeys, string.Empty, CancellationToken.None); + var results = await _substrateClient.State.GetQueryStorageAtAsync(storageKeys, blockHash, CancellationToken.None); Assert.IsNotNull(results); Assert.IsNotNull(results.First()); @@ -47,8 +47,8 @@ public async Task GetQueryStorageAtAsyncTestAsync(string storageKeyHex) var result = results.First(); Assert.True(result.Block.Value.StartsWith("0x")); Assert.AreEqual(1, result.Changes.Length); - Assert.AreEqual("0x26aa394eea5630e07c48ae0c9558cef7a44704b568d21667356a5a050c118746b4def25cfda6ef3a00000000", result.Changes[0][0]); - Assert.AreEqual("0x35a06bfec2edf0ff4be89a6428ccd9ff5bd0167d618c5a0d4341f9600a458d14", result.Changes[0][1]); + Assert.AreEqual("0x26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac", result.Changes[0][0]); + Assert.AreEqual("0xc50c4e01", result.Changes[0][1]); } [Test] diff --git a/Substrate.NetApi.TestNode/NodeTest.cs b/Substrate.NetApi.TestNode/NodeTest.cs index 7653da6..3f1ecaa 100644 --- a/Substrate.NetApi.TestNode/NodeTest.cs +++ b/Substrate.NetApi.TestNode/NodeTest.cs @@ -5,12 +5,15 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Substrate.NetApi.Model.Types.Base; namespace Substrate.NetApi.TestNode { public abstract class NodeTest { - protected const string WebSocketUrl = "ws://rpc-parachain.bajun.network"; + //protected const string WebSocketUrl = "wss://rpc-paseo.bajun.network"; + //protected const string WebSocketUrl = "wss://rpc-parachain.bajun.network"; + protected const string WebSocketUrl = "wss://polkadot-rpc.dwellir.com"; protected SubstrateClient _substrateClient; @@ -43,14 +46,13 @@ public void DisposeClient() /// Return the 20th hash block from now (totally arbitrary) /// /// - protected async Task GivenBlockAsync() + protected async Task GivenBlockAsync() { var lastBlockData = await _substrateClient.Chain.GetBlockAsync(); var lastBlockNumber = lastBlockData.Block.Header.Number.Value; - var blockNumber = new Model.Types.Base.BlockNumber(); - blockNumber.Create((uint)(lastBlockNumber - 20)); - return (await _substrateClient.Chain.GetBlockHashAsync(blockNumber)).Bytes; + var blockNumber = new BlockNumber((uint)(lastBlockNumber - 20)); + return await _substrateClient.Chain.GetBlockHashAsync(blockNumber); } } } diff --git a/Substrate.NetApi/Attributes/SubstrateNodeType.cs b/Substrate.NetApi/Attributes/SubstrateNodeType.cs index 8c4e87d..604fde4 100644 --- a/Substrate.NetApi/Attributes/SubstrateNodeType.cs +++ b/Substrate.NetApi/Attributes/SubstrateNodeType.cs @@ -1,5 +1,5 @@ using System; -using Substrate.NetApi.Model.Types.Metadata.V14; +using Substrate.NetApi.Model.Types.Metadata.Base; namespace Substrate.NetApi.Attributes { diff --git a/Substrate.NetApi/Model/Meta/MetaData.cs b/Substrate.NetApi/Model/Meta/MetaData.cs index 54b4142..609e047 100644 --- a/Substrate.NetApi/Model/Meta/MetaData.cs +++ b/Substrate.NetApi/Model/Meta/MetaData.cs @@ -4,7 +4,10 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Substrate.NetApi.Model.Types.Metadata; +using Substrate.NetApi.Model.Types.Metadata.Base; +using Substrate.NetApi.Model.Types.Metadata.Base.Portable; using Substrate.NetApi.Model.Types.Metadata.V14; +using Substrate.NetApi.Model.Types.Metadata.V15; namespace Substrate.NetApi.Model.Meta { @@ -18,7 +21,7 @@ public class MetaData /// /// /// - public MetaData(RuntimeMetadata rtmd, string origin = "unknown") + public MetaData(RuntimeMetadata rtmd, string origin = "unknown") { Origin = origin; Magic = Utils.Bytes2HexString(rtmd.MetaDataInfo.Magic.Bytes); @@ -255,7 +258,7 @@ public static Dictionary CreateNodeTypeDict(PortableType[] types /// /// /// - public static Dictionary CreateModuleDict(PalletMetadata[] modules) + public static Dictionary CreateModuleDict(PalletMetadataV14[] modules) { var result = new Dictionary(); @@ -286,7 +289,7 @@ public static Dictionary CreateModuleDict(PalletMetadata[] m Modifier = entry.StorageModifier.Value, StorageType = entry.StorageType.Value, Default = entry.StorageDefault.Value.Select(p => p.Value).ToArray(), - Docs = entry.Documentation.Value.Select(p => p.Value).ToArray(), + Docs = entry.Docs.Value.Select(p => p.Value).ToArray(), }; switch (entry.StorageType.Value) @@ -339,7 +342,7 @@ public static Dictionary CreateModuleDict(PalletMetadata[] m Name = constant.ConstantName.Value, TypeId = (uint)constant.ConstantType.Value, Value = constant.ConstantValue.Value.Select(p => p.Value).ToArray(), - Docs = constant.Documentation.Value.Select(p => p.Value).ToArray() + Docs = constant.Docs.Value.Select(p => p.Value).ToArray() }; } @@ -361,7 +364,7 @@ public static Dictionary CreateModuleDict(PalletMetadata[] m /// /// /// - private static ExtrinsicMetadata CreateExtrinsic(ExtrinsicMetadataStruct extrinsic) + private static ExtrinsicMetadata CreateExtrinsic(ExtrinsicMetadataV14 extrinsic) { return new ExtrinsicMetadata() { diff --git a/Substrate.NetApi/Model/Meta/MetadataTree.cs b/Substrate.NetApi/Model/Meta/MetadataTree.cs index 8d531ef..ed493a2 100644 --- a/Substrate.NetApi/Model/Meta/MetadataTree.cs +++ b/Substrate.NetApi/Model/Meta/MetadataTree.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using Newtonsoft.Json; using Newtonsoft.Json.Converters; -using Substrate.NetApi.Model.Types.Metadata.V14; +using Substrate.NetApi.Model.Types.Metadata.Base; namespace Substrate.NetApi.Model.Meta { diff --git a/Substrate.NetApi/Model/Types/Metadata/Base/ByteGetter.cs b/Substrate.NetApi/Model/Types/Metadata/Base/ByteGetter.cs new file mode 100644 index 0000000..acfffbd --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/Base/ByteGetter.cs @@ -0,0 +1,12 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Primitive; + +namespace Substrate.NetApi.Model.Types.Metadata.Base +{ + /// + /// Byte Getter + /// + public class ByteGetter : BaseVec + { + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/Base/ErrorMetadata.cs b/Substrate.NetApi/Model/Types/Metadata/Base/ErrorMetadata.cs new file mode 100644 index 0000000..42de5da --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/Base/ErrorMetadata.cs @@ -0,0 +1,34 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.V14 +{ + /// + /// Error Metadata + /// + public class ErrorMetadata : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + ErrorType = new TType(); + ErrorType.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Error Type + /// + public TType ErrorType { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V14/Field.cs b/Substrate.NetApi/Model/Types/Metadata/Base/Field.cs similarity index 93% rename from Substrate.NetApi/Model/Types/Metadata/V14/Field.cs rename to Substrate.NetApi/Model/Types/Metadata/Base/Field.cs index d6a6052..e9d6a41 100644 --- a/Substrate.NetApi/Model/Types/Metadata/V14/Field.cs +++ b/Substrate.NetApi/Model/Types/Metadata/Base/Field.cs @@ -1,6 +1,7 @@ -using System; -using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; using Substrate.NetApi.Model.Types.Primitive; +using System; namespace Substrate.NetApi.Model.Types.Metadata.V14 { diff --git a/Substrate.NetApi/Model/Types/Metadata/Base/MetaDataInfo.cs b/Substrate.NetApi/Model/Types/Metadata/Base/MetaDataInfo.cs new file mode 100644 index 0000000..6f5dbfc --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/Base/MetaDataInfo.cs @@ -0,0 +1,46 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Primitive; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.Base +{ + /// + /// Meta Data Info Type + /// + public class MetaDataInfo : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + /// Decode from byte array + /// + /// + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + Magic = new U32(); + Magic.Decode(byteArray, ref p); + + Version = new U8(); + Version.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Magic + /// + public U32 Magic { get; private set; } + + /// + /// Version + /// + public U8 Version { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/Base/PalletCallMetadata.cs b/Substrate.NetApi/Model/Types/Metadata/Base/PalletCallMetadata.cs new file mode 100644 index 0000000..ca32fc0 --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/Base/PalletCallMetadata.cs @@ -0,0 +1,33 @@ +using Substrate.NetApi.Model.Types.Base; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.Base +{ + /// + /// Pallet Call Metadata + /// + public class PalletCallMetadata : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + CallType = new TType(); + CallType.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Call Type + /// + public TType CallType { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/Base/PalletConstantMetadata.cs b/Substrate.NetApi/Model/Types/Metadata/Base/PalletConstantMetadata.cs new file mode 100644 index 0000000..2221460 --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/Base/PalletConstantMetadata.cs @@ -0,0 +1,67 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; +using Substrate.NetApi.Model.Types.Primitive; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.V14 +{ + /// + /// Pallet Constant Metadata + /// + public class PalletConstantMetadata : BaseType + { + /// + /// Encode to Bytes + /// + /// + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + /// Decode from a byte array at certain position + /// + /// + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + ConstantName = new Str(); + ConstantName.Decode(byteArray, ref p); + + ConstantType = new TType(); + ConstantType.Decode(byteArray, ref p); + + ConstantValue = new ByteGetter(); + ConstantValue.Decode(byteArray, ref p); + + Docs = new BaseVec(); + Docs.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Constant Name + /// + public Str ConstantName { get; private set; } + + /// + /// Constant Type + /// + public TType ConstantType { get; private set; } + + /// + /// Constant Value + /// + public ByteGetter ConstantValue { get; private set; } + + /// + /// Docs + /// + public BaseVec Docs { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/Base/PalletEventMetadata.cs b/Substrate.NetApi/Model/Types/Metadata/Base/PalletEventMetadata.cs new file mode 100644 index 0000000..6d6c89f --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/Base/PalletEventMetadata.cs @@ -0,0 +1,34 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.V14 +{ + /// + /// Palette Event Metadata + /// + public class PalletEventMetadata : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + EventType = new TType(); + EventType.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Event Type + /// + public TType EventType { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V14/PortableRegistry.cs b/Substrate.NetApi/Model/Types/Metadata/Base/Portable/PortableRegistry.cs similarity index 81% rename from Substrate.NetApi/Model/Types/Metadata/V14/PortableRegistry.cs rename to Substrate.NetApi/Model/Types/Metadata/Base/Portable/PortableRegistry.cs index 09a60af..a4f4c50 100644 --- a/Substrate.NetApi/Model/Types/Metadata/V14/PortableRegistry.cs +++ b/Substrate.NetApi/Model/Types/Metadata/Base/Portable/PortableRegistry.cs @@ -1,6 +1,6 @@ using Substrate.NetApi.Model.Types.Base; -namespace Substrate.NetApi.Model.Types.Metadata.V14 +namespace Substrate.NetApi.Model.Types.Metadata.Base.Portable { /// /// Portable Registry diff --git a/Substrate.NetApi/Model/Types/Metadata/V14/PortableType.cs b/Substrate.NetApi/Model/Types/Metadata/Base/Portable/PortableType.cs similarity index 85% rename from Substrate.NetApi/Model/Types/Metadata/V14/PortableType.cs rename to Substrate.NetApi/Model/Types/Metadata/Base/Portable/PortableType.cs index 76d5d1f..fcbfaed 100644 --- a/Substrate.NetApi/Model/Types/Metadata/V14/PortableType.cs +++ b/Substrate.NetApi/Model/Types/Metadata/Base/Portable/PortableType.cs @@ -1,8 +1,9 @@ -using System; -using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.V14; using Substrate.NetApi.Model.Types.Primitive; +using System; -namespace Substrate.NetApi.Model.Types.Metadata.V14 +namespace Substrate.NetApi.Model.Types.Metadata.Base.Portable { /// /// Portable Type @@ -37,7 +38,7 @@ public override void Decode(byte[] byteArray, ref int p) /// Id /// public U32 Id { get; private set; } - + /// /// Ty /// diff --git a/Substrate.NetApi/Model/Types/Metadata/V14/TypePortableForm.cs b/Substrate.NetApi/Model/Types/Metadata/Base/Portable/TypePortableForm.cs similarity index 96% rename from Substrate.NetApi/Model/Types/Metadata/V14/TypePortableForm.cs rename to Substrate.NetApi/Model/Types/Metadata/Base/Portable/TypePortableForm.cs index 13e90f0..870091d 100644 --- a/Substrate.NetApi/Model/Types/Metadata/V14/TypePortableForm.cs +++ b/Substrate.NetApi/Model/Types/Metadata/Base/Portable/TypePortableForm.cs @@ -1,6 +1,7 @@ -using System; -using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; using Substrate.NetApi.Model.Types.Primitive; +using System; namespace Substrate.NetApi.Model.Types.Metadata.V14 { @@ -52,7 +53,7 @@ public override void Decode(byte[] byteArray, ref int p) /// Type Definition /// public BaseEnumExt, TypeDefCompact, TypeDefBitSequence, BaseVoid> TypeDef { get; private set; } - + /// /// Docs /// diff --git a/Substrate.NetApi/Model/Types/Metadata/Base/SignedExtensionMetadataStruct.cs b/Substrate.NetApi/Model/Types/Metadata/Base/SignedExtensionMetadataStruct.cs new file mode 100644 index 0000000..8980a7a --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/Base/SignedExtensionMetadataStruct.cs @@ -0,0 +1,53 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Primitive; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.Base +{ + /// + /// Signed Extension Metadata Struct + /// + public class SignedExtensionMetadataStruct : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + SignedIdentifier = new Str(); + SignedIdentifier.Decode(byteArray, ref p); + + SignedExtType = new TType(); + SignedExtType.Decode(byteArray, ref p); + + AddSignedExtType = new TType(); + AddSignedExtType.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Signed Identifier + /// The unique signed extension identifier, which may be different from the type name. + /// + public Str SignedIdentifier { get; private set; } + + /// + /// Signed Extension Type + /// The type of the signed extension, with the data to be included in the extrinsic. + /// + public TType SignedExtType { get; private set; } + + /// + /// Add Signed Extension Type + /// The type of the additional signed data, with the data to be included in the signed payload + /// + public TType AddSignedExtType { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/Base/StorageEntryMetadata.cs b/Substrate.NetApi/Model/Types/Metadata/Base/StorageEntryMetadata.cs new file mode 100644 index 0000000..e9e56bc --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/Base/StorageEntryMetadata.cs @@ -0,0 +1,68 @@ +using Substrate.NetApi.Model.Meta; +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Primitive; +using System; +using static Substrate.NetApi.Model.Meta.Storage; + +namespace Substrate.NetApi.Model.Types.Metadata.Base +{ + /// + /// Storage Entry Metadata + /// + public class StorageEntryMetadata : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + StorageName = new Str(); + StorageName.Decode(byteArray, ref p); + + StorageModifier = new BaseEnum(); + StorageModifier.Decode(byteArray, ref p); + + StorageType = new BaseEnumExt(); + StorageType.Decode(byteArray, ref p); + + StorageDefault = new ByteGetter(); + StorageDefault.Decode(byteArray, ref p); + + Docs = new BaseVec(); + Docs.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Storage Name + /// + public Str StorageName { get; private set; } + + /// + /// Storage Modifier + /// + public BaseEnum StorageModifier { get; private set; } + + /// + /// Storage Type + /// + public BaseEnumExt StorageType { get; private set; } + + /// + /// Storage Default + /// + public ByteGetter StorageDefault { get; private set; } + + /// + /// Docs + /// + public BaseVec Docs { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/Base/StorageEntryTypeMap.cs b/Substrate.NetApi/Model/Types/Metadata/Base/StorageEntryTypeMap.cs new file mode 100644 index 0000000..e609893 --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/Base/StorageEntryTypeMap.cs @@ -0,0 +1,50 @@ +using Substrate.NetApi.Model.Types.Base; +using System; +using static Substrate.NetApi.Model.Meta.Storage; + +namespace Substrate.NetApi.Model.Types.Metadata.Base +{ + /// + /// Storage Entry Type Map + /// + public class StorageEntryTypeMap : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + Hashers = new BaseVec>(); + Hashers.Decode(byteArray, ref p); + + Key = new TType(); + Key.Decode(byteArray, ref p); + + Value = new TType(); + Value.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Hashers + /// + public BaseVec> Hashers { get; private set; } + + /// + /// Key + /// + public TType Key { get; private set; } + + /// + /// Value + /// + public TType Value { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/Base/StorageMetadata.cs b/Substrate.NetApi/Model/Types/Metadata/Base/StorageMetadata.cs new file mode 100644 index 0000000..feb9417 --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/Base/StorageMetadata.cs @@ -0,0 +1,42 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Primitive; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.Base +{ + /// + /// Storage Metadata + /// + public class StorageMetadata : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + Prefix = new Str(); + Prefix.Decode(byteArray, ref p); + + Entries = new BaseVec(); + Entries.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Prefix + /// + public Str Prefix { get; private set; } + + /// + /// Entries + /// + public BaseVec Entries { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V14/TypeDefs.cs b/Substrate.NetApi/Model/Types/Metadata/Base/TypeDefs.cs similarity index 98% rename from Substrate.NetApi/Model/Types/Metadata/V14/TypeDefs.cs rename to Substrate.NetApi/Model/Types/Metadata/Base/TypeDefs.cs index 3b75726..4f2cfde 100644 --- a/Substrate.NetApi/Model/Types/Metadata/V14/TypeDefs.cs +++ b/Substrate.NetApi/Model/Types/Metadata/Base/TypeDefs.cs @@ -1,9 +1,10 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.V14; using Substrate.NetApi.Model.Types.Primitive; +using System; -namespace Substrate.NetApi.Model.Types.Metadata.V14 +namespace Substrate.NetApi.Model.Types.Metadata.Base { /// /// Compact Integer Type @@ -252,7 +253,7 @@ public override void Decode(byte[] byteArray, ref int p) /// Len /// public U32 Len { get; private set; } - + /// /// Type Param /// @@ -404,7 +405,7 @@ public override void Decode(byte[] byteArray, ref int p) /// Bit Store Type /// public TType BitStoreType { get; private set; } - + /// /// Bit Order Type /// diff --git a/Substrate.NetApi/Model/Types/Metadata/V14/Variant.cs b/Substrate.NetApi/Model/Types/Metadata/Base/Variant.cs similarity index 89% rename from Substrate.NetApi/Model/Types/Metadata/V14/Variant.cs rename to Substrate.NetApi/Model/Types/Metadata/Base/Variant.cs index 750bf67..025c666 100644 --- a/Substrate.NetApi/Model/Types/Metadata/V14/Variant.cs +++ b/Substrate.NetApi/Model/Types/Metadata/Base/Variant.cs @@ -1,8 +1,9 @@ -using System; -using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.V14; using Substrate.NetApi.Model.Types.Primitive; +using System; -namespace Substrate.NetApi.Model.Types.Metadata.V14 +namespace Substrate.NetApi.Model.Types.Metadata.Base { /// /// Variant Type diff --git a/Substrate.NetApi/Model/Types/Metadata/RuntimeMetadata.cs b/Substrate.NetApi/Model/Types/Metadata/RuntimeMetadata.cs index fa2e914..9c5684a 100644 --- a/Substrate.NetApi/Model/Types/Metadata/RuntimeMetadata.cs +++ b/Substrate.NetApi/Model/Types/Metadata/RuntimeMetadata.cs @@ -1,13 +1,13 @@ -using System; -using Substrate.NetApi.Model.Types.Base; -using Substrate.NetApi.Model.Types.Metadata.V14; +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; +using System; namespace Substrate.NetApi.Model.Types.Metadata { /// /// Runtime Metadata Type /// - public class RuntimeMetadata : BaseType + public class RuntimeMetadata : BaseType where T : BaseType, new() { /// public override string TypeName() => "RuntimeMetadata"; @@ -26,7 +26,7 @@ public override void Decode(byte[] byteArray, ref int p) MetaDataInfo = new MetaDataInfo(); MetaDataInfo.Decode(byteArray, ref p); - RuntimeMetadataData = new RuntimeMetadataV14(); + RuntimeMetadataData = new T(); RuntimeMetadataData.Decode(byteArray, ref p); TypeSize = p - start; @@ -36,10 +36,10 @@ public override void Decode(byte[] byteArray, ref int p) /// Meta Data Info /// public MetaDataInfo MetaDataInfo { get; private set; } - + /// /// Runtime Metadata Data /// - public RuntimeMetadataV14 RuntimeMetadataData { get; private set; } + public T RuntimeMetadataData { get; private set; } } } \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V14/ExtrinsicMetadataV14.cs b/Substrate.NetApi/Model/Types/Metadata/V14/ExtrinsicMetadataV14.cs new file mode 100644 index 0000000..0ad6eae --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/V14/ExtrinsicMetadataV14.cs @@ -0,0 +1,51 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; +using Substrate.NetApi.Model.Types.Primitive; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.V14 +{ + /// + /// Extrinsic Metadata Struct + /// + public class ExtrinsicMetadataV14 : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + ExtrinsicType = new TType(); + ExtrinsicType.Decode(byteArray, ref p); + + Version = new U8(); + Version.Decode(byteArray, ref p); + + SignedExtensions = new BaseVec(); + SignedExtensions.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Extrinsic Type + /// + public TType ExtrinsicType { get; private set; } + + /// + /// Version + /// + public U8 Version { get; private set; } + + /// + /// Signed Extensions + /// + public BaseVec SignedExtensions { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V14/PalletMetadataV14.cs b/Substrate.NetApi/Model/Types/Metadata/V14/PalletMetadataV14.cs new file mode 100644 index 0000000..27add55 --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/V14/PalletMetadataV14.cs @@ -0,0 +1,83 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; +using Substrate.NetApi.Model.Types.Primitive; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.V14 +{ + /// + /// Palette Metadata + /// + public class PalletMetadataV14 : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + PalletName = new Str(); + PalletName.Decode(byteArray, ref p); + + PalletStorage = new BaseOpt(); + PalletStorage.Decode(byteArray, ref p); + + PalletCalls = new BaseOpt(); + PalletCalls.Decode(byteArray, ref p); + + PalletEvents = new BaseOpt(); + PalletEvents.Decode(byteArray, ref p); + + PalletConstants = new BaseVec(); + PalletConstants.Decode(byteArray, ref p); + + PalletErrors = new BaseOpt(); + PalletErrors.Decode(byteArray, ref p); + + Index = new U8(); + Index.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Palette Name + /// + public Str PalletName { get; private set; } + + /// + /// Palette Storage + /// + public BaseOpt PalletStorage { get; private set; } + + /// + /// Palette Calls + /// + public BaseOpt PalletCalls { get; private set; } + + /// + /// Palette Events + /// + public BaseOpt PalletEvents { get; private set; } + + /// + /// Palette Constants + /// + public BaseVec PalletConstants { get; private set; } + + /// + /// Palette Errors + /// + public BaseOpt PalletErrors { get; private set; } + + /// + /// Index + /// + public U8 Index { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V14/RuntimeMetadataV14.cs b/Substrate.NetApi/Model/Types/Metadata/V14/RuntimeMetadataV14.cs index 0c4a5ba..593e02f 100644 --- a/Substrate.NetApi/Model/Types/Metadata/V14/RuntimeMetadataV14.cs +++ b/Substrate.NetApi/Model/Types/Metadata/V14/RuntimeMetadataV14.cs @@ -1,8 +1,7 @@ -using System; -using Substrate.NetApi.Model.Meta; -using Substrate.NetApi.Model.Types.Base; -using Substrate.NetApi.Model.Types.Primitive; -using static Substrate.NetApi.Model.Meta.Storage; +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; +using Substrate.NetApi.Model.Types.Metadata.Base.Portable; +using System; namespace Substrate.NetApi.Model.Types.Metadata.V14 { @@ -25,10 +24,10 @@ public override void Decode(byte[] byteArray, ref int p) Types = new PortableRegistry(); Types.Decode(byteArray, ref p); - Modules = new BaseVec(); + Modules = new BaseVec(); Modules.Decode(byteArray, ref p); - Extrinsic = new ExtrinsicMetadataStruct(); + Extrinsic = new ExtrinsicMetadataV14(); Extrinsic.Decode(byteArray, ref p); TypeId = new TType(); @@ -45,511 +44,16 @@ public override void Decode(byte[] byteArray, ref int p) /// /// Modules /// - public BaseVec Modules { get; private set; } + public BaseVec Modules { get; private set; } /// /// Extrinsic /// - public ExtrinsicMetadataStruct Extrinsic { get; private set; } + public ExtrinsicMetadataV14 Extrinsic { get; private set; } /// /// Type Id /// public TType TypeId { get; private set; } } - - /// - /// Meta Data Info Type - /// - public class MetaDataInfo : BaseType - { - /// - public override byte[] Encode() - { - throw new NotImplementedException(); - } - - /// - /// Decode from byte array - /// - /// - /// - public override void Decode(byte[] byteArray, ref int p) - { - var start = p; - - Magic = new U32(); - Magic.Decode(byteArray, ref p); - - Version = new U8(); - Version.Decode(byteArray, ref p); - - TypeSize = p - start; - } - - /// - /// Magic - /// - public U32 Magic { get; private set; } - - /// - /// Version - /// - public U8 Version { get; private set; } - } - - /// - /// Palette Metadata - /// - public class PalletMetadata : BaseType - { - /// - public override byte[] Encode() - { - throw new NotImplementedException(); - } - - /// - public override void Decode(byte[] byteArray, ref int p) - { - var start = p; - - PalletName = new Str(); - PalletName.Decode(byteArray, ref p); - - PalletStorage = new BaseOpt(); - PalletStorage.Decode(byteArray, ref p); - - PalletCalls = new BaseOpt(); - PalletCalls.Decode(byteArray, ref p); - - PalletEvents = new BaseOpt(); - PalletEvents.Decode(byteArray, ref p); - - PalletConstants = new BaseVec(); - PalletConstants.Decode(byteArray, ref p); - - PalletErrors = new BaseOpt(); - PalletErrors.Decode(byteArray, ref p); - - Index = new U8(); - Index.Decode(byteArray, ref p); - - TypeSize = p - start; - } - - /// - /// Palette Name - /// - public Str PalletName { get; private set; } - - /// - /// Palette Storage - /// - public BaseOpt PalletStorage { get; private set; } - - /// - /// Palette Calls - /// - public BaseOpt PalletCalls { get; private set; } - - /// - /// Palette Events - /// - public BaseOpt PalletEvents { get; private set; } - - /// - /// Palette Constants - /// - public BaseVec PalletConstants { get; private set; } - - /// - /// Palette Errors - /// - public BaseOpt PalletErrors { get; private set; } - - /// - /// Index - /// - public U8 Index { get; private set; } - } - - /// - /// Storage Metadata - /// - public class StorageMetadata : BaseType - { - /// - public override byte[] Encode() - { - throw new NotImplementedException(); - } - - /// - public override void Decode(byte[] byteArray, ref int p) - { - var start = p; - - Prefix = new Str(); - Prefix.Decode(byteArray, ref p); - - Entries = new BaseVec(); - Entries.Decode(byteArray, ref p); - - TypeSize = p - start; - } - - /// - /// Prefix - /// - public Str Prefix { get; private set; } - - /// - /// Entries - /// - public BaseVec Entries { get; private set; } - } - - /// - /// Storage Entry Metadata - /// - public class StorageEntryMetadata : BaseType - { - /// - public override byte[] Encode() - { - throw new NotImplementedException(); - } - - /// - public override void Decode(byte[] byteArray, ref int p) - { - var start = p; - - StorageName = new Str(); - StorageName.Decode(byteArray, ref p); - - StorageModifier = new BaseEnum(); - StorageModifier.Decode(byteArray, ref p); - - StorageType = new BaseEnumExt(); - StorageType.Decode(byteArray, ref p); - - StorageDefault = new ByteGetter(); - StorageDefault.Decode(byteArray, ref p); - - Documentation = new BaseVec(); - Documentation.Decode(byteArray, ref p); - - TypeSize = p - start; - } - - /// - /// Storage Name - /// - public Str StorageName { get; private set; } - - /// - /// Storage Modifier - /// - public BaseEnum StorageModifier { get; private set; } - - /// - /// Storage Type - /// - public BaseEnumExt StorageType { get; private set; } - - /// - /// Storage Default - /// - public ByteGetter StorageDefault { get; private set; } - - /// - /// Documentation - /// - public BaseVec Documentation { get; private set; } - } - - /// - /// Byte Getter - /// - public class ByteGetter : BaseVec - { - } - - /// - /// Storage Entry Type Map - /// - public class StorageEntryTypeMap : BaseType - { - /// - public override byte[] Encode() - { - throw new NotImplementedException(); - } - - /// - public override void Decode(byte[] byteArray, ref int p) - { - var start = p; - - Hashers = new BaseVec>(); - Hashers.Decode(byteArray, ref p); - - Key = new TType(); - Key.Decode(byteArray, ref p); - - Value = new TType(); - Value.Decode(byteArray, ref p); - - TypeSize = p - start; - } - - /// - /// Hashers - /// - public BaseVec> Hashers { get; private set; } - - /// - /// Key - /// - public TType Key { get; private set; } - - /// - /// Value - /// - public TType Value { get; private set; } - } - - /// - /// Pallet Call Metadata - /// - public class PalletCallMetadata : BaseType - { - /// - public override byte[] Encode() - { - throw new NotImplementedException(); - } - - /// - public override void Decode(byte[] byteArray, ref int p) - { - var start = p; - - CallType = new TType(); - CallType.Decode(byteArray, ref p); - - TypeSize = p - start; - } - - /// - /// Call Type - /// - public TType CallType { get; private set; } - } - - /// - /// Palette Event Metadata - /// - public class PalletEventMetadata : BaseType - { - /// - public override byte[] Encode() - { - throw new NotImplementedException(); - } - - /// - public override void Decode(byte[] byteArray, ref int p) - { - var start = p; - - EventType = new TType(); - EventType.Decode(byteArray, ref p); - - TypeSize = p - start; - } - - /// - /// Event Type - /// - public TType EventType { get; private set; } - } - - /// - /// Pallet Constant Metadata - /// - public class PalletConstantMetadata : BaseType - { - /// - /// Encode to Bytes - /// - /// - /// - public override byte[] Encode() - { - throw new NotImplementedException(); - } - - /// - /// Decode from a byte array at certain position - /// - /// - /// - public override void Decode(byte[] byteArray, ref int p) - { - var start = p; - - ConstantName = new Str(); - ConstantName.Decode(byteArray, ref p); - - ConstantType = new TType(); - ConstantType.Decode(byteArray, ref p); - - ConstantValue = new ByteGetter(); - ConstantValue.Decode(byteArray, ref p); - - Documentation = new BaseVec(); - Documentation.Decode(byteArray, ref p); - - TypeSize = p - start; - } - - /// - /// Constant Name - /// - public Str ConstantName { get; private set; } - - /// - /// Constant Type - /// - public TType ConstantType { get; private set; } - - /// - /// Constant Value - /// - public ByteGetter ConstantValue { get; private set; } - - /// - /// Documentation - /// - public BaseVec Documentation { get; private set; } - } - - /// - /// Error Metadata - /// - public class ErrorMetadata : BaseType - { - /// - public override byte[] Encode() - { - throw new NotImplementedException(); - } - - /// - public override void Decode(byte[] byteArray, ref int p) - { - var start = p; - - ErrorType = new TType(); - ErrorType.Decode(byteArray, ref p); - - TypeSize = p - start; - } - - /// - /// Error Type - /// - public TType ErrorType { get; private set; } - } - - /// - /// Extrinsic Metadata Struct - /// - public class ExtrinsicMetadataStruct : BaseType - { - /// - public override byte[] Encode() - { - throw new NotImplementedException(); - } - - /// - public override void Decode(byte[] byteArray, ref int p) - { - var start = p; - - ExtrinsicType = new TType(); - ExtrinsicType.Decode(byteArray, ref p); - - Version = new U8(); - Version.Decode(byteArray, ref p); - - SignedExtensions = new BaseVec(); - SignedExtensions.Decode(byteArray, ref p); - - TypeSize = p - start; - } - - /// - /// Extrinsic Type - /// - public TType ExtrinsicType { get; private set; } - - /// - /// Version - /// - public U8 Version { get; private set; } - - /// - /// Signed Extensions - /// - public BaseVec SignedExtensions { get; private set; } - } - - /// - /// Signed Extension Metadata Struct - /// - public class SignedExtensionMetadataStruct : BaseType - { - /// - public override byte[] Encode() - { - throw new NotImplementedException(); - } - - /// - public override void Decode(byte[] byteArray, ref int p) - { - var start = p; - - SignedIdentifier = new Str(); - SignedIdentifier.Decode(byteArray, ref p); - - SignedExtType = new TType(); - SignedExtType.Decode(byteArray, ref p); - - AddSignedExtType = new TType(); - AddSignedExtType.Decode(byteArray, ref p); - - TypeSize = p - start; - } - - /// - /// Signed Identifier - /// - public Str SignedIdentifier { get; private set; } - - /// - /// Signed Extension Type - /// - public TType SignedExtType { get; private set; } - - /// - /// Add Signed Extension Type - /// - public TType AddSignedExtType { get; private set; } - } } \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V15/CustomMetadataV15.cs b/Substrate.NetApi/Model/Types/Metadata/V15/CustomMetadataV15.cs new file mode 100644 index 0000000..67bdf36 --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/V15/CustomMetadataV15.cs @@ -0,0 +1,68 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; +using Substrate.NetApi.Model.Types.Primitive; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.V15 +{ + public class CustomMetadataV15 : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + Map = new BaseVec>(); + Map.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Map + /// + public BaseVec> Map { get; private set; } + } + + /// + /// Custom Value Metadata + /// + public class CustomValueMetadataV15 : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + CustomType = new TType(); + CustomType.Decode(byteArray, ref p); + + Value = new BaseVec(); + Value.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Custom Type + /// + public TType CustomType { get; private set; } + + /// + /// Value + /// + public BaseVec Value { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V15/ExtrinsicMetadataV15.cs b/Substrate.NetApi/Model/Types/Metadata/V15/ExtrinsicMetadataV15.cs new file mode 100644 index 0000000..9bfe846 --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/V15/ExtrinsicMetadataV15.cs @@ -0,0 +1,79 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Primitive; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.Base +{ + /// + /// Extrinsic Metadata Struct + /// + public class ExtrinsicMetadataV15 : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + Version = new U8(); + Version.Decode(byteArray, ref p); + + AddressType = new TType(); + AddressType.Decode(byteArray, ref p); + + CallType = new TType(); + CallType.Decode(byteArray, ref p); + + SignatureType = new TType(); + SignatureType.Decode(byteArray, ref p); + + ExtraType = new TType(); + ExtraType.Decode(byteArray, ref p); + + SignedExtensions = new BaseVec(); + SignedExtensions.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Extrinsic Type + /// + public TType ExtrinsicType { get; private set; } + + /// + /// Version + /// + public U8 Version { get; private set; } + + /// + /// Address Type + /// + public TType AddressType { get; private set; } + + /// + /// Call Type + /// + public TType CallType { get; private set; } + + /// + /// Signature Type + /// + public TType SignatureType { get; private set; } + + /// + /// Extra Type + /// + public TType ExtraType { get; private set; } + + /// + /// Signed Extensions + /// + public BaseVec SignedExtensions { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V15/OuterEnumsV15.cs b/Substrate.NetApi/Model/Types/Metadata/V15/OuterEnumsV15.cs new file mode 100644 index 0000000..df04b16 --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/V15/OuterEnumsV15.cs @@ -0,0 +1,50 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.V15 +{ + /// + /// Outer Enums + /// + public class OuterEnumsV15 : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + CallEnumTypeId = new TType(); + CallEnumTypeId.Decode(byteArray, ref p); + + EventEnumTypeId = new TType(); + EventEnumTypeId.Decode(byteArray, ref p); + + ErrorEnumTypeId = new TType(); + ErrorEnumTypeId.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Call Enum Type Id + /// + public TType CallEnumTypeId { get; private set; } + + /// + /// Event Enum Type Id + /// + public TType EventEnumTypeId { get; private set; } + + /// + /// Error Enum Type Id + /// + public TType ErrorEnumTypeId { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V15/PalletMetadataV15.cs b/Substrate.NetApi/Model/Types/Metadata/V15/PalletMetadataV15.cs new file mode 100644 index 0000000..e241994 --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/V15/PalletMetadataV15.cs @@ -0,0 +1,92 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; +using Substrate.NetApi.Model.Types.Metadata.V14; +using Substrate.NetApi.Model.Types.Primitive; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.V15 +{ + /// + /// Palette Metadata + /// + public class PalletMetadataV15 : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + PalletName = new Str(); + PalletName.Decode(byteArray, ref p); + + PalletStorage = new BaseOpt(); + PalletStorage.Decode(byteArray, ref p); + + PalletCalls = new BaseOpt(); + PalletCalls.Decode(byteArray, ref p); + + PalletEvents = new BaseOpt(); + PalletEvents.Decode(byteArray, ref p); + + PalletConstants = new BaseVec(); + PalletConstants.Decode(byteArray, ref p); + + PalletErrors = new BaseOpt(); + PalletErrors.Decode(byteArray, ref p); + + Index = new U8(); + Index.Decode(byteArray, ref p); + + Docs = new BaseVec(); + Docs.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Palette Name + /// + public Str PalletName { get; private set; } + + /// + /// Palette Storage + /// + public BaseOpt PalletStorage { get; private set; } + + /// + /// Palette Calls + /// + public BaseOpt PalletCalls { get; private set; } + + /// + /// Palette Events + /// + public BaseOpt PalletEvents { get; private set; } + + /// + /// Palette Constants + /// + public BaseVec PalletConstants { get; private set; } + + /// + /// Palette Errors + /// + public BaseOpt PalletErrors { get; private set; } + + /// + /// Index + /// + public U8 Index { get; private set; } + + /// + /// Docs + /// + public BaseVec Docs { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V15/RuntimeApiMetadataV15.cs b/Substrate.NetApi/Model/Types/Metadata/V15/RuntimeApiMetadataV15.cs new file mode 100644 index 0000000..1d2e7b2 --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/V15/RuntimeApiMetadataV15.cs @@ -0,0 +1,138 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Primitive; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.Base +{ + /// + /// Runtime API Metadata + /// + public class RuntimeApiMetadataV15 : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + Name = new Str(); + Name.Decode(byteArray, ref p); + + Methods = new BaseVec(); + Methods.Decode(byteArray, ref p); + + Docs = new BaseVec(); + Docs.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Name + /// + public Str Name { get; private set; } + + /// + /// Methods + /// + public BaseVec Methods { get; private set; } + + /// + /// Docs + /// + public BaseVec Docs { get; private set; } + } + + /// + /// Runtime API Method Metadata + /// + public class RuntimeApiMethodMetadataV15 : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + Name = new Str(); + Name.Decode(byteArray, ref p); + + Inputs = new BaseVec(); + Inputs.Decode(byteArray, ref p); + + Output = new TType(); + Output.Decode(byteArray, ref p); + + Docs = new BaseVec(); + Docs.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Name + /// + public Str Name { get; private set; } + + /// + /// Inputs + /// + public BaseVec Inputs { get; private set; } + + /// + /// Output + /// + public TType Output { get; private set; } + + /// + /// Docs + /// + public BaseVec Docs { get; private set; } + } + + /// + /// Runtime API Method Param Metadata + /// + public class RuntimeApiMethodParamMetadataV15 : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + Name = new Str(); + Name.Decode(byteArray, ref p); + + TypeId = new TType(); + TypeId.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Name + /// + public Str Name { get; private set; } + + /// + /// Type Id + /// + public TType TypeId { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Model/Types/Metadata/V15/RuntimeMetadataV15.cs b/Substrate.NetApi/Model/Types/Metadata/V15/RuntimeMetadataV15.cs new file mode 100644 index 0000000..5b1872c --- /dev/null +++ b/Substrate.NetApi/Model/Types/Metadata/V15/RuntimeMetadataV15.cs @@ -0,0 +1,84 @@ +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Metadata.Base; +using Substrate.NetApi.Model.Types.Metadata.Base.Portable; +using Substrate.NetApi.Model.Types.Metadata.V15; +using System; + +namespace Substrate.NetApi.Model.Types.Metadata.V14 +{ + /// + /// Runtime Metadata V14 + /// + public class RuntimeMetadataV15 : BaseType + { + /// + public override byte[] Encode() + { + throw new NotImplementedException(); + } + + /// + public override void Decode(byte[] byteArray, ref int p) + { + var start = p; + + Types = new PortableRegistry(); + Types.Decode(byteArray, ref p); + + Modules = new BaseVec(); + Modules.Decode(byteArray, ref p); + + Extrinsic = new ExtrinsicMetadataV15(); + Extrinsic.Decode(byteArray, ref p); + + TypeId = new TType(); + TypeId.Decode(byteArray, ref p); + + Apis = new BaseVec(); + Apis.Decode(byteArray, ref p); + + OuterEnums = new OuterEnumsV15(); + OuterEnums.Decode(byteArray, ref p); + + Custom = new CustomMetadataV15(); + Custom.Decode(byteArray, ref p); + + TypeSize = p - start; + } + + /// + /// Types + /// + public PortableRegistry Types { get; private set; } + + /// + /// Modules + /// + public BaseVec Modules { get; private set; } + + /// + /// Extrinsic + /// + public ExtrinsicMetadataV15 Extrinsic { get; private set; } + + /// + /// Type Id + /// + public TType TypeId { get; private set; } + + /// + /// Apis + /// + public BaseVec Apis { get; private set; } + + /// + /// OuterEnums + /// + public OuterEnumsV15 OuterEnums { get; private set; } + + /// + /// Custom + /// + public CustomMetadataV15 Custom { get; private set; } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Modules/Legacy/Contracts/IRuntimeCall.cs b/Substrate.NetApi/Modules/Legacy/Contracts/IRuntimeCall.cs new file mode 100644 index 0000000..45ae5e1 --- /dev/null +++ b/Substrate.NetApi/Modules/Legacy/Contracts/IRuntimeCall.cs @@ -0,0 +1,36 @@ +using Substrate.NetApi.Model.Rpc; +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Primitive; +using System.Threading; +using System.Threading.Tasks; + +namespace Substrate.NetApi.Modules.Contracts +{ + /// + /// Runtime Call Module Interface + /// + public interface IRuntimeCall + { + /// + /// Returns the metadata of a runtime. + /// + /// + /// + Task> MetadataAsync(CancellationToken token); + + /// + /// Returns the metadata at a given version. + /// + /// + /// + /// + Task>> MetadataAtVersionAsync(uint version, CancellationToken token); + + /// + /// Returns the supported metadata versions. + /// + /// + /// + Task> MetadataVersionsAsync(CancellationToken token); + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Modules/Legacy/RuntimeCall.cs b/Substrate.NetApi/Modules/Legacy/RuntimeCall.cs new file mode 100644 index 0000000..76667ce --- /dev/null +++ b/Substrate.NetApi/Modules/Legacy/RuntimeCall.cs @@ -0,0 +1,96 @@ +using Newtonsoft.Json.Linq; +using Substrate.NetApi.Model.Types.Base; +using Substrate.NetApi.Model.Types.Primitive; +using Substrate.NetApi.Modules.Contracts; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Substrate.NetApi.Modules +{ + /// + /// RuntimeCall Module + /// + public class RuntimeCall : IRuntimeCall + { + private readonly SubstrateClient _client; + + /// + /// RuntimeCall Module Constructor + /// + /// + internal RuntimeCall(SubstrateClient client) + { + _client = client; + } + + /// + public async Task> MetadataAsync( CancellationToken token) + { + var fullParams = new object[] + { + "Metadata_metadata", + Array.Empty(), + null + }; + + var str = await _client.InvokeAsync("state_call", fullParams, token); + + if (str == null || str.Length == 0) + { + return default; + } + + var t = new BaseVec(); + t.Create(str); + + return t; + } + + /// + public async Task>> MetadataAtVersionAsync(uint version, CancellationToken token) + { + var fullParams = new object[] + { + "Metadata_metadata_at_version", + Utils.Bytes2HexString(new U32(version).Encode()), + null + }; + + var str = await _client.InvokeAsync("state_call", fullParams, token); + + if (str == null || str.Length == 0) + { + return default; + } + + var t = new BaseOpt>(); + t.Create(str); + + return t; + } + + /// + public async Task> MetadataVersionsAsync(CancellationToken token) + { + var fullParams = new object[] + { + "Metadata_metadata_versions", + Array.Empty(), + null + }; + + var str = await _client.InvokeAsync("state_call", fullParams, token); + + if (str == null || str.Length == 0) + { + return default; + } + + var t = new BaseVec(); + t.Create(str); + + return t; + } + } +} \ No newline at end of file diff --git a/Substrate.NetApi/Substrate.NetApi.csproj b/Substrate.NetApi/Substrate.NetApi.csproj index 08f7c2a..9128034 100644 --- a/Substrate.NetApi/Substrate.NetApi.csproj +++ b/Substrate.NetApi/Substrate.NetApi.csproj @@ -3,7 +3,7 @@ Substrate.NET.API netstandard2.0;netstandard2.1;net6.0 - 0.9.23 + 0.9.24-rc1 Substrate Gaming Substrate Gaming true diff --git a/Substrate.NetApi/SubstrateClient.cs b/Substrate.NetApi/SubstrateClient.cs index fc1035e..9feb73f 100644 --- a/Substrate.NetApi/SubstrateClient.cs +++ b/Substrate.NetApi/SubstrateClient.cs @@ -20,6 +20,7 @@ using Serilog; using StreamJsonRpc; using Newtonsoft.Json; +using Substrate.NetApi.Model.Types.Metadata.V14; [assembly: InternalsVisibleTo("Substrate.NetApi.Test")] @@ -79,6 +80,7 @@ public SubstrateClient(Uri uri, ChargeType chargeType, bool bypassRemoteCertific Payment = new Payment(this); State = new State(this); Author = new Author(this); + RuntimeCall = new RuntimeCall(this); TransactionWatchCalls = new TransactionWatchCalls(this); _requestTokenSourceDict = new ConcurrentDictionary(); @@ -122,6 +124,8 @@ public SubstrateClient(Uri uri, ChargeType chargeType, bool bypassRemoteCertific /// The author. public Author Author { get; } + public RuntimeCall RuntimeCall { get; } + /// /// New Api 2 /// @@ -241,7 +245,7 @@ public async Task ConnectAsync(bool useMetaData, bool standardSubstrate, Cancell { var result = await State.GetMetaDataAsync(token); - var mdv14 = new RuntimeMetadata(); + var mdv14 = new RuntimeMetadata(); mdv14.Create(result); MetaData = new MetaData(mdv14, _uri.OriginalString); Logger.Debug("MetaData parsed.");