-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60bc47d
commit 3d189c7
Showing
5 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,75 @@ | ||
package sqlite | ||
|
||
import "go.sia.tech/core/types" | ||
import ( | ||
"time" | ||
|
||
"go.sia.tech/core/types" | ||
) | ||
|
||
func decode(obj types.DecoderFrom, data []byte) error { | ||
d := types.NewBufDecoder(data) | ||
obj.DecodeFrom(d) | ||
return d.Err() | ||
} | ||
|
||
func decodeUint64(x *uint64, data []byte) error { | ||
d := types.NewBufDecoder(data) | ||
if x != nil { | ||
*x = d.ReadUint64() | ||
} | ||
return d.Err() | ||
} | ||
|
||
// Tip implements explorer.Store. | ||
func (s *Store) Tip() (result types.ChainIndex, err error) { | ||
var data []byte | ||
if err = s.queryRow("SELECT id, height FROM Blocks WHERE height = (SELECT MAX(height) from Blocks)").Scan(&data, &result.Height); err != nil { | ||
return | ||
} | ||
decode(&result.ID, data) | ||
if err = decode(&result.ID, data); err != nil { | ||
return | ||
} | ||
return | ||
} | ||
|
||
// Block implements explorer.Store. | ||
func (s *Store) Block(id types.BlockID) (result types.Block, err error) { | ||
{ | ||
var timestamp int64 | ||
var parentID, nonce []byte | ||
if err = s.queryRow("SELECT parent_id, nonce, timestamp FROM Blocks WHERE id = ?", encode(id)).Scan(&parentID, &nonce, ×tamp); err != nil { | ||
return | ||
} | ||
result.Timestamp = time.Unix(timestamp, 0).UTC() | ||
if err = decode(&result.ParentID, parentID); err != nil { | ||
return | ||
} | ||
if err = decodeUint64(&result.Nonce, nonce); err != nil { | ||
return | ||
} | ||
} | ||
|
||
{ | ||
var rows *loggedRows | ||
if rows, err = s.query("SELECT address, value FROM MinerPayouts WHERE block_id = ? ORDER BY block_order", encode(id)); err != nil { | ||
return | ||
} | ||
|
||
var address, value []byte | ||
for rows.Next() { | ||
if err = rows.Scan(&address, &value); err != nil { | ||
return | ||
} | ||
var minerPayout types.SiacoinOutput | ||
if err = decode(&minerPayout.Address, address); err != nil { | ||
return | ||
} | ||
if err = decode(&minerPayout.Value, value); err != nil { | ||
return | ||
} | ||
result.MinerPayouts = append(result.MinerPayouts, minerPayout) | ||
} | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters