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.

59 lines
1.4 KiB

  1. package account
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io"
  6. "github.com/tendermint/tendermint/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. }
  32. func (account *Account) Copy() *Account {
  33. accountCopy := *account
  34. return &accountCopy
  35. }
  36. func (account *Account) String() string {
  37. return fmt.Sprintf("Account{%X:%v}", account.Address, account.PubKey)
  38. }
  39. func AccountEncoder(o interface{}, w io.Writer, n *int64, err *error) {
  40. binary.WriteBinary(o.(*Account), w, n, err)
  41. }
  42. func AccountDecoder(r io.Reader, n *int64, err *error) interface{} {
  43. return binary.ReadBinary(&Account{}, r, n, err)
  44. }
  45. var AccountCodec = binary.Codec{
  46. Encode: AccountEncoder,
  47. Decode: AccountDecoder,
  48. }