-
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 19 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,4 +1,4 @@ | ||
package main | ||
package bc | ||
|
||
import ( | ||
"bytes" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package bc | ||
|
||
import ( | ||
"log" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package bc | ||
|
||
import ( | ||
"fmt" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package bc | ||
|
||
import "fmt" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package bc | ||
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. Not sure about this file and commands. Looks like its purpose is just to debug/test things. 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. yep, this is some cli commands which helps me to understand the blockchain:-) |
||
|
||
import ( | ||
"crypto/elliptic" | ||
"encoding/hex" | ||
"fmt" | ||
) | ||
|
||
func (cli *CLI) getPubKey(privateKey string) { | ||
curve := elliptic.P256() | ||
priv_key, _ := hex.DecodeString(privateKey) | ||
x, y := curve.ScalarBaseMult(priv_key) | ||
pubKey := append(x.Bytes(), y.Bytes()...) | ||
fmt.Println(hex.EncodeToString(pubKey)) | ||
} | ||
|
||
func (cli *CLI) generatePrivKey() { | ||
private, _ := newKeyPair() | ||
fmt.Println(hex.EncodeToString(private.D.Bytes())) | ||
} | ||
|
||
func (cli *CLI) getAddress(pubKey string) { | ||
public, _ := hex.DecodeString(pubKey) | ||
|
||
pubKeyHash := HashPubKey(public) | ||
|
||
versionedPayload := append([]byte{version}, pubKeyHash...) | ||
fullPayload := append(versionedPayload, checksum(versionedPayload)...) | ||
|
||
fmt.Println() | ||
fmt.Printf("PubKey : %s\n", pubKey) | ||
fmt.Printf("PubKeyHash : %x\n", pubKeyHash) | ||
fmt.Printf("Address : %s\n", Base58Encode(fullPayload)) | ||
} | ||
|
||
func (cli *CLI) getPubKeyHash(address string) { | ||
pubKeyHash := Base58Decode([]byte(address)) | ||
fmt.Printf("%x\n", pubKeyHash[1:len(pubKeyHash)-4]) | ||
} | ||
|
||
func (cli *CLI) validateAddr(address string) { | ||
fmt.Printf("Address: %s\n", address) | ||
if !ValidateAddress(address) { | ||
fmt.Println("Not valid!") | ||
} else { | ||
fmt.Println("Valid!") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package bc | ||
|
||
import ( | ||
"fmt" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package bc | ||
|
||
import ( | ||
"fmt" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package bc | ||
|
||
import "fmt" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package bc | ||
|
||
import ( | ||
"fmt" | ||
|
This file was deleted.
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?