Skip to content

Commit

Permalink
renamed RuntimeType to the NetworkType
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych committed Sep 2, 2023
1 parent 8be1081 commit f687317
Show file tree
Hide file tree
Showing 62 changed files with 696 additions and 680 deletions.
2 changes: 1 addition & 1 deletion Sources/Substrate/Api/ConstantsApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public extension ConstantsApiRegistry {
}

@inlinable
func `dynamic`(name: String, pallet: String) throws -> Value<RuntimeType.Id> {
func `dynamic`(name: String, pallet: String) throws -> Value<NetworkType.Id> {
try get(name: name, pallet: pallet)
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Substrate/Block/Block.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public protocol SomeBlock: RuntimeDynamicSwiftDecodable {
var extrinsics: [TExtrinsic] { get }

static func headerType(runtime: any Runtime,
block id: RuntimeType.Id) throws -> RuntimeType.Id
block id: NetworkType.Id) throws -> NetworkType.Id
}

public extension SomeBlock {
Expand All @@ -38,13 +38,13 @@ public protocol StaticBlock: SomeBlock, RuntimeSwiftDecodable where THeader: Run
public extension StaticBlock {
// Should never be called because of the static Header parsing
static func headerType(runtime: any Runtime,
block id: RuntimeType.Id) throws -> RuntimeType.Id {
try RuntimeType.IdNever(runtime)
block id: NetworkType.Id) throws -> NetworkType.Id {
try NetworkType.IdNever(runtime)
}
}

public protocol SomeChainBlock<TBlock>: ContextDecodable where
DecodingContext == (runtime: Runtime, blockType: RuntimeType.LazyId)
DecodingContext == (runtime: Runtime, blockType: NetworkType.LazyId)
{
associatedtype TBlock: SomeBlock

Expand All @@ -57,7 +57,7 @@ public protocol StaticChainBlock: SomeChainBlock where TBlock: StaticBlock {

public extension StaticChainBlock {
init(from decoder: Swift.Decoder,
context: (runtime: Runtime, blockType: RuntimeType.LazyId)) throws {
context: (runtime: Runtime, blockType: NetworkType.LazyId)) throws {
try self.init(from: decoder, runtime: context.runtime)
}
}
6 changes: 3 additions & 3 deletions Sources/Substrate/Block/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public extension StaticEvent {
}

public extension IdentifiableEvent where Self: RuntimeValidatableComposite {
static func validatableFieldIds(runtime: any Runtime) -> Result<[RuntimeType.Id], ValidationError> {
static func validatableFieldIds(runtime: any Runtime) -> Result<[NetworkType.Id], ValidationError> {
guard let info = runtime.resolve(eventParams: name, pallet: pallet) else {
return .failure(.infoNotFound(for: Self.self))
}
Expand All @@ -53,6 +53,6 @@ public protocol SomeEventRecord: RuntimeDynamicDecodable, RuntimeDynamicValidata
public enum EventDecodingError: Error {
case eventNotFound(index: UInt8, pallet: UInt8)
case foundWrongEvent(found: (name: String, pallet: String), expected: (name: String, pallet: String))
case decodedNonVariantValue(Value<RuntimeType.Id>)
case tooManyFieldsInVariant(variant: Value<RuntimeType.Id>, expected: Int)
case decodedNonVariantValue(Value<NetworkType.Id>)
case tooManyFieldsInVariant(variant: Value<NetworkType.Id>, expected: Int)
}
66 changes: 33 additions & 33 deletions Sources/Substrate/Config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public protocol Config {
associatedtype TExtrinsicManager: ExtrinsicManager<BC>

// Metadata Info Providers
func blockType(metadata: any Metadata) throws -> RuntimeType.Info
func hashType(metadata: any Metadata) throws -> RuntimeType.Info
func dispatchErrorType(metadata: any Metadata) throws -> RuntimeType.Info
func transactionValidityErrorType(metadata: any Metadata) throws -> RuntimeType.Info
func accountType(metadata: any Metadata, address: RuntimeType.Info) throws -> RuntimeType.Info
func blockType(metadata: any Metadata) throws -> NetworkType.Info
func hashType(metadata: any Metadata) throws -> NetworkType.Info
func dispatchErrorType(metadata: any Metadata) throws -> NetworkType.Info
func transactionValidityErrorType(metadata: any Metadata) throws -> NetworkType.Info
func accountType(metadata: any Metadata, address: NetworkType.Info) throws -> NetworkType.Info
// Сan be safely removed after removing metadata v14 (v15 has them)
func eventType(metadata: any Metadata) throws -> RuntimeType.Info
func extrinsicTypes(metadata: any Metadata) throws -> (call: RuntimeType.Info, addr: RuntimeType.Info,
signature: RuntimeType.Info, extra: RuntimeType.Info)
func eventType(metadata: any Metadata) throws -> NetworkType.Info
func extrinsicTypes(metadata: any Metadata) throws -> (call: NetworkType.Info, addr: NetworkType.Info,
signature: NetworkType.Info, extra: NetworkType.Info)
// Object Builders
func hasher(metadata: any Metadata) throws -> ST<Self>.Hasher
func defaultPayment(runtime: any Runtime) throws -> ST<Self>.ExtrinsicPayment
Expand Down Expand Up @@ -237,13 +237,13 @@ public extension Config {

// Сan be safely removed after removing metadata v14 (v15 has types inside)
public extension Config {
func extrinsicTypes(metadata: any Metadata) throws -> (call: RuntimeType.Info, addr: RuntimeType.Info,
signature: RuntimeType.Info, extra: RuntimeType.Info)
func extrinsicTypes(metadata: any Metadata) throws -> (call: NetworkType.Info, addr: NetworkType.Info,
signature: NetworkType.Info, extra: NetworkType.Info)
{
var addressTypeId: RuntimeType.Id? = nil
var sigTypeId: RuntimeType.Id? = nil
var extraTypeId: RuntimeType.Id? = nil
var callTypeId: RuntimeType.Id? = nil
var addressTypeId: NetworkType.Id? = nil
var sigTypeId: NetworkType.Id? = nil
var extraTypeId: NetworkType.Id? = nil
var callTypeId: NetworkType.Id? = nil
for param in metadata.extrinsic.type.type.parameters {
switch param.name.lowercased() {
case "address": addressTypeId = param.type
Expand All @@ -264,13 +264,13 @@ public extension Config {
{
throw ConfigTypeLookupError.extrinsicTypesNotFound
}
return (call: RuntimeType.Info(id: callTypeId, type: callType),
addr: RuntimeType.Info(id: addressTypeId, type: addressType),
signature: RuntimeType.Info(id: sigTypeId, type: sigType),
extra: RuntimeType.Info(id: extraTypeId, type: extraType))
return (call: NetworkType.Info(id: callTypeId, type: callType),
addr: NetworkType.Info(id: addressTypeId, type: addressType),
signature: NetworkType.Info(id: sigTypeId, type: sigType),
extra: NetworkType.Info(id: extraTypeId, type: extraType))
}

func eventType(metadata: any Metadata) throws -> RuntimeType.Info {
func eventType(metadata: any Metadata) throws -> NetworkType.Info {
let eventsName = EventsStorageKey<ST<Self>.BlockEvents>.name
let eventsPallet = EventsStorageKey<ST<Self>.BlockEvents>.pallet
guard let beStorage = metadata.resolve(pallet: eventsPallet)?.storage(name: eventsName) else {
Expand All @@ -285,44 +285,44 @@ public extension Config {
guard let info = metadata.resolve(type: id) else {
throw ConfigTypeLookupError.typeNotFound(id: id)
}
return RuntimeType.Info(id: id, type: info)
return NetworkType.Info(id: id, type: info)
}
}

public extension Config where ST<Self>.Hasher: StaticHasher {
// Static hasher creates Hash without type lookup
func hashType(metadata: any Metadata) throws -> RuntimeType.Info {
throw RuntimeType.IdNeverCalledError()
func hashType(metadata: any Metadata) throws -> NetworkType.Info {
throw NetworkType.IdNeverCalledError()
}
// Static Hasher can be returned by singleton instance
func hasher(metadata: Metadata) throws -> ST<Self>.Hasher { ST<Self>.Hasher.instance }
}

// Static Block doesn't need runtime type
public extension Config where TBlock: StaticBlock {
func blockType(metadata: Metadata) throws -> RuntimeType.Info {
throw RuntimeType.IdNeverCalledError()
func blockType(metadata: Metadata) throws -> NetworkType.Info {
throw NetworkType.IdNeverCalledError()
}
}

// Static Transaction Validity Error doesn't need runtime type
public extension Config where TTransactionValidityError: StaticCallError {
func transactionValidityErrorType(metadata: any Metadata) throws -> RuntimeType.Info {
throw RuntimeType.IdNeverCalledError()
func transactionValidityErrorType(metadata: any Metadata) throws -> NetworkType.Info {
throw NetworkType.IdNeverCalledError()
}
}

// Static Dispatch Error doesn't need runtime type
public extension Config where TDispatchError: StaticCallError {
func dispatchErrorType(metadata: any Metadata) throws -> RuntimeType.Info {
throw RuntimeType.IdNeverCalledError()
func dispatchErrorType(metadata: any Metadata) throws -> NetworkType.Info {
throw NetworkType.IdNeverCalledError()
}
}

// Static Account doesn't need runtime type
public extension Config where ST<Self>.AccountId: StaticAccountId {
func accountType(metadata: any Metadata, address: RuntimeType.Info) throws -> RuntimeType.Info {
throw RuntimeType.IdNeverCalledError()
func accountType(metadata: any Metadata, address: NetworkType.Info) throws -> NetworkType.Info {
throw NetworkType.IdNeverCalledError()
}
}

Expand All @@ -336,9 +336,9 @@ public enum ConfigTypeLookupError: Error {
case paymentTypeNotFound
case extrinsicTypesNotFound
case hashTypeNotFound
case badHeaderType(header: RuntimeType.Info)
case typeNotFound(id: RuntimeType.Id)
case badHeaderType(header: NetworkType.Info)
case typeNotFound(id: NetworkType.Id)
case typeNotFound(name: String, selector: String)
case cantProvideDefaultPayment(forType: RuntimeType.Info)
case cantProvideDefaultPayment(forType: NetworkType.Info)
case unknownHashName(String)
}
22 changes: 11 additions & 11 deletions Sources/Substrate/Config/DynamicConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public extension Configs {
public typealias TExtrinsicPayment = Value<Void>
public typealias TSystemProperties = AnySystemProperties
public typealias TRuntimeVersion = AnyRuntimeVersion<UInt32>
public typealias TFeeDetails = Value<RuntimeType.Id>
public typealias TRuntimeDispatchInfo = Value<RuntimeType.Id>
public typealias TFeeDetails = Value<NetworkType.Id>
public typealias TRuntimeDispatchInfo = Value<NetworkType.Id>
}

struct Dynamic: Config, BatchSupportedConfig {
Expand Down Expand Up @@ -102,11 +102,11 @@ public extension Configs.Dynamic {
@inlinable
func customCoders() throws -> [RuntimeCustomDynamicCoder] { runtimeCustomCoders }

func headerType(metadata: any Metadata) throws -> RuntimeType.Info {
func headerType(metadata: any Metadata) throws -> NetworkType.Info {
if let block = try? blockType(metadata: metadata) {
let headerType = block.type.parameters.first{ $0.name.lowercased() == "header" }?.type
if let id = headerType, let type = metadata.resolve(type: id) {
return RuntimeType.Info(id: id, type: type)
return NetworkType.Info(id: id, type: type)
}
}
guard let type = metadata.search(type: { headerSelector.matches($0) }) else {
Expand All @@ -116,7 +116,7 @@ public extension Configs.Dynamic {
return type
}

func hashType(metadata: any Metadata) throws -> RuntimeType.Info {
func hashType(metadata: any Metadata) throws -> NetworkType.Info {
let header = try headerType(metadata: metadata)
guard case .composite(let fields) = header.type.definition else {
throw ConfigTypeLookupError.badHeaderType(header: header)
Expand All @@ -125,7 +125,7 @@ public extension Configs.Dynamic {
guard let hashType = hashType, let hashInfo = metadata.resolve(type: hashType) else {
throw ConfigTypeLookupError.hashTypeNotFound
}
return RuntimeType.Info(id: hashType, type: hashInfo)
return NetworkType.Info(id: hashType, type: hashInfo)
}

func hasher(metadata: Metadata) throws -> ST<Self>.Hasher {
Expand Down Expand Up @@ -162,7 +162,7 @@ public extension Configs.Dynamic {

// Type lookups
public extension Configs.Dynamic {
func blockType(metadata: any Metadata) throws -> RuntimeType.Info {
func blockType(metadata: any Metadata) throws -> NetworkType.Info {
guard let type = metadata.search(type: { blockSelector.matches($0) }) else {
throw ConfigTypeLookupError.typeNotFound(name: "Block", selector:
blockSelector.pattern)
Expand All @@ -171,12 +171,12 @@ public extension Configs.Dynamic {
}

func accountType(metadata: any Metadata,
address: RuntimeType.Info) throws -> RuntimeType.Info
address: NetworkType.Info) throws -> NetworkType.Info
{
let selectors = ["accountid", "t::accountid", "account", "acc", "a"]
let accid = address.type.parameters.first{selectors.contains($0.name.lowercased())}?.type
if let id = accid, let info = metadata.resolve(type: id) {
return RuntimeType.Info(id: id, type: info)
return NetworkType.Info(id: id, type: info)
}
guard let type = metadata.search(type: {accountSelector.matches($0)}) else {
throw ConfigTypeLookupError.typeNotFound(name: "AccountId",
Expand All @@ -185,15 +185,15 @@ public extension Configs.Dynamic {
return type
}

func dispatchErrorType(metadata: any Metadata) throws -> RuntimeType.Info {
func dispatchErrorType(metadata: any Metadata) throws -> NetworkType.Info {
guard let type = metadata.search(type: {dispatchErrorSelector.matches($0)}) else {
throw ConfigTypeLookupError.typeNotFound(name: "DispatchError",
selector: dispatchErrorSelector.pattern)
}
return type
}

func transactionValidityErrorType(metadata: any Metadata) throws -> RuntimeType.Info {
func transactionValidityErrorType(metadata: any Metadata) throws -> NetworkType.Info {
guard let type = metadata.search(type: {transactionValidityErrorSelector.matches($0)}) else {
throw ConfigTypeLookupError.typeNotFound(name: "TransactionValidityError",
selector: transactionValidityErrorSelector.pattern)
Expand Down
18 changes: 9 additions & 9 deletions Sources/Substrate/Extrinsic/AccountId.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public protocol AccountId: RuntimeDynamicCodable, RuntimeDynamicSwiftCodable,
ValueRepresentable, RuntimeDynamicValidatable
{
init(from string: String, runtime: any Runtime,
id: RuntimeType.LazyId) throws
id: NetworkType.LazyId) throws
init(pub: any PublicKey, runtime: any Runtime,
id: RuntimeType.LazyId) throws
id: NetworkType.LazyId) throws
init(raw: Data, runtime: any Runtime,
id: RuntimeType.LazyId) throws
id: NetworkType.LazyId) throws

var raw: Data { get }
var string: String { get }
Expand All @@ -25,7 +25,7 @@ public protocol AccountId: RuntimeDynamicCodable, RuntimeDynamicSwiftCodable,

public extension AccountId {
init(from string: String, runtime: any Runtime,
id: RuntimeType.LazyId) throws
id: NetworkType.LazyId) throws
{
let (raw, format) = try SS58.decode(string: string)
guard format == runtime.addressFormat else {
Expand Down Expand Up @@ -62,23 +62,23 @@ public extension StaticAccountId {
}

init(from string: String, runtime: any Runtime) throws {
try self.init(from: string, runtime: runtime, id: RuntimeType.IdNever)
try self.init(from: string, runtime: runtime, id: NetworkType.IdNever)
}

init(from string: String, runtime: any Runtime,
id: RuntimeType.LazyId) throws
id: NetworkType.LazyId) throws
{
try self.init(from: string, runtime: runtime)
}

init(pub: any PublicKey, runtime: any Runtime,
id: RuntimeType.LazyId) throws
id: NetworkType.LazyId) throws
{
try self.init(pub: pub, runtime: runtime)
}

init(raw: Data, runtime: any Runtime,
id: RuntimeType.LazyId) throws
id: NetworkType.LazyId) throws
{
try self.init(raw: raw, runtime: runtime)
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public extension StaticAccountId {
}

static func validate(runtime: any Runtime,
type id: RuntimeType.Id) -> Result<Void, DynamicValidationError> {
type id: NetworkType.Id) -> Result<Void, DynamicValidationError> {
guard let info = runtime.resolve(type: id) else {
return .failure(.typeNotFound(id))
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Substrate/Extrinsic/Address.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public protocol Address<TAccountId>: RuntimeDynamicCodable, ValueRepresentable,

init(accountId: TAccountId,
runtime: any Runtime,
id: RuntimeType.LazyId) throws
id: NetworkType.LazyId) throws
}

public protocol StaticAddress<TAccountId>: Address, RuntimeCodable {
Expand All @@ -24,7 +24,7 @@ public extension StaticAddress {
@inlinable
init(accountId: TAccountId,
runtime: any Runtime,
id: RuntimeType.LazyId) throws
id: NetworkType.LazyId) throws
{
try self.init(accountId: accountId, runtime: runtime)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Substrate/Extrinsic/Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public extension StaticCall {
}

public extension IdentifiableCall where Self: RuntimeValidatableComposite {
static func validatableFieldIds(runtime: any Runtime) -> Result<[RuntimeType.Id], ValidationError> {
static func validatableFieldIds(runtime: any Runtime) -> Result<[NetworkType.Id], ValidationError> {
guard let info = runtime.resolve(callParams: name, pallet: pallet) else {
return .failure(.infoNotFound(for: Self.self))
}
Expand All @@ -74,9 +74,9 @@ public enum CallCodingError: Error {
case callNotFound(name: String, pallet: String)
case foundWrongCall(found: (name: String, pallet: String), expected: (name: String, pallet: String))
case valueNotFound(key: String)
case wrongFieldCountInVariant(variant: Value<RuntimeType.Id>, expected: Int)
case wrongFieldCountInVariant(variant: Value<NetworkType.Id>, expected: Int)
case wrongParametersCount(in: AnyCall<Void>, expected: Int)
case decodedNonVariantValue(Value<RuntimeType.Id>)
case decodedNonVariantValue(Value<NetworkType.Id>)
}

public protocol CallError: Error, RuntimeDynamicValidatable, RuntimeDynamicDecodable,
Expand Down
Loading

0 comments on commit f687317

Please sign in to comment.