Class Invoke

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

public class Invoke extends ATransaction
Transaction class representing the Invoke of an on-chain operation. The command provided may be specified as either:
  • A Form (will be compiled and executed)
  • A pre-compiled Op (will be executed directly, cheaper)
Peers may separately implement functionality to parse and compile a command provided as a String: this must be performed outside the CVM which not provide a parser internally.
  • Field Details

    • command

      protected final ACell command
  • Constructor Details

    • Invoke

      protected Invoke(Address address, long sequence, ACell args)
  • Method Details

    • create

      public static Invoke create(Address address, long sequence, ACell command)
    • create

      public static Invoke create(Address address, long sequence, String command)
      Creates an Invoke transaction
      Parameters:
      address - Address of origin Account
      sequence - Sequence number
      command - Command as a string, which will be read as Convex Lisp code
      Returns:
      New Invoke transaction instance
    • encode

      public int encode(byte[] bs, int pos)
      Description copied from class: ATransaction
      Writes this transaction to a byte array, including the message tag
      Specified by:
      encode in interface IWriteable
      Specified by:
      encode in class ATransaction
      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 ATransaction
      Parameters:
      bs - Array to write to
      pos - The offset into the byte array
      Returns:
      New position after writing
    • getCommand

      public Object getCommand()
      Get the command for this transaction, as code.
      Returns:
      Command object.
    • read

      public static Invoke read(Blob b, int pos) throws BadFormatException
      Read a Transfer transaction from a Blob encoding
      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
    • apply

      public Context apply(Context context)
      Description copied from class: ATransaction
      Applies the functional effect of this transaction to the current state. Important points:
      • Assumes all relevant accounting preparation already complete, including juice reservation
      • Performs complete state update (including any rollbacks from errors)
      • Produces result, which may be exceptional
      • Does not finalise memory/juice accounting (will be completed afterwards)
      Specified by:
      apply in class ATransaction
      Parameters:
      context - Context for which to apply this Transaction
      Returns:
      The updated chain state
    • 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
      Specified by:
      estimatedEncodingSize in class ATransaction
      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.
      Specified by:
      validateCell in class ACell
      Throws:
      InvalidDataException - If the Cell is invalid
    • 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
    • updateRefs

      public Invoke 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
    • withSequence

      public Invoke withSequence(long newSequence)
      Description copied from class: ATransaction
      Updates this transaction with the specified sequence number
      Specified by:
      withSequence in class ATransaction
      Parameters:
      newSequence - New sequence number
      Returns:
      Updated transaction, or this transaction if the sequence number is unchanged.
    • withOrigin

      public Invoke withOrigin(Address newAddress)
      Description copied from class: ATransaction
      Updates this transaction with the specified origin address
      Specified by:
      withOrigin in class ATransaction
      Parameters:
      newAddress - New address
      Returns:
      Updated transaction, or this transaction if unchanged.
    • 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
    • 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
    • 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