cmn "github.com/tendermint/tmlibs/common"
"github.com/bytom/accesstoken"
- "github.com/bytom/blockchain"
+ "github.com/bytom/blockchain/txfeed"
cfg "github.com/bytom/config"
"github.com/bytom/dashboard"
"github.com/bytom/errors"
- "github.com/bytom/net/http/gzip"
+ "github.com/bytom/mining/cpuminer"
+ "github.com/bytom/mining/miningpool"
"github.com/bytom/net/http/authn"
+ "github.com/bytom/net/http/gzip"
"github.com/bytom/net/http/httpjson"
"github.com/bytom/net/http/static"
+ "github.com/bytom/netsync"
"github.com/bytom/protocol"
"github.com/bytom/wallet"
)
// API is the scheduling center for server
type API struct {
- bcr *blockchain.BlockchainReactor
- wallet *wallet.Wallet
- accessTokens *accesstoken.CredentialStore
- chain *protocol.Chain
- server *http.Server
- handler http.Handler
+ sync *netsync.SyncManager
+ wallet *wallet.Wallet
+ accessTokens *accesstoken.CredentialStore
+ chain *protocol.Chain
+ server *http.Server
+ handler http.Handler
+ txFeedTracker *txfeed.Tracker
+ cpuMiner *cpuminer.CPUMiner
+ miningPool *miningpool.MiningPool
}
func (a *API) initServer(config *cfg.Config) {
}
// NewAPI create and initialize the API
-func NewAPI(bcr *blockchain.BlockchainReactor, wallet *wallet.Wallet, chain *protocol.Chain, config *cfg.Config, token *accesstoken.CredentialStore) *API {
+func NewAPI(sync *netsync.SyncManager, wallet *wallet.Wallet, txfeeds *txfeed.Tracker, cpuMiner *cpuminer.CPUMiner, miningPool *miningpool.MiningPool, chain *protocol.Chain, config *cfg.Config, token *accesstoken.CredentialStore) *API {
api := &API{
- bcr: bcr,
- wallet: wallet,
- chain: chain,
- accessTokens: token,
+ sync: sync,
+ wallet: wallet,
+ chain: chain,
+ accessTokens: token,
+ txFeedTracker: txfeeds,
+ cpuMiner: cpuMiner,
+ miningPool: miningPool,
}
api.buildHandler()
api.initServer(config)
walletEnable = true
m.Handle("/create-account", jsonHandler(a.createAccount))
- m.Handle("/update-account-tags", jsonHandler(a.updateAccountTags))
m.Handle("/list-accounts", jsonHandler(a.listAccounts))
m.Handle("/delete-account", jsonHandler(a.deleteAccount))
m.Handle("/create-asset", jsonHandler(a.createAsset))
m.Handle("/update-asset-alias", jsonHandler(a.updateAssetAlias))
- m.Handle("/update-asset-tags", jsonHandler(a.updateAssetTags))
m.Handle("/list-assets", jsonHandler(a.listAssets))
m.Handle("/create-key", jsonHandler(a.pseudohsmCreateKey))
m.Handle("/delete-key", jsonHandler(a.pseudohsmDeleteKey))
m.Handle("/reset-key-password", jsonHandler(a.pseudohsmResetPassword))
- m.Handle("/export-private-key", jsonHandler(a.walletExportKey))
- m.Handle("/import-private-key", jsonHandler(a.walletImportKey))
- m.Handle("/import-key-progress", jsonHandler(a.keyImportProgress))
-
m.Handle("/build-transaction", jsonHandler(a.build))
m.Handle("/sign-transaction", jsonHandler(a.pseudohsmSignTemplates))
m.Handle("/submit-transaction", jsonHandler(a.submit))
- m.Handle("/sign-submit-transaction", jsonHandler(a.signSubmit))
+ m.Handle("/estimate-transaction-gas", jsonHandler(a.estimateTxGas))
+
m.Handle("/get-transaction", jsonHandler(a.getTransaction))
m.Handle("/list-transactions", jsonHandler(a.listTransactions))
+ m.Handle("/get-unconfirmed-transaction", jsonHandler(a.getUnconfirmedTx))
+ m.Handle("/list-unconfirmed-transactions", jsonHandler(a.listUnconfirmedTxs))
+
m.Handle("/list-balances", jsonHandler(a.listBalances))
m.Handle("/list-unspent-outputs", jsonHandler(a.listUnspentOutputs))
} else {
m.Handle("/", alwaysError(errors.New("not Found")))
m.Handle("/error", jsonHandler(a.walletError))
- m.Handle("/info", jsonHandler(a.bcr.Info))
m.Handle("/net-info", jsonHandler(a.getNetInfo))
m.Handle("/create-access-token", jsonHandler(a.createAccessToken))
m.Handle("/delete-transaction-feed", jsonHandler(a.deleteTxFeed))
m.Handle("/list-transaction-feeds", jsonHandler(a.listTxFeeds))
- m.Handle("/block-hash", jsonHandler(a.getBestBlockHash))
+ m.Handle("/get-block-hash", jsonHandler(a.getBestBlockHash))
m.Handle("/get-block-header-by-hash", jsonHandler(a.getBlockHeaderByHash))
m.Handle("/get-block-header-by-height", jsonHandler(a.getBlockHeaderByHeight))
m.Handle("/get-block", jsonHandler(a.getBlock))
m.Handle("/is-mining", jsonHandler(a.isMining))
m.Handle("/gas-rate", jsonHandler(a.gasRate))
- m.Handle("/getwork", jsonHandler(a.getWork))
- m.Handle("/submitwork", jsonHandler(a.submitWork))
+ m.Handle("/get-work", jsonHandler(a.getWork))
+ m.Handle("/submit-work", jsonHandler(a.submitWork))
+ m.Handle("/set-mining", jsonHandler(a.setMining))
handler := latencyHandler(m, walletEnable)
- handler = walletRedirectHandler(handler)
handler = maxBytesHandler(handler) // TODO(tessr): consider moving this to non-core specific mux
handler = webAssetsHandler(handler)
handler = gzip.Handler{Handler: handler}
}
// when the wallet is not been opened and the url path is not been found, modify url path to error,
- // and after redirecting to the new url in func walletRedirectHandler
+ // and redirect handler to error
if _, pattern := m.Handler(req); pattern != req.URL.Path && !walletEnable {
req.URL.Path = "/error"
+ walletRedirectHandler(w, req)
+ return
}
m.ServeHTTP(w, req)
}
// walletRedirectHandler redirect to error when the wallet is closed
-func walletRedirectHandler(handler http.Handler) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
- if req.URL.Path == "/error" {
- http.Redirect(w, req, req.URL.String(), http.StatusOK)
- return
- }
- handler.ServeHTTP(w, req)
- })
+func walletRedirectHandler(w http.ResponseWriter, req *http.Request) {
+ h := http.RedirectHandler(req.URL.String(), http.StatusMovedPermanently)
+ h.ServeHTTP(w, req)
}