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, formatFields inherited from class convex.core.data.ADataStructure
countFields 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 AccountStatuscreate()Create a completely empty Account record, with no balance or public keystatic AccountStatuscreate(long sequence, long balance, AccountKey key)Create a regular account, with the specified balance and zero allowancestatic AccountStatuscreate(long balance, AccountKey key)static AccountStatusstatic AccountStatuscreateGovernance(long balance)Create a governance account.intencode(byte[] bs, int pos)Writes this Cell's encoding to a byte array, including a tag byte which will be written first.intencodeRaw(byte[] bs, int pos)Writes the raw fields of this record in declared orderbooleanequals(AccountStatus a)Tests if this account is equal to another AccountbooleanChecks this map for equality with another map.intEstimate 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.longgetCallableFunction(Symbol sym)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> RgetEnvironmentValue(Symbol symbol)Gets the value in the Account's environment for the given symbol.getHolding(Address addr)Gets the holdings for this account.longGets the memory allowance for this accountlongGets the memory usage for this Account.getRef(int i)Gets a numbered child Ref from within this Cell.intGets the number of Refs contained within this Cell.longGets the sequence number for this Account.bytegetTag()Gets the tag byte for this record type.booleanhasBalance(long amt)Checks if this account has enough balance for a transaction consuming the specified amount.booleanisActor()booleanReturns true if this Cell is in a canonical representation for message writing.static AccountStatusread(ByteBuffer bb)protected AccountStatusUpdates all values in this record, in declared field order.updateSequence(long newSequence)Updates this account with a new sequence number.voidValidates 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, equalsKeys, forEach, get, getEntry, getEntryByHash, getFormat, getKeyRefEntry, getKeys, getType, getValuesArray, isCVMValue, keySet, reduceEntries, reduceValues, toCanonical, toHashMap, updateRefs, valuesMethods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, entryVector, equals, filterValues, get, get, getElementRef, print, put, putAll, remove, sliceMethods inherited from class convex.core.data.ADataStructure
conjAll, count, isEmpty, size, toCVMStringMethods inherited from class convex.core.data.ACountable
sliceMethods 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, writeMethods inherited from class convex.core.data.AObject
attachEncoding, print, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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 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:ACellWrites 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:
encodein interfaceIWriteable- Specified by:
encodein 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:ARecordWrites the raw fields of this record in declared order -
read
- Throws:
BadFormatException
-
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteableEstimate 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:
estimatedEncodingSizein interfaceIWriteable- Overrides:
estimatedEncodingSizein classARecord- Returns:
- The estimated size for the binary representation of this object.
-
isCanonical
public boolean isCanonical()Description copied from class:ACellReturns 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:
isCanonicalin classARecord- Returns:
- true if the object is in canonical format, false otherwise
-
isActor
public boolean isActor() -
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:AMapChecks 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. -
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:ACellValidates 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:
validateCellin 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:ACellGets 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:
getRefCountin classARecord- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACellGets a numbered child Ref from within this Cell. -
get
Description copied from class:ARecordGets the record field content for a given key, or null if not found. -
getTag
public byte getTag()Description copied from class:ARecordGets 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:ARecordUpdates 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
-