Class AccountStatus

All Implemented Interfaces:
IAssociative<Keyword,ACell>, IValidated, IWriteable, Map<Keyword,ACell>

public class AccountStatus extends ARecord
Class representing the current on-chain status of an account. Accounts may be User accounts or Actor accounts. "People said I should accept the world. Bullshit! I don't accept the world." - Richard Stallman
  • Method Details

    • create

      public static AccountStatus create(long sequence, long balance, AccountKey key)
      Create a regular account, with the specified balance and zero allowance
      Parameters:
      sequence - Sequence number
      balance - Convex Coin balance of Account
      key - Public Key of new Account
      Returns:
      New AccountStatus
    • createGovernance

      public static AccountStatus createGovernance(long balance)
      Create a governance account.
      Parameters:
      balance - Balance for governance account
      Returns:
      New governance AccountStatus
    • createActor

      public static AccountStatus createActor()
    • create

      public static AccountStatus create(long balance, AccountKey key)
    • create

      public static AccountStatus create()
      Create a completely empty Account record, with no balance or public key
      Returns:
      Empty Account record
    • getSequence

      public long getSequence()
      Gets the sequence number for this Account. The sequence number is the number of transactions executed by this account to date. It will be zero for new Accounts. The next transaction executed must have a sequence number equal to this value plus one.
      Returns:
      The sequence number for this Account.
    • getBalance

      public long getBalance()
    • encode

      public int encode(byte[] bs, int pos)
      Description copied from class: ACell
      Writes this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.
      Specified by:
      encode in interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • encodeRaw

      public int encodeRaw(byte[] bs, int pos)
      Description copied from class: ARecord
      Writes the raw fields of this record in declared order
      Overrides:
      encodeRaw in class ARecord
      Parameters:
      bs - Array to write to
      pos - The offset into the byte array
      Returns:
      New position after writing
    • read

      public static AccountStatus read(Blob b, int pos) throws BadFormatException
      Decode AccountStatus from Blob
      Parameters:
      b - Blob to read from
      pos - start position in Blob
      Returns:
      AccountStatus instance
      Throws:
      BadFormatException - in case of any encoding error
    • estimatedEncodingSize

      public int estimatedEncodingSize()
      Description copied from interface: IWriteable
      Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is highly likely to contain the entire object when encoded, including the tag byte. Should not traverse soft Refs, i.e. must be usable on arbitrary partial data structures
      Specified by:
      estimatedEncodingSize in interface IWriteable
      Overrides:
      estimatedEncodingSize in class ARecord
      Returns:
      The estimated size for the binary representation of this object.
    • isCanonical

      public boolean isCanonical()
      Description copied from class: ACell
      Returns true if this Cell is in a canonical representation for message writing. Non-canonical objects may be used on a temporary internal basis, they must always be converted to canonical representations for external use (e.g. Encoding).
      Overrides:
      isCanonical in class ARecord
      Returns:
      true if the object is in canonical format, false otherwise
    • isActor

      public boolean isActor()
      Returns true if this account is an Actor, i.e. is not a user account (null public key)
      Returns:
      true if actor, false otherwise
    • getController

      public ACell getController()
      Get the controller for this Account
      Returns:
      Controller Address, or null if there is no controller
    • withBalance

      public AccountStatus withBalance(long newBalance)
    • withAccountKey

      public AccountStatus withAccountKey(AccountKey newKey)
    • withMemory

      public AccountStatus withMemory(long newMemory)
    • withBalances

      public AccountStatus withBalances(long newBalance, long newAllowance)
    • withEnvironment

      public AccountStatus withEnvironment(AHashMap<Symbol,ACell> newEnvironment)
    • withMetadata

      public AccountStatus withMetadata(AHashMap<Symbol,AHashMap<ACell,ACell>> newMeta)
    • equals

      public boolean equals(ACell a)
      Description copied from class: ACell
      Checks for equality with another Cell. In general, Cells are considered equal if they have the same canonical representation, i.e. an identical encoding with the same hash value. Subclasses SHOULD override this if they have a more efficient equals implementation. MUST NOT require reads from Store.
      Overrides:
      equals in class ACell
      Parameters:
      a - Cell to compare with. May be null.
      Returns:
      True if this cell is equal to the other object
    • equals

      public boolean equals(AccountStatus a)
      Tests if this account is equal to another Account
      Parameters:
      a - AccountStatus to compare with
      Returns:
      true if equal, false otherwise
    • updateSequence

      public AccountStatus updateSequence(long newSequence)
      Updates this account with a new sequence number.
      Parameters:
      newSequence - New sequence number
      Returns:
      Updated account, or null if the sequence number was wrong
    • validateCell

      public void validateCell() throws InvalidDataException
      Description copied from class: ACell
      Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.
      Specified by:
      validateCell in class ACell
      Throws:
      InvalidDataException - If the Cell is invalid
    • getEnvironmentValue

      public <R> R getEnvironmentValue(Symbol symbol)
      Gets the value in the Account's environment for the given symbol.
      Type Parameters:
      R - Result type
      Parameters:
      symbol - Symbol to get in Environment
      Returns:
      The value from the environment, or null if not found
    • getHoldings

      public BlobMap<Address,ACell> getHoldings()
      Gets the holdings for this account. Will always be a non-null map.
      Returns:
      Holdings map for this account
    • getHolding

      public ACell getHolding(Address addr)
    • withHolding

      public AccountStatus withHolding(Address addr, ACell value)
    • withController

      public AccountStatus withController(ACell newController)
    • getRefCount

      public int getRefCount()
      Description copied from class: ACell
      Gets the number of Refs contained within this Cell. This number is final / immutable for any given instance and is defined by the Cell encoding rules. WARNING: may not be valid id Cell is not canonical Contained Refs may be either external or embedded.
      Specified by:
      getRefCount in class ACell
      Returns:
      The number of Refs in this Cell
    • getRef

      public <R extends ACell> Ref<R> getRef(int i)
      Description copied from class: ACell
      Gets a numbered child Ref from within this Cell. WARNING: May be unreliable is cell is not canonical
      Overrides:
      getRef in class ACell
      Type Parameters:
      R - Type of referenced Cell
      Parameters:
      i - Index of ref to get
      Returns:
      The Ref at the specified index
    • get

      public ACell get(Keyword key)
      Description copied from class: ARecord
      Gets the record field content for a given key, or null if not found.
      Specified by:
      get in class ARecord
      Parameters:
      key - Key to look up in this record
      Returns:
      Field value for the given key
    • getTag

      public byte getTag()
      Description copied from class: ARecord
      Gets the tag byte for this record type. The Tag is the byte used to identify the record in the binary encoding.
      Specified by:
      getTag in class ARecord
      Returns:
      Record tag byte
    • updateRefs

      public AccountStatus updateRefs(IRefFunction func)
      Description copied from class: ACell
      Updates all Refs in this object using the given function. The function *must not* change the hash value of Refs, in order to ensure structural integrity of modified data structures. The implementation *should* re-attach any original encoding in order to prevent re-encoding or surplus hashing This is a building block for a very sneaky trick that enables use to do a lot of efficient operations on large trees of smart references. Must return the same object if no Refs are altered.
      Overrides:
      updateRefs in class ACell
      Parameters:
      func - Ref update function
      Returns:
      Cell with updated Refs
    • getMemory

      public long getMemory()
      Gets the memory allowance for this account
      Returns:
      Memory allowance in bytes
    • getMemoryUsage

      public long getMemoryUsage()
      Gets the memory usage for this Account. Memory usage is defined as the size of the AccountStatus Cell
      Returns:
      Memory usage of this Account in bytes.
    • addBalance

      public AccountStatus addBalance(long delta)
      Adds a change in balance to this account. Must not cause an illegal balance. Returns this instance unchanged if the delta is zero
      Parameters:
      delta - Amount of Convex copper to add
      Returns:
      Updates account record
    • getAccountKey

      public AccountKey getAccountKey()
      Gets the public key for this Account. May bu null (e.g. for Actors)
      Returns:
      Account public key
    • getMetadata

      public AHashMap<Symbol,AHashMap<ACell,ACell>> getMetadata()
      Gets the Metadata map for this Account
      Returns:
      Metadata map (never null, but may be empty)
    • getEnvironment

      public AHashMap<Symbol,ACell> getEnvironment()
      Gets the Environment for this account. Defaults to the an empty map if no Environment has been created.
      Returns:
      Environment map for this Account
    • getCallableFunctions

      public ASet<Symbol> getCallableFunctions()
      Gets the callable functions from this Account.
      Returns:
      Set of callable Symbols
    • getCallableFunction

      public <R extends ACell> AFn<R> getCallableFunction(Symbol sym)
      Gets a callable function from the environment, or null if not callable
      Parameters:
      sym - Symbol to look up
      Returns:
      Callable function if found, null otherwise
    • getFormat

      public RecordFormat getFormat()
      Description copied from class: ARecord
      Gets the RecordFormat instance that describes this Record's layout
      Specified by:
      getFormat in class ARecord
      Returns:
      RecordFormat instance