Package convex.core.data
Class PeerStatus
java.lang.Object
- All Implemented Interfaces:
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, format
Fields inherited from class convex.core.data.ADataStructure
count
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Method Summary
Modifier and TypeMethodDescriptionprotected static long
computeDelegatedStake(ABlobMap<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 firstint
encodeRaw(byte[] bs, int pos)
Writes the raw fields of this record in declared orderboolean
Checks this map for equality with another map.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.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 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 peerbyte
getTag()
Gets the tag byte for this record type.long
Gets the stake of this peerboolean
Returns true if this Cell is in a canonical format for message writing.static PeerStatus
read(ByteBuffer bb)
protected PeerStatus
Updates all values in this record, in declared field order.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.withHostname(AString newHostname)
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, equalsKeys, forEach, get, getEntry, getEntryByHash, getFormat, getKeyRefEntry, getKeys, getRef, getRefCount, getType, getValuesArray, isCVMValue, keySet, print, reduceEntries, reduceValues, toCanonical, toHashMap, updateRefs, values
Methods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, entryVector, equals, filterValues, get, get, getElementRef, put, putAll, remove
Methods inherited from class convex.core.data.ADataStructure
conjAll, count, isEmpty, size
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, hashCode, isEmbedded, toString, validate, write
Methods inherited from class convex.core.data.AObject
attachEncoding, 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 stake of this peer- Returns:
- Total stake, including own stake + delegated stake
-
getPeerStake
public long getPeerStake()Gets the self-owned stake of this peer- Returns:
- Own stake, excluding delegated stake
-
getController
Gets the controller of this peer- Returns:
- The controller of this peer
-
getDelegatedStake
public long getDelegatedStake()Gets the delegated stake of this peer- Returns:
- Total of delegated stake
-
getHostname
Gets the String representation of the hostname set for the current Peer status, or null if not specified.- Returns:
- Hostname String
-
getMetadata
Gets the Metadata of this Peer- Returns:
- Host String
-
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- 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:ARecord
Writes the raw fields of this record in declared order -
read
- Throws:
BadFormatException
-
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 likely to contain the entire object when represented in binary format, including the tag byte.- 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 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.- 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 Delegated stake for the given Address- Returns:
- Value of delegated stake
-
withHostname
-
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
Description copied from class:ARecord
Gets the record field content for a given key, or null if not found. -
getTag
public byte getTag()Description copied from class:ARecord
Gets the tag byte for this record type. The Tag is the byte used to identify the record in the binary encoding. -
updateAll
Description copied from class:ARecord
Updates all values in this record, in declared field order. Returns this if all values are identical. -
computeDelegatedStake
-
equals
Description copied from class:AMap
Checks this map for equality with another map. In general, maps should be considered equal if they have the same canonical representation, i.e. the same hash value. Subclasses may override this this they have a more efficient equals implementation or a more specific definition of equality. -
equals
Tests if this PeerStatus is equal to another- Parameters:
a
- PeerStatus to compare with- Returns:
- true if equal, false otherwise
-