Package convex.core.transactions
Class ATransaction
java.lang.Object
- All Implemented Interfaces:
IAssociative<Keyword,
,ACell> IValidated
,IWriteable
,Map<Keyword,
ACell>
Abstract base class for immutable transactions
Transactions may modify the on-chain State according to the rules of the
specific transaction type. When applied to a State, a transaction must
produce either: a) A valid updated State b) A TransactionException
Any other class of exception should be regarded as a serious failure,
indicating a code error or system integrity issue.
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Address
protected final long
static final long
Sequence number for transactions where required sequence is currently unknownFields 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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Context
Applies the functional effect of this transaction to the current state.abstract int
encode
(byte[] bs, int pos) Writes this transaction to a byte array, including the message tagint
encodeRaw
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, excluding the tag byte.boolean
Checks for equality with another Cell.abstract int
Estimate the encoded data size for this Cell.Gets the *origin* Address for this transactionfinal long
Gets the sequence number for this transaction.getType()
Gets the most specific known runtime Type for this Cell.boolean
Returns true if this Cell is in a canonical representation.final boolean
Returns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false.abstract ATransaction
withOrigin
(Address newAddress) Updates this transaction with the specified origin addressabstract ATransaction
withSequence
(long newSequence) Updates this transaction with the specified sequence numberMethods inherited from class convex.core.data.ARecord
accumulateEntrySet, accumulateKeySet, accumulateValues, assoc, assocEntry, containsKey, containsValue, dissoc, dissoc, empty, entryAt, entrySet, forEach, get, get, getEntry, getEntryByHash, getFormat, getKeyRefEntry, getKeys, getTag, getValuesArray, 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, getRef, getRefCount, hashCode, isEmbedded, toString, updateRefs, validate, validateCell
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
-
UNKNOWN_SEQUENCE
public static final long UNKNOWN_SEQUENCESequence number for transactions where required sequence is currently unknown- See Also:
-
origin
-
sequence
protected final long sequence
-
-
Constructor Details
-
ATransaction
-
-
Method Details
-
encode
public abstract int encode(byte[] bs, int pos) Writes this transaction to a byte array, including the message tag- 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. -
estimatedEncodingSize
public abstract 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.
-
apply
Applies the functional effect of this transaction to the current state. Important points:- Assumes all relevant accounting preparation already complete, including juice reservation
- Performs complete state update (including any rollbacks from errors)
- Produces result, which may be exceptional
- Does not finalise memory/juice accounting (will be completed afterwards)
- Parameters:
ctx
- Context for which to apply this Transaction- Returns:
- The updated Context
-
getOrigin
Gets the *origin* Address for this transaction- Returns:
- Address for this Transaction
-
getSequence
public final long getSequence()Gets the sequence number for this transaction. The first transaction for any account should have sequence number 1. The sequence number must be incremented by 1 for each subsequent transaction. A sequence number of 0 stands for "unknown".- Returns:
- Sequence number
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACell
Returns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false. Pretty much everything else should return true. Note: CVM values might not be in a canonical format, e.g. temporary data structures- Overrides:
isCVMValue
in classARecord
- Returns:
- true if the object is a CVM Value, false otherwise
-
getType
-
withSequence
Updates this transaction with the specified sequence number- Parameters:
newSequence
- New sequence number- Returns:
- Updated transaction, or this transaction if the sequence number is unchanged.
-
withOrigin
Updates this transaction with the specified origin address- Parameters:
newAddress
- New address- Returns:
- Updated transaction, or this transaction if unchanged.
-
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
-
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.
-