Skip to content

feature/ethereum-service - #4

Open
ec2 wants to merge 19 commits into
masterfrom
feature/ethereum-service
Open

feature/ethereum-service#4
ec2 wants to merge 19 commits into
masterfrom
feature/ethereum-service

Conversation

@ec2

@ec2 ec2 commented Sep 26, 2019

Copy link
Copy Markdown
Member

No description provided.

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

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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
Comment thread Sources/Relayer/main.swift Outdated

// @todo handle CLI input, repl

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

Copy link
Copy Markdown
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?

Comment thread Sources/RelayerFramework/Services/EthereumService.swift Outdated
Comment thread Sources/RelayerFramework/Services/EthereumService.swift Outdated
Comment thread Sources/RelayerFramework/Services/EthereumService.swift Outdated
Comment thread Tests/RelayerTests/RelayerTests.swift Outdated
Comment thread Tests/RelayerFrameworkTests/RelayerTests.swift Outdated
}.resume()
}

internal func getBalance(address: String, completion: @escaping (Result<Data, Error>) -> Void) {

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Comment thread Sources/RelayerFramework/Services/EthereumService.swift
Comment thread Sources/RelayerFramework/Services/EthereumService.swift Outdated
Comment thread Sources/RelayerFramework/Services/EthereumService.swift Outdated
]

// Grab two characters at a time, map them and turn it into a byte
for i in stride(from: 0, to: count, by: 2) {

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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
]

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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.

Comment thread Sources/Relayer/main.swift Outdated
// @todo handle CLI input, repl
let service = EthereumService(url: URL(string: "https://rinkeby.infura.io/f7a08ae0242843f1b1cf480454a6bba5")!)


Copy link
Copy Markdown

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

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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
Copy Markdown

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.

2 participants