Package convex.core.data
Class AccountStatus
java.lang.Object
- All Implemented Interfaces:
IValidated
,IWriteable
,Map<Keyword,
ACell>
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
-
Nested Class Summary
-
Field Summary
Fields inherited from class convex.core.data.ARecord
DEFAULT_VALUE, format
Fields inherited from class convex.core.data.ADataStructure
count
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Method Summary
Modifier and TypeMethodDescriptionaddBalance
(long delta) Adds a change in balance to this account.static AccountStatus
create()
Create a completely empty Account record, with no balance or public keystatic AccountStatus
create
(long sequence, long balance, AccountKey key) Create a regular account, with the specified balance and zero allowancestatic AccountStatus
create
(long balance, AccountKey key) static AccountStatus
static AccountStatus
createGovernance
(long balance) Create a governance account.int
encode
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.int
encodeRaw
(byte[] bs, int pos) Writes the raw fields of this record in declared orderboolean
Tests if this account is equal to another Accountboolean
Checks for equality with another Cell.int
Estimate the encoded data size for this Cell.Gets the record field content for a given key, or null if not found.Gets the public key for this Account.long
Gets a callable function from the environment, or null if not callableGets the callable functions from this Account.Get the controller for this AccountGets the Environment for this account.<R> R
getEnvironmentValue
(Symbol symbol) Gets the value in the Account's environment for the given symbol.getHolding
(Address addr) Gets the holdings for this account.long
Gets the memory allowance for this accountlong
Gets the memory usage for this Account.getRef
(int i) Gets a numbered child Ref from within this Cell.int
Gets the number of Refs contained within this Cell.long
Gets the sequence number for this Account.byte
getTag()
Gets the tag byte for this record type.boolean
hasBalance
(long amt) Checks if this account has enough balance for a transaction consuming the specified amount.boolean
isActor()
Returns true if this account is an Actor, i.e.boolean
Returns true if this Cell is in a canonical representation for message writing.static AccountStatus
read
(ByteBuffer bb) protected AccountStatus
Updates all values in this record, in declared field order.updateSequence
(long newSequence) Updates this account with a new sequence number.void
Validates the local structure and invariants of this cell.withAccountKey
(AccountKey newKey) withBalance
(long newBalance) withBalances
(long newBalance, long newAllowance) withController
(Address newController) withEnvironment
(AHashMap<Symbol, ACell> newEnvironment) withHolding
(Address addr, ACell value) withMemory
(long newMemory) Methods inherited from class convex.core.data.ARecord
accumulateEntrySet, accumulateKeySet, accumulateValues, assoc, assocEntry, containsKey, containsValue, dissoc, dissoc, empty, entryAt, entrySet, forEach, get, getEntry, getEntryByHash, getFormat, getKeyRefEntry, getKeys, getType, getValuesArray, isCVMValue, keySet, reduceEntries, reduceValues, toCanonical, toHashMap, updateRefs, values
Methods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, entryVector, filterValues, get, get, getElementRef, print, put, putAll, remove, slice
Methods inherited from class convex.core.data.ADataStructure
conjAll, count, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACountable
slice
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, hashCode, isCompletelyEncoded, isEmbedded, mark, mark, toString, validate, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, size
-
Method Details
-
create
Create a regular account, with the specified balance and zero allowance- Parameters:
sequence
- Sequence numberbalance
- Convex Coin balance of Accountkey
- Public Key of new Account- Returns:
- New AccountStatus
-
createGovernance
Create a governance account.- Parameters:
balance
- Balance for governance account- Returns:
- New governance AccountStatus
-
createActor
-
create
-
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 interfaceIWriteable
- Specified by:
encode
in classACell
- Parameters:
bs
- A byte array to which to write the encodingpos
- 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 -
read
- 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 interfaceIWriteable
- Overrides:
estimatedEncodingSize
in classARecord
- 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 classARecord
- 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
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
-
withAccountKey
-
withMemory
-
withBalances
-
withEnvironment
-
withMetadata
-
equals
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. -
equals
Tests if this account is equal to another Account- Parameters:
a
- AccountStatus to compare with- Returns:
- true if equal, false otherwise
-
updateSequence
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
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 classACell
- Throws:
InvalidDataException
- If the Cell is invalid
-
getEnvironmentValue
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
Gets the holdings for this account. Will always be a non-null map.- Returns:
- Holdings map for this account
-
getHolding
-
withHolding
-
withController
-
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. Contained Refs may be either external or embedded.- Overrides:
getRefCount
in classARecord
- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACell
Gets a numbered child Ref from within this Cell. -
get
Description copied from class:ARecord
Gets the record field content for a given key, or null if not found. -
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. -
updateAll
Description copied from class:ARecord
Updates all values in this record, in declared field order. Returns this if all values are identical. -
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
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
Gets the public key for this Account. May bu null (e.g. for Actors)- Returns:
- Account public key
-
getMetadata
-
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
Gets the callable functions from this Account.- Returns:
- Set of callable Symbols
-
getCallableFunction
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
-