-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
cli: show timestamp of the block #3
base: master
Are you sure you want to change the base?
Changes from all commits
c0accf3
5e43c77
cee6700
f9935da
782db48
42b9dbb
8ea4bc8
29099f0
009fda2
2974ee8
5f4f2f5
36cfffc
01d18ce
5c88b24
c410eb2
9f6ac35
64cf474
04318d7
b415f08
c72ff7f
cb4ae18
9b2f73b
56c9e3f
db3fe41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
*.db | ||
*.dat | ||
cscope.* | ||
.*.swp | ||
blockchain_go |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package bc | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBase58(t *testing.T) { | ||
for i := 0; i < 100; i++ { | ||
_, public := newKeyPair() | ||
pubKeyHash := HashPubKey(public) | ||
|
||
versionedPayload := append([]byte{version}, pubKeyHash...) | ||
checksum := checksum(versionedPayload) | ||
|
||
fullPayload := append(versionedPayload, checksum...) | ||
address := Base58Encode(fullPayload) | ||
|
||
assert.Equal( | ||
t, | ||
ValidateAddress(string(address[:])), | ||
true, | ||
"Address: %s is invalid", address, | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package main | ||
package bc | ||
|
||
import ( | ||
"bytes" | ||
"encoding/gob" | ||
"fmt" | ||
"log" | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
|
@@ -71,3 +74,20 @@ func DeserializeBlock(d []byte) *Block { | |
|
||
return &block | ||
} | ||
|
||
func (b *Block) PrintHTML(detail bool) string { | ||
var lines []string | ||
lines = append(lines, fmt.Sprintf("<h2>Block <a href=\"/block/%x\">%x</a> </h2>", b.Hash, b.Hash)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to do this via 'html/template', and this should be a separate package, because it's not directly related to the logic of the blockchain. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, I just learn go, so... |
||
lines = append(lines, fmt.Sprintf("Height: %d</br>", b.Height)) | ||
lines = append(lines, fmt.Sprintf("Prev. block: <a href=\"/block/%x\">%x</a></br>", b.PrevBlockHash, b.PrevBlockHash)) | ||
lines = append(lines, fmt.Sprintf("Created at : %s</br>", time.Unix(b.Timestamp, 0))) | ||
pow := NewProofOfWork(b) | ||
lines = append(lines, fmt.Sprintf("PoW: %s</br></br>", strconv.FormatBool(pow.Validate()))) | ||
if detail { | ||
for _, tx := range b.Transactions { | ||
lines = append(lines, tx.PrintHTML()) | ||
} | ||
} | ||
lines = append(lines, fmt.Sprintf("</br></br>")) | ||
return strings.Join(lines, "\n") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package bc | ||
|
||
import ( | ||
"log" | ||
|
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'm afraid this is against the idea of the project: it should be a standalone app, not a package. Why did you decide to make this change?
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.
sure, this is up to you. I just add it for my purpose.
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.
hmm, actually, I am not comfortable with the GitHub pull request.
Since what I want you to take is the fix on Decoder and merkle tree, the #2 - #4 commit.
While GitHub automatically create the pull request with all my new commits on master branch.
How could I send a pull request just with dedicated commit? or you could pick up the one you want? or I have to make a clean master branch so that you can pull?