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.

66 lines
1.1 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. }
  30. type Log struct {
  31. Address Word
  32. Topics []Word
  33. Data []byte
  34. Height uint64
  35. }
  36. type AppState interface {
  37. // Accounts
  38. GetAccount(addr Word) (*Account, error)
  39. UpdateAccount(*Account) error
  40. DeleteAccount(*Account) error
  41. CreateAccount(addr Word) (*Account, error)
  42. // Storage
  43. GetStorage(Word, Word) (Word, error)
  44. SetStorage(Word, Word, Word) (bool, error) // Setting to Zero is deleting.
  45. // Logs
  46. AddLog(*Log)
  47. }
  48. type Params struct {
  49. BlockHeight uint64
  50. BlockHash Word
  51. BlockTime int64
  52. GasLimit uint64
  53. }