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 static int |
FEE_CANNOT_CALCULATE |
protected static int |
FEE_EXCEEDS_AMOUNT |
static int |
INTERNAL_ERROR_CODE_THRESHOLD |
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) |
JO |
createTransaction(APICall.Builder builder)
Submit a transaction to the blockchain
|
JO |
createTransaction(APICall.Builder builder,
boolean reduceFeeFromAmount)
Submit a transaction to the blockchain
|
byte[] |
decryptFrom(byte[] publicKey,
EncryptedData encryptedData,
java.lang.String recipientSecretPhrase,
boolean uncompress)
Decrypt message sent to a specific account
|
EncryptedData |
encryptTo(byte[] publicKey,
byte[] data,
java.lang.String senderSecretPhrase,
boolean compress)
Encrypt message sent to specific 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
|
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
|
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.
|
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
|
ChainWrapper |
getParentChain()
Returns the parent chain object
|
byte[] |
getPublicKey(java.lang.String secretPhrase)
Convert secret phrase to public key
|
java.util.Random |
getRandom()
Return an initialized random object
|
protected abstract java.lang.String |
getReferencedTransaction() |
JO |
getResponse()
Returns the contract invocation response
|
AbstractContractContext.EventSource |
getSource()
Returns the source of the contract invocation event
|
java.util.Random |
initRandom(long userSeed)
Initializes a predictable random seed so that all nodes running the contract will generate the same random values
|
Contract |
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 |
setErrorResponse(int code,
java.lang.String description,
java.lang.Object... args)
Set the response of the contract invocation to an error condition
|
protected void |
setInternalErrorResponse(int code,
java.lang.String description,
java.lang.Object... args) |
void |
setResponse(JO response)
Set the response of the contract invocation
|
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
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 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 final java.lang.String contractName
public abstract BlockResponse getBlock()
public java.util.Random initRandom(long userSeed)
userSeed
- the predictable seed based on user specified info which ideally should be encrypted when submittedpublic java.util.Random getRandom()
public AbstractContractContext.EventSource getSource()
public JO getContractRunnerConfigParams(java.lang.String contractName)
contractName
- the contract namepublic ContractRunnerConfig getConfig()
public JO getBlockchainConstants()
public JO getResponse()
public void setResponse(JO response)
response
- the Json object which represents the contract invocation responsepublic void setErrorResponse(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 void setInternalErrorResponse(int code, java.lang.String description, java.lang.Object... args)
protected abstract java.lang.String getReferencedTransaction()
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 Contract loadContract(java.lang.String name)
name
- the contract reference name for the contract runnner accountpublic byte[] getHash(byte[] b)
b
- the message bytespublic byte[] getHash(byte[] b, java.lang.String algorithm)
b
- the message bytesalgorithm
- the hashing algorithmpublic 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 EncryptedData encryptTo(byte[] publicKey, byte[] data, java.lang.String senderSecretPhrase, boolean compress)
publicKey
- the recipient public keydata
- the message bytessenderSecretPhrase
- the secret phrase of the sendercompress
- the compression modepublic byte[] decryptFrom(byte[] publicKey, EncryptedData encryptedData, java.lang.String recipientSecretPhrase, boolean uncompress)
publicKey
- the sender account public keyencryptedData
- the encrypted message objectrecipientSecretPhrase
- the recipient account secret phraseuncompress
- the compression modepublic 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 phrase