- All Implemented Interfaces:
IAssociative<Keyword,
,ACell> IValidated
,IWriteable
,Map<Keyword,
ACell>
Class representing the result of a Convex interaction (typically a query or transaction).
A Result is typically used to communicate the outcome of a query or a transaction from a peer to a client.
Contains:
- Message ID - used for message correlation
- Result value - Any CVM value as the result (may be an error message)
- Error Code - Error Code, or null if the Result was a success
- Log Records
- Additional info
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Result
static final Result
static final Result
static final Result
Fields inherited from class convex.core.cvm.ARecordGeneric
format, values
Fields inherited from class convex.core.data.ARecord
DEFAULT_VALUE, tag
Fields inherited from class convex.core.data.ADataStructure
count
Fields inherited from class convex.core.data.ACell
cachedRef, memorySize
-
Method Summary
Modifier and TypeMethodDescriptionstatic Result
buildFromVector
(AVector<ACell> values) Build a Result from a vector.static Result
Create a Resultstatic Result
Create a Resultstatic Result
Create a Resultstatic Result
create
(ACell id, ACell value, ACell errorCode, AVector<AVector<ACell>> log, AHashMap<Keyword, ACell> info) Create a Resultstatic Result
static Result
static Result
fromContext
(Context ctx) Constructs a Result from a Context.static Result
fromContext
(ACell id, ResultContext rc) Constructs a Result from a Contextstatic Result
Construct a result from a cell of datastatic Result
Constructs a result from a caught exceptionstatic Result
Construct a result from a JSON structure.Returns the Error Code from this Result.getID()
Returns the message ID for this result.getInfo()
Returns the info for this Result.getLog()
Returns the log for this Result.Returns the error source code from this Result (see CAD11).getTrace()
Returns the stack trace for this result.<T extends ACell>
TgetValue()
Returns the value for this result.boolean
isError()
Tests is the Result represents an Errorstatic ACell
peekResultID
(Blob messageData, int i) boolean
print
(BlobBuilder sb, long limit) Prints this Object to a readable String Representation.static Result
Reads a Result from a Blob encoding.toJSON()
Converts this result to a JSON representation.void
validate()
Validates the complete structure of this object.void
Validates the local structure and invariants of this cell.static Result
values()
Gets a vector of values for this Record, in format-determined orderwithExtraInfo
(Map<Keyword, ACell> extInfo) Updates result with a given message ID.Returns this Result with extra info fieldwithSource
(Keyword source) protected Result
withValues
(AVector<ACell> newValues) Updates the record with a new set of values.Methods inherited from class convex.core.cvm.ARecordGeneric
encode, encodeRaw, entryAt, equals, equals, estimatedEncodingSize, get, getFormat, getRef, getRefCount, updateRefs, validateStructure
Methods inherited from class convex.core.cvm.ACVMRecord
get, getKeys, isCVMValue, keySet
Methods inherited from class convex.core.data.ARecord
accumulateEntries, accumulateKeySet, accumulateValues, assoc, assocEntry, containsKey, containsValue, dissoc, dissoc, empty, entrySet, forEach, get, getEntry, getEntryByHash, getKeyRefEntry, getTag, getType, getValuesArray, isCanonical, reduceEntries, reduceValues, toCanonical, toHashMap
Methods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, containsValue, entryVector, filterValues, get, get, getElementRef, merge, put, putAll, remove, slice, slice
Methods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, equals, getBranchCount, getBranchRef, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, hashCode, isEmbedded, toString
Methods inherited from class convex.core.data.AObject
attachEncoding, print, 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
-
Field Details
-
CLOSED_CONNECTION
-
SENT_MESSAGE
-
FULL_CLIENT_BUFFER
-
BAD_FORMAT
-
-
Method Details
-
buildFromVector
Build a Result from a vector. WARNING: does not validate values- Parameters:
values
-- Returns:
- Result instance
-
create
Create a Result- Parameters:
id
- ID of Result messagevalue
- Result ValueerrorCode
- Error Code (may be null for success)info
- Additional info- Returns:
- Result instance
-
create
public static Result create(ACell id, ACell value, ACell errorCode, AVector<AVector<ACell>> log, AHashMap<Keyword, ACell> info) Create a Result- Parameters:
id
- ID of Result messagevalue
- Result ValueerrorCode
- Error Code (may be null for success)log
- Log entries created during transactioninfo
- Additional info- Returns:
- Result instance
-
create
Create a Result- Parameters:
id
- ID of Result messagevalue
- Result ValueerrorCode
- Error Code (may be null for success)- Returns:
- Result instance
-
create
Create a Result- Parameters:
id
- ID of Result messagevalue
- Result Value- Returns:
- Result instance
-
error
-
value
-
error
-
getID
Returns the message ID for this result. Message ID is an arbitrary ID assigned by a client requesting a transaction.- Returns:
- ID from this result
-
getValue
Returns the value for this result. The value is the result of transaction execution (may be an error message if the transaction failed)- Type Parameters:
T
- Type of Value- Returns:
- ID from this result
-
getTrace
Returns the stack trace for this result. May be null- Returns:
- Trace vector from this result
-
getInfo
Returns the info for this Result. May be null- Returns:
- Info map from this result
-
withInfo
Returns this Result with extra info field- Parameters:
k
- Information field keyv
- Information field value- Returns:
- Updated result
-
withSource
-
getLog
Returns the log for this Result. May be an empty vector.- Returns:
- Log Vector from this Result
-
getErrorCode
Returns the Error Code from this Result. Normally this should be a Keyword. Will be null if no error occurred.- Returns:
- Error code from this result
-
getSource
Returns the error source code from this Result (see CAD11). This a Keyword. Will be null if :source info not available- Returns:
- Source code keyword from this result,. or null if not present / invalid
-
values
Description copied from class:ARecord
Gets a vector of values for this Record, in format-determined order -
withValues
Description copied from class:ARecordGeneric
Updates the record with a new set of values. Returns this if and only if values vector is identical.- Specified by:
withValues
in classARecordGeneric
- Parameters:
newValues
- New values to use- Returns:
- Updated Record (or null if values not valid)
-
validateCell
Description copied from class:ACell
Validates the local structure and invariants of this cell. 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 classARecordGeneric
- Throws:
InvalidDataException
- If the Cell is invalid
-
validate
Description copied from interface:IValidated
Validates the complete structure of this object. It is necessary to ensure all child Refs are validated, so the general contract for validate is:- Call super.validate() - which will indirectly call validateCell()
- Call validate() on any contained cells in this class
- Specified by:
validate
in interfaceIValidated
- Overrides:
validate
in classACell
- Throws:
InvalidDataException
- If the data Value is invalid in any way
-
read
Reads a Result from a Blob encoding. Assumes tag byte already checked.- Parameters:
b
- Blob to read frompos
- Start position in Blob (location of tag byte)- Returns:
- New decoded instance
- Throws:
BadFormatException
- In the event of any encoding error
-
isError
public boolean isError()Tests is the Result represents an Error- Returns:
- True if error, false otherwise
-
fromContext
Constructs a Result from a Context- Parameters:
id
- Id for Resultrc
- ResultContext instance from which to extract Result- Returns:
- New Result instance
-
withExtraInfo
-
fromContext
Constructs a Result from a Context. No ResultContext implies we are not in a top level transaction, so minimise work- Parameters:
ctx
- Context- Returns:
- New Result instance
-
withID
Updates result with a given message ID. Used to tag Results for return to Clients- Parameters:
id
- New Result message ID- Returns:
- Updated Result
-
fromException
Constructs a result from a caught exception- Parameters:
e
- Exception caught- Returns:
- Result instance representing the exception (will be an error)
-
toJSON
Converts this result to a JSON representation. WARNING: some information may be lost because JSON is a terrible format.- Returns:
- JSON Object containing values from this Result
-
print
Description copied from class:AObject
Prints this Object to a readable String Representation. SECURITY: Must halt and return false in O(1) time when limit of printing is exceeded otherwise DoS attacks may be possible. -
fromData
Construct a result from a cell of data- Parameters:
data
- Result or Map including Result fields- Returns:
- Result value
- Throws:
IllegalArgumentException
- if data is of incorrect type
-
fromJSON
Construct a result from a JSON structure. WARNING: some data may be lost- Parameters:
json
- Result as represented in JSON- Returns:
- Result containing key fields
- Throws:
IllegalArgumentException
- if data is of incorrect type
-
peekResultID
- Throws:
BadFormatException
-