Module convex.peer
Package convex.api

Class ConvexLocal

java.lang.Object
convex.api.Convex
convex.api.ConvexLocal
All Implemented Interfaces:
AutoCloseable

public class ConvexLocal extends Convex
Convex Client implementation supporting a direct connection to a Peer Server in the same JVM.
  • Constructor Details

  • Method Details

    • create

      public static ConvexLocal create(Server server)
    • create

      public static ConvexLocal create(Server server, Address address, AKeyPair keyPair)
    • isConnected

      public boolean isConnected()
      Description copied from class: Convex
      Checks if this Convex client instance has an open connection.
      Specified by:
      isConnected in class Convex
      Returns:
      true if connected, false otherwise
    • acquire

      public <T extends ACell> CompletableFuture<T> acquire(Hash hash, AStore store)
      Description copied from class: Convex
      Attempts to acquire a complete persistent data structure for the given hash from the connected peer. Uses the store provided as a destination.
      Specified by:
      acquire in class Convex
      Parameters:
      hash - Hash of value to acquire.
      store - Store to acquire the persistent data to.
      Returns:
      Future for the Cell being acquired. May fail exceptionally or timeout if the given data cannot be acquired (most likely missing from the peer's store)
    • requestStatus

      public CompletableFuture<Result> requestStatus()
      Description copied from class: Convex
      Submits a status request to the Convex network peer, returning a Future once the request has been successfully queued.
      Specified by:
      requestStatus in class Convex
      Returns:
      A Future for the result of the requestStatus
    • transact

      public CompletableFuture<Result> transact(SignedData<ATransaction> signed)
      Description copied from class: Convex
      Submits a signed transaction to the Convex network, returning a Future once the transaction has been successfully queued. Updates cached sequence number on best effort basis.
      Specified by:
      transact in class Convex
      Parameters:
      signed - Signed transaction to execute
      Returns:
      A Future for the result of the transaction
    • requestChallenge

      public CompletableFuture<Result> requestChallenge(SignedData<ACell> data)
      Description copied from class: Convex
      Request a challenge. This is request is made by any peer that needs to find out if another peer can be trusted.
      Specified by:
      requestChallenge in class Convex
      Parameters:
      data - Signed data to send to the peer for the challenge.
      Returns:
      A Future for the result of the requestChallenge
    • query

      public CompletableFuture<Result> query(ACell query, Address address)
      Description copied from class: Convex
      Submits a query to the Convex network, returning a Future once the query has been successfully queued.
      Specified by:
      query in class Convex
      Parameters:
      query - Query to execute, as a Form or Op
      address - Address to use for the query
      Returns:
      A Future for the result of the query
    • messageRaw

      public CompletableFuture<Result> messageRaw(Blob rawData)
      Description copied from class: Convex
      Submits raw message data to the Convex network, returning a Future for any Result
      Specified by:
      messageRaw in class Convex
      Parameters:
      rawData - Raw message data
      Returns:
      A Future for the result of the query
    • message

      public CompletableFuture<Result> message(Message message)
      Description copied from class: Convex
      Submits a Message to the connected peer, returning a Future for any Result
      Specified by:
      message in class Convex
      Parameters:
      message - Message data
      Returns:
      A Future for the Result of the query. May just be "Sent" if no other result expected, or an immediate error if sending failed.
    • close

      public void close()
      Description copied from class: Convex
      Disconnects the client from the network, releasing any connection resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in class Convex
    • acquireState

      public CompletableFuture<State> acquireState()
      Description copied from class: Convex
      Gets the consensus state from the connected Peer. The acquired state will be a snapshot of the network global state as calculated by the Peer. SECURITY: Be aware that if this client instance is connected to an untrusted Peer, the Peer may lie about the latest state. If this is a security concern, the client should validate the consensus state independently.
      Overrides:
      acquireState in class Convex
      Returns:
      Future for consensus state
    • getState

      public State getState()
    • getLocalServer

      public Server getLocalServer()
      Description copied from class: Convex
      Gets the local Server instance, or null if not a local connection
      Overrides:
      getLocalServer in class Convex
      Returns:
      Server instance (or null)
    • getSequence

      public long getSequence()
      Description copied from class: Convex
      Gets the current sequence number for this Client, which is the sequence number of the last transaction observed for the current client's Account. Will attempt to acquire the sequence number from the network if not known. The next valid sequence number will be one higher than the result.
      Overrides:
      getSequence in class Convex
      Returns:
      Sequence number as a Long value (zero or positive)
    • getSequence

      public long getSequence(Address addr)
      Description copied from class: Convex
      Gets the current sequence number for an account, which is the sequence number of the last transaction observed for the Account. Will attempt to acquire the sequence number from the network if not known.
      Overrides:
      getSequence in class Convex
      Parameters:
      addr - Address for which to query the sequence number
      Returns:
      Sequence number as a Long value (zero or positive)
    • toString

      public String toString()
      Specified by:
      toString in class Convex
    • getHostAddress

      public InetSocketAddress getHostAddress()
      Description copied from class: Convex
      Gets the remote address for this Convex client instance
      Specified by:
      getHostAddress in class Convex
      Returns:
      Socket address
    • getBalance

      public Long getBalance()
      Description copied from class: Convex
      Query the balance for the current account
      Overrides:
      getBalance in class Convex
      Returns:
      Long balance in Convex coins,
    • reconnect

      public void reconnect()
      Specified by:
      reconnect in class Convex