Skip to content

Conversation

@ec2
Copy link
Member

@ec2 ec2 commented Sep 26, 2019

No description provided.

@ec2 ec2 requested a review from decanus September 26, 2019 21:23
"method": "eth_getBalance",
"params": ["0x0F64928EcA02147075c7614A7d67B0C3Cb37D5DA", "latest"],
"id": 1]
jsonPayload = try! JSONSerialization.data(withJSONObject: payload)

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)

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)

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)

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) {

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.

@decanus decanus changed the title Feature/ethereum service feature/ethereum-service Sep 26, 2019

// @todo handle CLI input, repl

let url = URL(string: "https://rinkeby.infura.io/f7a08ae0242843f1b1cf480454a6bba5")!
Copy link
Collaborator

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) {

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) {

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

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) {

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) {

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) {

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) {

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])
}

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)

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
]

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)

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])
}

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)

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.

// @todo handle CLI input, repl
let service = EthereumService(url: URL(string: "https://rinkeby.infura.io/f7a08ae0242843f1b1cf480454a6bba5")!)


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) {

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)

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

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.

@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 2701f54 and detected 6 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3
Duplication 3

View more on Code Climate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants