Class Address

All Implemented Interfaces:
IValidated, IWriteable, Comparable<ABlob>

public final class Address extends ALongBlob
Immutable class representing an Address, generally used to uniquely identify an Account. An Address is a specialised 8-byte long blob instance that wraps a non-negative long Account number. This number serves as an index into the vector of accounts for the current state.
  • Field Details

    • ZERO

      public static final Address ZERO
      The Zero Address
    • MAX_ENCODING_LENGTH

      public static final int MAX_ENCODING_LENGTH
      See Also:
  • Method Details

    • create

      public static Address create(long number)
      Creates an Address from a blob. Number be a valid non-negative long value.
      Parameters:
      number - Account number
      Returns:
      Address instance, or null if not valid
    • create

      public static Address create(ABlob b)
      Creates an Address from a blob. Must be a valid long value
      Parameters:
      b - Blob to convert to an Address
      Returns:
      Address instance, or null if not valid
    • getType

      public AType getType()
      Description copied from class: ACell
      Gets the most specific known runtime Type for this Cell.
      Overrides:
      getType in class ABlob
      Returns:
      The Type of this Call
    • hashCode

      public int hashCode()
      Description copied from class: ACell
      Gets the Java hashCode for this cell. Must be consistent with equals. Default is the first bytes (big-endian) of the Cell Encoding's hash, since this is consistent with encoding-based equality. However, different Types may provide more efficient hashcodes provided that the usual invariants are preserved
      Overrides:
      hashCode in class ABlob
      Returns:
      integer hash code.
    • equals

      public boolean equals(ACell o)
      Description copied from class: ABlob
      Determines if this Blob is equal to another Object. Blobs are defined to be equal if they have the same on-chain representation, i.e. if and only if all of the following are true: - Blob is of the same general type - Blobs are of the same length - All byte values are equal
      Overrides:
      equals in class ABlob
      Parameters:
      o - Cell to compare with. May be null.
      Returns:
      True if this cell is equal to the other object
    • equals

      public boolean equals(ABlob o)
      Description copied from class: ABlob
      Determines if this Blob is equal to another Blob. Blobs are defined to be equal if they have the same on-chain representation, i.e. if and only if all of the following are true: - Blob is of the same general type - Blobs are of the same length - All byte values are equal
      Specified by:
      equals in class ALongBlob
      Parameters:
      o - Blob to compare with
      Returns:
      true if Blobs are equal, false otherwise
    • equals

      public final boolean equals(Address o)
    • fromHex

      public static Address fromHex(String hexString)
      Constructs an Address object from a hex string
      Parameters:
      hexString - String to read Address from
      Returns:
      An Address constructed from the hex string, or null if not a valid hex string
    • parse

      public static Address parse(String s)
      Constructs an Address from an arbitrary String, attempting to parse different possible formats
      Parameters:
      s - String to parse
      Returns:
      Address parsed, or null if not valid
    • parse

      public static Address parse(Object o)
      Attempts to parse an address from an arbitrary object. Accepts strings and numbers on a best efforts basis.
      Parameters:
      o - Object to parse as an Address
      Returns:
      Address parsed, or null if not valid
    • readRaw

      public static Address readRaw(ByteBuffer bb) throws BadFormatException
      Throws:
      BadFormatException
    • readRaw

      public static Address readRaw(Blob b, int pos) throws BadFormatException
      Throws:
      BadFormatException
    • 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
    • print

      public boolean print(BlobBuilder sb, long limit)
      Description copied from class: ABlob
      Prints this Blob in a readable Hex representation, typically in the format "0x01abcd...." Subclasses may override this if they require a different representation.
      Overrides:
      print in class ABlob
      Parameters:
      sb - BlobBuilder to append to. May be partially written if print limit exceeded
      limit - Limit of printing in string bytes
      Returns:
      True if fully printed within limit, false otherwise
    • toCVMString

      public AString toCVMString(long limit)
      Description copied from class: ACell
      Returns the CVM String representation of this Cell. Normally, this is as printed, but may be different for some types. MUST return null in O(1) time if the length of the CVM String would exceed limit. The String representation is intended to be a easy-to-read textual representation of the Cell's data content.
      Overrides:
      toCVMString in class ACell
      Parameters:
      limit - Limit of CVM String length in UTF-8 bytes
      Returns:
      CVM String, or null if limit exceeded
    • 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 ALongBlob
      Returns:
      true if the object is in canonical format, false otherwise
    • 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
      Returns:
      The estimated size for the binary representation of this object.
    • 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.
      Overrides:
      validateCell in class ABlob
      Throws:
      InvalidDataException - If the Cell is invalid
    • isRegularBlob

      public boolean isRegularBlob()
      Description copied from class: ABlob
      Returns true if this object is a regular blob (i.e. not a special blob type like Address)
      Overrides:
      isRegularBlob in class ABlob
      Returns:
      True if a regular blob
    • slice

      public Blob slice(long start, long end)
      Description copied from class: ABlob
      Gets a contiguous slice of this Blob, as a new Blob. Shares underlying backing data where possible
      Specified by:
      slice in class ALongBlob
      Parameters:
      start - Start position for the created slice (inclusive)
      end - End of the slice (exclusive)
      Returns:
      A blob of the specified length, representing a slice of this blob.
    • toFlatBlob

      public Blob toFlatBlob()
      Description copied from class: ABlob
      Converts this object to a flat array-backed Blob instance. Warning: might be O(n) in size of Blob, may not be canonical etc.
      Specified by:
      toFlatBlob in class ALongBlob
      Returns:
      A Blob instance containing the same data as this Blob.
    • updateDigest

      protected void updateDigest(MessageDigest digest)
      Specified by:
      updateDigest in class ABlob
    • equalsBytes

      public boolean equalsBytes(byte[] bytes, int byteOffset)
      Description copied from class: ABlob
      Tests if the byte contents of this instance are equal to a subset of a byte array
      Specified by:
      equalsBytes in class ABlob
      Parameters:
      bytes - Byte array to compare with
      byteOffset - Offset into byte array from which to start comparison
      Returns:
      true if exactly equal, false otherwise
    • toExactLong

      public long toExactLong()
      Description copied from class: ABlob
      Gets the long value of this Blob if the length is exactly 8 bytes, otherwise throws an Exception
      Overrides:
      toExactLong in class ALongBlob
      Returns:
      The long value represented by the Blob
    • encodeRaw

      public int encodeRaw(byte[] bs, int pos)
      Description copied from class: ABlob
      Writes this Blob's encoding to a byte array, excluding the tag byte
      Specified by:
      encodeRaw in class ABlob
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • getTag

      public byte getTag()
      Description copied from class: ACell
      Gets the tag byte for this cell. The tag byte is always equal to the first byte of the Cell's canonical Encoding, and is sufficient to distinguish how to read the rest of the encoding.
      Specified by:
      getTag in class ALongBlob
      Returns:
      Tag byte for this Cell
    • toCanonical

      public Address toCanonical()
      Description copied from class: ACell
      Converts this Cell to its canonical version. Must return this Cell if already canonical, may be O(n) in size of value otherwise.
      Specified by:
      toCanonical in class ABlob
      Returns:
      Canonical version of Cell
    • offset

      public Address offset(long offset)
      Creates a new Address at an offset to this Address
      Parameters:
      offset - Offset to add to this Address (may be negative)
      Returns:
      New Address