OSDN Git Service

Merge pull request #38 from Bytom/dev_module_cliam
[bytom/vapor.git] / api / api.go
index b8cbcfb..1e0d303 100644 (file)
@@ -17,8 +17,7 @@ import (
        "github.com/vapor/dashboard/dashboard"
        "github.com/vapor/dashboard/equity"
        "github.com/vapor/errors"
-       "github.com/vapor/mining/cpuminer"
-       "github.com/vapor/mining/miningpool"
+       "github.com/vapor/mining/miner"
        "github.com/vapor/net/http/authn"
        "github.com/vapor/net/http/gzip"
        "github.com/vapor/net/http/httpjson"
@@ -105,15 +104,15 @@ func (wh *waitHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
 
 // API is the scheduling center for server
 type API struct {
-       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
+       sync          *netsync.SyncManager
+       wallet        *wallet.Wallet
+       accessTokens  *accesstoken.CredentialStore
+       chain         *protocol.Chain
+       server        *http.Server
+       handler       http.Handler
+       txFeedTracker *txfeed.Tracker
+       //cpuMiner        *cpuminer.CPUMiner
+       miner           *miner.Miner
        notificationMgr *websocket.WSNotificationManager
        newBlockCh      chan *bc.Hash
 }
@@ -169,15 +168,14 @@ func (a *API) StartServer(address string) {
 }
 
 // NewAPI create and initialize the 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, newBlockCh chan *bc.Hash, notificationMgr *websocket.WSNotificationManager) *API {
+func NewAPI(sync *netsync.SyncManager, wallet *wallet.Wallet, txfeeds *txfeed.Tracker, miner *miner.Miner, chain *protocol.Chain, config *cfg.Config, token *accesstoken.CredentialStore, newBlockCh chan *bc.Hash, notificationMgr *websocket.WSNotificationManager) *API {
        api := &API{
                sync:          sync,
                wallet:        wallet,
                chain:         chain,
                accessTokens:  token,
                txFeedTracker: txfeeds,
-               cpuMiner:      cpuMiner,
-               miningPool:    miningPool,
+               miner:         miner,
 
                newBlockCh:      newBlockCh,
                notificationMgr: notificationMgr,
@@ -255,6 +253,17 @@ func (a *API) buildHandler() {
                m.Handle("/get-side-raw-transaction", jsonHandler(a.getSideRawTransaction))
                m.Handle("/build-mainchain-tx", jsonHandler(a.buildMainChainTxForContract))
                m.Handle("/sign-with-key", jsonHandler(a.signWithKey))
+               m.Handle("/sign-with-xprv", jsonHandler(a.signWithPriKey))
+               // listdelegates
+               m.Handle("/list-delegates", jsonHandler(a.listDelegates))
+               // getdelegatevotes
+               m.Handle("/get-delegate-votes", jsonHandler(a.getDelegateVotes))
+               // listvoteddelegates
+               m.Handle("/list-voted-delegates", jsonHandler(a.listVotedDelegates))
+               // listreceivedvotes
+               m.Handle("/list-received-votes", jsonHandler(a.listReceivedVotes))
+
+               m.Handle("/get-address-balance", jsonHandler(a.getAddressBalance))
        } else {
                log.Warn("Please enable wallet")
        }
@@ -293,12 +302,6 @@ func (a *API) buildHandler() {
        m.Handle("/is-mining", jsonHandler(a.isMining))
        m.Handle("/set-mining", jsonHandler(a.setMining))
 
-       m.Handle("/get-work", jsonHandler(a.getWork))
-       m.Handle("/get-work-json", jsonHandler(a.getWorkJSON))
-       m.Handle("/submit-block", jsonHandler(a.submitBlock))
-       m.Handle("/submit-work", jsonHandler(a.submitWork))
-       m.Handle("/submit-work-json", jsonHandler(a.submitWorkJSON))
-
        m.Handle("/verify-message", jsonHandler(a.verifyMessage))
        m.Handle("/compile", jsonHandler(a.compileEquity))