diff --git a/Sources/SolanaSwift/Provider/SolanaRPCProvider.swift b/Sources/SolanaSwift/Provider/SolanaRPCProvider.swift index 98c99b4..7231df9 100644 --- a/Sources/SolanaSwift/Provider/SolanaRPCProvider.swift +++ b/Sources/SolanaSwift/Provider/SolanaRPCProvider.swift @@ -135,18 +135,15 @@ public struct SolanaRPCProvider { } } -extension SolanaRPCProvider { - public enum SolanaRpcProviderError: Error { - case unknown - case server(message: String) - - var errorDescription: String? { - switch self { - case .server(let message): - return message - default: - return "Unknown error" - } +public enum SolanaRpcProviderError: Error { + case unknown + case server(message: String) + public var errorDescription: String? { + switch self { + case .server(let message): + return message + default: + return "Unknown error" } } } diff --git a/Sources/SolanaSwift/Transaction/Instruction/SolanaInstructionAssetOwner.swift b/Sources/SolanaSwift/Transaction/Instruction/SolanaInstructionAssetOwner.swift index 7467d9d..2d02f1b 100644 --- a/Sources/SolanaSwift/Transaction/Instruction/SolanaInstructionAssetOwner.swift +++ b/Sources/SolanaSwift/Transaction/Instruction/SolanaInstructionAssetOwner.swift @@ -34,7 +34,11 @@ public struct SolanaInstructionAssetOwner: SolanaInstructionBase { extension SolanaInstructionAssetOwner: SolanaHumanReadable { public func toHuman() -> Dictionary { return [ - "type": "Asset Owner" + "type": "Asset Owner", + "data": [ + "destination":self.signers.first?.publicKey.address, + "data":self.data.toHexString() + ] ] } } diff --git a/Sources/SolanaSwift/Transaction/Instruction/SolanaInstructionAssociatedAccount.swift b/Sources/SolanaSwift/Transaction/Instruction/SolanaInstructionAssociatedAccount.swift index c1f1e88..5c4b18f 100644 --- a/Sources/SolanaSwift/Transaction/Instruction/SolanaInstructionAssociatedAccount.swift +++ b/Sources/SolanaSwift/Transaction/Instruction/SolanaInstructionAssociatedAccount.swift @@ -42,8 +42,24 @@ public struct SolanaInstructionAssociatedAccount: SolanaInstructionBase { extension SolanaInstructionAssociatedAccount: SolanaHumanReadable { public func toHuman() -> Dictionary { + var dataDic:[String:String] = [String:String]() + for i in 0.. Dictionary { -// let type = self.data.readUInt8(at: 0) + var dataDic:[String:String] = [String:String]() + for i in 0.. Dictionary { -// let type = self.data.readUInt32(at: 0) + + var from = "" + var to = "" + self.signers.forEach({ signer in + if signer.isSigner { + from = signer.publicKey.address + } else { + to = signer.publicKey.address + } + }) let lamports = self.data.readUInt64(at: 4) return [ - "type": "Transfer Token", + "type": "Transfer", "data": [ - "lamports": lamports + "from":from, + "to":to, + "lamports":"\(lamports)" ] ] } diff --git a/Tests/SolanaSwiftTests/SolanaSwiftTests.swift b/Tests/SolanaSwiftTests/SolanaSwiftTests.swift index 944030d..3747472 100644 --- a/Tests/SolanaSwiftTests/SolanaSwiftTests.swift +++ b/Tests/SolanaSwiftTests/SolanaSwiftTests.swift @@ -167,5 +167,15 @@ final class SolanaSwiftTests: XCTestCase { + } + func testToHuman() throws { + let array:[SolanaSigner] = [SolanaSigner(publicKey: SolanaPublicKey(base58String: "D37m1SKWnyY4fmhEntD84uZpjejUZkbHQUBEP3X74LuH")!,isSigner: true,isWritable: true),SolanaSigner(publicKey: SolanaPublicKey(base58String: "EY2kNS5hKfxxLSkbaBMQtQuHYYbjyYk6Ai2phcGMNgpC")!,isSigner: false,isWritable: true),SolanaSigner(publicKey: SolanaPublicKey(base58String: "DcaWQQGErxtzTTph7r5xWMxEvWEywGahtjnRvoJPN9Vz")!)] + let instruction = SolanaInstructionTransfer(promgramId: SolanaPublicKey(base58String: "TokenwAJbNbGKPFXCWuBvf9Ss623VQ5DA")!, signers: array, data: Data(hex: "0x02000000a08601000000000002000000a086010000000000")) + + let dataDic:Dictionary = instruction!.toHuman() + let dataarray = dataDic["data"] as! Dictionary + let data = try? JSONSerialization.data(withJSONObject: dataarray, options: []) + let str = String(data: data!, encoding: String.Encoding.utf8) + debugPrint(str!) } }