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.

61 lines
1.5 KiB

10 years ago
  1. package account
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io"
  6. "github.com/tendermint/tendermint2/binary"
  7. )
  8. // Signable is an interface for all signable things.
  9. // It typically removes signatures before serializing.
  10. type Signable interface {
  11. WriteSignBytes(w io.Writer, n *int64, err *error)
  12. }
  13. // SignBytes is a convenience method for getting the bytes to sign of a Signable.
  14. func SignBytes(o Signable) []byte {
  15. buf, n, err := new(bytes.Buffer), new(int64), new(error)
  16. o.WriteSignBytes(buf, n, err)
  17. if *err != nil {
  18. panic(err)
  19. }
  20. return buf.Bytes()
  21. }
  22. //-----------------------------------------------------------------------------
  23. // Account resides in the application state, and is mutated by transactions
  24. // on the blockchain.
  25. // Serialized by binary.[read|write]Reflect
  26. type Account struct {
  27. Address []byte
  28. PubKey PubKey
  29. Sequence uint
  30. Balance uint64
  31. Code []byte // VM code
  32. StorageRoot []byte // VM storage merkle root.
  33. }
  34. func (acc *Account) Copy() *Account {
  35. accCopy := *acc
  36. return &accCopy
  37. }
  38. func (acc *Account) String() string {
  39. return fmt.Sprintf("Account{%X:%v C:%v S:%X}", acc.Address, acc.PubKey, len(acc.Code), acc.StorageRoot)
  40. }
  41. func AccountEncoder(o interface{}, w io.Writer, n *int64, err *error) {
  42. binary.WriteBinary(o.(*Account), w, n, err)
  43. }
  44. func AccountDecoder(r io.Reader, n *int64, err *error) interface{} {
  45. return binary.ReadBinary(&Account{}, r, n, err)
  46. }
  47. var AccountCodec = binary.Codec{
  48. Encode: AccountEncoder,
  49. Decode: AccountDecoder,
  50. }