Package convex.core
Class Block
- All Implemented Interfaces:
IValidated,IWriteable,Map<Keyword,ACell>
A Block contains an ordered collection of signed transactions that may be applied
collectively as part of a state update.
Blocks represent the units of novelty in the consensus system: a future state is
100% deterministic given the previous state and the Block to be applied.
"Man, the living creature, the creating individual, is always more important
than any established style or system." - Bruce Lee
-
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 TypeMethodDescriptionstatic Blockcreate(long timestamp, AVector<SignedData<ATransaction>> transactions) Creates a block with the given transactions.static Blockcreate(long timestamp, List<SignedData<ATransaction>> transactions) Creates a block with the given timestamp and transactionsintencode(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 orderbooleanTests if this Block is equal to anotherbooleanChecks for equality with another Cell.intEstimate the encoded data size for this Cell.Gets the record field content for a given key, or null if not found.bytegetTag()Gets the tag byte for this record type.longGets the timestamp of this blockGet the vector of transactions in this BlockbooleanReturns true if this Cell is in a canonical representation for message writing.intlength()Gets the length of this block in number of transactionsstatic Blockof(long timestamp, SignedData<ATransaction>... transactions) Creates a block with the given transactions.static Blockread(ByteBuffer bb) Reads a Block from the given bytebuffer, assuming tag is already readprotected BlockUpdates all values in this record, in declared field order.voidValidates the local structure and invariants of this cell.Methods inherited from class convex.core.data.ARecord
accumulateEntrySet, accumulateKeySet, accumulateValues, assoc, assocEntry, containsKey, containsValue, dissoc, dissoc, empty, entryAt, entrySet, forEach, get, getEntry, getEntryByHash, getFormat, getKeyRefEntry, getKeys, getRef, getRefCount, getType, getValuesArray, isCVMValue, keySet, reduceEntries, reduceValues, toCanonical, toHashMap, updateRefs, valuesMethods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, entryVector, 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
-
get
Description copied from class:ARecordGets the record field content for a given key, or null if not found. -
updateAll
Description copied from class:ARecordUpdates all values in this record, in declared field order. Returns this if all values are identical. -
getTimeStamp
public long getTimeStamp()Gets the timestamp of this block- Returns:
- Timestamp, as a long value
-
create
Creates a block with the given timestamp and transactions- Parameters:
timestamp- Timestamp for the newly created Block.transactions- A java.util.List instance containing the required transactions- Returns:
- A new Block containing the specified signed transactions
-
create
Creates a block with the given transactions.- Parameters:
timestamp- Timestamp of block creation, according to Peertransactions- Vector of transactions to include in Block- Returns:
- A new Block containing the specified signed transactions
-
of
Creates a block with the given transactions.- Parameters:
timestamp- Timestamp of block creation, according to Peertransactions- Array of transactions to include in Block- Returns:
- New Block
-
length
public int length()Gets the length of this block in number of transactions- Returns:
- Number of transactions on this block
-
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 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.
-
read
Reads a Block from the given bytebuffer, assuming tag is already read- Parameters:
bb- ByteBuffer containing Block representation- Returns:
- A Block
- Throws:
BadFormatException- if a Block could noy be read.
-
getTransactions
Get the vector of transactions in this Block- Returns:
- Vector of transactions
-
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
-
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. -
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
-
equals
Description copied from class:ACellChecks 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 Block is equal to another- Parameters:
a- PeerStatus to compare with- Returns:
- true if equal, false otherwise
-