-
Notifications
You must be signed in to change notification settings - Fork 2
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
ValidTransaction and ValidBlock #28
Conversation
Add tests
…lement-verification
29 makefile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Couple extra things to check in validation (maybe add a test case for them) and we should add an issue for figuring out how to handle spending mined coins.
blockchain/blockchain.go
Outdated
// Find the transaction input (I) in the chain (by hash) | ||
var I *Transaction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use input
rather than I
if inAmount != outAmount { | ||
return false | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to check that input transaction hasn't been spent between when it was created and now, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇 I've added a test case.
return false | ||
} | ||
|
||
// Verify every Transaction in the block. | ||
for _, t := range b.Transactions { | ||
if !bc.ValidTransaction(t) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if two transactions in b.Transactions
reference the same input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇 I've added a test case.
return false | ||
} | ||
|
||
// Verify every Transaction in the block. | ||
for _, t := range b.Transactions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to discuss how to spend coins that were mined, since there is no transaction for them to refer to. Do we have the miner insert a special transaction for their mined coins, or modify the Transaction
struct to be able to refer to block rewards as inputs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like setting the Transaction.Input
to some special value is a good way to go. Perhaps then we could get away with treating it as a normal block during verification (ie. I'd like to avoid special cases in the VerifyX
functions). By convention, we could put the block reward in Transactions[0]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an issue for this
Going to merge this now @chadlagore |
Status: Ready to merge.
What Changed
ValidTransaction
andValidBlock
.Opening this up for visibility early!☺️ Not done yet.I've changed the base branch to
dev
TODO
Signature
verification.