Skip to content

Commit

Permalink
Merge branch 'master' into default-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nikooo777 authored Dec 31, 2018
2 parents 111736c + 0cf2ff4 commit 5f50099
Show file tree
Hide file tree
Showing 59 changed files with 5,583 additions and 3,155 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/vendor
/.idea
/bin
/test
swagger-codegen-cli.jar
chainqueryconfig.toml
cover.out
Expand Down
21 changes: 13 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
os: linux
dist: trusty
dist: xenial
language: go

# Only the last two Go releases are supported by the Go team with security
Expand All @@ -16,6 +16,11 @@ go:
# code in vendor/
install: true

cache:
directories:
- $HOME/.cache/go-build
- $HOME/gopath/pkg/mod

matrix:
# It's ok if our code fails on unstable development versions of Go.
allow_failures:
Expand All @@ -30,6 +35,7 @@ matrix:

services:
- mysql
- docker

before_install:
- mysql -u root -e 'CREATE DATABASE IF NOT EXISTS chainquery;'
Expand All @@ -55,6 +61,7 @@ before_script:




# script always run to completion (set +e). All of these code checks are must haves
# in a modern Go project.
script:
Expand All @@ -64,8 +71,6 @@ script:
- test -z $(gofmt -s -l $GO_FILES)
# Run unit tests
- ./scripts/test.sh
# Run integration tests
- ./scripts/int_tests.sh
# Checks for unused vars and fields on structs
- varcheck ./...
- structcheck ./...
Expand All @@ -81,11 +86,11 @@ script:
- unconvert -v $(go list ./... | grep -v /vendor/ | grep -v /model | grep -v /swagger/ | grep -v /migration )
# one last linter - ignore autogen code
- golint -set_exit_status $(go list ./... | grep -v /vendor/ | grep -v /model/ | grep -v /swagger/ | grep -v /migration )
# start up chainquery
- ./bin/chainquery api &
- sleep 10s
- "curl -i -H 'Accept: application/json' -H 'Content-Type: application/json' http://localhost:6300/api/status"
# ToDo need to wait until the SQLBoiler issues are resolved. - ./app/gen_models.sh
# end to end testing
- ./e2e/e2e.sh
# check model generation...
- ./bin/chainquery serve db && ./scripts/gen_models.sh
# matches what was commited
- git diff --exit-code

# calls goreleaser
Expand Down
61 changes: 45 additions & 16 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions apiactions/processing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package apiactions

import (
"net/http"

"github.com/lbryio/chainquery/auth"
"github.com/lbryio/chainquery/daemon/processing"
"github.com/lbryio/chainquery/lbrycrd"

"github.com/lbryio/lbry.go/api"
"github.com/lbryio/lbry.go/errors"

v "github.com/lbryio/ozzo-validation"
)

// ProcessBlocks processed a specific block or range of blocks if authorized.
func ProcessBlocks(r *http.Request) api.Response {
params := struct {
Block *uint64
From *uint64
To *uint64
Key string
}{}

err := api.FormValues(r, &params, []*v.FieldRules{
v.Field(&params.Block),
v.Field(&params.From),
v.Field(&params.To),
v.Field(&params.Key),
})
if err != nil {
return api.Response{Error: err, Status: http.StatusBadRequest}
}

if !auth.IsAuthorized(params.Key) {
return api.Response{Error: errors.Err("not authorized"), Status: http.StatusUnauthorized}
}

if params.Block != nil {
err = processBlocks(params.Block, nil, nil)
} else if params.To != nil {
err = processBlocks(nil, params.From, params.To)
} else {
err = processBlocks(nil, params.From, nil)
}

if err != nil {
return api.Response{Error: err}
}

return api.Response{Data: "OK"}

}

func processBlocks(block, from, to *uint64) error {
if block != nil {
from = block
end := *block
to = &end
} else {
if from == nil {
start := uint64(0)
from = &start
}
if to == nil {
currHeight, err := lbrycrd.GetBlockCount()
if err != nil {
return errors.Err(err)
}
to = currHeight
}
}

for *from <= *to {
processing.RunBlockProcessing(*from)
*from++
}
return nil
}
101 changes: 101 additions & 0 deletions apiactions/validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package apiactions

import (
"net/http"

"github.com/lbryio/chainquery/auth"
"github.com/lbryio/chainquery/daemon/jobs"

"github.com/lbryio/lbry.go/api"
"github.com/lbryio/lbry.go/errors"

v "github.com/lbryio/ozzo-validation"
)

//SyncAddressBalance will synchronize the balances for all addresses in chainquery.
func SyncAddressBalance(r *http.Request) api.Response {
params := struct {
Key string
}{}

err := api.FormValues(r, &params, []*v.FieldRules{
v.Field(&params.Key),
})
if err != nil {
return api.Response{Error: err, Status: http.StatusBadRequest}
}

if !auth.IsAuthorized(params.Key) {
return api.Response{Error: errors.Err("not authorized"), Status: http.StatusUnauthorized}
}

rowsAffected, err := jobs.SyncAddressBalances()
if err != nil {
return api.Response{Error: err}
}

return api.Response{Data: rowsAffected}

}

//SyncTransactionValue will synchronize the value of all transactions in chainquery.
func SyncTransactionValue(r *http.Request) api.Response {
params := struct {
Key string
}{}

err := api.FormValues(r, &params, []*v.FieldRules{
v.Field(&params.Key),
})
if err != nil {
return api.Response{Error: err, Status: http.StatusBadRequest}
}

if !auth.IsAuthorized(params.Key) {
return api.Response{Error: errors.Err("not authorized"), Status: http.StatusUnauthorized}
}

rowsAffected, err := jobs.SyncTransactionValue()
if err != nil {
return api.Response{Error: err}
}

return api.Response{Data: rowsAffected}

}

// ValidateChainData validates a range of blocks ensure that the block,Txs, and the same number of outputs,inputs exist.
//If a difference in data is identified it will return an array identifying where there are differences.
func ValidateChainData(r *http.Request) api.Response {
params := struct {
From uint64
To *uint64
Key string
}{}

err := api.FormValues(r, &params, []*v.FieldRules{
v.Field(&params.From, v.Required),
v.Field(&params.To),
v.Field(&params.Key),
})
if err != nil {
return api.Response{Error: err, Status: http.StatusBadRequest}
}

if !auth.IsAuthorized(params.Key) {
return api.Response{Error: errors.Err("not authorized"), Status: http.StatusUnauthorized}
}

var missing []jobs.BlockData
if params.To != nil {
missing, err = jobs.ValidateChainRange(&params.From, params.To)
} else {
missing, err = jobs.ValidateChainRange(&params.From, nil)
}

if err != nil {
return api.Response{Error: err}
}

return api.Response{Data: missing}
}
Loading

0 comments on commit 5f50099

Please sign in to comment.