Package convex.core.data
Class Address
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<ABlob>
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 Summary
FieldsFields inherited from class convex.core.data.ALongBlob
HEX_LENGTH, LENGTH, value
Fields inherited from class convex.core.data.ABlob
contentHash
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Method Summary
Modifier and TypeMethodDescriptionstatic Address
create
(long number) Creates an Address from a blob.static Address
Creates an Address from a blob.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 Blob's encoding to a byte array, excluding the tag byteboolean
Determines if this Blob is equal to another Blob.boolean
boolean
equalsBytes
(byte[] bytes, int byteOffset) Tests if this Blob is equal to a subset of a byte arrayint
Estimate the encoded data size for this Cell.static Address
Constructs an Address object from a hex stringvoid
getBytes
(byte[] dest, int destOffset) Copies the bytes from this blob to a given destinationbyte
getTag()
Gets the tag byte for this cell.getType()
Gets the most specific known runtime Type for this Cell.int
hashCode()
Gets the Java hashCode for this cell.boolean
Returns true if this Cell is in a canonical representation for message writing.boolean
Returns true if this object is a regular blob (i.e.long
Gets the long value of this Blob if the length is exactly 8 bytes, otherwise throws an Exceptionoffset
(long offset) Creates a new Address at an offset to this Addressstatic Address
Attempts to parse an address from an arbitrary object.static Address
Constructs an Address from an arbitrary String, attempting to parse different possible formatsboolean
print
(BlobBuilder sb, long limit) Prints this Blob in a readable Hex representation, typically in the format "0x01abcd...." Subclasses may override this if they require a different representation.static Address
readRaw
(ByteBuffer bb) slice
(long start, long end) Gets a contiguous slice of this Blob, as a new Blob.Converts this Cell to its canonical version.toCVMString
(long limit) Returns the CVM String representation of this Cell.Converts this object to a flat array-backed Blob instance.protected void
updateDigest
(MessageDigest digest) void
Validates the local structure and invariants of this cell.Methods inherited from class convex.core.data.ALongBlob
append, appendHex, byteAt, calcMemorySize, commonHexPrefixLength, compareTo, compareTo, count, createRef, equalsBytes, getByteBuffer, getChunk, getHexDigit, getRefCount, getUnchecked, hexMatchLength, isEmbedded, toLong, writeToBuffer, writeToBuffer
Methods inherited from class convex.core.data.ABlob
computeHash, empty, encodeRawData, equals, get, getBytes, getContentHash, getElementRef, hexEquals, hexEquals, hexLength, isCVMValue, slice, toByteBuffer, toHexString, toHexString, validate
Methods inherited from class convex.core.data.ACountable
isEmpty, size
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, createAnnounced, createEncoding, createPersisted, createPersisted, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, isCompletelyEncoded, mark, mark, toString, updateRefs, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Field Details
-
ZERO
The Zero Address -
MAX_ENCODING_LENGTH
public static final int MAX_ENCODING_LENGTH- See Also:
-
-
Method Details
-
create
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
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
Description copied from class:ACell
Gets the most specific known runtime Type for this Cell. -
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 -
equals
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 -
equals
-
fromHex
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
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
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
- 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 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
-
print
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. -
toCVMString
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 classACell
- 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 classALongBlob
- 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 likely to contain the entire object when represented in binary format, including the tag byte.- Returns:
- The estimated size for the binary representation of this object.
-
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.- Overrides:
validateCell
in classABlob
- 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 classABlob
- Returns:
- True if a regular blob
-
getBytes
public void getBytes(byte[] dest, int destOffset) Description copied from class:ABlob
Copies the bytes from this blob to a given destination -
slice
Description copied from class:ABlob
Gets a contiguous slice of this Blob, as a new Blob. Shares underlying backing data where possible -
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 classALongBlob
- Returns:
- A Blob instance containing the same data as this Blob.
-
updateDigest
- Specified by:
updateDigest
in classABlob
-
equalsBytes
public boolean equalsBytes(byte[] bytes, int byteOffset) Description copied from class:ABlob
Tests if this Blob is equal to a subset of a byte array- Specified by:
equalsBytes
in classABlob
- Parameters:
bytes
- Byte array to compare withbyteOffset
- Offset into byte array- Returns:
- true if exactly equal, false otherwise
-
longValue
public long longValue()Description copied from class:ABlob
Gets the long value of this Blob if the length is exactly 8 bytes, otherwise throws an Exception -
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 -
getTag
public byte getTag()Description copied from class:ACell
Gets the tag byte for this cell. The tag byte is always written as the first byte of the Cell's Encoding -
toCanonical
Description copied from class:ACell
Converts this Cell to its canonical version. Returns this Cell if already canonical, may be O(n) in size of value otherwise.- Specified by:
toCanonical
in classABlob
- Returns:
- Canonical version of Cell
-
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
-