database.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2018 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. // Package database defines the interfaces for an Ethereum data store.
  17. package ethdb
  18. import "io"
  19. // Reader wraps the Has and Get method of a backing data store.
  20. type Reader interface {
  21. // Has retrieves if a key is present in the key-value data store.
  22. Has(key []byte) (bool, error)
  23. // Get retrieves the given key if it's present in the key-value data store.
  24. Get(key []byte) ([]byte, error)
  25. }
  26. // Writer wraps the Put method of a backing data store.
  27. type Writer interface {
  28. // Put inserts the given value into the key-value data store.
  29. Put(key []byte, value []byte) error
  30. }
  31. // Deleter wraps the Delete method of a backing data store.
  32. type Deleter interface {
  33. // Delete removes the key from the key-value data store.
  34. Delete(key []byte) error
  35. }
  36. // Stater wraps the Stat method of a backing data store.
  37. type Stater interface {
  38. // Stat returns a particular internal stat of the database.
  39. Stat(property string) (string, error)
  40. }
  41. // Compacter wraps the Compact method of a backing data store.
  42. type Compacter interface {
  43. // Compact flattens the underlying data store for the given key range. In essence,
  44. // deleted and overwritten versions are discarded, and the data is rearranged to
  45. // reduce the cost of operations needed to access them.
  46. //
  47. // A nil start is treated as a key before all keys in the data store; a nil limit
  48. // is treated as a key after all keys in the data store. If both is nil then it
  49. // will compact entire data store.
  50. Compact(start []byte, limit []byte) error
  51. }
  52. // KeyValueStore contains all the methods required to allow handling different
  53. // key-value data stores backing the high level database.
  54. type KeyValueStore interface {
  55. Reader
  56. Writer
  57. Deleter
  58. Batcher
  59. Iteratee
  60. Stater
  61. Compacter
  62. io.Closer
  63. }
  64. // Database contains all the methods required by the high level database to not
  65. // only access the key-value data store but also the chain freezer.
  66. type Database interface {
  67. Reader
  68. Writer
  69. Deleter
  70. Batcher
  71. Iteratee
  72. Stater
  73. Compacter
  74. io.Closer
  75. }