Skip to content
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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

feature/ethereum-service #4

wants to merge 19 commits into from

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)
Copy link

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

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

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

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

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
@@ -10,4 +10,31 @@ node.add(transport: CoreBluetoothTransport())

// @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?

Sources/RelayerFramework/Services/EthereumService.swift Outdated Show resolved Hide resolved
Sources/RelayerFramework/Services/EthereumService.swift Outdated Show resolved Hide resolved
Sources/RelayerFramework/Services/EthereumService.swift Outdated Show resolved Hide resolved
Tests/RelayerTests/RelayerTests.swift Outdated Show resolved Hide resolved
Tests/RelayerFrameworkTests/RelayerTests.swift Outdated Show resolved Hide resolved
}.resume()
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

@@ -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")!)


Copy link

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

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

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

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.

@codeclimate
Copy link

codeclimate bot commented Sep 27, 2019

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