-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
8 changed files
with
251 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package explorer | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/hanchon/hanchond/playground/explorer/database" | ||
) | ||
|
||
type Database struct { | ||
queries *database.Queries | ||
mutex *sync.Mutex | ||
ctx context.Context | ||
} | ||
|
||
func NewDatabase(ctx context.Context, queries *database.Queries) *Database { | ||
return &Database{ | ||
queries: queries, | ||
mutex: &sync.Mutex{}, | ||
ctx: ctx, | ||
} | ||
} | ||
|
||
func (d *Database) GetLatestBlock() (database.Block, error) { | ||
d.mutex.Lock() | ||
defer d.mutex.Unlock() | ||
return d.queries.GetLatestBlock(d.ctx) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 +1,22 @@ | ||
CREATE TABLE IF NOT EXISTS blocks( | ||
id BIGSERIAL NOT NULL PRIMARY KEY, | ||
height BIGINT UNIQUE NOT NULL, | ||
time TIMESTAMP WITHOUT TIME ZONE NOT NULL, | ||
txcount INTEGER NOT NULL, | ||
totalValue NUMERIC(65, 0) NOT NULL, | ||
proposer TEXT NOT NULL, | ||
gasused NUMERIC(65, 0) NOT NULL, | ||
gaslimit NUMERIC(65, 0) NOT NULL, | ||
basefee NUMERIC(65, 0) NOT NULL, | ||
hash TEXT NOT NULL, | ||
parenthash TEXT NOT NULL | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS blocksindex on blocks (height); | ||
|
||
CREATE TABLE IF NOT EXISTS transactions( | ||
id BIGSERIAL NOT NULL PRIMARY KEY, | ||
cosmoshash TEXT NOT NULL, | ||
ethhash TEXT NOT NULL, | ||
content TEXT NOT NULL, | ||
sender TEXT NOT NULL, | ||
blockheight BIGINT NOT NULL REFERENCES blocks(height) ON DELETE CASCADE | ||
); | ||
|
||
|
||
CREATE INDEX IF NOT EXISTS cosmoshash on transactions (cosmoshash); | ||
CREATE INDEX IF NOT EXISTS ethhash on transactions (ethhash); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.