-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1281 from novasamatech/fix/xcm4-multilocation
Support xcm v4 multilocation for asset conversion
- Loading branch information
Showing
8 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
novawallet/Common/Substrate/Types/Xcm/V4/XcmJunctionV4.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Foundation | ||
import SubstrateSdk | ||
|
||
extension XcmV4 { | ||
struct GenericJunctions<J>: Codable where J: Codable { | ||
let items: [J] | ||
|
||
init(items: [J]) { | ||
self.items = items | ||
} | ||
|
||
init(from decoder: Decoder) throws { | ||
var container = try decoder.unkeyedContainer() | ||
|
||
let type = try container.decode(String.self) | ||
|
||
if type == Xcm.JunctionsConstants.hereField { | ||
items = [] | ||
} else { | ||
items = try container.decode([J].self) | ||
} | ||
} | ||
|
||
func encode(to encoder: Encoder) throws { | ||
var container = encoder.unkeyedContainer() | ||
|
||
if items.isEmpty { | ||
try container.encode(Xcm.JunctionsConstants.hereField) | ||
} else { | ||
let xLocation = "\(Xcm.JunctionsConstants.junctionPrefix)\(items.count)" | ||
try container.encode(xLocation) | ||
} | ||
|
||
if items.isEmpty { | ||
try container.encode(JSON.null) | ||
} else { | ||
try container.encode(items) | ||
} | ||
} | ||
} | ||
|
||
typealias Junctions = GenericJunctions<XcmV4.Junction> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import Foundation | ||
|
||
enum XcmV4 {} | ||
enum XcmV4 { | ||
typealias Junction = XcmV3.Junction | ||
} |
9 changes: 9 additions & 0 deletions
9
novawallet/Common/Substrate/Types/Xcm/V4/XcmV4Multilocation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Foundation | ||
import SubstrateSdk | ||
|
||
extension XcmV4 { | ||
struct Multilocation: Codable { | ||
@StringCodable var parents: UInt8 | ||
let interior: XcmV4.Junctions | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters