Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Add transaction signing #7

Merged
merged 3 commits into from
Apr 24, 2018
Merged

Add transaction signing #7

merged 3 commits into from
Apr 24, 2018

Conversation

alejandro-isaza
Copy link
Contributor

No description provided.

@codecov-io
Copy link

codecov-io commented Apr 24, 2018

Codecov Report

Merging #7 into master will increase coverage by 0.48%.
The diff coverage is 85.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #7      +/-   ##
==========================================
+ Coverage   82.03%   82.51%   +0.48%     
==========================================
  Files          17       20       +3     
  Lines         757      858     +101     
==========================================
+ Hits          621      708      +87     
- Misses        136      150      +14
Impacted Files Coverage Δ
Sources/Transaction.swift 100% <100%> (ø)
Tests/TransactionSigningTests.swift 100% <100%> (ø)
Sources/RLP.swift 58.27% <18.75%> (-3.95%) ⬇️
Sources/TransactionSigning.swift 94.87% <94.87%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 17f933a...0e61b63. Read the comment docs.

public var gasLimit: BigInt
public var recipient: Address?
public var gasLimit: UInt64
public var recipient: Address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we change recipient => to for consitency?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it could be optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based it on the geth implementation, I think it's more important to be consistent with that: https://github.com/ethereum/go-ethereum/blob/ba1030b6b84f810c04a82221a1b1c0a3dbf499a8/core/types/transaction.go

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, I was comparing to JS implementation

/// - Parameters:
/// - chainID: chain identifier, defaults to `1`
/// - hashSigner: function to use for signing the hash
public mutating func sign(chainID: Int = 1, hashSigner: (Data) throws -> Data) rethrows {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I would ditch HomesteadSigner at all. everyone use EIP155 for this stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this is based on geth. I don't think it's harmful to have.

precondition(signature.count == 65, "Wrong size for signature")
let r = BigInt(sign: .plus, magnitude: BigUInt(Data(signature[..<32])))
let s = BigInt(sign: .plus, magnitude: BigUInt(Data(signature[32..<64])))
let v = BigInt(sign: .plus, magnitude: BigUInt(Data(bytes: [signature[64] + 27])))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember there was something where we wanted to make 27 customizable? can't remember

@@ -10,13 +10,40 @@ import BigInt
public struct Transaction {
public var accountNonce: UInt64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we call it nonce for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, based on the geth implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the JSON names do match what you suggest, I'll change it.

public var s = BigInt()

/// Creates a `Transaction` with default values and the given recipient address.
public init(recipient: Address) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you consider leaving initializer for all the values for safety? to avoid any issues, in that case creator would be aware of all the values to pass in, otherwise transaction won't succeed if everything is 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor

@vikmeup vikmeup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

@alejandro-isaza alejandro-isaza merged commit acca5f6 into master Apr 24, 2018
@alejandro-isaza alejandro-isaza deleted the sign-transaction branch April 24, 2018 16:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants