-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/ethereum-service #4
base: master
Are you sure you want to change the base?
Conversation
…/Relayer.swift into feature/ethereum-service
Sources/Relayer/main.swift
Outdated
"method": "eth_getBalance", | ||
"params": ["0x0F64928EcA02147075c7614A7d67B0C3Cb37D5DA", "latest"], | ||
"id": 1] | ||
jsonPayload = try! JSONSerialization.data(withJSONObject: payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force tries should be avoided.
"method": "eth_getBalance", | ||
"params": [address, "latest"], | ||
"id": 1] | ||
let jsonPayload = try! JSONSerialization.data(withJSONObject: payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force tries should be avoided.
"method": "eth_sendRawTransaction", | ||
"params": [signedTransaction], | ||
"id": 1] | ||
let jsonPayload = try! JSONSerialization.data(withJSONObject: payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force tries should be avoided.
"method": "eth_getTransactionCount", | ||
"params": [address, "latest"], | ||
"id": 1] | ||
let jsonPayload = try! JSONSerialization.data(withJSONObject: payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force tries should be avoided.
} | ||
} | ||
|
||
internal func getTransactionCount(address: String, completion: @escaping (Result<Data, Error>) -> Void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
Sources/Relayer/main.swift
Outdated
@@ -10,4 +10,31 @@ node.add(transport: CoreBluetoothTransport()) | |||
|
|||
// @todo handle CLI input, repl | |||
|
|||
let url = URL(string: "https://rinkeby.infura.io/f7a08ae0242843f1b1cf480454a6bba5")! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this stuff doesn't belong in main. This is demo code isn't it?
}.resume() | ||
} | ||
|
||
internal func getBalance(address: String, completion: @escaping (Result<Data, Error>) -> Void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
} | ||
|
||
// handle gets called when an Ethereum service is called. | ||
public func handle(message: Message, node: Node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function handle
has 63 lines of code (exceeds 25 allowed). Consider refactoring.
@@ -0,0 +1,161 @@ | |||
import Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
} | ||
|
||
// handle gets called when an Ethereum service is called. | ||
public func handle(message: Message, node: Node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function handle
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
} | ||
|
||
// handle gets called when an Ethereum service is called. | ||
public func handle(message: Message, node: Node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function body should span 40 lines or less excluding comments and whitespace: currently spans 53 lines
] | ||
|
||
// Grab two characters at a time, map them and turn it into a byte | ||
for i in stride(from: 0, to: count, by: 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable name should be between 3 and 40 characters long: 'i'
} | ||
|
||
// handle gets called when an Ethereum service is called. | ||
public func handle(message: Message, node: Node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function handle
has 58 lines of code (exceeds 25 allowed). Consider refactoring.
let index2 = Int(chars[i + 1] & 0x1F ^ 0x10) | ||
bytes.append(map[index1] << 4 | map[index2]) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines should not have trailing whitespace.
// Keep the bytes in an UInt8 array and later convert it to Data | ||
var bytes = [UInt8]() | ||
bytes.reserveCapacity(count / 2) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines should not have trailing whitespace.
0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, // @ABCDEFG | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // HIJKLMNO | ||
] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines should not have trailing whitespace.
let hexDigits = Array("0123456789abcdef".utf16) | ||
var hexChars = [UTF16.CodeUnit]() | ||
hexChars.reserveCapacity(count * 2) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines should not have trailing whitespace.
hexChars.append(hexDigits[index1]) | ||
hexChars.append(hexDigits[index2]) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines should not have trailing whitespace.
func hexDecodedData() -> Data { | ||
// Get the UTF8 characters of this string | ||
let chars = Array(utf8) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines should not have trailing whitespace.
Sources/Relayer/main.swift
Outdated
@@ -9,5 +9,18 @@ node.delegate = handler | |||
node.add(transport: CoreBluetoothTransport()) | |||
|
|||
// @todo handle CLI input, repl | |||
let service = EthereumService(url: URL(string: "https://rinkeby.infura.io/f7a08ae0242843f1b1cf480454a6bba5")!) | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limit vertical whitespace to a single empty line. Currently 2.
} | ||
|
||
// handle gets called when an Ethereum service is called. | ||
public func handle(message: Message, node: Node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function body should span 40 lines or less excluding comments and whitespace: currently spans 48 lines
"params": params, | ||
"id": 1 | ||
] | ||
let jsonPayload = try! JSONSerialization.data(withJSONObject: payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force tries should be avoided.
] | ||
let jsonPayload = try! JSONSerialization.data(withJSONObject: payload) | ||
request.httpBody = jsonPayload | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines should not have trailing whitespace.
Code Climate has analyzed commit 2701f54 and detected 6 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
No description provided.