func (db *T) GetTransactionBlock(hash types.Hash) (b *block.Block, e error) { readable(&e, db, func(dbtx *bolt.Tx) { bucket := dbtx.Bucket([]byte("blocks")) if bucket != nil { blockHash := bucket.Get(append([]byte("T"), hash...)) if blockHash == nil { e = fmt.Errorf("transaction %s isn't included in any block", hash) return } encodedBlock := bucket.Get(blockHash) b, e = block.Decode(encodedBlock) } }) return }
func (db *T) GetBlock(hash []byte) (blk *block.Block, e error) { readable(&e, db, func(dbtx *bolt.Tx) { bucket := dbtx.Bucket([]byte("blocks")) if bucket == nil { e = errors.New("blocks bucket does not exist") return } b := bucket.Get(hash) if b == nil { e = errors.New("block not found") return } blk, e = block.Decode(b) }) return }
func (db *T) GetLastBlock() (blk *block.Block, e error) { readable(&e, db, func(dbtx *bolt.Tx) { bucket := dbtx.Bucket([]byte("blocks")) if bucket == nil { return } last := bucket.Get([]byte("last")) if last == nil { return } b := bucket.Get(last) if b == nil { e = errors.New("block not found") return } blk, e = block.Decode(b) }) return }
func (db *T) GetNextBlock(hash types.Hash) (blk *block.Block, e error) { readable(&e, db, func(dbtx *bolt.Tx) { bucket := dbtx.Bucket([]byte("blocks")) if bucket == nil { return } next := bucket.Get(append(hash, []byte("+")...)) if next == nil { return } b := bucket.Get(next) if b == nil { e = errors.New("block not found") return } blk, e = block.Decode(b) }) return }
func (db *T) GetBlock(hash []byte) (*block.Block, error) { dbtx, err := db.DB.Begin(false) defer dbtx.Rollback() if err != nil { return nil, err } bucket := dbtx.Bucket([]byte("blocks")) if bucket == nil { return nil, errors.New("blocks bucket does not exist") } b := bucket.Get(hash) if b == nil { return nil, errors.New("block not found") } decodedBlock, err := block.Decode(b) if err != nil { return decodedBlock, err } return decodedBlock, nil }
func (db *T) GetTransactionBlock(hash []byte) (*block.Block, error) { dbtx, err := db.DB.Begin(false) defer dbtx.Rollback() if err != nil { return nil, err } bucket := dbtx.Bucket([]byte("blocks")) if bucket == nil { return nil, nil } blockHash := bucket.Get(hash) if blockHash == nil { return nil, errors.New(fmt.Sprintf("referenced block %v not found", blockHash)) } b := bucket.Get(blockHash) decodedBlock, err := block.Decode(b) if err != nil { return decodedBlock, err } return decodedBlock, nil }
func (db *T) GetLastBlock() (*block.Block, error) { dbtx, err := db.DB.Begin(false) defer dbtx.Rollback() if err != nil { return nil, err } bucket := dbtx.Bucket([]byte("blocks")) if bucket == nil { return nil, nil } last := bucket.Get([]byte("last")) if last == nil { return nil, nil } b := bucket.Get(last) if b == nil { return nil, errors.New("block not found") } decodedBlock, err := block.Decode(b) if err != nil { return decodedBlock, err } return decodedBlock, nil }