public class Client
extends java.lang.Object
Modifier and Type | Class | Description |
---|---|---|
protected static interface |
Client.Executor<T> |
|
class |
Client.NodeRecord |
Class that stores minimal node information such as url and public key
|
Constructor | Description |
---|---|
Client(com.icodici.crypto.PrivateKey myPrivateKey,
NodeInfo nodeInfo,
BasicHttpClientSession session) |
Deprecated.
use
Client(String, String, PrivateKey) instead. |
Client(java.lang.String rootUrlString,
com.icodici.crypto.PrivateKey clientPrivateKey,
com.icodici.crypto.PublicKey nodePublicKey,
BasicHttpClientSession session) |
Start the new client protocol session.
|
Client(java.lang.String someNodeUrl,
com.icodici.crypto.PrivateKey clientPrivateKey,
BasicHttpClientSession session) |
Deprecated.
use
Client(String, String, PrivateKey) instead. |
Client(java.lang.String someNodeUrl,
com.icodici.crypto.PrivateKey clientPrivateKey,
BasicHttpClientSession session,
boolean delayedStart) |
Deprecated.
use
Client(String, String, PrivateKey) instead. |
Client(java.lang.String someNodeUrl,
com.icodici.crypto.PrivateKey clientPrivateKey,
BasicHttpClientSession session,
boolean delayedStart,
com.icodici.crypto.PublicKey verifyWith) |
Deprecated.
use
Client(String, String, PrivateKey) instead. |
Client(java.lang.String topologyInput,
java.lang.String topologyCacheDir,
com.icodici.crypto.PrivateKey clientPrivateKey) |
Start the new client protocol session, according to the known topology.
|
Modifier and Type | Method | Description |
---|---|---|
net.sergeych.tools.Binder |
command(java.lang.String name,
java.lang.Object... params) |
Execute some custom command on the node.
|
BasicHttpClient |
connectToUbot(int ubotNumber) |
|
net.sergeych.tools.Binder |
createSession(Contract requestContract,
byte[] packedU,
boolean waitPreviousSession) |
|
net.sergeych.tools.Binder |
executeCloudMethod(byte[] packedRequest,
byte[] packedU,
boolean waitPreviousSession,
float trustLevel) |
|
net.sergeych.tools.Binder |
followerGetRate() |
Get current network rate to run the FOLLOWER1 contracts.
|
byte[] |
getBody(HashId itemId) |
Get the contract with the given contract id.
|
net.sergeych.tools.Binder |
getChildren(HashId parent,
int limit) |
Get the body of the active contract with the given parent (if only one active contract is returned),
orthe list of IDs for the active contracts (if there are more than one in result).
|
net.sergeych.tools.Binder |
getChildren(HashId parent,
int limit,
int offset) |
Get the body of the active contract with the given parent (if only one active contract is returned),
or the list of IDs for the active contracts (if there are more than one in result).
|
net.sergeych.tools.Binder |
getChildren(HashId parent,
java.util.Map<java.lang.String,java.lang.String> tags,
int limit,
int offset) |
Get the body of the active contract with the given parent (if only one active contract is returned),
or the list of IDs for the active contracts (if there are more than one in result).
|
Client |
getClient(int i) |
Get the client connection to network node (by the node index).
|
net.sergeych.tools.Binder |
getCloudMethodState(HashId requestContractId,
java.lang.Integer ubotNumber) |
Gets the current state of the cloud method.
|
NodeConfigProvider |
getConfigProvider() |
Get the current network config provider.
|
net.sergeych.tools.Binder |
getContract(HashId origin) |
Get the body of active contract with the given origin (if only one active contract is returned),
or the list of IDs for the active contracts (if there are more than one in result).
|
net.sergeych.tools.Binder |
getContract(HashId origin,
int limit) |
Get the body of the active contract with the given origin (if only one active contract is returned),
or the list of IDs for the active contracts (if there are more than one in result).
|
net.sergeych.tools.Binder |
getContract(HashId origin,
int limit,
int offset) |
Get the body of active contract with the given origin (if ony one active contract is returned),
or the list of IDs for the active contracts (if there are more than one in result).
|
net.sergeych.tools.Binder |
getContract(HashId origin,
net.sergeych.tools.Binder tags,
int limit,
int offset) |
Get the body of the active contract with the given origin (if only one active contract is returned),
or the list of IDs for the active contracts (if there are more than one in result).
|
net.sergeych.tools.Binder |
getContractKeys(HashId itemId) |
|
ItemResult |
getExtendedState(HashId itemId,
int nodeNumber) |
|
int |
getNodeNumber() |
Get the node number of rhe currently connected node.
|
java.util.List<Client.NodeRecord> |
getNodes() |
Deprecated.
use
getTopology() instead. |
ParcelProcessingState |
getPaidOperationProcessingState(HashId operationId) |
Get the processing state of given PaidOperation.
|
ParcelProcessingState |
getParcelProcessingState(HashId parcelId) |
Get the processing state of given parcel.
|
int |
getPositiveConsensus() |
|
net.sergeych.tools.Binder |
getServiceContracts() |
|
BasicHttpClientSession |
getSession() |
Get the current session of this client.
|
BasicHttpClientSession |
getSession(int i) |
Get the client session of the client for the connection to some node, by the node index.getState
|
ItemResult |
getState(@NonNull Approvable item) |
Get the state of the contract on the currently connected node.
|
ItemResult |
getState(HashId itemId) |
Get the state of the contract (given by its id) on the currently connected node.
|
ItemResult |
getState(HashId itemId,
net.sergeych.tools.Reporter reporter) |
Get the state of the contract according to the network consensus.
|
net.sergeych.tools.Binder |
getStats() |
Get the statistics of the node.
|
net.sergeych.tools.Binder |
getStats(java.lang.Integer showPaymentsDays) |
Get the extended statistics of the node including by-day payments in "U".
|
java.util.List<net.sergeych.tools.Binder> |
getTopology() |
Get the topology of the network.
|
java.lang.String |
getUrl() |
Get url of the currently connected node.
|
java.lang.String |
getVersion() |
Get the network version.
|
HashId |
initiateVote(byte[] packedU,
Contract votingContract,
java.lang.String votingRole,
java.util.Collection<HashId> candidates) |
|
boolean |
isApprovedByNetwork(HashId itemId,
double trustLevel,
long millisToWait) |
Check if the contract has APPROVED status across the network.
|
boolean |
ping() |
Ping the currently connected node.
|
boolean |
ping(int i) |
Ping the network node by its index.
|
net.sergeych.tools.Binder |
pingNode(java.lang.Integer nodeNumber,
java.lang.Integer timeoutMillis) |
Pings given node from the node client currently connected to
Accessible to the network admins only.
|
protected <T> T |
protect(Client.Executor<T> e) |
|
byte[] |
queryContract(HashId slotId,
HashId originId,
HashId contractId) |
Look for the contract stored using the given slot contract id.
|
net.sergeych.tools.Binder |
queryFollowerInfo(HashId followerId) |
Lookup the state data of the follower contract in the network.
|
byte[] |
queryNameContract(java.lang.String name) |
Query the
UnsContract that registers the name
(passed as the argument). |
byte[] |
queryNameContract(java.lang.String name,
NSmartContract.SmartContractType type) |
Query the
UnsContract that registers the name
(passed as the argument). |
net.sergeych.tools.Binder |
queryNameRecord(HashId origin) |
Look for the name associated with a given origin (passed as an argument).
|
net.sergeych.tools.Binder |
queryNameRecord(java.lang.String address) |
Look for the name associated with some address (passed as an argument).
|
net.sergeych.tools.Binder |
querySlotInfo(HashId slotId) |
Look for state data of some slot contract.
|
ItemResult |
register(byte[] packed) |
Register contract on the network (no payment).
|
ItemResult |
register(byte[] packed,
long millisToWait) |
Register the contract on the network (no payment).
|
ItemResult |
registerPaidOperationWithState(byte[] packed,
long millisToWait) |
Send the PaidOperation to network and wait for it processing is complete.
|
boolean |
registerParcel(byte[] packed) |
Register the contract on the network using parcel (to provide payment).
|
boolean |
registerParcel(byte[] packed,
long millisToWait) |
Deprecated.
use
registerParcelWithState(byte[], long) instead. |
ItemResult |
registerParcelWithState(byte[] packed,
long millisToWait) |
Register the contract on the network using parcel (to provide payment).
|
BasicHttpClient.Answer |
request(java.lang.String name,
java.lang.Object... params) |
|
void |
restart() |
Restart the client connection to node
|
ItemResult |
resyncItem(HashId itemId) |
Force synchronization of some item (given by its id) with the rest of the network.
|
void |
setNodes(java.util.List<Client.NodeRecord> nodes) |
Deprecated.
|
ItemResult |
setVerboseLevel(int node,
int network,
int udp) |
Set log levels for different node components: node, network и udp.
|
java.time.ZonedDateTime |
signContractBySessionKey(HashId itemId) |
|
int |
size() |
Get the size of the network.
|
void |
start(BasicHttpClientSession session) |
Deprecated.
|
net.sergeych.tools.Binder |
startCloudMethod(Contract requestContract,
byte[] packedU,
boolean waitPreviousSession) |
|
void |
startProxyToNode(int targetNode,
BasicHttpClientSession targetSession) |
Convert this client into proxy to targetNode.
|
Decimal |
storageGetRate() |
Get the current network rate for operating SLOT1 contracts
|
Decimal |
unsRate() |
Get the current network rate for operating UNS1 contracts.
|
HashId |
voteForContract(byte[] packedU,
HashId votingId,
HashId candidateId) |
|
HashId |
voteForContract(byte[] packedU,
HashId votingId,
HashId candidateId,
java.util.List<byte[]> referencedItems) |
public Client(java.lang.String rootUrlString, com.icodici.crypto.PrivateKey clientPrivateKey, com.icodici.crypto.PublicKey nodePublicKey, BasicHttpClientSession session) throws java.io.IOException
rootUrlString
- node urlclientPrivateKey
- client private keynodePublicKey
- node keysession
- set to null or to the reconstructed instancejava.io.IOException
@Deprecated public Client(com.icodici.crypto.PrivateKey myPrivateKey, NodeInfo nodeInfo, BasicHttpClientSession session) throws java.io.IOException
Client(String, String, PrivateKey)
instead.myPrivateKey
- client private keynodeInfo
- node info specifying node public key and urlsession
- set to null or to the reconstructed instancejava.io.IOException
@Deprecated public Client(java.lang.String someNodeUrl, com.icodici.crypto.PrivateKey clientPrivateKey, BasicHttpClientSession session) throws java.io.IOException
Client(String, String, PrivateKey)
instead.someNodeUrl
- url on some node in networkclientPrivateKey
- client private keysession
- set to null or to the reconstructed instancejava.io.IOException
@Deprecated public Client(java.lang.String someNodeUrl, com.icodici.crypto.PrivateKey clientPrivateKey, BasicHttpClientSession session, boolean delayedStart) throws java.io.IOException
Client(String, String, PrivateKey)
instead.someNodeUrl
- url on some node in networkclientPrivateKey
- client private keysession
- set to null or to the reconstructed instancedelayedStart
- indicates if start of http client should be delayedjava.io.IOException
@Deprecated public Client(java.lang.String someNodeUrl, com.icodici.crypto.PrivateKey clientPrivateKey, BasicHttpClientSession session, boolean delayedStart, com.icodici.crypto.PublicKey verifyWith) throws java.io.IOException
Client(String, String, PrivateKey)
instead.someNodeUrl
- url on some node in networkclientPrivateKey
- client private keysession
- set to null or to the reconstructed instancedelayedStart
- indicates if start of http client should be delayedverifyWith
- key to verify loaded network info. Must be the key of the node,
for which user is attempting to connectjava.io.IOException
public Client(java.lang.String topologyInput, java.lang.String topologyCacheDir, com.icodici.crypto.PrivateKey clientPrivateKey) throws java.io.IOException
topologyInput
- name of known topology (without .json) or path to json-file containing topology.
Pass "mainnet" to use the default topology.topologyCacheDir
- path where the named topologies are stored for later use. Pass null to use the standard
~/.universa/topology pathclientPrivateKey
- private key for client connection.
The client key defines the limit of getState calls per minute and also restricts
access to a some of operations available the network administrator only.java.io.IOException
public java.util.List<net.sergeych.tools.Binder> getTopology()
Binder
s in the result list contain the following fields:
"number" - node number,
"name" - node name,
"direct_urls" - the urls to access the node by IP (directly),
"domain_urls" - the urls to access node by hostname if the access by IP is impossible
(for example, inside the web browser for https access),
"key" - PublicKey
of the node, Base64-encoded.public final int size()
public boolean ping(int i)
i
- index of node in topology (not the node's number)public boolean ping() throws java.io.IOException
java.io.IOException
public Client getClient(int i) throws java.io.IOException
Client
returned by this method will be unable to perform network-wise operations
like getTopology()
, ping(int)
()}, size()
etc.i
- index of node in topology (not the node number)java.io.IOException
public ItemResult setVerboseLevel(int node, int network, int udp) throws ClientError
node
- log level for nodenetwork
- log level for networkudp
- log level for udpClientError
@Deprecated public void setNodes(java.util.List<Client.NodeRecord> nodes)
public net.sergeych.tools.Binder getServiceContracts() throws ClientError
ClientError
public HashId initiateVote(byte[] packedU, Contract votingContract, java.lang.String votingRole, java.util.Collection<HashId> candidates) throws ClientError
ClientError
public HashId voteForContract(byte[] packedU, HashId votingId, HashId candidateId, java.util.List<byte[]> referencedItems) throws ClientError
ClientError
public HashId voteForContract(byte[] packedU, HashId votingId, HashId candidateId) throws ClientError
ClientError
public java.time.ZonedDateTime signContractBySessionKey(HashId itemId) throws ClientError
ClientError
public net.sergeych.tools.Binder getContractKeys(HashId itemId) throws ClientError
ClientError
@Deprecated public void start(BasicHttpClientSession session) throws java.io.IOException
session
- set to null or to the reconstructed instancejava.io.IOException
public void restart() throws java.io.IOException
java.io.IOException
public java.lang.String getUrl()
public BasicHttpClientSession getSession() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public BasicHttpClientSession getSession(int i) throws java.lang.IllegalStateException, java.io.IOException
i
- index of node in topology (not the node number)java.lang.IllegalStateException
java.io.IOException
@Deprecated public java.util.List<Client.NodeRecord> getNodes()
getTopology()
instead.public java.lang.String getVersion()
public ItemResult register(byte[] packed) throws ClientError
packed
- TransactionPack
binaryClientError
public ItemResult register(byte[] packed, long millisToWait) throws ClientError
packed
- TransactionPack
binarymillisToWait
- maximum time to wait for final ItemState
ClientError
public boolean registerParcel(byte[] packed) throws ClientError
getParcelProcessingState(HashId)
while it is ParcelProcessingState.isProcessing()
.
The status of the actual contract Parcel.getPayload()
can be checked
with getState(HashId)
then.
Getting ItemState.UNDEFINED
on payload contract means something went wrong with payment:
either it is not valid or insufficient U.packed
- Parcel
binaryClientError
@Deprecated public boolean registerParcel(byte[] packed, long millisToWait) throws ClientError
registerParcelWithState(byte[], long)
instead.packed
- Parcel
binarymillisToWait
- maximum time to wait for final ItemState
ClientError
public ItemResult registerParcelWithState(byte[] packed, long millisToWait) throws ClientError
registerParcel(byte[])
that waits until registration is complete
for a given amount of time.packed
- Parcel
binarymillisToWait
- maximum time to wait for final ItemState
ItemState.UNDEFINED
means either
payment wasn't processed yet or something is wrong with it (invalid or insufficient U)ClientError
public ItemResult registerPaidOperationWithState(byte[] packed, long millisToWait) throws ClientError
packed
- binarymillisToWait
- maximum time to waitClientError
public final ItemResult getState(@NonNull Approvable item) throws ClientError
getState(Approvable)
calls
per minute per client key. Make sure method is not called too often with the same client connection.item
- to get state ofItemState
if exist or ItemState.UNDEFINEDClientError
public ItemResult getState(HashId itemId) throws ClientError
getState(Approvable)
calls
per minute per client key. Make sure method is not called too often with the same client connection.itemId
- to get state byItemState
if exist or ItemState.UNDEFINEDClientError
public boolean isApprovedByNetwork(HashId itemId, double trustLevel, long millisToWait) throws ClientError
trustLevel
parameter (what ratio of the total node count you would consider trusted).itemId
- to get state oftrustLevel
- a value from 0 (exclusive) to 0.9; how many nodes (of all ones available in the network) do you needmillisToWait
- maximum time to get the positive or negative result from the network. If result is not received
within given time ClientError
is thrownClientError
public ItemResult resyncItem(HashId itemId) throws ClientError
itemId
- to synchronizeItemState
before synchronization. Query the state later to get it synchronized.ClientError
public net.sergeych.tools.Binder getStats() throws ClientError
PrivateKey
as session key) and the network admins only.ClientError
public net.sergeych.tools.Binder getStats(java.lang.Integer showPaymentsDays) throws ClientError
PrivateKey
as session key) and the network admins only.showPaymentsDays
- the number of days to provide payments volume forClientError
public net.sergeych.tools.Binder pingNode(java.lang.Integer nodeNumber, java.lang.Integer timeoutMillis) throws ClientError
nodeNumber
- node number to send ping totimeoutMillis
- maximum waiting timeClientError
public ParcelProcessingState getParcelProcessingState(HashId parcelId) throws ClientError
parcelId
- id of the parcel to get state ofClientError
public ParcelProcessingState getPaidOperationProcessingState(HashId operationId) throws ClientError
operationId
- id of the PaidOperation
to get state ofClientError
public ItemResult getExtendedState(HashId itemId, int nodeNumber) throws ClientError
ClientError
public ItemResult getState(HashId itemId, net.sergeych.tools.Reporter reporter) throws ClientError
getState(Approvable)
calls per minute for each particular
client key.
Make sure the method is not called too often with the same client connection.reporter
- reporter used to log the current status, or errors from nodes if any etcitemId
- to get state byItemState
if exist or ItemState.UNDEFINEDClientError
public int getNodeNumber()
public net.sergeych.tools.Binder command(java.lang.String name, java.lang.Object... params) throws java.io.IOException
name
- name of the commandparams
- parameters of the commandjava.io.IOException
public void startProxyToNode(int targetNode, BasicHttpClientSession targetSession) throws java.io.IOException
command(String, Object...)
will works through selected proxy node.targetNode
- index of node in topology (not the node number)targetSession
- saved session to target node. Pass here null to create new session.java.io.IOException
public BasicHttpClient.Answer request(java.lang.String name, java.lang.Object... params) throws java.io.IOException
java.io.IOException
protected final <T> T protect(Client.Executor<T> e) throws ClientError
ClientError
public int getPositiveConsensus()
public Decimal storageGetRate() throws ClientError
ClientError
public net.sergeych.tools.Binder querySlotInfo(HashId slotId) throws ClientError
slotId
- slot contract idBinder
containing state data of slot contractClientError
public byte[] queryContract(HashId slotId, HashId originId, HashId contractId) throws ClientError
null
)slotId
- id of slot contract storing queried contractoriginId
- queried contract origincontractId
- queried contract idTransactionPack
of stored contract or nullClientError
public Decimal unsRate() throws ClientError
ClientError
public NodeConfigProvider getConfigProvider() throws ClientError
NSmartContract
ClientError
public net.sergeych.tools.Binder queryNameRecord(HashId origin) throws ClientError
origin
- to look forBinder
containing names - an array of objects containing name and description associated with given origin
or null
if not foundClientError
public net.sergeych.tools.Binder queryNameRecord(java.lang.String address) throws ClientError
address
- to look forBinder
containing names - an array of objects containing name and description associated with given origin
or null
if not foundClientError
public byte[] queryNameContract(java.lang.String name) throws ClientError
UnsContract
that registers the name
(passed as the argument).name
- to look forUnsContract
if found;
or null
if not foundClientError
public byte[] queryNameContract(java.lang.String name, NSmartContract.SmartContractType type) throws ClientError
UnsContract
that registers the name
(passed as the argument).name
- to look fortype
- to look for UNS1 or UNS2UnsContract
if found;
or null
if not foundClientError
public byte[] getBody(HashId itemId) throws ClientError
itemId
- contract hashnull
if not foundClientError
public net.sergeych.tools.Binder getContract(HashId origin, int limit, int offset) throws ClientError
origin
- contract originlimit
- of list itemsoffset
- of list itemsBinder
containing the packed transaction
or (at the "contractIds" key) limited list of IDs for the active contracts;
or null
(if no active contracts found)ClientError
public net.sergeych.tools.Binder getContract(HashId origin, net.sergeych.tools.Binder tags, int limit, int offset) throws ClientError
origin
- contract origintags
- tags to search forlimit
- of list itemsoffset
- of list itemsBinder
containing the packed transaction
or (at the "contractIds" key) limited list of IDs for the active contracts;
or null
(if no active contracts found)ClientError
public net.sergeych.tools.Binder getContract(HashId origin, int limit) throws ClientError
origin
- contract originlimit
- of list itemsBinder
containing the packed transaction
or (at the "contractIds" key) limited list of IDs for the active contracts;
or null
(if no active contracts found)ClientError
public net.sergeych.tools.Binder getChildren(HashId parent, int limit, int offset) throws ClientError
parent
- id of parent contractlimit
- of list itemsoffset
- of list itemsBinder
containing the packed transaction
or (at the "contractIds" key) limited list of IDs for the active contracts;
or null
(if no active contracts found)ClientError
public net.sergeych.tools.Binder getChildren(HashId parent, java.util.Map<java.lang.String,java.lang.String> tags, int limit, int offset) throws ClientError
parent
- id of parent contracttags
- tags to search for (state.data.search_tags.key=value)limit
- of list itemsoffset
- of list itemsBinder
containing the packed transaction
or (at the "contractIds" key) limited list of IDs for the active contracts;
or null
(if no active contracts found)ClientError
public net.sergeych.tools.Binder getChildren(HashId parent, int limit) throws ClientError
parent
- id of parent contractlimit
- of list itemsBinder
containing the packed transaction
or (at the "contractIds" key) limited list of IDs for the active contracts;
or null
(if no active contracts found)ClientError
public net.sergeych.tools.Binder getContract(HashId origin) throws ClientError
origin
- contract originBinder
containing the packed transaction
or (at the "contractIds" key) limited list of IDs for the active contracts;
or null
(if no active contracts found)ClientError
public net.sergeych.tools.Binder followerGetRate() throws ClientError
Binder
containing data for the following keys:
"rateOriginDays" - origins-days per U rate;
"rateCallback" - callback cost in U.ClientError
public net.sergeych.tools.Binder queryFollowerInfo(HashId followerId) throws ClientError
followerId
- follower contract idBinder
containing state data of follower contractClientError
public net.sergeych.tools.Binder createSession(Contract requestContract, byte[] packedU, boolean waitPreviousSession) throws ClientError
ClientError
public net.sergeych.tools.Binder startCloudMethod(Contract requestContract, byte[] packedU, boolean waitPreviousSession) throws ClientError
ClientError
public BasicHttpClient connectToUbot(int ubotNumber) throws ClientError
ClientError
public net.sergeych.tools.Binder getCloudMethodState(HashId requestContractId, java.lang.Integer ubotNumber) throws ClientError
requestContractId
- - The Request contract id.ubotNumber
- - UBot number to request the current state from.ClientError
public net.sergeych.tools.Binder executeCloudMethod(byte[] packedRequest, byte[] packedU, boolean waitPreviousSession, float trustLevel) throws java.io.IOException
java.io.IOException