public abstract class AbstractContractContext
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
AbstractContractContext.EventSource |
Modifier and Type | Field and Description |
---|---|
protected static java.util.Map<java.lang.Integer,ChainWrapper> |
chainById |
protected static java.util.Map<java.lang.String,ChainWrapper> |
chainByName |
protected ContractRunnerConfig |
config |
protected java.lang.String |
contractName |
protected JO |
contractSetupParameters |
protected static int |
FEE_CANNOT_CALCULATE |
protected static int |
FEE_EXCEEDS_AMOUNT |
static int |
INTERNAL_ERROR_CODE_THRESHOLD |
static java.lang.String |
MANAGED_ACCOUNTS_INDEX_HINT_FIELD |
protected static int |
MESSAGE_TO_ENCRYPT_WITHOUT_SECRET_PHRASE |
protected JO |
response |
protected AbstractContractContext.EventSource |
source |
protected static int |
VALIDATE_SAME_ACCOUNT_CODE |
protected static int |
VALIDATE_SAME_CHAIN |
protected static int |
VALIDATE_SAME_TRANSACTION_TYPE |
Modifier and Type | Method and Description |
---|---|
protected JO |
addTriggerData(JO jo,
int managedAccountIndex) |
boolean |
canSetResponse() |
JO |
createTransaction(APICall.Builder builder)
Submit a transaction to the blockchain
|
JO |
createTransaction(APICall.Builder builder,
boolean reduceFeeFromAmount)
Submit a transaction to the blockchain
|
JO |
createTransaction(APICall.Builder builder,
boolean reduceFeeFromAmount,
int managedAccountIndex)
Submit a transaction to the blockchain by a managed account.
|
long |
fullHashToId(byte[] fullHash)
Convert a 32 byte hash represented as byte array to a numeric entity id
|
long |
fullHashToId(java.lang.String fullHashStr)
Convert a 32 byte hash represented as hex string to a numeric entity id
|
JO |
generateErrorResponse(int code,
java.lang.String description,
java.lang.Object... args)
Generate error response for the contract invocation
|
JO |
generateInfoResponse(java.lang.String description,
java.lang.Object... args)
Generate info response for the contract invocation
|
protected JO |
generateInternalErrorResponse(int code,
java.lang.String description,
java.lang.Object... args) |
JO |
generateResponse(JO response)
Generate response of the contract invocation
|
java.lang.String |
getAccount()
Returns the contract runner account as unsigned long number
|
java.lang.String |
getAccountRs()
Returns the contract runner account in Reed Solomon format
|
abstract BlockResponse |
getBlock()
Returns the Json representation of the current block
|
JO |
getBlockchainConstants()
Returns a Json object representing the response of the getConstants API call
|
int |
getBlockchainHeight() |
ChainWrapper |
getChain(int id)
Returns the chain object represented by this chain id
|
ChainWrapper |
getChain(java.lang.String name)
Returns the chain object represented by this chain name
|
ContractRunnerConfig |
getConfig()
Returns the contract runner configuration parameters
|
<T extends AbstractContractContext> |
getContext() |
java.lang.String |
getContractName()
Returns the contract name
|
JO |
getContractRunnerConfigParams(java.lang.String contractName)
Returns the node specific configuration for a specific contract loaded from the contract runner configuration file
Only use these parameters for secret information which cannot be deployed to the blockchain like secret phrases and admin passwords.
|
JO |
getContractSetupParameters() |
byte[] |
getHash(byte[] b)
Calculate the SHA-256 hash of a message
|
byte[] |
getHash(byte[] b,
java.lang.String algorithm)
Calculate the hash of a message
|
java.lang.String |
getNetworkType() |
<Params> Params |
getParams(java.lang.Class<Params> clazz) |
ChainWrapper |
getParentChain()
Returns the parent chain object
|
protected JO |
getPhasingAttachment() |
byte[] |
getPublicKey()
Returns the public key as byte array
|
byte[] |
getPublicKey(byte[] privateKey)
Convert private key to public key
|
byte[] |
getPublicKey(java.lang.String secretPhrase)
Convert secret phrase to public key
|
java.lang.String |
getPublicKeyHexString()
Returns the public key in hex string format
|
RandomnessSource |
getRandomnessSource()
Return an initialized random object
|
JO |
getResponse()
Returns the contract invocation response
|
JO |
getRuntimeParams() |
AbstractContractContext.EventSource |
getSource()
Returns the source of the contract invocation event
|
RandomnessSource |
initRandom(long userSeed)
Initializes a predictable random seed so that all nodes running the contract will generate the same random values
|
boolean |
isPermissionGranted(java.security.Permission permission)
Check with the Security Manager if the contract code has a specific permission
|
ContractAndSetupParameters |
loadContract(java.lang.String name)
Load a contract instance from the blockchain cloud data based on the contract reference name
|
void |
logErrorMessage(java.lang.Throwable t)
Log an exception message and stack trace into the node log file
|
void |
logInfoMessage(java.lang.String format,
java.lang.Object... args)
Log a formatted string into the node log file
|
long |
parseAccountId(java.lang.String account) |
byte[] |
parseHexString(java.lang.String hex)
Parse hex string into a byte array
|
long |
publicKeyToAccountId(byte[] publicKey)
Convert a public key represented as byte array to a numeric account id
|
long |
publicKeyToAccountId(java.lang.String publicKeyStr)
Convert a public key represented as hex string to a numeric account id
|
java.lang.String |
rsAccount(long accountId)
Convert a numeric account id to its Reed Solomon representation
|
void |
setContractSetupParameters(JO contractSetupParameters) |
void |
setResponse(JO response) |
byte[] |
sign(byte[] message,
java.lang.String secretPhrase)
Sign a message with an account secret phrase
|
java.lang.String |
toHexString(byte[] bytes)
Convert byte array to hex string
|
boolean |
verify(byte[] signature,
byte[] message,
byte[] publicKey)
Verify an account signature
|
public static final int INTERNAL_ERROR_CODE_THRESHOLD
public static final java.lang.String MANAGED_ACCOUNTS_INDEX_HINT_FIELD
protected static final int VALIDATE_SAME_ACCOUNT_CODE
protected static final int VALIDATE_SAME_TRANSACTION_TYPE
protected static final int VALIDATE_SAME_CHAIN
protected static final int FEE_CANNOT_CALCULATE
protected static final int FEE_EXCEEDS_AMOUNT
protected static final int MESSAGE_TO_ENCRYPT_WITHOUT_SECRET_PHRASE
protected static final java.util.Map<java.lang.Integer,ChainWrapper> chainById
protected static final java.util.Map<java.lang.String,ChainWrapper> chainByName
protected AbstractContractContext.EventSource source
protected ContractRunnerConfig config
protected JO contractSetupParameters
protected final java.lang.String contractName
protected JO response
public <T extends AbstractContractContext> T getContext()
public java.lang.String getContractName()
public abstract BlockResponse getBlock()
public RandomnessSource initRandom(long userSeed)
userSeed
- the predictable seed based on user specified info which ideally should be encrypted when submittedpublic RandomnessSource getRandomnessSource()
public AbstractContractContext.EventSource getSource()
public JO getContractRunnerConfigParams(java.lang.String contractName)
contractName
- the contract namepublic ContractRunnerConfig getConfig()
public java.lang.String getAccount()
public java.lang.String getAccountRs()
public byte[] getPublicKey()
public java.lang.String getPublicKeyHexString()
public JO getBlockchainConstants()
public JO getResponse()
public void setResponse(JO response)
public boolean canSetResponse()
public JO generateResponse(JO response)
response
- the Json object which represents the contract invocation responsepublic JO generateInfoResponse(java.lang.String description, java.lang.Object... args)
description
- the description as a string formatargs
- the description string format argumentspublic JO generateErrorResponse(int code, java.lang.String description, java.lang.Object... args)
code
- the error codedescription
- the error description as a string formatargs
- the description string format argumentsprotected JO generateInternalErrorResponse(int code, java.lang.String description, java.lang.Object... args)
public JO createTransaction(APICall.Builder builder)
builder
- the API caller for the specific transaction typepublic JO createTransaction(APICall.Builder builder, boolean reduceFeeFromAmount)
builder
- the API caller for the specific transaction typereduceFeeFromAmount
- set to true to reduce the transaction fee from the transaction amount if applicable, false otherwisepublic JO createTransaction(APICall.Builder builder, boolean reduceFeeFromAmount, int managedAccountIndex)
ManagedAccountsBundler
can be used to
bundle such transactions.
Note that a negative index will create the transaction with a hardened extended private key, which prevents the
generation of the public key from the master public key
.
This will prevent the ManagedAccountsBundler
to bundle the transaction.
builder
- the API caller for the specific transaction typereduceFeeFromAmount
- set to true to reduce the transaction fee from the transaction amount if applicable, false otherwisemanagedAccountIndex
- index of the managed account with whose private key the transaction will be signed.
If set to Integer.MAX_VALUE
, the transaction is signed by the contract accountprotected JO getPhasingAttachment()
public ContractAndSetupParameters loadContract(java.lang.String name)
name
- the contract reference name for the contract runner accountpublic byte[] getHash(byte[] b)
b
- the message bytespublic byte[] getHash(byte[] b, java.lang.String algorithm)
b
- the message bytesalgorithm
- the hashing algorithmpublic java.lang.String getNetworkType()
public byte[] sign(byte[] message, java.lang.String secretPhrase)
message
- the message bytessecretPhrase
- the account secret phrasepublic boolean verify(byte[] signature, byte[] message, byte[] publicKey)
signature
- the signature bytesmessage
- the message bytespublicKey
- the signer account public keypublic long fullHashToId(byte[] fullHash)
fullHash
- the hash represented as byte arraypublic long fullHashToId(java.lang.String fullHashStr)
fullHashStr
- the hash represented as hex stringpublic long publicKeyToAccountId(byte[] publicKey)
publicKey
- the public key represented as byte arraypublic long publicKeyToAccountId(java.lang.String publicKeyStr)
publicKeyStr
- the public key represented as hex stringpublic ChainWrapper getChain(java.lang.String name)
name
- the chain namepublic ChainWrapper getChain(int id)
id
- the chain idpublic ChainWrapper getParentChain()
public long parseAccountId(java.lang.String account)
account
- the RS or unsigned long account idpublic java.lang.String rsAccount(long accountId)
accountId
- the numeric account idpublic int getBlockchainHeight()
public void logInfoMessage(java.lang.String format, java.lang.Object... args)
format
- the format stringargs
- the format argumentspublic void logErrorMessage(java.lang.Throwable t)
t
- the throwable objectpublic byte[] parseHexString(java.lang.String hex)
hex
- the hex stringpublic java.lang.String toHexString(byte[] bytes)
bytes
- the byte arraypublic byte[] getPublicKey(java.lang.String secretPhrase)
secretPhrase
- the secret phrasepublic byte[] getPublicKey(byte[] privateKey)
privateKey
- the secret phrasepublic boolean isPermissionGranted(java.security.Permission permission)
permission
- the permission to checkpublic JO getRuntimeParams()
public JO getContractSetupParameters()
public <Params> Params getParams(java.lang.Class<Params> clazz)
public void setContractSetupParameters(JO contractSetupParameters)