Package com.exonum.binding.service
Class NodeProxy
- java.lang.Object
-
- com.exonum.binding.proxy.AbstractNativeProxy
-
- com.exonum.binding.proxy.AbstractCloseableNativeProxy
-
- com.exonum.binding.service.NodeProxy
-
- All Implemented Interfaces:
CloseableNativeProxy
,Node
,java.lang.AutoCloseable
public final class NodeProxy extends AbstractCloseableNativeProxy implements Node
An Exonum node context. Allows to add transactions to Exonum network and get a snapshot of the database state.
-
-
Field Summary
-
Fields inherited from class com.exonum.binding.proxy.AbstractNativeProxy
nativeHandle
-
-
Constructor Summary
Constructors Constructor Description NodeProxy(long nativeHandle)
Creates a proxy of a node.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
disposeInternal()
Releases any resources owned by this proxy (e.g., the corresponding native object).com.exonum.binding.common.crypto.PublicKey
getPublicKey()
Returns the service public key of this node.com.exonum.binding.common.hash.HashCode
submitTransaction(RawTransaction rawTransaction)
Creates a transaction from the given parameters, signs it with the node service key, and then submits it into Exonum network.<ResultT> ResultT
withSnapshot(java.util.function.Function<Snapshot,ResultT> snapshotFunction)
Performs a given function with a snapshot of the current database state.-
Methods inherited from class com.exonum.binding.proxy.AbstractCloseableNativeProxy
close, getNativeHandle
-
Methods inherited from class com.exonum.binding.proxy.AbstractNativeProxy
isValidHandle
-
-
-
-
Method Detail
-
submitTransaction
public com.exonum.binding.common.hash.HashCode submitTransaction(RawTransaction rawTransaction) throws InternalServerError
Creates a transaction from the given parameters, signs it with the node service key, and then submits it into Exonum network. This node does not execute the transaction immediately, but broadcasts it to all the nodes in the network. Then each node verifies the transaction and, if it is correct, adds it to the pool of unconfirmed transactions. The transaction is executed later asynchronously.Incorrect transactions (e.g., the payload of which cannot be deserialized by the target service, or which have unknown message id) are rejected by the network.
Be aware that each node has its own service key pair, therefore invocations of this method on different nodes will produce different transactions.- Specified by:
submitTransaction
in interfaceNode
- Parameters:
rawTransaction
- transaction parameters to include in transaction message- Returns:
- hash of the transaction message created by the framework
- Throws:
java.lang.IllegalStateException
- if the node proxy is closedInternalServerError
- if this node failed to process the transaction- See Also:
Blockchain.getTxMessages()
-
withSnapshot
public <ResultT> ResultT withSnapshot(java.util.function.Function<Snapshot,ResultT> snapshotFunction)
Performs a given function with a snapshot of the current database state.- Specified by:
withSnapshot
in interfaceNode
- Type Parameters:
ResultT
- a type the function returns- Parameters:
snapshotFunction
- a function to execute- Returns:
- the result of applying the given function to the database state
- Throws:
java.lang.IllegalStateException
- if the node proxy is closed
-
getPublicKey
public com.exonum.binding.common.crypto.PublicKey getPublicKey()
Returns the service public key of this node. The corresponding private key is used for signing transactions inNode.submitTransaction(RawTransaction)
.This key is stored under "service_public_key" key in the node configuration file.
- Specified by:
getPublicKey
in interfaceNode
- Throws:
java.lang.IllegalStateException
- if the node proxy is closed
-
disposeInternal
protected void disposeInternal()
Description copied from class:AbstractCloseableNativeProxy
Releases any resources owned by this proxy (e.g., the corresponding native object).This method is only called once from
AbstractCloseableNativeProxy.close()
for a valid proxy and shall not be called directly.- Specified by:
disposeInternal
in classAbstractCloseableNativeProxy
-
-