Package convex.core
Class Order
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.Order
- All Implemented Interfaces:
IValidated,IWriteable
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)
-
Field Summary
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckConsistent(Order bc)Checks if another Order is consistent with this Order.static Ordercreate()Create an empty Orderintencode(byte[] bs, int pos)Writes this Cell's encoding to a byte array, including a tag byte which will be written firstintencodeRaw(byte[] bs, int pos)Writes this Cell's encoding to a byte array, excluding the tag byteintEstimate the encoded data size for this Cell.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 OrderlongGets 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 cell.booleanReturns true if this Cell is in a canonical format for message writing.booleanReturns true if this object represents a first class CVM Value.voidprint(StringBuilder sb)Prints this Object to a readable String RepresentationPropose a new block of transactions in this Orderstatic Orderread(ByteBuffer bb)Decode an Order from a ByteBufferConverts this Cell to its canonical version.updateBlocks(AVector<Block> newBlocks)Update this chain with a new list of blocksupdateRefs(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<Block> newBlocks)Updates blocks in this Order.withConsenusPoint(long newConsensusPoint)Updates this Order with a new consensus position.Clears the consensus and proposal pointwithProposalPoint(long newProposalPoint)Updates this Order with a new proposal position.Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getType, hashCode, isEmbedded, toString, writeMethods inherited from class convex.core.data.AObject
attachEncoding, print
-
Method Details
-
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- 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:ACellWrites this Cell's encoding to a byte array, excluding the tag byte -
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.- Returns:
- The estimated size for the binary representation of this object.
-
read
Decode an Order from a ByteBuffer- Parameters:
bb- ByteBuffer to read from- Returns:
- Order instance
- Throws:
BadFormatException- If encoding format is invalid
-
isCanonical
public boolean isCanonical()Description copied from class:ACellReturns true if this Cell is in a canonical format for message writing. Reading or writing a non-canonical value should be considered illegal, but non-canonical objects may be used on a temporary internal basis.- Specified by:
isCanonicalin classACell- Returns:
- true if the object is in canonical format, false otherwise
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACellReturns true if this object represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false. CVM values might not be in a canonical format, e.g. temporary data structures- Specified by:
isCVMValuein classACell- Returns:
- true if the object is a CVM Value, false otherwise
-
print
Description copied from class:AObjectPrints this Object to a readable String Representation -
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()Gets the Consensus Point of this Order- Returns:
- Consensus Point
-
getProposalPoint
public long getProposalPoint()Gets the Proposal Point 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.
-
propose
Propose 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
-
withProposalPoint
Updates this Order with a new proposal position. It is an error to set the proposal point before the consensus point, or beyond the last block.- Parameters:
newProposalPoint- New Proposal Point in Order- Returns:
- Updated Order
-
withConsenusPoint
Updates this Order with a new consensus position. Proposal point will be set to the max of the consensus point and the current proposal point- Parameters:
newConsensusPoint- New consensus point- Returns:
- Updated chain, or this Chain 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
-
updateBlocks
Update this chain with a new list of blocks- Parameters:
newBlocks- New vector of blocks to use in this Chain- Returns:
- The updated Order
-
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 Valie 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. 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. -
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. 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
-
getTag
public byte getTag()Description copied from class:ACellGets the tag byte for this cell. The tag byte will be the first byte of the encoding -
toCanonical
Description copied from class:ACellConverts this Cell to its canonical version. Returns this if already canonical- Specified by:
toCanonicalin classACell- Returns:
- Canonical version of Cell
-