Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 10 additions & 56 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,61 +1,15 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Temporary / cached
.idea
.vscode

# Runtime data
pids
*.pid
*.seed
*.pid.lock
.DS_Store

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
Gopkg.lock

# Coverage directory used by tools like istanbul
coverage
tests/config.toml

# nyc test coverage
.nyc_output
# vendors
vendor/*

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
# builds
main
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

GOTOOLS = \
github.com/golang/dep/cmd/dep \
gopkg.in/alecthomas/gometalinter.v2 \
github.com/golang/protobuf/proto \
github.com/golang/protobuf/ptypes/struct \
google.golang.org/grpc \
github.com/gogo/protobuf/proto \
github.com/gogo/protobuf/jsonpb \
github.com/gogo/protobuf/protoc-gen-gogo \
github.com/gogo/protobuf/gogoproto \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger \
github.com/lib/pq

PROTOPATH = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf:. -I=${GOPATH}/src/github.com/gallactic/gallactic/rpc/grpc/proto3 -I=${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis
#--proto_path=${GOPATH}/src:${GOPATH}/src/github.com/gogo/protobuf/protobuf:.
HUBBLE = ${GOPATH}/src/github.com/gallactic/hubble_server

########################################
### make all
all: tools deps build

########################################
### Tools & dependencies
deps:

dep ensure

tools:

go get $(GOTOOLS)
@gometalinter.v2 --install

########################################
### Protobuf
proto:

--protoc $(PROTOPATH) --gogo_out=plugins=grpc:$(HUBBLE) ./proto3/blockchain.proto

########################################
### Formatting, linting, and vetting
fmt:
@go fmt ./...

########################################
### building
build:
@go build main.go

run:
@go run main.go

# To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: tools deps
.PHONY: build
.PHONY: fmt metalinter
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# hubble-server
API server for hubble scan block explorer
# Hubble Scan Server

*Hubble Scan Server that checks blocks of [Gallactic Blockchain](https://github.com/gallactic/gallactic) and saves them in Postgre database.

## Compiling the code

You need to make sure you have install [Go](https://golang.org/) (version 1.10.1 or higher) and [postgre](https://www.postgresql.org). After installing them, import HubbleScan.sql from script folder into postgre to create database and then you can follow these steps to compile and build the project:

```bash
mkdir -p $GOPATH/src/github.com/gallactic/hubbleServer
cd $GOPATH/src/github.com/gallactic/hubbleServer
git clone https://github.com/gallactic/HUBBLE_SERVER.git .
make
```
84 changes: 84 additions & 0 deletions blockchain/adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package blockchain

import (
"time"
)

//Account struct
type Account struct {
Address string
Balance uint64
Permission string
Sequence uint64
Code string
ID uint64
}

//BlockInfo struct in blocks
type BlockInfo struct {
//block ID
BlockHash string
// basic block info
VersionBlock uint64
VersionApp uint64
ChainID string
Height int64
Time time.Time
NumTxs int64
TotalTxs int64
// prev block info
LastBlockHash string
// hashes of block data
LastCommitHash string
DataHash string
// hashes from the app output from the prev block
ValidatorsHash string
NextValidatorsHash string
ConsensusHash string
AppHash string
LastResultsHash string
// consensus info
EvidenceHash string
ProposerAddress string
}

//Block struct
type Block struct {
Height int64
Hash string
ChainID string
Time time.Time
LastBlockHash string
TxCounts int64
}

//Transaction struct
type Transaction struct {
BlockID int64
Hash string
GasUsed int64
GasWanted int64
Data string
Time time.Time
}

//Adapter for data base
type Adapter interface {
CreateGRPCClient() error

Update() error

GetAccountsCount() int
GetAccount(id int) (*Account, error)
GetAccounts() ([]*Account, error)

GetBlocksLastHeight() (uint64, error)
GetBlockInfo(height uint64) (*BlockInfo, error)
GetBlock(height uint64) (*Block, error)
GetBlocksInfo(from uint64, to uint64) ([]*BlockInfo, error)
GetBlocks(from uint64, to uint64) ([]*Block, error)

GetTXsCount(height uint64) int
GetTx(height uint64, hash []byte) (*Transaction, error)
GetTXs(height uint64) ([]Transaction, error)
}
Loading