Package convex.core.data
Class AccountStatus
- All Implemented Interfaces:
IAssociative<Keyword,
,ACell> 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
FieldsFields inherited from class convex.core.data.ARecord
DEFAULT_VALUE
Fields inherited from class convex.core.data.ADataStructure
count
Fields inherited from class convex.core.data.ACell
cachedRef, memorySize
-
Method Summary
Modifier and TypeMethodDescriptionaddBalanceAndSequence
(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 memory allowancestatic AccountStatus
create
(long balance, AccountKey key) static AccountStatus
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 this Cell's encoding to a byte array, excluding the tag byte.boolean
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 extends ACell>
RgetEnvironmentValue
(Symbol symbol) Gets the value in the Account's environment for the given symbol.Gets the RecordFormat instance that describes this Record's layoutgetHolding
(Address addr) Gets the holdings for this account.long
Gets the memory allowance for this accountlong
Gets the memory usage for this Account.Gets the Metadata map for this AccountGets the parent address for this accountgetRef
(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
isActor()
Returns true if this account is an Actor, i.e.boolean
Returns true if this Cell is in a canonical representation.static AccountStatus
Decode AccountStatus from BlobupdateRefs
(IRefFunction func) Updates all Refs in this object using the given function.void
Validates the local structure and invariants of this cell.withAccountKey
(AccountKey newKey) withBalance
(long newBalance) withBalances
(long newBalance, long newAllowance) withController
(ACell newController) withEnvironment
(AHashMap<Symbol, ACell> newEnvironment) withHolding
(Address addr, ACell value) withMemory
(long newMemory) withParent
(Address newParent) Methods inherited from class convex.core.data.ARecord
accumulateEntrySet, accumulateKeySet, accumulateValues, assoc, assocEntry, containsKey, containsValue, dissoc, dissoc, empty, entryAt, entrySet, forEach, get, getEntry, getEntryByHash, getKeyRefEntry, getKeys, getType, getValuesArray, isCVMValue, keySet, reduceEntries, reduceValues, toCanonical, toHashMap, values
Methods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, containsValue, entryVector, filterValues, get, get, get, getElementRef, merge, print, put, putAll, remove, slice, slice
Methods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, isDataValue, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, hashCode, isEmbedded, toString, validate
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
-
Field Details
-
INCLUSION_MASK
protected static final int INCLUSION_MASK- See Also:
-
-
Method Details
-
create
Create a regular account, with the specified balance and zero memory allowance- Parameters:
sequence
- Sequence numberbalance
- Convex Coin balance of Accountkey
- Public Key of new Account- Returns:
- New 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:ACell
Writes this Cell's encoding to a byte array, excluding the tag byte. -
read
Decode AccountStatus from Blob- Parameters:
b
- Blob to read frompos
- 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 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. Non-canonical objects may be used on a temporary internal basis, they should be converted to canonical representations for general purpose use.- 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
-
withBalance
-
withAccountKey
-
withMemory
-
withBalances
-
withEnvironment
-
withMetadata
-
withParent
-
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
-
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
-
getHoldings
-
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 classACell
- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACell
Gets a numbered child Ref from within this Cell. WARNING: May need to convert to a canonical instance -
get
-
getTag
-
updateRefs
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 classACell
- 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.
-
addBalanceAndSequence
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:
- Updated account record
-
getAccountKey
Gets the public key for this Account. May bu null (e.g. for Actors)- Returns:
- Account public key
-
getParent
Gets the parent address for this account- Returns:
- Address of parent account
-
getMetadata
-
getEnvironment
-
getCallableFunctions
-
getCallableFunction
-
getFormat
Description copied from class:ARecord
Gets the RecordFormat instance that describes this Record's layout
-