@Immutable
public class ClientService
extends java.lang.Object
implements java.lang.AutoCloseable
ClientService
. ClientService
should always be created with ClientServiceFactory
, which reuses internal instances as
much as possible for better performance and less resource usage.
ClientServiceFactory factory = new ClientServiceFactory(); // the factory should be reused
ClientService service = factory.create(new ClientConfig(new File(properties));
try {
JsonNode jsonArgument = ...; // create an application-specific argument
ContractExecutionResult result = service.executeContract(contractId, jsonArgument);
result.getContractResult().ifPresent(System.out::println);
} catch (ClientException e) {
System.err.println(e.getStatusCode());
System.err.println(e.getMessage());
}
factory.close();
Constructor and Description |
---|
ClientService(ClientConfig config,
ClientServiceHandler handler,
RequestSigner signer)
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Deprecated.
This method will be removed in release 5.0.0.
|
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 contractId,
com.fasterxml.jackson.databind.JsonNode contractArgument)
Executes the specified contract with the specified argument.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String contractId,
com.fasterxml.jackson.databind.JsonNode contractArgument,
java.lang.String functionId,
com.fasterxml.jackson.databind.JsonNode functionArgument)
Executes the specified contract (and functions) with the specified arguments.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String contractId,
javax.json.JsonObject contractArgument)
Executes the specified contract (and functions) with the specified argument.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String contractId,
javax.json.JsonObject contractArgument,
java.util.Optional<javax.json.JsonObject> functionArgument)
Deprecated.
This method will be removed in release 5.0.0.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String contractId,
javax.json.JsonObject contractArgument,
java.lang.String functionId,
javax.json.JsonObject functionArgument)
Executes the specified contract (and function) with the specified arguments.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String contractId,
java.lang.String contractArgument)
Executes the specified contract with the specified argument.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String nonce,
java.lang.String contractId,
com.fasterxml.jackson.databind.JsonNode contractArgument)
Executes the specified contract with the specified argument.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String nonce,
java.lang.String contractId,
com.fasterxml.jackson.databind.JsonNode contractArgument,
java.lang.String functionId,
com.fasterxml.jackson.databind.JsonNode functionArgument)
Executes the specified contract (and functions) with the specified arguments.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String nonce,
java.lang.String contractId,
javax.json.JsonObject contractArgument)
Executes the specified contract (and functions) with the specified argument.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String nonce,
java.lang.String contractId,
javax.json.JsonObject contractArgument,
java.util.Optional<javax.json.JsonObject> functionArgument)
Deprecated.
This method will be removed in release 5.0.0.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String nonce,
java.lang.String contractId,
javax.json.JsonObject contractArgument,
java.lang.String functionId,
javax.json.JsonObject functionArgument)
Executes the specified contract (and functions) with the specified arguments.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String nonce,
java.lang.String contractId,
java.lang.String contractArgument)
Executes the specified contract with the specified argument.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String contractId,
java.lang.String contractArgument,
java.lang.String functionId,
java.lang.String functionArgument)
Executes the specified contract (and function) with the specified arguments.
|
com.scalar.dl.ledger.model.ContractExecutionResult |
executeContract(java.lang.String nonce,
java.lang.String contractId,
java.lang.String contractArgument,
java.lang.String functionId,
java.lang.String functionArgument)
Executes the specified contract (and function) with the specified arguments.
|
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 for digital signature
authentication. |
void |
registerCertificate(byte[] serializedBinary)
Registers the certificate specified with the serialized byte array of a
CertificateRegistrationRequest for digital signature authentication. |
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)
Registers the specified contract for the certificate holder specified in
ClientConfig . |
void |
registerContract(java.lang.String id,
java.lang.String name,
byte[] contractBytes,
com.fasterxml.jackson.databind.JsonNode properties)
Registers the specified contract for the certificate holder specified in
ClientConfig . |
void |
registerContract(java.lang.String id,
java.lang.String name,
byte[] contractBytes,
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,
byte[] contractBytes,
java.util.Optional<javax.json.JsonObject> properties)
Deprecated.
This method will be removed in release 5.0.0.
|
void |
registerContract(java.lang.String id,
java.lang.String name,
byte[] contractBytes,
java.lang.String 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)
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,
com.fasterxml.jackson.databind.JsonNode 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,
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)
Deprecated.
This method will be removed in release 5.0.0.
|
void |
registerContract(java.lang.String id,
java.lang.String name,
java.lang.String contractPath,
java.lang.String 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.
|
void |
registerSecret()
Registers the secret key specified in the given
ClientConfig for HMAC authentication. |
void |
registerSecret(byte[] serializedBinary)
Registers the secret key specified with the serialized byte array of a
SecretRegistrationRequest for HMAC authentication. |
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.
|
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.
|
public ClientService(ClientConfig config, ClientServiceHandler handler, @Nullable RequestSigner signer)
config
- a configuration for the clienthandler
- a client service handler to interact the server(s)signer
- a request signer for requestspublic void registerCertificate()
ClientConfig
for digital signature
authentication.ClientException
- if a request fails for some reasonpublic void registerCertificate(byte[] serializedBinary)
CertificateRegistrationRequest
for digital signature authentication.serializedBinary
- a serialized byte array of CertificateRegistrationRequest
.ClientException
- if a request fails for some reasonpublic void registerSecret()
ClientConfig
for HMAC authentication.ClientException
- if a request fails for some reasonpublic void registerSecret(byte[] serializedBinary)
SecretRegistrationRequest
for HMAC authentication.serializedBinary
- a serialized byte array of SecretRegistrationRequest
.ClientException
- if a request fails for some reasonpublic void registerFunction(java.lang.String id, java.lang.String name, byte[] functionBytes)
executeContract
methods that match the type of the function.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)
executeContract
methods that match the type of the function.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 reason@Deprecated public void registerContract(java.lang.String id, java.lang.String name, byte[] contractBytes, java.util.Optional<javax.json.JsonObject> properties)
ClientConfig
.
To execute the contract, you need to use the corresponding executeContract
methods that
match the type of the contract.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 reason@Deprecated public void registerContract(java.lang.String id, java.lang.String name, java.lang.String contractPath, java.util.Optional<javax.json.JsonObject> properties)
ClientConfig
.
To execute the contract, you need to use the corresponding executeContract
methods that
match the type of the contract.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(java.lang.String id, java.lang.String name, byte[] contractBytes)
ClientConfig
.
To execute the contract, you need to use the corresponding executeContract
methods that
match the type of the contract.id
- an ID for the contractname
- the binary name of the contract classcontractBytes
- the byte array of the contract classClientException
- if a request fails for some reasonpublic void registerContract(java.lang.String id, java.lang.String name, java.lang.String contractPath)
ClientConfig
.
To execute the contract, you need to use the corresponding executeContract
methods that
match the type of the contract.id
- an ID for the contractname
- the binary name of the contract classcontractPath
- the relative path of the contract classClientException
- if a request fails for some reasonpublic void registerContract(java.lang.String id, java.lang.String name, byte[] contractBytes, @Nullable javax.json.JsonObject properties)
ClientConfig
.
To execute the contract, you need to use the corresponding executeContract
methods that
match the type of the contract.id
- an ID for the contractname
- the binary name of the contract classcontractBytes
- the byte array 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, @Nullable javax.json.JsonObject properties)
ClientConfig
.
To execute the contract, you need to use the corresponding executeContract
methods that
match the type of the contract.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(java.lang.String id, java.lang.String name, byte[] contractBytes, @Nullable com.fasterxml.jackson.databind.JsonNode properties)
ClientConfig
.
To execute the contract, you need to use the corresponding executeContract
methods that
match the type of the contract.id
- an ID for the contractname
- the binary name of the contract classcontractBytes
- the byte array 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, @Nullable com.fasterxml.jackson.databind.JsonNode properties)
ClientConfig
.
To execute the contract, you need to use the corresponding executeContract
methods that
match the type of the contract.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(java.lang.String id, java.lang.String name, java.lang.String contractPath, @Nullable java.lang.String properties)
ClientConfig
.
To execute the contract, you need to use the corresponding executeContract
methods that
match the type of the contract.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(java.lang.String id, java.lang.String name, byte[] contractBytes, @Nullable java.lang.String properties)
ClientConfig
.
To execute the contract, you need to use the corresponding executeContract
methods that
match the type of the contract.id
- an ID for the contractname
- the binary name of the contract classcontractBytes
- the byte array 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 contractId, javax.json.JsonObject contractArgument)
JsonpBasedContract
and JsonpBasedFunction
.contractId
- an ID of the contractcontractArgument
- an argument of the contractContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String nonce, java.lang.String contractId, javax.json.JsonObject contractArgument)
JsonpBasedContract
and JsonpBasedFunction
.nonce
- a unique ID of the execution requestcontractId
- an ID of the contractcontractArgument
- an argument of the contractContractExecutionResult
ClientException
- if a request fails for some reason@Deprecated public com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String contractId, javax.json.JsonObject contractArgument, java.util.Optional<javax.json.JsonObject> functionArgument)
JsonpBasedContract
and JsonpBasedFunction
.
The contract argument can have a "_functions_" key to specify an array of function IDs to execute with the specified contract, but this feature is deprecated and will be removed in release 5.0.0.
contractId
- an ID of the contractcontractArgument
- an argument of the contractfunctionArgument
- an argument of the functionContractExecutionResult
ClientException
- if a request fails for some reason@Deprecated public com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String nonce, java.lang.String contractId, javax.json.JsonObject contractArgument, java.util.Optional<javax.json.JsonObject> functionArgument)
JsonpBasedContract
and JsonpBasedFunction
.
The contract argument can have a "_functions_" key to specify an array of function IDs to execute with the specified contract, but this feature is deprecated and will be removed in release 5.0.0.
nonce
- a unique ID of the execution requestcontractId
- an ID of the contractcontractArgument
- 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(java.lang.String contractId, javax.json.JsonObject contractArgument, @Nullable java.lang.String functionId, @Nullable javax.json.JsonObject functionArgument)
JsonpBasedContract
and JsonpBasedFunction
.contractId
- an ID of the contractcontractArgument
- an argument of the contractfunctionId
- an ID of the functionfunctionArgument
- an argument of the functionContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String nonce, java.lang.String contractId, javax.json.JsonObject contractArgument, @Nullable java.lang.String functionId, @Nullable javax.json.JsonObject functionArgument)
JsonpBasedContract
and JsonpBasedFunction
.nonce
- a unique ID of the execution requestcontractId
- an ID of the contractcontractArgument
- an argument of the contractfunctionId
- an ID of the functionfunctionArgument
- an argument of the functionContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String contractId, com.fasterxml.jackson.databind.JsonNode contractArgument)
JacksonBasedContract
and JacksonBasedFunction
.contractId
- an ID of the contractcontractArgument
- an argument of the contractContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String nonce, java.lang.String contractId, com.fasterxml.jackson.databind.JsonNode contractArgument)
JacksonBasedContract
).nonce
- a unique ID of the execution requestcontractId
- an ID of the contractcontractArgument
- an argument of the contractContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String contractId, com.fasterxml.jackson.databind.JsonNode contractArgument, @Nullable java.lang.String functionId, @Nullable com.fasterxml.jackson.databind.JsonNode functionArgument)
JacksonBasedContract
and JacksonBasedFunction
.contractId
- an ID of the contractcontractArgument
- an argument of the contractfunctionId
- an ID of the functionfunctionArgument
- an argument of the functionContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String nonce, java.lang.String contractId, com.fasterxml.jackson.databind.JsonNode contractArgument, @Nullable java.lang.String functionId, @Nullable com.fasterxml.jackson.databind.JsonNode functionArgument)
JacksonBasedContract
and JacksonBasedFunction
.nonce
- a unique ID of the execution requestcontractId
- an ID of the contractcontractArgument
- an argument of the contractfunctionId
- an ID of the functionfunctionArgument
- an argument of the functionContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String contractId, java.lang.String contractArgument)
StringBasedContract
).contractId
- an ID of the contractcontractArgument
- an argument of the contractContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String nonce, java.lang.String contractId, java.lang.String contractArgument)
StringBasedContract
).nonce
- a unique ID of the execution requestcontractId
- an ID of the contractcontractArgument
- an argument of the contractContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String contractId, java.lang.String contractArgument, @Nullable java.lang.String functionId, @Nullable java.lang.String functionArgument)
StringBasedContract
and StringBasedFunction
.contractId
- an ID of the contractcontractArgument
- an argument of the contractfunctionId
- an ID of the functionfunctionArgument
- an argument of the functionContractExecutionResult
ClientException
- if a request fails for some reasonpublic com.scalar.dl.ledger.model.ContractExecutionResult executeContract(java.lang.String nonce, java.lang.String contractId, java.lang.String contractArgument, @Nullable java.lang.String functionId, @Nullable java.lang.String functionArgument)
StringBasedContract
and StringBasedFunction
.nonce
- a unique ID of the execution requestcontractId
- an ID of the contractcontractArgument
- an argument of the contractfunctionId
- an ID of the functionfunctionArgument
- 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)
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)
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 reason@Deprecated public void close()
close
in interface java.lang.AutoCloseable