OSDN Git Service

Remove unused code (#548)
authorYongfeng LI <wliyongfeng@gmail.com>
Sun, 8 Apr 2018 09:59:39 +0000 (17:59 +0800)
committerPaladz <yzhu101@uottawa.ca>
Sun, 8 Apr 2018 09:59:39 +0000 (17:59 +0800)
* remove unused code in accoun and api

* remove unused code in crypto

* remove unused code in asset and protocol

account/accounts.go
api/api_test.go
api/metrics.go
asset/asset.go
crypto/crypto.go
protocol/protocol.go

index c6837c2..cfa6b23 100755 (executable)
@@ -105,7 +105,6 @@ type Manager struct {
        delayedACPsMu sync.Mutex
        delayedACPs   map[*txbuilder.TemplateBuilder][]*CtrlProgram
 
-       acpIndexCap uint64 // points to end of block
        accIndexMu  sync.Mutex
 }
 
@@ -292,7 +291,7 @@ func (m *Manager) createAddress(ctx context.Context, account *Account, change bo
 }
 
 func (m *Manager) createP2PKH(ctx context.Context, account *Account, change bool) (*CtrlProgram, error) {
-       idx := m.nextAccountIndex(account)
+       idx := m.getNextXpubsIndex(account.Signer.XPubs)
        path := signers.Path(account.Signer, signers.AccountKeySpace, idx)
        derivedXPubs := chainkd.DeriveXPubs(account.XPubs, path)
        derivedPK := derivedXPubs[0].PublicKey()
@@ -319,7 +318,7 @@ func (m *Manager) createP2PKH(ctx context.Context, account *Account, change bool
 }
 
 func (m *Manager) createP2SH(ctx context.Context, account *Account, change bool) (*CtrlProgram, error) {
-       idx := m.nextAccountIndex(account)
+       idx := m.getNextXpubsIndex(account.Signer.XPubs)
        path := signers.Path(account.Signer, signers.AccountKeySpace, idx)
        derivedXPubs := chainkd.DeriveXPubs(account.XPubs, path)
        derivedPKs := chainkd.XPubKeys(derivedXPubs)
@@ -413,10 +412,6 @@ func (m *Manager) GetCoinbaseControlProgram() ([]byte, error) {
        return program.ControlProgram, nil
 }
 
-func (m *Manager) nextAccountIndex(account *Account) uint64 {
-       return m.getNextXpubsIndex(account.Signer.XPubs)
-}
-
 // DeleteAccount deletes the account's ID or alias matching accountInfo.
 func (m *Manager) DeleteAccount(in struct {
        AccountInfo string `json:"account_info"`
index 188c8ea..5906f0f 100644 (file)
@@ -36,7 +36,6 @@ func TestAPIHandler(t *testing.T) {
                path        string
                request     interface{}
                respWant    *Response
-               respWantErr error
        }{
                {
                        path: "/create-key",
index 3ead8a7..32b7410 100644 (file)
@@ -1,13 +1,11 @@
 package api
 
 import (
-       "expvar"
        "net/http"
        "sync"
        "time"
 
        "github.com/bytom/metrics"
-       "github.com/bytom/net/http/reqid"
 )
 
 var (
@@ -42,29 +40,3 @@ func latency(tab *http.ServeMux, req *http.Request) *metrics.RotatingLatency {
        }
        return nil
 }
-
-var (
-       ncoreMu   sync.Mutex
-       ncore     = expvar.NewInt("ncore")
-       ncoreTime time.Time
-       coresSeen map[string]bool
-)
-
-func coreCounter(h http.Handler) http.Handler {
-       return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
-               countCore(reqid.CoreIDFromContext(req.Context()))
-               h.ServeHTTP(w, req)
-       })
-}
-
-func countCore(id string) {
-       t := time.Now()
-       ncoreMu.Lock()
-       defer ncoreMu.Unlock()
-       if t.Sub(ncoreTime) > time.Minute {
-               ncore.Set(int64(len(coresSeen)))
-               ncoreTime = t
-               coresSeen = make(map[string]bool)
-       }
-       coresSeen[id] = true
-}
index d2b53a5..d8b2ff8 100755 (executable)
@@ -8,7 +8,6 @@ import (
        "sync"
 
        "github.com/golang/groupcache/lru"
-       "github.com/golang/groupcache/singleflight"
        dbm "github.com/tendermint/tmlibs/db"
        "golang.org/x/crypto/sha3"
 
@@ -97,9 +96,6 @@ type Registry struct {
        db    dbm.DB
        chain *protocol.Chain
 
-       idGroup    singleflight.Group
-       aliasGroup singleflight.Group
-
        cacheMu    sync.Mutex
        cache      *lru.Cache
        aliasCache *lru.Cache
index 45111b4..cd33037 100644 (file)
@@ -48,25 +48,3 @@ func Ripemd160(data []byte) []byte {
 
        return ripemd.Sum(nil)
 }
-
-func zeroBytes(bytes []byte) {
-       for i := range bytes {
-               bytes[i] = 0
-       }
-}
-
-func toInt(bytes []byte) []int {
-       ints := make([]int, len(bytes))
-       for i := range bytes {
-               ints[i] = int(bytes[i])
-       }
-       return ints
-}
-
-func toBytes(ints []int) []byte {
-       bytes := make([]byte, len(ints))
-       for i := range ints {
-               bytes[i] = byte(ints[i])
-       }
-       return bytes
-}
index 446d4c0..3e80d8d 100755 (executable)
@@ -15,9 +15,7 @@ import (
        "github.com/bytom/protocol/state"
 )
 
-// maxCachedValidatedTxs is the max number of validated txs to cache.
 const (
-       maxCachedValidatedTxs = 1000
        maxProcessBlockChSize = 1024
 )