Skip to content

Commit

Permalink
Fixed timestamp handling in new blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoras committed Feb 11, 2019
1 parent fec6ad2 commit 34c08ee
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,11 @@ func OpenBlockFile(fileName string) (*Block, error) {
return nil, err
}
if b.TimeAccepted, err = b.dbGetMetaTime("Timestamp"); err != nil {
return nil, err
st, err := os.Stat(fileName)
if err != nil {
return nil, err
}
b.TimeAccepted = st.ModTime()
}
return &b, nil
}
Expand Down
6 changes: 6 additions & 0 deletions cliactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func actionSignImportBlock(fn string) {
if err != nil {
log.Fatalln(err)
}
err = dbSetMetaString(db, "Timestamp", time.Now().Format(time.RFC3339))
if err != nil {
log.Fatalln(err)
}

pkdb, err := dbGetPublicKey(publicKeyHash)
if err != nil {
log.Panic(err)
Expand Down Expand Up @@ -468,6 +473,7 @@ func actionPull(baseURL string) {

// Step 4: Initialise databases
dbInit()
dbClearSavedPeers()
cryptoInit()

blk, err := OpenBlockFile(blockFilename)
Expand Down
5 changes: 5 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ func dbInsertBlock(dbb *DbBlockchainBlock) error {
return err
}

func dbClearSavedPeers() error {
_, err := mainDb.Exec("DELETE FROM peers")
return err
}

// Gets a list of saved p2p peer addresses
func dbGetSavedPeers() peerStringMap {
result := peerStringMap{}
Expand Down
6 changes: 3 additions & 3 deletions p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ func (p2pc *p2pConnection) handleBlock(msg StrIfMap) {
defer resp.Body.Close()
blockFile, err = ioutil.TempFile("", "daisy")
if err != nil {
log.Println(err)
log.Println("Error creating temp file", err)
return
}
written, err := io.Copy(blockFile, resp.Body)
Expand Down Expand Up @@ -711,12 +711,12 @@ func (p2pc *p2pConnection) handleBlock(msg StrIfMap) {

blk, err := OpenBlockFile(blockFile.Name())
if err != nil {
log.Println(p2pc.conn, err)
log.Println("Error opening block file", p2pc.conn, err)
return
}
blk.HashSignature, err = hex.DecodeString(hashSignature)
if err != nil {
log.Println(p2pc.conn, err)
log.Println("Error decoding hash signature", p2pc.conn, err)
return
}
height, err := checkAcceptBlock(blk)
Expand Down

0 comments on commit 34c08ee

Please sign in to comment.