-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
515 additions
and
76 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
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
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,41 +1,41 @@ | ||
import Utils | ||
import Vapor | ||
|
||
struct JSONRequest: Content { | ||
let jsonrpc: String | ||
let method: String | ||
let params: JSON? | ||
let id: JSON | ||
public struct JSONRequest: Content { | ||
public let jsonrpc: String | ||
public let method: String | ||
public let params: JSON? | ||
public let id: JSON | ||
} | ||
|
||
struct JSONResponse: Content { | ||
let jsonrpc: String | ||
let result: AnyCodable? | ||
let error: JSONError? | ||
let id: JSON? | ||
public struct JSONResponse: Content { | ||
public let jsonrpc: String | ||
public let result: AnyCodable? | ||
public let error: JSONError? | ||
public let id: JSON? | ||
|
||
init(id: JSON?, result: (any Encodable)?) { | ||
public init(id: JSON?, result: (any Encodable)?) { | ||
jsonrpc = "2.0" | ||
self.result = result.map(AnyCodable.init) | ||
error = nil | ||
self.id = id | ||
} | ||
|
||
init(id: JSON?, error: JSONError) { | ||
public init(id: JSON?, error: JSONError) { | ||
jsonrpc = "2.0" | ||
result = nil | ||
self.error = error | ||
self.id = id | ||
} | ||
} | ||
|
||
struct JSONError: Content, Error { | ||
public struct JSONError: Content, Error { | ||
let code: Int | ||
let message: String | ||
} | ||
|
||
extension JSONError { | ||
static func methodNotFound(_ method: String) -> JSONError { | ||
public static func methodNotFound(_ method: String) -> JSONError { | ||
JSONError(code: -32601, message: "Method not found: \(method)") | ||
} | ||
} |
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
Oops, something went wrong.