Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
Sia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
NebulousLabs
Sia
Commits
237d74d6
Unverified
Commit
237d74d6
authored
8 years ago
by
Ava Howell
Browse files
Options
Downloads
Patches
Plain Diff
add dbGetBlockFacts
parent
79b002bd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/explorer/database.go
+12
-0
12 additions, 0 deletions
modules/explorer/database.go
modules/explorer/info.go
+3
-19
3 additions, 19 deletions
modules/explorer/info.go
with
15 additions
and
19 deletions
modules/explorer/database.go
+
12
−
0
View file @
237d74d6
...
...
@@ -90,6 +90,18 @@ func dbGetTransactionIDSet(bucket []byte, key interface{}, ids *[]types.Transact
}
}
// dbGetBlockFacts returns a 'func(*bolt.Tx) error' that decodes
// the block facts for `height` into blockfacts
func
(
e
*
Explorer
)
dbGetBlockFacts
(
height
types
.
BlockHeight
,
bf
*
blockFacts
)
func
(
*
bolt
.
Tx
)
error
{
return
func
(
tx
*
bolt
.
Tx
)
error
{
block
,
exists
:=
e
.
cs
.
BlockAtHeight
(
height
)
if
!
exists
{
return
errors
.
New
(
"requested block facts for a block that does not exist"
)
}
return
dbGetAndDecode
(
bucketBlockFacts
,
block
.
ID
(),
bf
)(
tx
)
}
}
// dbSetInternal sets the specified key of bucketInternal to the encoded value.
func
dbSetInternal
(
key
[]
byte
,
val
interface
{})
func
(
*
bolt
.
Tx
)
error
{
return
func
(
tx
*
bolt
.
Tx
)
error
{
...
...
This diff is collapsed.
Click to expand it.
modules/explorer/info.go
+
3
−
19
View file @
237d74d6
package
explorer
import
(
"errors"
"github.com/NebulousLabs/Sia/build"
"github.com/NebulousLabs/Sia/encoding"
"github.com/NebulousLabs/Sia/modules"
"github.com/NebulousLabs/Sia/types"
...
...
@@ -30,13 +27,8 @@ func (e *Explorer) Block(id types.BlockID) (types.Block, types.BlockHeight, bool
// at a given block height, and a bool indicating whether facts exist for the
// given height.
func
(
e
*
Explorer
)
BlockFacts
(
height
types
.
BlockHeight
)
(
modules
.
BlockFacts
,
bool
)
{
block
,
exists
:=
e
.
cs
.
BlockAtHeight
(
height
)
if
!
exists
{
return
modules
.
BlockFacts
{},
false
}
var
bf
blockFacts
err
:=
e
.
db
.
View
(
dbGetAndDecode
(
bucketBlockFacts
,
block
.
ID
()
,
&
bf
))
err
:=
e
.
db
.
View
(
e
.
dbGetBlockFacts
(
height
,
&
bf
))
if
err
!=
nil
{
return
modules
.
BlockFacts
{},
false
}
...
...
@@ -50,19 +42,11 @@ func (e *Explorer) LatestBlockFacts() modules.BlockFacts {
var
bf
blockFacts
err
:=
e
.
db
.
View
(
func
(
tx
*
bolt
.
Tx
)
error
{
var
height
types
.
BlockHeight
err
:=
encoding
.
Unmarshal
(
tx
.
Bucket
(
buck
etInternal
)
.
Get
(
internalBlockHeight
)
,
&
height
)
err
:=
dbG
etInternal
(
internalBlockHeight
,
&
height
)
(
tx
)
if
err
!=
nil
{
return
err
}
block
,
exists
:=
e
.
cs
.
BlockAtHeight
(
height
)
if
!
exists
{
build
.
Critical
(
errors
.
New
(
"latest explorer block doesnt exist in consensus set"
))
}
bfBytes
:=
tx
.
Bucket
(
bucketBlockFacts
)
.
Get
(
encoding
.
Marshal
(
block
.
ID
()))
if
bfBytes
==
nil
{
build
.
Critical
(
errors
.
New
(
"block facts for the latest explorer block dont exist"
))
}
return
encoding
.
Unmarshal
(
bfBytes
,
&
bf
)
return
e
.
dbGetBlockFacts
(
height
,
&
bf
)(
tx
)
})
if
err
!=
nil
{
build
.
Critical
(
err
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment