Class AccountStatus

All Implemented Interfaces:
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 nonce 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
      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(ByteBuffer bb) throws BadFormatException
      Throws:
      BadFormatException
    • 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 likely to contain the entire object when represented in binary format, including the tag byte.
      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 format for message writing. Reading or writing a non-canonical value should be considered illegal, but non-canonical objects may be used on a temporary internal basis.
      Overrides:
      isCanonical in class ARecord
      Returns:
      true if the object is in canonical format, false otherwise
    • isActor

      public boolean isActor()
    • getController

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

      public boolean hasBalance(long amt)
      Checks if this account has enough balance for a transaction consuming the specified amount.
      Parameters:
      amt - minimum amount that must be present in the specified balance
      Returns:
      true if Account has at least the balance specified, false otherwise
    • 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(AMap<Keyword,​ACell> a)
      Description copied from class: AMap
      Checks this map for equality with another map. In general, maps should be considered equal if they have the same canonical representation, i.e. the same hash value. Subclasses may override this this they have a more efficient equals implementation or a more specific definition of equality.
      Specified by:
      equals in class AMap<Keyword,​ACell>
      Parameters:
      a - Map to compare with
      Returns:
      true if maps are equal, false otherwise.
    • 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 ABlobMap<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(Address 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. Contained Refs may be either external or embedded.
      Overrides:
      getRefCount in class ARecord
      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.
      Overrides:
      getRef in class ARecord
      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(ACell 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
    • updateAll

      protected AccountStatus updateAll(ACell[] newVals)
      Description copied from class: ARecord
      Updates all values in this record, in declared field order. Returns this if all values are identical.
      Specified by:
      updateAll in class ARecord
      Parameters:
      newVals - New values to replace current
      Returns:
      Updated Record
    • 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()
    • 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