Class PeerStatus

All Implemented Interfaces:
IAssociative<Keyword,ACell>, IValidated, IWriteable, Map<Keyword,ACell>

public class PeerStatus extends ARecord
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
  • Method Details

    • create

      public static PeerStatus create(Address controller, long stake)
    • create

      public static PeerStatus create(Address controller, long stake, AHashMap<ACell,ACell> metadata)
    • 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
    • getTimestamp

      public long getTimestamp()
      Gets the timestamp of the last Block issued by this Peer in consensus
      Returns:
      Timestamp of last block
    • getController

      public Address 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

      public AString getHostname()
      Gets the String representation of the hostname set for the current Peer status, or null if not specified.
      Returns:
      Hostname String
    • getMetadata

      public AHashMap<ACell,ACell> 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. Cell must be canonical, or else an error may occur.
      Specified by:
      encode in interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - 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
      Overrides:
      encodeRaw in class ARecord
      Parameters:
      bs - Array to write to
      pos - The offset into the byte array
      Returns:
      New position after writing
    • read

      public static PeerStatus read(Blob b, int pos) throws BadFormatException
      Decodes a PeerStatus from a Blob.
      Parameters:
      b - Blob to read from
      pos - 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 interface IWriteable
      Overrides:
      estimatedEncodingSize in class ARecord
      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 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:
      isCanonical in class ARecord
      Returns:
      true if the object is in canonical format, false otherwise
    • getDelegatedStake

      public long getDelegatedStake(Address delegator)
      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

      public PeerStatus withDelegatedStake(Address delegator, long newStake)
      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 delegator
      newStake - New Delegated stake for the given Address
      Returns:
      Value of delegated stake
    • withPeerStake

      public PeerStatus withPeerStake(long newStake)
      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
    • withPeerData

      public PeerStatus withPeerData(AHashMap<ACell,ACell> newMeta)
    • validateCell

      public void validateCell() throws InvalidDataException
      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 class ACell
      Throws:
      InvalidDataException - If the Cell is invalid
    • get

      public ACell get(Keyword key)
      Description copied from class: ARecord
      Gets the record field content for a given key, or null if not found.
      Specified by:
      get in class ARecord
      Parameters:
      key - Key to look up in this record
      Returns:
      Field value for the given key
    • 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.
      Specified by:
      getTag in class ARecord
      Returns:
      Record tag byte
    • updateRefs

      public PeerStatus updateRefs(IRefFunction func)
      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 class ACell
      Parameters:
      func - Ref update function
      Returns:
      Cell with updated Refs
    • computeDelegatedStake

      protected static long computeDelegatedStake(BlobMap<Address,CVMLong> stakes)
    • equals

      public boolean equals(ACell a)
      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.
      Overrides:
      equals in class ACell
      Parameters:
      a - Cell to compare with. May be null.
      Returns:
      True if this cell is equal to the other object
    • equals

      public boolean equals(PeerStatus a)
      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. WARNING: may not be valid id Cell is not canonical Contained Refs may be either external or embedded.
      Specified by:
      getRefCount in class ACell
      Returns:
      The number of Refs in this Cell
    • getRef

      public <R extends ACell> Ref<R> getRef(int i)
      Description copied from class: ACell
      Gets a numbered child Ref from within this Cell. WARNING: May be unreliable is cell is not canonical
      Overrides:
      getRef in class ACell
      Type Parameters:
      R - Type of referenced Cell
      Parameters:
      i - Index of ref to get
      Returns:
      The Ref at the specified index
    • getFormat

      public RecordFormat getFormat()
      Description copied from class: ARecord
      Gets the RecordFormat instance that describes this Record's layout
      Specified by:
      getFormat in class ARecord
      Returns:
      RecordFormat instance