Class PeerStatus

All Implemented Interfaces:
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<Keyword,​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
    • 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<Keyword,​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
      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(ByteBuffer bb) throws BadFormatException
      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 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 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 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
    • withHostname

      public PeerStatus withHostname(AString newHostname)
    • 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(ACell 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
    • updateAll

      protected PeerStatus updateAll(ACell[] newVals)
      Description copied from class: ARecord
      Updates all values in this record, in declared field order. Returns this if all values are identical.
      Specified by:
      updateAll in class ARecord
      Parameters:
      newVals - New values to replace current
      Returns:
      Updated Record
    • computeDelegatedStake

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

      public boolean equals(AMap<Keyword,​ACell> a)
      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.
      Specified by:
      equals in class AMap<Keyword,​ACell>
      Parameters:
      a - Map to compare with
      Returns:
      true if maps are equal, false otherwise.
    • 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