func (p *onePeer) Save() { p.where = "aaa" peerDB.Put(qdb.KeyType(p.UniqID()), p.Bytes()) p.where = "bbb" pers_do_cleanup() p.where = "ccc" }
func (db *unwindDb) undo(height uint32, unsp *unspentDb) { if height != db.lastBlockHeight { panic("Unexpected height") } v := db.tdb.Get(qdb.KeyType(height)) if v == nil { panic("Unwind data not found") } unwindFromReader(bytes.NewReader(v[32:]), unsp) db.del(height) db.lastBlockHeight-- v = db.tdb.Get(qdb.KeyType(db.lastBlockHeight)) if v == nil { panic("Parent data not found") } copy(db.lastBlockHash[:], v[:32]) return }
func (db *unwindDb) commit(changes *btc.BlockChanges, blhash []byte) { if db.lastBlockHeight+1 != changes.Height { println(db.lastBlockHeight+1, changes.Height) panic("Unexpected height") } db.lastBlockHeight++ copy(db.lastBlockHash[:], blhash[0:32]) f := new(bytes.Buffer) f.Write(blhash[0:32]) for k, _ := range changes.AddedTxs { writeSpent(f, &k, nil) } for k, v := range changes.DeledTxs { writeSpent(f, &k, v) } db.tdb.Put(qdb.KeyType(changes.Height), f.Bytes()) if changes.Height >= UnwindBufferMaxHistory { db.del(changes.Height - UnwindBufferMaxHistory) } }
func ParseAddr(pl []byte) { b := bytes.NewBuffer(pl) now := uint32(time.Now().Unix()) cnt, _ := btc.ReadVLen(b) for i := 0; i < int(cnt); i++ { var buf [30]byte n, e := b.Read(buf[:]) if n != len(buf) || e != nil { println("ParseAddr:", n, e) break } a := newPeer(buf[:]) if a.Time > now-expirePeerAfter { k := qdb.KeyType(a.UniqID()) v := peerDB.Get(k) if v != nil { a.Banned = newPeer(v[:]).Banned } peerDB.Put(k, a.Bytes()) } } peerDB.Defrag() }
func (db *unwindDb) del(height uint32) { db.tdb.Del(qdb.KeyType(height)) }
func getUnspIndex(po *btc.TxPrevOut) qdb.KeyType { return qdb.KeyType(binary.LittleEndian.Uint64(po.Hash[:8]) ^ uint64(po.Vout)) }