From 2e6ef848f2e8bd17cd396d6faf64cf7ca203890a Mon Sep 17 00:00:00 2001 From: gguoss <1536310027@qq.com> Date: Thu, 12 Oct 2017 10:19:20 +0800 Subject: [PATCH] wallet.enable control account and asset --- blockchain/reactor.go | 23 ++++++++++++++++------- node/node.go | 12 ++++++++---- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/blockchain/reactor.go b/blockchain/reactor.go index 4ed13928..17770666 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -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)) diff --git a/node/node.go b/node/node.go index 1f8311b5..7a79d8c7 100644 --- a/node/node.go +++ b/node/node.go @@ -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 /* -- 2.11.0