You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.2 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. package vm
  2. import ()
  3. const (
  4. defaultDataStackCapacity = 10
  5. )
  6. var (
  7. Zero = Word{0}
  8. One = Word{1}
  9. )
  10. type Word [32]byte
  11. func (w Word) String() string { return string(w[:]) }
  12. func (w Word) Copy() Word { return w }
  13. func (w Word) Bytes() []byte { return w[:] } // copied.
  14. func (w Word) Address() []byte { return w[:20] }
  15. func (w Word) IsZero() bool {
  16. accum := byte(0)
  17. for _, byt := range w {
  18. accum |= byt
  19. }
  20. return accum == 0
  21. }
  22. //-----------------------------------------------------------------------------
  23. type Account struct {
  24. Address Word
  25. Balance uint64
  26. Code []byte
  27. Nonce uint64
  28. StorageRoot Word
  29. Other interface{} // For holding all other data.
  30. }
  31. type Log struct {
  32. Address Word
  33. Topics []Word
  34. Data []byte
  35. Height uint64
  36. }
  37. type AppState interface {
  38. // Accounts
  39. GetAccount(addr Word) (*Account, error)
  40. UpdateAccount(*Account) error
  41. DeleteAccount(*Account) error
  42. CreateAccount(*Account) (*Account, error)
  43. // Storage
  44. GetStorage(Word, Word) (Word, error)
  45. SetStorage(Word, Word, Word) (bool, error) // Setting to Zero is deleting.
  46. // Logs
  47. AddLog(*Log)
  48. }
  49. type Params struct {
  50. BlockHeight uint64
  51. BlockHash Word
  52. BlockTime int64
  53. GasLimit uint64
  54. }