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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation Refactor and Error Codes #52

Merged
merged 7 commits into from
Jun 4, 2017
Merged

Conversation

chadlagore
Copy link
Contributor

@chadlagore chadlagore commented Jun 3, 2017

Status Ready for review.

What Changed

馃椇 Refactored the validation functions into their own file (along with tests).
鈿欙笍 Added error codes to enforce proper failing in test suite.

TODO

  • Finish refactor (make it easy to swap out []*Transactions data structure.
  • Test bc.GetInputTransaction method.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 89.178% when pulling c86b3f2 on 15-implement-verification into c7d29b5 on dev.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 89.178% when pulling d17bd41 on 15-implement-verification into c7d29b5 on dev.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 89.178% when pulling d17bd41 on 15-implement-verification into c7d29b5 on dev.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 89.307% when pulling 58ad841 on 15-implement-verification into c7d29b5 on dev.

Copy link
Member

@jordanschalm jordanschalm left a comment

Choose a reason for hiding this comment

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

馃憤

@@ -73,11 +73,11 @@ func DecodeBlock(r io.Reader) *Block {

// ContainsTransaction returns true and the transaction itself if the Block
// contains the transaction.
func (b *Block) ContainsTransaction(t *Transaction) (bool, *Transaction) {
for _, tr := range b.Transactions {
func (b *Block) ContainsTransaction(t *Transaction) (bool, uint32) {
Copy link
Member

Choose a reason for hiding this comment

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

Why uint32?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. uint32 for blocks because thats baked into the data structure, avoid overflow if we have billions of blocks. Thought we might as well keep the same datatype for transactions as well, no such thing as a negative transaction index.


// InputsEqualOutputs returns true if t.Inputs == other.Outputs, as well
// as the difference between the two (outputs - inputs).
func (t *Transaction) InputsEqualOutputs(other ...*Transaction) (bool, int) {
Copy link
Member

Choose a reason for hiding this comment

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

Checking that the addresses match is done somewhere else?

Copy link
Member

Choose a reason for hiding this comment

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

Also, why are we returning the diff as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case we want to verify that the diff is equal to some fee.

Copy link
Member

Choose a reason for hiding this comment

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

If we aren't using it, I'd leave it out until we need it. Fees will eventually be part of the transaction so we can verify as part of this function anyway right?


const (
// ValidTransaction is returned when transaction is valid.
ValidTransaction TransactionCode = 0
Copy link
Member

Choose a reason for hiding this comment

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

)

const (
// ValidBlock is returned when the block is valid.
Copy link
Member

Choose a reason for hiding this comment

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

Same -- use iota

package blockchain

import (
crand "crypto/rand"
Copy link
Member

Choose a reason for hiding this comment

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

Just use rand if we aren't distinguishing between math/rand and crypto/rand

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 89.307% when pulling 0e6e5bb on 15-implement-verification into c7d29b5 on dev.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 89.264% when pulling c0f998c on 15-implement-verification into c7d29b5 on dev.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 89.264% when pulling a23b0f5 on 15-implement-verification into c7d29b5 on dev.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 86.379% when pulling a76410f on 15-implement-verification into 7e25a10 on dev.

@chadlagore chadlagore merged commit b8cb862 into dev Jun 4, 2017
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.

None yet

3 participants