Package nxt.addons
Class AbstractContractContext
java.lang.Object
nxt.addons.AbstractContractContext
- Direct Known Subclasses:
AbstractOperationContext,BlockContext,DelegatedContext,InitializationContext,RequestContext,ShutdownContext
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Map<Integer,ChainWrapper> protected static final Map<String,ChainWrapper> protected ContractRunnerConfigprotected final Stringprotected JOprotected static final intprotected static final intstatic final intstatic final Stringprotected static final intprotected JOprotected AbstractContractContext.EventSourceprotected static final intprotected static final intprotected static final int -
Method Summary
Modifier and TypeMethodDescriptionprotected JOaddTriggerData(JO jo, int managedAccountIndex) booleancreateTransaction(APICall.Builder builder) Submit a transaction to the blockchaincreateTransaction(APICall.Builder builder, boolean reduceFeeFromAmount) Submit a transaction to the blockchaincreateTransaction(APICall.Builder builder, boolean reduceFeeFromAmount, int managedAccountIndex) Submit a transaction to the blockchain by a managed account.longfullHashToId(byte[] fullHash) Convert a 32 byte hash represented as byte array to a numeric entity idlongfullHashToId(String fullHashStr) Convert a 32 byte hash represented as hex string to a numeric entity idgenerateErrorResponse(int code, String description, Object... args) Generate error response for the contract invocationgenerateInfoResponse(String description, Object... args) Generate info response for the contract invocationprotected JOgenerateInternalErrorResponse(int code, String description, Object... args) generateResponse(JO response) Generate response of the contract invocationReturns the contract runner account as unsigned long numberReturns the contract runner account in Reed Solomon formatabstract BlockResponsegetBlock()Returns the Json representation of the current blockReturns a Json object representing the response of the getConstants API callintgetChain(int id) Returns the chain object represented by this chain idReturns the chain object represented by this chain nameReturns the contract runner configuration parameters<T extends AbstractContractContext>
TReturns the contract namegetContractRunnerConfigParams(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 messagebyte[]Calculate the hash of a message<Params> ParamsReturns the parent chain objectprotected JObyte[]Returns the public key as byte arraybyte[]getPublicKey(byte[] privateKey) Convert private key to public keybyte[]getPublicKey(String secretPhrase) Convert secret phrase to public keyReturns the public key in hex string formatReturn an initialized random objectReturns the contract invocation responseReturns the source of the contract invocation eventinitRandom(long userSeed) Initializes a predictable random seed so that all nodes running the contract will generate the same random valuesbooleanisPermissionGranted(Permission permission) Check with the Security Manager if the contract code has a specific permissionloadContract(String name) Load a contract instance from the blockchain cloud data based on the contract reference namevoidLog an exception message and stack trace into the node log filevoidlogInfoMessage(String format, Object... args) Log a formatted string into the node log filelongparseAccountId(String account) byte[]parseHexString(String hex) Parse hex string into a byte arraylongpublicKeyToAccountId(byte[] publicKey) Convert a public key represented as byte array to a numeric account idlongpublicKeyToAccountId(String publicKeyStr) Convert a public key represented as hex string to a numeric account idrsAccount(long accountId) Convert a numeric account id to its Reed Solomon representationvoidsetContractSetupParameters(JO contractSetupParameters) voidsetResponse(JO response) byte[]Sign a message with an account secret phrasetoHexString(byte[] bytes) Convert byte array to hex stringbooleanverify(byte[] signature, byte[] message, byte[] publicKey) Verify an account signature
-
Field Details
-
INTERNAL_ERROR_CODE_THRESHOLD
public static final int INTERNAL_ERROR_CODE_THRESHOLD- See Also:
-
MANAGED_ACCOUNTS_INDEX_HINT_FIELD
- See Also:
-
VALIDATE_SAME_ACCOUNT_CODE
protected static final int VALIDATE_SAME_ACCOUNT_CODE- See Also:
-
VALIDATE_SAME_TRANSACTION_TYPE
protected static final int VALIDATE_SAME_TRANSACTION_TYPE- See Also:
-
VALIDATE_SAME_CHAIN
protected static final int VALIDATE_SAME_CHAIN- See Also:
-
FEE_CANNOT_CALCULATE
protected static final int FEE_CANNOT_CALCULATE- See Also:
-
FEE_EXCEEDS_AMOUNT
protected static final int FEE_EXCEEDS_AMOUNT- See Also:
-
MESSAGE_TO_ENCRYPT_WITHOUT_SECRET_PHRASE
protected static final int MESSAGE_TO_ENCRYPT_WITHOUT_SECRET_PHRASE- See Also:
-
chainById
-
chainByName
-
source
-
config
-
contractSetupParameters
-
contractName
-
response
-
-
Method Details
-
getContext
-
getContractName
Returns the contract name- Returns:
- the contract name
-
getBlock
Returns the Json representation of the current block- Returns:
- the current block represented as Json
-
initRandom
Initializes a predictable random seed so that all nodes running the contract will generate the same random values- Parameters:
userSeed- the predictable seed based on user specified info which ideally should be encrypted when submitted- Returns:
- the random number generator
-
getRandomnessSource
Return an initialized random object- Returns:
- the random number generator object
-
getSource
Returns the source of the contract invocation event- Returns:
- the event source
-
getContractRunnerConfigParams
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.- Parameters:
contractName- the contract name- Returns:
- the parameter object in json format
-
getConfig
Returns the contract runner configuration parameters- Returns:
- the contract runner configuration parameters formatted as Json
-
getAccount
Returns the contract runner account as unsigned long number- Returns:
- the account id
-
getAccountRs
Returns the contract runner account in Reed Solomon format- Returns:
- the account id
-
getPublicKey
public byte[] getPublicKey()Returns the public key as byte array- Returns:
- the public key
-
getPublicKeyHexString
Returns the public key in hex string format- Returns:
- the public key
-
getBlockchainConstants
Returns a Json object representing the response of the getConstants API call- Returns:
- a Json object
-
getResponse
Returns the contract invocation response- Returns:
- the contract invocation response formatted as Json
-
setResponse
-
canSetResponse
public boolean canSetResponse() -
generateResponse
Generate response of the contract invocation- Parameters:
response- the Json object which represents the contract invocation response- Returns:
- the generated response
-
generateInfoResponse
Generate info response for the contract invocation- Parameters:
description- the description as a string formatargs- the description string format arguments- Returns:
- the generated info response
-
generateErrorResponse
Generate error response for the contract invocation- Parameters:
code- the error codedescription- the error description as a string formatargs- the description string format arguments- Returns:
- the generated error response
-
generateInternalErrorResponse
-
addTriggerData
-
createTransaction
Submit a transaction to the blockchain- Parameters:
builder- the API caller for the specific transaction type- Returns:
- the response of the transaction creation
-
createTransaction
Submit a transaction to the blockchain- Parameters:
builder- the API caller for the specific transaction typereduceFeeFromAmount- set to true to reduce the transaction fee from the transaction amount if applicable, false otherwise- Returns:
- the response of the transaction creation
-
createTransaction
public JO createTransaction(APICall.Builder builder, boolean reduceFeeFromAmount, int managedAccountIndex) Submit a transaction to the blockchain by a managed account. AManagedAccountsBundlercan 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 theManagedAccountsBundlerto bundle the transaction.- Parameters:
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 toInteger.MAX_VALUE, the transaction is signed by the contract account- Returns:
- the response of the transaction creation
-
getPhasingAttachment
-
loadContract
Load a contract instance from the blockchain cloud data based on the contract reference name- Parameters:
name- the contract reference name for the contract runner account- Returns:
- an instance of the contract class stored in the blockchain as cloud data
-
getHash
public byte[] getHash(byte[] b) Calculate the SHA-256 hash of a message- Parameters:
b- the message bytes- Returns:
- the hash of the message
-
getHash
Calculate the hash of a message- Parameters:
b- the message bytesalgorithm- the hashing algorithm- Returns:
- the hash of the message
-
getNetworkType
-
sign
Sign a message with an account secret phrase- Parameters:
message- the message bytessecretPhrase- the account secret phrase- Returns:
- the signature bytes
-
verify
public boolean verify(byte[] signature, byte[] message, byte[] publicKey) Verify an account signature- Parameters:
signature- the signature bytesmessage- the message bytespublicKey- the signer account public key- Returns:
- true if the the signature is valid, false otherwise
-
fullHashToId
public long fullHashToId(byte[] fullHash) Convert a 32 byte hash represented as byte array to a numeric entity id- Parameters:
fullHash- the hash represented as byte array- Returns:
- the numeric entity id
-
fullHashToId
Convert a 32 byte hash represented as hex string to a numeric entity id- Parameters:
fullHashStr- the hash represented as hex string- Returns:
- the numeric entity id
-
publicKeyToAccountId
public long publicKeyToAccountId(byte[] publicKey) Convert a public key represented as byte array to a numeric account id- Parameters:
publicKey- the public key represented as byte array- Returns:
- the numeric account id
-
publicKeyToAccountId
Convert a public key represented as hex string to a numeric account id- Parameters:
publicKeyStr- the public key represented as hex string- Returns:
- the numeric account id
-
getChain
Returns the chain object represented by this chain name- Parameters:
name- the chain name- Returns:
- the chain object
-
getChain
Returns the chain object represented by this chain id- Parameters:
id- the chain id- Returns:
- the chain object
-
getParentChain
Returns the parent chain object- Returns:
- the parent chain object
-
parseAccountId
- Parameters:
account- the RS or unsigned long account id- Returns:
- the numeric account id
-
rsAccount
Convert a numeric account id to its Reed Solomon representation- Parameters:
accountId- the numeric account id- Returns:
- the RS account id
-
getBlockchainHeight
public int getBlockchainHeight() -
logInfoMessage
Log a formatted string into the node log file- Parameters:
format- the format stringargs- the format arguments
-
logErrorMessage
Log an exception message and stack trace into the node log file- Parameters:
t- the throwable object
-
parseHexString
Parse hex string into a byte array- Parameters:
hex- the hex string- Returns:
- the byte array
-
toHexString
Convert byte array to hex string- Parameters:
bytes- the byte array- Returns:
- the hex string
-
getPublicKey
Convert secret phrase to public key- Parameters:
secretPhrase- the secret phrase- Returns:
- the public key
-
getPublicKey
public byte[] getPublicKey(byte[] privateKey) Convert private key to public key- Parameters:
privateKey- the secret phrase- Returns:
- the public key
-
isPermissionGranted
Check with the Security Manager if the contract code has a specific permission- Parameters:
permission- the permission to check- Returns:
- true if permission is granted, false otherwise
-
getRuntimeParams
-
getContractSetupParameters
-
getParams
-
setContractSetupParameters
-