OSDN Git Service

wallet.enable control account and asset
authorgguoss <1536310027@qq.com>
Thu, 12 Oct 2017 02:19:20 +0000 (10:19 +0800)
committergguoss <1536310027@qq.com>
Thu, 12 Oct 2017 02:19:20 +0000 (10:19 +0800)
blockchain/reactor.go
node/node.go

index 4ed1392..1777066 100644 (file)
@@ -141,19 +141,28 @@ func maxBytes(h http.Handler) http.Handler {
 
 func (bcr *BlockchainReactor) BuildHander() {
        m := bcr.mux
-       m.Handle("/create-account", jsonHandler(bcr.createAccount))
-       m.Handle("/create-asset", jsonHandler(bcr.createAsset))
-       m.Handle("/update-account-tags", jsonHandler(bcr.updateAccountTags))
-       m.Handle("/update-asset-tags", jsonHandler(bcr.updateAssetTags))
+       if bcr.accounts != nil{
+               m.Handle("/create-account", jsonHandler(bcr.createAccount))
+               m.Handle("/update-account-tags", jsonHandler(bcr.updateAccountTags))
+               m.Handle("/create-account-receiver", jsonHandler(bcr.createAccountReceiver))
+               m.Handle("/list-accounts", jsonHandler(bcr.listAccounts))
+       } else {
+               log.Printf(context.Background(), "Warning: Please enable wallet")
+       }
+
+       if bcr.assets != nil {
+               m.Handle("/create-asset", jsonHandler(bcr.createAsset))
+               m.Handle("/update-asset-tags", jsonHandler(bcr.updateAssetTags))
+               m.Handle("/list-assets", jsonHandler(bcr.listAssets))
+       } else {
+               log.Printf(context.Background(), "Warning: Please enable wallet")
+       }
        m.Handle("/build-transaction", jsonHandler(bcr.build))
        m.Handle("/create-control-program", jsonHandler(bcr.createControlProgram))
-       m.Handle("/create-account-receiver", jsonHandler(bcr.createAccountReceiver))
        m.Handle("/create-transaction-feed", jsonHandler(bcr.createTxFeed))
        m.Handle("/get-transaction-feed", jsonHandler(bcr.getTxFeed))
        m.Handle("/update-transaction-feed", jsonHandler(bcr.updateTxFeed))
        m.Handle("/delete-transaction-feed", jsonHandler(bcr.deleteTxFeed))
-       m.Handle("/list-accounts", jsonHandler(bcr.listAccounts))
-       m.Handle("/list-assets", jsonHandler(bcr.listAssets))
        m.Handle("/list-transaction-feeds", jsonHandler(bcr.listTxFeeds))
        m.Handle("/list-transactions", jsonHandler(bcr.listTransactions))
        m.Handle("/list-balances", jsonHandler(bcr.listBalances))
index 1f8311b..7a79d8c 100644 (file)
@@ -194,10 +194,14 @@ func NewNode(config *cfg.Config, logger log.Logger) *Node {
                }
        }
 
-       accounts_db := dbm.NewDB("account", config.DBBackend, config.DBDir())
-       accounts := account.NewManager(accounts_db, chain)
-       assets_db := dbm.NewDB("asset", config.DBBackend, config.DBDir())
-       assets := asset.NewRegistry(assets_db, chain)
+       var accounts *account.Manager = nil
+       var assets *asset.Registry = nil
+       if config.Wallet.Enable {
+               accounts_db := dbm.NewDB("account", config.DBBackend, config.DBDir())
+               assets_db := dbm.NewDB("asset", config.DBBackend, config.DBDir())
+               accounts = account.NewManager(accounts_db, chain)
+               assets = asset.NewRegistry(assets_db, chain)
+       }
 
        //Todo HSM
        /*