// pushGetEntryDataMsg takes the passed EBlock // and return all the corresponding EBEntries func (p *peer) pushGetEntryDataMsg(eblock *common.EBlock) { binary, _ := eblock.MarshalBinary() commonHash := common.Sha(binary) hash, _ := wire.NewShaHash(commonHash.Bytes()) iv := wire.NewInvVect(wire.InvTypeFactomEntry, hash) gdmsg := wire.NewMsgGetEntryData() gdmsg.AddInvVect(iv) if len(gdmsg.InvList) > 0 { p.QueueMessage(gdmsg, nil) } }
func exportEBlock(block *common.EBlock) { if block == nil || procLog.Level() < factomlog.Info { return } data, err := block.MarshalBinary() if err != nil { panic(err) } strChainID := block.Header.ChainID.String() if fileNotExists(dataStorePath + strChainID) { err := os.MkdirAll(dataStorePath+strChainID, 0777) if err == nil { procLog.Info("Created directory " + dataStorePath + strChainID) } else { procLog.Error(err) } } err = ioutil.WriteFile(fmt.Sprintf(dataStorePath+strChainID+"/store.%09d.%09d.block", block.Header.EBSequence, block.Header.DBHeight), data, 0777) if err != nil { panic(err) } }
func (db *LevelDb) ProcessEBlockMultiBatch(eblock *common.EBlock) error { if eblock == nil { return nil } if db.lbatch == nil { return fmt.Errorf("db.lbatch == nil") } if len(eblock.Body.EBEntries) < 1 { return errors.New("Empty eblock!") } binaryEblock, err := eblock.MarshalBinary() if err != nil { return err } // Insert the binary entry block var key []byte = []byte{byte(TBL_EB)} hash, err := eblock.Hash() if err != nil { return err } key = append(key, hash.Bytes()...) db.lbatch.Put(key, binaryEblock) // Insert the entry block merkle root cross reference key = []byte{byte(TBL_EB_MR)} keyMR, err := eblock.KeyMR() if err != nil { return err } key = append(key, keyMR.Bytes()...) eBlockHash, err := eblock.Hash() if err != nil { return err } binaryEBHash, err := eBlockHash.MarshalBinary() if err != nil { return err } db.lbatch.Put(key, binaryEBHash) // Insert the entry block number cross reference key = []byte{byte(TBL_EB_CHAIN_NUM)} key = append(key, eblock.Header.ChainID.Bytes()...) bytes := make([]byte, 4) binary.BigEndian.PutUint32(bytes, eblock.Header.EBSequence) key = append(key, bytes...) db.lbatch.Put(key, binaryEBHash) // Update the chain head reference key = []byte{byte(TBL_CHAIN_HEAD)} key = append(key, eblock.Header.ChainID.Bytes()...) keyMR, err = eblock.KeyMR() if err != nil { return err } db.lbatch.Put(key, keyMR.Bytes()) return nil }