OSDN Git Service

remove accounts and assets from BlockchainReactor (#448)
authorYongfeng LI <wliyongfeng@gmail.com>
Wed, 21 Mar 2018 07:17:01 +0000 (15:17 +0800)
committerPaladz <yzhu101@uottawa.ca>
Wed, 21 Mar 2018 07:17:01 +0000 (15:17 +0800)
* remove accounts field in BlockchainReactor

* remove assets field in BlockchainReactor

blockchain/accounts.go
blockchain/assets.go
blockchain/query.go
blockchain/reactor.go
blockchain/receivers.go
blockchain/request.go
blockchain/rpc_reactor.go
blockchain/transact.go
node/node.go

index 251f367..fba26a7 100644 (file)
@@ -19,7 +19,7 @@ func (bcr *BlockchainReactor) createAccount(ctx context.Context, ins struct {
        Alias     string                 `json:"alias"`
        Tags      map[string]interface{} `json:"tags"`
 }) Response {
-       acc, err := bcr.accounts.Create(ctx, ins.RootXPubs, ins.Quorum, ins.Alias, ins.Tags)
+       acc, err := bcr.wallet.AccountMgr.Create(ctx, ins.RootXPubs, ins.Quorum, ins.Alias, ins.Tags)
        if err != nil {
                return NewErrorResponse(err)
        }
@@ -40,7 +40,7 @@ func (bcr *BlockchainReactor) updateAccountTags(ctx context.Context, updateTag s
        Tags        map[string]interface{} `json:"tags"`
 }) Response {
 
-       err := bcr.accounts.UpdateTags(nil, updateTag.AccountInfo, updateTag.Tags)
+       err := bcr.wallet.AccountMgr.UpdateTags(nil, updateTag.AccountInfo, updateTag.Tags)
        if err != nil {
                return NewErrorResponse(err)
        }
@@ -53,7 +53,7 @@ func (bcr *BlockchainReactor) updateAccountTags(ctx context.Context, updateTag s
 func (bcr *BlockchainReactor) deleteAccount(ctx context.Context, in struct {
        AccountInfo string `json:"account_info"`
 }) Response {
-       if err := bcr.accounts.DeleteAccount(in); err != nil {
+       if err := bcr.wallet.AccountMgr.DeleteAccount(in); err != nil {
                return NewErrorResponse(err)
        }
        return NewSuccessResponse(nil)
@@ -92,7 +92,7 @@ func (bcr *BlockchainReactor) validateAddress(ctx context.Context, ins struct {
        }
 
        resp.Vaild = true
-       resp.IsLocal = bcr.accounts.IsLocalControlProgram(program)
+       resp.IsLocal = bcr.wallet.AccountMgr.IsLocalControlProgram(program)
        return NewSuccessResponse(resp)
 }
 
@@ -102,7 +102,7 @@ type addressResp struct {
 }
 
 func (bcr *BlockchainReactor) listAddresses(ctx context.Context) Response {
-       cps, err := bcr.accounts.ListControlProgram()
+       cps, err := bcr.wallet.AccountMgr.ListControlProgram()
        if err != nil {
                return NewErrorResponse(err)
        }
index 682b768..178fde7 100644 (file)
@@ -17,7 +17,7 @@ func (bcr *BlockchainReactor) createAsset(ctx context.Context, ins struct {
        Definition map[string]interface{} `json:"definition"`
        Tags       map[string]interface{} `json:"tags"`
 }) Response {
-       ass, err := bcr.assets.Define(
+       ass, err := bcr.wallet.AssetReg.Define(
                ins.RootXPubs,
                ins.Quorum,
                ins.Definition,
@@ -43,7 +43,7 @@ func (bcr *BlockchainReactor) updateAssetTags(ctx context.Context, updateTag str
        AssetInfo string                 `json:"asset_info"`
        Tags      map[string]interface{} `json:"tags"`
 }) Response {
-       err := bcr.assets.UpdateTags(nil, updateTag.AssetInfo, updateTag.Tags)
+       err := bcr.wallet.AssetReg.UpdateTags(nil, updateTag.AssetInfo, updateTag.Tags)
        if err != nil {
                return NewErrorResponse(err)
        }
@@ -56,7 +56,7 @@ func (bcr *BlockchainReactor) updateAssetAlias(updateAlias struct {
        OldAlias string `json:"old_alias"`
        NewAlias string `json:"new_alias"`
 }) Response {
-       if err := bcr.assets.UpdateAssetAlias(updateAlias.OldAlias, updateAlias.NewAlias); err != nil {
+       if err := bcr.wallet.AssetReg.UpdateAssetAlias(updateAlias.OldAlias, updateAlias.NewAlias); err != nil {
                return NewErrorResponse(err)
        }
 
index 6686cfb..ee818e2 100755 (executable)
@@ -15,7 +15,7 @@ import (
 func (bcr *BlockchainReactor) listAccounts(ctx context.Context, filter struct {
        ID string `json:"id"`
 }) Response {
-       accounts, err := bcr.accounts.ListAccounts(filter.ID)
+       accounts, err := bcr.wallet.AccountMgr.ListAccounts(filter.ID)
        if err != nil {
                log.Errorf("listAccounts: %v", err)
                return NewErrorResponse(err)
@@ -38,7 +38,7 @@ func (bcr *BlockchainReactor) listAccounts(ctx context.Context, filter struct {
 func (bcr *BlockchainReactor) listAssets(ctx context.Context, filter struct {
        ID string `json:"id"`
 }) Response {
-       assets, err := bcr.assets.ListAssets(filter.ID)
+       assets, err := bcr.wallet.AssetReg.ListAssets(filter.ID)
        if err != nil {
                log.Errorf("listAssets: %v", err)
                return NewErrorResponse(err)
@@ -100,8 +100,8 @@ func (bcr *BlockchainReactor) indexBalances(accountUTXOs []account.UTXO) []accou
 
                for _, assetID := range sortedAsset {
 
-                       alias := bcr.accounts.GetAliasByID(id)
-                       assetAlias := bcr.assets.GetAliasByID(assetID)
+                       alias := bcr.wallet.AccountMgr.GetAliasByID(id)
+                       assetAlias := bcr.wallet.AssetReg.GetAliasByID(assetID)
                        tmpBalance.Alias = alias
                        tmpBalance.AccountID = id
                        tmpBalance.AssetID = assetID
@@ -194,8 +194,8 @@ func (bcr *BlockchainReactor) listUnspentOutputs(ctx context.Context, filter str
                tmpUTXO.Address = utxo.Address
                tmpUTXO.ValidHeight = utxo.ValidHeight
 
-               tmpUTXO.Alias = bcr.accounts.GetAliasByID(utxo.AccountID)
-               tmpUTXO.AssetAlias = bcr.assets.GetAliasByID(tmpUTXO.AssetID)
+               tmpUTXO.Alias = bcr.wallet.AccountMgr.GetAliasByID(utxo.AccountID)
+               tmpUTXO.AssetAlias = bcr.wallet.AssetReg.GetAliasByID(tmpUTXO.AssetID)
 
                UTXOs = append(UTXOs, tmpUTXO)
        }
index a6aefe9..284640c 100755 (executable)
@@ -10,8 +10,6 @@ import (
        cmn "github.com/tendermint/tmlibs/common"
 
        "github.com/bytom/blockchain/accesstoken"
-       "github.com/bytom/blockchain/account"
-       "github.com/bytom/blockchain/asset"
        "github.com/bytom/blockchain/pseudohsm"
        "github.com/bytom/blockchain/txfeed"
        "github.com/bytom/blockchain/wallet"
@@ -65,8 +63,6 @@ type BlockchainReactor struct {
 
        chain         *protocol.Chain
        wallet        *wallet.Wallet
-       accounts      *account.Manager
-       assets        *asset.Registry
        accessTokens  *accesstoken.CredentialStore
        txFeedTracker *txfeed.Tracker
        blockKeeper   *blockKeeper
@@ -105,17 +101,15 @@ func maxBytes(h http.Handler) http.Handler {
 }
 
 // NewBlockchainReactor returns the reactor of whole blockchain.
-func NewBlockchainReactor(chain *protocol.Chain, txPool *protocol.TxPool, accounts *account.Manager, assets *asset.Registry, sw *p2p.Switch, hsm *pseudohsm.HSM, wallet *wallet.Wallet, txfeeds *txfeed.Tracker, accessTokens *accesstoken.CredentialStore, miningEnable bool) *BlockchainReactor {
+func NewBlockchainReactor(chain *protocol.Chain, txPool *protocol.TxPool, sw *p2p.Switch, hsm *pseudohsm.HSM, wallet *wallet.Wallet, txfeeds *txfeed.Tracker, accessTokens *accesstoken.CredentialStore, miningEnable bool) *BlockchainReactor {
        newBlockCh := make(chan *bc.Hash, maxNewBlockChSize)
        bcr := &BlockchainReactor{
                chain:         chain,
                wallet:        wallet,
-               accounts:      accounts,
-               assets:        assets,
                blockKeeper:   newBlockKeeper(chain, sw),
                txPool:        txPool,
-               mining:        cpuminer.NewCPUMiner(chain, accounts, txPool, newBlockCh),
-               miningPool:    miningpool.NewMiningPool(chain, accounts, txPool, newBlockCh),
+               mining:        cpuminer.NewCPUMiner(chain, wallet.AccountMgr, txPool, newBlockCh),
+               miningPool:    miningpool.NewMiningPool(chain, wallet.AccountMgr, txPool, newBlockCh),
                mux:           http.NewServeMux(),
                sw:            sw,
                hsm:           hsm,
index f415b4a..321b6ce 100755 (executable)
@@ -7,7 +7,7 @@ import (
 func (bcr *BlockchainReactor) createAccountReceiver(ctx context.Context, ins struct {
        AccountInfo string `json:"account_info"`
 }) Response {
-       receiver, err := bcr.accounts.CreateAccountReceiver(ctx, ins.AccountInfo)
+       receiver, err := bcr.wallet.AccountMgr.CreateAccountReceiver(ctx, ins.AccountInfo)
        if err != nil {
                return NewErrorResponse(err)
        }
index 380d602..25ab297 100644 (file)
@@ -30,7 +30,7 @@ func (bcr *BlockchainReactor) filterAliases(ctx context.Context, br *BuildReques
                        case consensus.BTMAlias:
                                m["asset_id"] = consensus.BTMAssetID.String()
                        default:
-                               id, err := bcr.assets.GetIDByAlias(alias)
+                               id, err := bcr.wallet.AssetReg.GetIDByAlias(alias)
                                if err != nil {
                                        return errors.WithDetailf(err, "invalid asset alias %s on action %d", alias, i)
                                }
@@ -41,7 +41,7 @@ func (bcr *BlockchainReactor) filterAliases(ctx context.Context, br *BuildReques
                id, _ = m["account_id"].(string)
                alias, _ = m["account_alias"].(string)
                if id == "" && alias != "" {
-                       acc, err := bcr.accounts.FindByAlias(ctx, alias)
+                       acc, err := bcr.wallet.AccountMgr.FindByAlias(ctx, alias)
                        if err != nil {
                                return errors.WithDetailf(err, "invalid account alias %s on action %d", alias, i)
                        }
index 10ab312..5655655 100644 (file)
@@ -53,7 +53,7 @@ func webAssetsHandler(next http.Handler) http.Handler {
 // BuildHandler is in charge of all the rpc handling.
 func (bcr *BlockchainReactor) BuildHandler() {
        m := bcr.mux
-       if bcr.accounts != nil && bcr.assets != nil {
+       if bcr.wallet.AccountMgr != nil && bcr.wallet.AssetReg != nil {
                m.Handle("/create-account", jsonHandler(bcr.createAccount))
                m.Handle("/update-account-tags", jsonHandler(bcr.updateAccountTags))
                m.Handle("/create-account-receiver", jsonHandler(bcr.createAccountReceiver))
index d3e4c23..afcc3b2 100644 (file)
@@ -20,7 +20,7 @@ func (bcr *BlockchainReactor) actionDecoder(action string) (func([]byte) (txbuil
        var decoder func([]byte) (txbuilder.Action, error)
        switch action {
        case "control_account":
-               decoder = bcr.accounts.DecodeControlAction
+               decoder = bcr.wallet.AccountMgr.DecodeControlAction
        case "control_address":
                decoder = txbuilder.DecodeControlAddressAction
        case "control_program":
@@ -28,13 +28,13 @@ func (bcr *BlockchainReactor) actionDecoder(action string) (func([]byte) (txbuil
        case "control_receiver":
                decoder = txbuilder.DecodeControlReceiverAction
        case "issue":
-               decoder = bcr.assets.DecodeIssueAction
+               decoder = bcr.wallet.AssetReg.DecodeIssueAction
        case "retire":
                decoder = txbuilder.DecodeRetireAction
        case "spend_account":
-               decoder = bcr.accounts.DecodeSpendAction
+               decoder = bcr.wallet.AccountMgr.DecodeSpendAction
        case "spend_account_unspent_output":
-               decoder = bcr.accounts.DecodeSpendUTXOAction
+               decoder = bcr.wallet.AccountMgr.DecodeSpendUTXOAction
        default:
                return nil, false
        }
index 4cd01ba..aeca6c0 100755 (executable)
@@ -210,7 +210,7 @@ func NewNode(config *cfg.Config) *Node {
                go accounts.ExpireReservations(ctx, expireReservationsPeriod)
        }
 
-       bcReactor := bc.NewBlockchainReactor(chain, txPool, accounts, assets, sw, hsm, wallet, txFeed, accessTokens, config.Mining)
+       bcReactor := bc.NewBlockchainReactor(chain, txPool,sw, hsm, wallet, txFeed, accessTokens, config.Mining)
 
        sw.AddReactor("BLOCKCHAIN", bcReactor)