@Immutable
public class ClientService
extends java.lang.Object
implements java.lang.AutoCloseable
ClientService
should always be
initialized with Guice
, which maintains application-level singleton. Using this with a
try-with-resources statement is also recommended to close it properly.
Injector injector = Guice.createInjector(new ClientModule(new ClientConfig(new File(properties))));
try (ClientService service = injector.getInstance(ClientService.class)) {
JsonObject jsonArgument = Json.createReader(new StringReader(contractArgument)).readObject();
ContractExecutionResult result = service.executeContract(contractId, jsonArgument);
result.getResult().ifPresent(System.out::println);
} catch (ClientException e) {
System.err.println(e.getStatusCode());
System.err.println(e.getMessage());
}
Constructor and Description |
---|
ClientService(ClientConfig config,
AbstractLedgerClient client,
RequestSigner signer)
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Releases resources such as TCP connections.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(byte[] serializedBinary)
Executes the specified contract with the specified serialized byte array of a
ContractExecutionRequest . |
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String id,
javax.json.JsonObject argument)
Executes the specified contract with the specified argument for the certificate holder
specified in
ClientConfig . |
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String id,
javax.json.JsonObject argument,
java.util.Optional<javax.json.JsonObject> functionArgument)
Executes the specified contract with the specified argument for the certificate holder
specified in
ClientConfig . |
javax.json.JsonObject |
listContracts(byte[] serializedBinary)
Retrieves a list of contracts with the specified serialized byte array of a
ContractsListingRequest . |
javax.json.JsonObject |
listContracts(java.lang.String id)
Retrieves a list of contracts for the certificate holder specified in
ClientConfig . |
void |
registerCertificate()
Registers the certificate specified in the given
ClientConfig . |
void |
registerCertificate(byte[] serializedBinary)
Registers the certificate with the specified serialized byte array of a
CertificateRegistrationRequest . |
void |
registerContract(byte[] serializedBinary)
Registers the contract with the specified serialized byte array of a
ContractRegistrationRequest . |
void |
registerContract(java.lang.String id,
java.lang.String name,
byte[] contractBytes,
java.util.Optional<javax.json.JsonObject> properties)
Registers the specified contract for the certificate holder specified in
ClientConfig . |
void |
registerContract(java.lang.String id,
java.lang.String name,
java.lang.String contractPath,
java.util.Optional<javax.json.JsonObject> properties)
Registers the specified contract for the certificate holder specified in
ClientConfig . |
void |
registerFunction(byte[] serializedBinary)
Registers the function with the specified serialized byte array of a
FunctionRegistrationRequest . |
void |
registerFunction(java.lang.String id,
java.lang.String name,
byte[] functionBytes)
Registers the specified function.
|
void |
registerFunction(java.lang.String id,
java.lang.String name,
java.lang.String functionPath)
Registers the specified function.
|
com.scalar.dl.ledger.model.LedgerValidationResult |
validateLedger(byte[] serializedBinary)
Validates the specified asset in the ledger with the specified serialized byte array of a
LedgerValidationRequest . |
com.scalar.dl.ledger.model.LedgerValidationResult |
validateLedger(java.lang.String assetId)
Validates the specified asset in the ledger for the certificate holder specified in
ClientConfig . |
com.scalar.dl.ledger.model.LedgerValidationResult |
validateLedger(java.lang.String assetId,
int startAge,
int endAge)
Validates the specified asset between the specified ages in the ledger for the certificate
holder specified in
ClientConfig . |
com.scalar.dl.ledger.model.LedgersValidationResult |
validateLedgers(byte[] serializedBinary)
Validates the specified asset in multiple ledgers with the specified serialized byte array of a
LedgersValidationRequest . |
com.scalar.dl.ledger.model.LedgersValidationResult |
validateLedgers(java.lang.String assetId)
Validates the specified asset in multiple ledgers for the certificate holder specified in
ClientConfig . |
@Inject public ClientService(ClientConfig config, AbstractLedgerClient client, @Nullable RequestSigner signer)
ClientService
with the specified ClientConfig
, AbstractLedgerClient
and RequestSigner
. This constructor shouldn't be called
explicitly and should be called implicitly by Guice
.config
- a configuration for the clientclient
- a client for the ledger serversigner
- a request signer for requestspublic void registerCertificate()
ClientConfig
.ClientException
- if a request fails for some reasonpublic void registerCertificate(byte[] serializedBinary)
CertificateRegistrationRequest
. request.serializedBinary
- a serialized byte array of CertificateRegistrationRequest
.ClientException
- if a request fails for some reasonpublic void registerFunction(java.lang.String id, java.lang.String name, byte[] functionBytes)
id
- an ID of the functionname
- the binary name of the function classfunctionBytes
- the byte code of the function classClientException
- if a request fails for some reasonpublic void registerFunction(java.lang.String id, java.lang.String name, java.lang.String functionPath)
id
- an ID of the functionname
- the binary name of the function classfunctionPath
- the relative path of the function classClientException
- if a request fails for some reasonpublic void registerFunction(byte[] serializedBinary)
FunctionRegistrationRequest
.serializedBinary
- a serialized byte array of FunctionRegistrationRequest
.ClientException
- if a request fails for some reasonpublic void registerContract(java.lang.String id, java.lang.String name, byte[] contractBytes, java.util.Optional<javax.json.JsonObject> properties)
ClientConfig
.id
- an ID of the contractname
- the binary name of the contract classcontractBytes
- the byte code of the contract classproperties
- a contract propertiesClientException
- if a request fails for some reasonpublic void registerContract(java.lang.String id, java.lang.String name, java.lang.String contractPath, java.util.Optional<javax.json.JsonObject> properties)
ClientConfig
.id
- an ID for the contractname
- the binary name of the contract classcontractPath
- the relative path of the contract classproperties
- a contract propertiesClientException
- if a request fails for some reasonpublic void registerContract(byte[] serializedBinary)
ContractRegistrationRequest
.serializedBinary
- a serialized byte array of ContractRegistrationRequest
.ClientException
- if a request fails for some reasonpublic javax.json.JsonObject listContracts(java.lang.String id)
ClientConfig
. If
specified with a contract ID, it will return the matching contract only.id
- a contract IDJsonObject
ClientException
- if a request fails for some reasonpublic javax.json.JsonObject listContracts(byte[] serializedBinary)
ContractsListingRequest
.serializedBinary
- a serialized byte array of ContractsListingRequest
.JsonObject
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String id, javax.json.JsonObject argument)
ClientConfig
.id
- an ID of the contractargument
- an argument of the contractContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String id, javax.json.JsonObject argument, java.util.Optional<javax.json.JsonObject> functionArgument)
ClientConfig
.id
- an ID of the contractargument
- an argument of the contractfunctionArgument
- an argument of the functionContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(byte[] serializedBinary)
ContractExecutionRequest
.serializedBinary
- a serialized byte array of ContractExecutionRequest
.ContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.LedgerValidationResult validateLedger(java.lang.String assetId)
ClientConfig
.assetId
- an asset IDLedgerValidationResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.LedgerValidationResult validateLedger(java.lang.String assetId, int startAge, int endAge)
ClientConfig
.assetId
- an asset IDstartAge
- an age to be validated from (inclusive)endAge
- an age to be validated to (inclusive)LedgerValidationResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.LedgerValidationResult validateLedger(byte[] serializedBinary)
LedgerValidationRequest
.serializedBinary
- a serialized byte array of LedgerValidationRequest
.LedgerValidationResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.LedgersValidationResult validateLedgers(java.lang.String assetId)
ClientConfig
.assetId
- an asset IDLedgersValidationResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.LedgersValidationResult validateLedgers(byte[] serializedBinary)
LedgersValidationRequest
.serializedBinary
- a serialized byte array of LedgersValidationRequest
.LedgersValidationResult
ClientException
- if a request fails for some reasonpublic void close()
close
in interface java.lang.AutoCloseable