-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into default-changes
- Loading branch information
Showing
59 changed files
with
5,583 additions
and
3,155 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
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 | ||
|
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 |
---|---|---|
@@ -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, ¶ms, []*v.FieldRules{ | ||
v.Field(¶ms.Block), | ||
v.Field(¶ms.From), | ||
v.Field(¶ms.To), | ||
v.Field(¶ms.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 | ||
} |
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,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, ¶ms, []*v.FieldRules{ | ||
v.Field(¶ms.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, ¶ms, []*v.FieldRules{ | ||
v.Field(¶ms.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, ¶ms, []*v.FieldRules{ | ||
v.Field(¶ms.From, v.Required), | ||
v.Field(¶ms.To), | ||
v.Field(¶ms.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(¶ms.From, params.To) | ||
} else { | ||
missing, err = jobs.ValidateChainRange(¶ms.From, nil) | ||
} | ||
|
||
if err != nil { | ||
return api.Response{Error: err} | ||
} | ||
|
||
return api.Response{Data: missing} | ||
} |
Oops, something went wrong.