java.lang.Object
tech.deplant.java4ever.binding.Abi
Abi
Contains methods of "abi" module of EVER-SDK API
Provides message encoding and decoding according to the ABI specification.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static final record
static final record
static enum
static final record
static final record
static final record
static final record
static enum
static final record
static final record
static final record
Includes several hidden function parameters that contract uses for security, message delivery monitoring and replay protection reasons.static enum
static interface
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static final record
static interface
static final record
static interface
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Abi.ResultOfAttachSignature
Combines `hex`-encoded `signature` with `base64`-encoded `unsigned_message`.attachSignatureToMessageBody
(Context ctx, Abi.ABI abi, String publicKey, String message, String signature) static Abi.ResultOfCalcFunctionId
calcFunctionId
(Context ctx, Abi.ABI abi, String functionName, Boolean output) Calculates contract function ID by contract ABIdecodeAccountData
(Context ctx, Abi.ABI abi, String data, Boolean allowPartial) Note: this feature requires ABI 2.1 or higher.static Abi.ResultOfDecodeBoc
decodeBoc
(Context ctx, Abi.AbiParam[] params, String boc, Boolean allowPartial) Solidity functions use ABI types for [builder encoding](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/API.md#tvmbuilderstore).decodeInitialData
(Context ctx, Abi.ABI abi, String data, Boolean allowPartial) Decodes initial values of a contract's static variables and owner's public key from account initial data This operation is applicable only for initial account data (before deploy).static Abi.DecodedMessageBody
decodeMessage
(Context ctx, Abi.ABI abi, String message, Boolean allowPartial, String functionName, Abi.DataLayout dataLayout) Decodes message body using provided message BOC and ABI.static Abi.DecodedMessageBody
decodeMessageBody
(Context ctx, Abi.ABI abi, String body, Boolean isInternal, Boolean allowPartial, String functionName, Abi.DataLayout dataLayout) Decodes message body using provided body BOC and ABI.static Abi.ResultOfEncodeAccount
encodeAccount
(Context ctx, Abi.StateInitSource stateInit, Long balance, Long lastTransLt, Integer lastPaid, Boc.BocCacheType bocCache) Creates account state provided with one of these sets of data : 1.static Abi.ResultOfAbiEncodeBoc
encodeBoc
(Context ctx, Abi.AbiParam[] params, Map<String, Object> data, Boc.BocCacheType bocCache) Encodes given parameters in JSON into a BOC using param types from ABI.encodeInitialData
(Context ctx, Abi.ABI abi, Map<String, Object> initialData, String initialPubkey, Boc.BocCacheType bocCache) This function is analogue of `tvm.buildDataInit` function in Solidity.encodeInternalMessage
(Context ctx, Abi.ABI abi, String address, String srcAddress, Abi.DeploySet deploySet, Abi.CallSet callSet, String value, Boolean bounce, Boolean enableIhr) Allows to encode deploy and function call messages.static Abi.ResultOfEncodeMessage
encodeMessage
(Context ctx, Abi.ABI abi, String address, Abi.DeploySet deploySet, Abi.CallSet callSet, Abi.Signer signer, Integer processingTryIndex, Integer signatureId) Allows to encode deploy and function call messages, both signed and unsigned.encodeMessageBody
(Context ctx, Abi.ABI abi, Abi.CallSet callSet, Boolean isInternal, Abi.Signer signer, Integer processingTryIndex, String address, Integer signatureId) Encodes message body according to ABI function call.static Abi.ResultOfGetSignatureData
getSignatureData
(Context ctx, Abi.ABI abi, String message, Integer signatureId) Extracts signature from message body and calculates hash to verify the signatureupdateInitialData
(Context ctx, Abi.ABI abi, String data, Map<String, Object> initialData, String initialPubkey, Boc.BocCacheType bocCache) Updates initial account data with initial values for the contract's static variables and owner's public key.
-
Constructor Details
-
Abi
public Abi()
-
-
Method Details
-
encodeMessageBody
public static Abi.ResultOfEncodeMessageBody encodeMessageBody(Context ctx, Abi.ABI abi, Abi.CallSet callSet, Boolean isInternal, Abi.Signer signer, Integer processingTryIndex, String address, Integer signatureId) throws EverSdkException Encodes message body according to ABI function call.- Parameters:
abi
- Contract ABI.callSet
- Must be specified in non deploy message. In case of deploy message contains parameters of constructor. Function call parameters.isInternal
- True if internal message body must be encoded.signer
- Signing parameters.processingTryIndex
- Used in message processing with retries. Encoder uses the provided try index to calculate message expiration time. Expiration timeouts will grow with every retry. Default value is 0. Processing try index.address
- Since ABI version 2.3 destination address of external inbound message is used in message body signature calculation. Should be provided when signed external inbound message body is created. Otherwise can be omitted. Destination address of the messagesignatureId
- Signature ID to be used in data to sign preparing when CapSignatureWithId capability is enabled- Throws:
EverSdkException
-
attachSignatureToMessageBody
public static Abi.ResultOfAttachSignatureToMessageBody attachSignatureToMessageBody(Context ctx, Abi.ABI abi, String publicKey, String message, String signature) throws EverSdkException - Parameters:
abi
- Contract ABIpublicKey
- Must be encoded with `hex`. Public key.message
- Must be encoded with `base64`. Unsigned message body BOC.signature
- Must be encoded with `hex`. Signature.- Throws:
EverSdkException
-
encodeMessage
public static Abi.ResultOfEncodeMessage encodeMessage(Context ctx, Abi.ABI abi, String address, Abi.DeploySet deploySet, Abi.CallSet callSet, Abi.Signer signer, Integer processingTryIndex, Integer signatureId) throws EverSdkException Allows to encode deploy and function call messages, both signed and unsigned. Use cases include messages of any possible type: - deploy with initial function call (i.e. `constructor` or any other function that is used for some kind of initialization); - deploy without initial function call; - signed/unsigned + data for signing. `Signer` defines how the message should or shouldn't be signed: `Signer::None` creates an unsigned message. This may be needed in case of some public methods, that do not require authorization by pubkey. `Signer::External` takes public key and returns `data_to_sign` for later signing. Use `attach_signature` method with the result signature to get the signed message. `Signer::Keys` creates a signed message with provided key pair. [SOON] `Signer::SigningBox` Allows using a special interface to implement signing without private key disclosure to SDK. For instance, in case of using a cold wallet or HSM, when application calls some API to sign data. There is an optional public key can be provided in deploy set in order to substitute one in TVM file. Public key resolving priority: 1. Public key from deploy set. 2. Public key, specified in TVM file. 3. Public key, provided by signer. Encodes an ABI-compatible message- Parameters:
abi
- Contract ABI.address
- Must be specified in case of non-deploy message. Target address the message will be sent to.deploySet
- Must be specified in case of deploy message. Deploy parameters.callSet
- Must be specified in case of non-deploy message. In case of deploy message it is optional and contains parameters of the functions that will to be called upon deploy transaction. Function call parameters.signer
- Signing parameters.processingTryIndex
- Used in message processing with retries (if contract's ABI includes "expire" header). Encoder uses the provided try index to calculate message expiration time. The 1st message expiration time is specified in Client config. Expiration timeouts will grow with every retry. Retry grow factor is set in Client config: invalid input: '<'.....add config parameter with default value here> Default value is 0. Processing try index.signatureId
- Signature ID to be used in data to sign preparing when CapSignatureWithId capability is enabled- Throws:
EverSdkException
-
encodeInternalMessage
public static Abi.ResultOfEncodeInternalMessage encodeInternalMessage(Context ctx, Abi.ABI abi, String address, String srcAddress, Abi.DeploySet deploySet, Abi.CallSet callSet, String value, Boolean bounce, Boolean enableIhr) throws EverSdkException Allows to encode deploy and function call messages. Use cases include messages of any possible type: - deploy with initial function call (i.e. `constructor` or any other function that is used for some kind of initialization); - deploy without initial function call; - simple function call There is an optional public key can be provided in deploy set in order to substitute one in TVM file. Public key resolving priority: 1. Public key from deploy set. 2. Public key, specified in TVM file. Encodes an internal ABI-compatible message- Parameters:
abi
- Can be None if both deploy_set and call_set are None. Contract ABI.address
- Must be specified in case of non-deploy message. Target address the message will be sent to.srcAddress
- Source address of the message.deploySet
- Must be specified in case of deploy message. Deploy parameters.callSet
- Must be specified in case of non-deploy message. In case of deploy message it is optional and contains parameters of the functions that will to be called upon deploy transaction. Function call parameters.value
- Value in nanotokens to be sent with message.bounce
- Default is true. Flag of bounceable message.enableIhr
- Default is false. Enable Instant Hypercube Routing for the message.- Throws:
EverSdkException
-
attachSignature
public static Abi.ResultOfAttachSignature attachSignature(Context ctx, Abi.ABI abi, String publicKey, String message, String signature) throws EverSdkException Combines `hex`-encoded `signature` with `base64`-encoded `unsigned_message`. Returns signed message encoded in `base64`.- Parameters:
abi
- Contract ABIpublicKey
- Public key encoded in `hex`.message
- Unsigned message BOC encoded in `base64`.signature
- Signature encoded in `hex`.- Throws:
EverSdkException
-
decodeMessage
public static Abi.DecodedMessageBody decodeMessage(Context ctx, Abi.ABI abi, String message, Boolean allowPartial, String functionName, Abi.DataLayout dataLayout) throws EverSdkException Decodes message body using provided message BOC and ABI.- Parameters:
abi
- contract ABImessage
- Message BOCallowPartial
- Flag allowing partial BOC decoding when ABI doesn't describe the full body BOC. Controls decoder behaviour when after decoding all described in ABI params there are some data left in BOC: `true` - return decoded values `false` - return error of incomplete BOC deserialization (default)functionName
- Function name or function id if is known in advance- Throws:
EverSdkException
-
decodeMessageBody
public static Abi.DecodedMessageBody decodeMessageBody(Context ctx, Abi.ABI abi, String body, Boolean isInternal, Boolean allowPartial, String functionName, Abi.DataLayout dataLayout) throws EverSdkException Decodes message body using provided body BOC and ABI.- Parameters:
abi
- Contract ABI used to decode.body
- Message body BOC encoded in `base64`.isInternal
- True if the body belongs to the internal message.allowPartial
- Flag allowing partial BOC decoding when ABI doesn't describe the full body BOC. Controls decoder behaviour when after decoding all described in ABI params there are some data left in BOC: `true` - return decoded values `false` - return error of incomplete BOC deserialization (default)functionName
- Function name or function id if is known in advance- Throws:
EverSdkException
-
encodeAccount
public static Abi.ResultOfEncodeAccount encodeAccount(Context ctx, Abi.StateInitSource stateInit, Long balance, Long lastTransLt, Integer lastPaid, Boc.BocCacheType bocCache) throws EverSdkException Creates account state provided with one of these sets of data : 1. BOC of code, BOC of data, BOC of library 2. TVC (string in `base64`), keys, init params Creates account state BOC- Parameters:
stateInit
- Source of the account state init.balance
- Initial balance.lastTransLt
- Initial value for the `last_trans_lt`.lastPaid
- Initial value for the `last_paid`.bocCache
- The BOC itself returned if no cache type provided Cache type to put the result.- Throws:
EverSdkException
-
decodeAccountData
public static Abi.ResultOfDecodeAccountData decodeAccountData(Context ctx, Abi.ABI abi, String data, Boolean allowPartial) throws EverSdkException Note: this feature requires ABI 2.1 or higher. Decodes account data using provided data BOC and ABI.- Parameters:
abi
- Contract ABIdata
- Data BOC or BOC handleallowPartial
- Flag allowing partial BOC decoding when ABI doesn't describe the full body BOC. Controls decoder behaviour when after decoding all described in ABI params there are some data left in BOC: `true` - return decoded values `false` - return error of incomplete BOC deserialization (default)- Throws:
EverSdkException
-
updateInitialData
public static Abi.ResultOfUpdateInitialData updateInitialData(Context ctx, Abi.ABI abi, String data, Map<String, Object> initialData, String initialPubkey, Boc.BocCacheType bocCache) throws EverSdkExceptionUpdates initial account data with initial values for the contract's static variables and owner's public key. This operation is applicable only for initial account data (before deploy). If the contract is already deployed, its data doesn't contain this data section any more.- Parameters:
abi
- Contract ABIdata
- Data BOC or BOC handleinitialData
- `abi` parameter should be provided to set initial data List of initial values for contract's static variables.initialPubkey
- Initial account owner's public key to set into account databocCache
- Cache type to put the result. The BOC itself returned if no cache type provided.- Throws:
EverSdkException
-
encodeInitialData
public static Abi.ResultOfEncodeInitialData encodeInitialData(Context ctx, Abi.ABI abi, Map<String, Object> initialData, String initialPubkey, Boc.BocCacheType bocCache) throws EverSdkExceptionThis function is analogue of `tvm.buildDataInit` function in Solidity. Encodes initial account data with initial values for the contract's static variables and owner's public key into a data BOC that can be passed to `encode_tvc` function afterwards.- Parameters:
abi
- Contract ABIinitialData
- `abi` parameter should be provided to set initial data List of initial values for contract's static variables.initialPubkey
- Initial account owner's public key to set into account databocCache
- Cache type to put the result. The BOC itself returned if no cache type provided.- Throws:
EverSdkException
-
decodeInitialData
public static Abi.ResultOfDecodeInitialData decodeInitialData(Context ctx, Abi.ABI abi, String data, Boolean allowPartial) throws EverSdkException Decodes initial values of a contract's static variables and owner's public key from account initial data This operation is applicable only for initial account data (before deploy). If the contract is already deployed, its data doesn't contain this data section any more.- Parameters:
abi
- Initial data is decoded if this parameter is provided Contract ABI.data
- Data BOC or BOC handleallowPartial
- Flag allowing partial BOC decoding when ABI doesn't describe the full body BOC. Controls decoder behaviour when after decoding all described in ABI params there are some data left in BOC: `true` - return decoded values `false` - return error of incomplete BOC deserialization (default)- Throws:
EverSdkException
-
decodeBoc
public static Abi.ResultOfDecodeBoc decodeBoc(Context ctx, Abi.AbiParam[] params, String boc, Boolean allowPartial) throws EverSdkException Solidity functions use ABI types for [builder encoding](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/API.md#tvmbuilderstore). The simplest way to decode such a BOC is to use ABI decoding. ABI has it own rules for fields layout in cells so manually encoded BOC can not be described in terms of ABI rules. To solve this problem we introduce a new ABI type `Ref()` which allows to store `ParamType` ABI parameter in cell reference and, thus, decode manually encoded BOCs. This type is available only in `decode_boc` function and will not be available in ABI messages encoding until it is included into some ABI revision. Such BOC descriptions covers most users needs. If someone wants to decode some BOC which can not be described by these rules (i.e. BOC with TLB containing constructors of flags defining some parsing conditions) then they can decode the fields up to fork condition, check the parsed data manually, expand the parsing schema and then decode the whole BOC with the full schema. Decodes BOC into JSON as a set of provided parameters. - Parameters:
params
- Parameters to decode from BOCboc
- Data BOC or BOC handle- Throws:
EverSdkException
-
encodeBoc
public static Abi.ResultOfAbiEncodeBoc encodeBoc(Context ctx, Abi.AbiParam[] params, Map<String, Object> data, Boc.BocCacheType bocCache) throws EverSdkExceptionEncodes given parameters in JSON into a BOC using param types from ABI.- Parameters:
params
- Parameters to encode into BOCdata
- Parameters and values as a JSON structurebocCache
- The BOC itself returned if no cache type provided Cache type to put the result.- Throws:
EverSdkException
-
calcFunctionId
public static Abi.ResultOfCalcFunctionId calcFunctionId(Context ctx, Abi.ABI abi, String functionName, Boolean output) throws EverSdkException Calculates contract function ID by contract ABI- Parameters:
abi
- Contract ABI.functionName
- Contract function nameoutput
- If set to `true` output function ID will be returned which is used in contract response. Default is `false`- Throws:
EverSdkException
-
getSignatureData
public static Abi.ResultOfGetSignatureData getSignatureData(Context ctx, Abi.ABI abi, String message, Integer signatureId) throws EverSdkException Extracts signature from message body and calculates hash to verify the signature- Parameters:
abi
- Contract ABI used to decode.message
- Message BOC encoded in `base64`.signatureId
- Signature ID to be used in unsigned data preparing when CapSignatureWithId capability is enabled- Throws:
EverSdkException
-