Package convex.core
Class Order
- All Implemented Interfaces:
IAssociative<Keyword,,ACell> IValidated,IWriteable,Map<Keyword,ACell>
Class representing an Ordering of transactions, along with the consensus position.
An Ordering contains:
- The Vector of known verified Blocks announced by the Peer
- The proposed consensus point (point at which the peer believes there is sufficient alignment for consensus)
- The current consensus point (point at which the peer has observed sufficient consistent consensus proposals)
-
Nested Class Summary
-
Field Summary
Fields inherited from class convex.core.data.ARecord
DEFAULT_VALUEFields inherited from class convex.core.data.ADataStructure
countFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionappend(SignedData<Block> block) Append a new block of transactions in this OrderbooleancheckConsistent(Order bc) Checks if another Order is consistent with this Order.booleanTests if this Order is equivalent to another in terms of consensus (timestamp ignored)static Ordercreate()Create an empty Orderstatic Ordercreate(long proposalPoint, long consensusPoint, SignedData<Block>... blocks) Create an Order with the given consensus positions and Blocks.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 orderintEstimate the encoded data size for this Cell.Gets the record field content for a given key, or null if not found.getBlock(long i) Get a specific Block in this OrderlongGet the number of Blocks in this OrderGets the Blocks in this OrderlongGets the Consensus Point of this OrderlonggetConsensusPoint(int level) Gets the Consensus Point of this Order for the specified levellong[]Gets the RecordFormat instance that describes this Record's layoutlongGets the Proposal Point of this OrdergetRef(int i) Gets a numbered child Ref from within this Cell.intGets the number of Refs contained within this Cell.bytegetTag()Gets the tag byte for this record type.longGets the timestamp of this Orderfinal booleanReturns true if this Cell represents a first class CVM Value.static OrderDecode an Order from a Blob encodingupdateRefs(IRefFunction func) Updates all Refs in this object using the given function.voidvalidate()Validates the complete structure of this object.voidValidates the local structure and invariants of this cell.withBlocks(AVector<SignedData<Block>> newBlocks) Updates blocks in this Order.withConsensusPoint(int level, long newPosition) Updates this Order with a new consensus position.withConsensusPoints(long[] newPositions) Updates this Order with new consensus positios.Clears the consensus and proposal pointwithTimestamp(long newTimestamp) Updates timestamp in this Order.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, isCanonical, keySet, reduceEntries, reduceValues, toCanonical, toHashMap, valuesMethods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, containsValue, entryVector, filterValues, get, get, get, getElementRef, merge, print, put, putAll, remove, slice, sliceMethods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, isEmpty, size, toCVMStringMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, hashCode, isCompletelyEncoded, isEmbedded, mark, mark, toStringMethods 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 an Order with the given consensus positions and Blocks. Mainly for testing.- Parameters:
proposalPoint- Proposal PointconsensusPoint- Consensus Pointblocks- Blocks in Order- Returns:
- New Order instance
-
create
Create an empty Order- Returns:
- New Order instance
-
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 -
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 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:
estimatedEncodingSizein interfaceIWriteable- Overrides:
estimatedEncodingSizein classARecord- Returns:
- The estimated size for the binary representation of this object.
-
read
Decode an Order from a Blob encoding- Parameters:
b- Blob to read frompos- Start position in Blob (location of tag byte)- Returns:
- New decoded instance
- Throws:
BadFormatException- In the event of any encoding error
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACellReturns true if this Cell represents a first class CVM Value. Sub-structural cells that are not themselves first class values 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:
isCVMValuein classARecord- Returns:
- true if the object is a CVM Value, false otherwise
-
checkConsistent
Checks if another Order is consistent with this Order. Order is defined as consistent iff:- Blocks are equal up to the Consensus Point of this Order
- Parameters:
bc- Order to compare with- Returns:
- True if chains are consistent, false otherwise.
-
getConsensusPoint
public long getConsensusPoint(int level) Gets the Consensus Point of this Order for the specified level- Parameters:
level- Consensus level- Returns:
- Consensus Point
-
getConsensusPoints
public long[] getConsensusPoints() -
getProposalPoint
public long getProposalPoint()Gets the Proposal Point of this Order- Returns:
- Proposal Point
-
getConsensusPoint
public long getConsensusPoint()Gets the Consensus Point of this Order- Returns:
- Consensus Point
-
getTimestamp
public long getTimestamp()Gets the timestamp of this Order- Returns:
- Proposal Point
-
getBlocks
Gets the Blocks in this Order- Returns:
- Vector of Blocks
-
getBlock
Get a specific Block in this Order- Parameters:
i- Index of Block- Returns:
- Block at specified index.
-
append
Append a new block of transactions in this Order- Parameters:
block- Block to append- Returns:
- The updated chain
-
withBlocks
Updates blocks in this Order. Returns the same Order if the blocks are identical.- Parameters:
newBlocks- New blocks to use- Returns:
- Updated Order, or the same order if unchanged
-
withTimestamp
Updates timestamp in this Order. Returns the same Order if timestamp is identical.- Parameters:
newTimestamp- New timestamp to use- Returns:
- Updated Order, or the same Order if unchanged
-
withConsensusPoint
Updates this Order with a new consensus position.- Parameters:
level- Consensus level to updatenewPosition- New consensus point- Returns:
- Updated Order, or this Order instance if no change.
-
withConsensusPoints
Updates this Order with new consensus positios.- Parameters:
newPositions- New consensus points- Returns:
- Updated Order, or this Order instance if no change.
-
getBlockCount
public long getBlockCount()Get the number of Blocks in this Order- Returns:
- Number of Blocks
-
withoutConsenus
Clears the consensus and proposal point- Returns:
- Updated order with zeroed consensus positions
-
validate
Description copied from interface:IValidatedValidates the complete structure of this object. It is necessary to ensure all child Refs are validated, so the general contract for validate is:- Call super.validate() - which will indirectly call validateCell()
- Call validate() on any contained cells in this class
- Specified by:
validatein interfaceIValidated- Overrides:
validatein classACell- Throws:
InvalidDataException- If the data Value is invalid in any way
-
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
-
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. WARNING: may not be valid id Cell is not canonical Contained Refs may be either external or embedded.- Specified by:
getRefCountin classACell- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACellGets a numbered child Ref from within this Cell. WARNING: May be unreliable is cell is not canonical -
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. -
get
Description copied from class:ARecordGets the record field content for a given key, or null if not found. -
updateRefs
Description copied from class:ACellUpdates 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:
updateRefsin classACell- Parameters:
func- Ref update function- Returns:
- Cell with updated Refs
-
consensusEquals
Tests if this Order is equivalent to another in terms of consensus (timestamp ignored)- Parameters:
b- Order to compare with- Returns:
- True if Orders are functionally equal, false otherwise
-
getFormat
Description copied from class:ARecordGets the RecordFormat instance that describes this Record's layout
-