func (db *LevelDb) InsertChainMultiBatch(chain *common.EChain) error { if chain == nil { return nil } if db.lbatch == nil { return fmt.Errorf("db.lbatch == nil") } binaryChain, err := chain.MarshalBinary() if err != nil { return err } var chainByHashKey []byte = []byte{byte(TBL_CHAIN_HASH)} chainByHashKey = append(chainByHashKey, chain.ChainID.Bytes()...) db.lbatch.Put(chainByHashKey, binaryChain) return nil }
// InsertChain inserts the newly created chain into db func (db *LevelDb) InsertChain(chain *common.EChain) (err error) { db.dbLock.Lock() defer db.dbLock.Unlock() if db.lbatch == nil { db.lbatch = new(leveldb.Batch) } defer db.lbatch.Reset() binaryChain, _ := chain.MarshalBinary() var chainByHashKey []byte = []byte{byte(TBL_CHAIN_HASH)} chainByHashKey = append(chainByHashKey, chain.ChainID.Bytes()...) db.lbatch.Put(chainByHashKey, binaryChain) err = db.lDb.Write(db.lbatch, db.wo) if err != nil { log.Println("batch failed %v\n", err) return err } return nil }