Package convex.core.data
Class PeerStatus
- All Implemented Interfaces:
IAssociative<Keyword,
,ACell> IValidated
,IWriteable
,Map<Keyword,
ACell>
Class describing the on-chain state of a Peer declared on the network.
State includes: - Stake placed by this Peer - A host address for peer
connections / client requests
-
Nested Class Summary
-
Field Summary
Fields 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 TypeMethodDescriptionprotected static long
computeDelegatedStake
(Index<Address, CVMLong> stakes) static PeerStatus
static PeerStatus
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
Checks for equality with another Cell.boolean
equals
(PeerStatus a) Tests if this PeerStatus is equal to anotherint
Estimate the encoded data size for this Cell.Gets the record field content for a given key, or null if not found.long
Gets the Convex Coin balance for this Peer.Gets the controller of this peerlong
Gets the delegated stake of this peerlong
getDelegatedStake
(Address delegator) Gets the delegated stake on this peer for the given delegator.Gets the RecordFormat instance that describes this Record's layoutGets the String representation of the hostname set for the current Peer status, or null if not specified.Gets the Metadata of this Peerlong
Gets the self-owned stake of this peergetRef
(int i) Gets a numbered child Ref from within this Cell.int
Gets the number of Refs contained within this Cell.byte
getTag()
Gets the tag byte for this record type.long
Gets the timestamp of the last Block issued by this Peer in consensuslong
Gets the total stake shares for this peerboolean
Returns true if this Cell is in a canonical representation.static PeerStatus
Decodes a PeerStatus from a Blob.updateRefs
(IRefFunction func) Updates all Refs in this object using the given function.void
Validates the local structure and invariants of this cell.withDelegatedStake
(Address delegator, long newStake) Sets the delegated stake on this peer for the given delegator.withPeerData
(AHashMap<ACell, ACell> newMeta) withPeerStake
(long newStake) Sets the Peer Stake on this peer for the given delegator.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
-
Method Details
-
create
-
create
-
getTotalStake
public long getTotalStake()Gets the total stake shares for this peer- Returns:
- Total stake, including own stake + delegated stake
-
getBalance
public long getBalance()Gets the Convex Coin balance for this Peer. Owned jointly by peer and delegators- Returns:
- The total Convex Coin balance of this peer
-
getDelegatedStake
public long getDelegatedStake()Gets the delegated stake of this peer- Returns:
- Total of delegated stake
-
getPeerStake
public long getPeerStake()Gets the self-owned stake of this peer- Returns:
- Own stake, excluding delegated stake
-
getTimestamp
public long getTimestamp()Gets the timestamp of the last Block issued by this Peer in consensus- Returns:
- Timestamp of last block, or -1 if no block yet issued.
-
getController
Gets the controller of this peer- Returns:
- The controller of this peer
-
getHostname
Gets the String representation of the hostname set for the current Peer status, or null if not specified.- Returns:
- Hostname String
-
getMetadata
-
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
Decodes a PeerStatus from a Blob.- 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
-
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
-
getDelegatedStake
Gets the delegated stake on this peer for the given delegator. Returns 0 if the delegator has no stake.- Parameters:
delegator
- Address of delegator- Returns:
- Value of delegated stake
-
withDelegatedStake
Sets the delegated stake on this peer for the given delegator. A value of 0 will remove the delegator's stake entirely- Parameters:
delegator
- Address of delegatornewStake
- New Delegated stake for the given Address- Returns:
- Value of delegated stake
-
withPeerStake
Sets the Peer Stake on this peer for the given delegator. A value of 0 will remove the Peer stake entirely- Parameters:
newStake
- New Peer stake- Returns:
- Updates PeerStatus
-
withPeerData
-
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
-
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
-
computeDelegatedStake
-
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 PeerStatus is equal to another- Parameters:
a
- PeerStatus to compare with- Returns:
- true if equal, false otherwise
-
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 -
getFormat
Description copied from class:ARecord
Gets the RecordFormat instance that describes this Record's layout
-