Skip to main content
Ame Component is an onchain component based on EIP-7654 that decomposes complex onchain processes into independent, composable, reusable, and highly adaptable functional units.

Rationale

Type of request method

In order to enable the client to operate the contract in a standardized and predictable way, three request method types GET, POST, and PUT are set. The functions of each need to be defined in these three types to facilitate the contract caller to understand and process the information required for the request. However, there is no DELETE operation type because deleting data in the contract is an inefficient operation. Developers can add a PUT request method by themselves to set the data to be valid and invalid, and only return valid data in the GET method.

Request method parameter type

Some functions are defined in each request method type. They all include request parameter data type and response parameter data type, which need to be set in the constructor and then obtained according to the method name through getMethodReqAndRes. The data type of the parameter is defined by the enumeration of the data type. When processing the request parameter, abi.decode is used to decode according to the request parameter type and the request value. When returning the response, abi.encode is used to encode according to the response value and the response parameter type. In addition, we can get the method usage instructions by calling getMethodInstruction.

Interface

IComponent.sol
The library Types.sol contains an enumeration of Solidity types used in the above interfaces.
Types.sol

Specifications

  • getMethods Get method names based on request method type.
  • getMethodReqAndRes Get the data types of request parameters and return parameters based on the requested method name.
  • getMethodInstruction Get the instruction of method.
  • get Request the contract to retrieve records.
  • post Request the contract to create a new record.
  • put Request the contract to update a record.
  • options Supported request method types.
The methodRequests and methodResponses are used to define the request parameter type and response data type of Method. Types.sol is a data type Library, which contains all data types of solidity.
Method Types has 4 request types, GET, POST, PUT, OPTIONS. methods is used to store the method name array of each request type.
instructions is used to store method instructions
The options function will return the request method type supported by the component.
The setMethod is used to set the request parameter type and response data type of the method.
The getMethods returns the response method names according to the request type.
The getMethodReqAndRes is used to obtain the request parameter type and response value type of the method based on the method name.
The getMethodInstruction is used to query the usage of method.
Implement the functions of each method in get, post, and put .

Workflow

Component Workflow Pn
1

options

Call options to obtain supported request method types.
2

getMethods

Call getMethods to obtain the request method name.
3

getMethodInstruction

Call getMethodInstruction to obtain the request method instruction.
4

getMethodReqAndRes

Call getMethodReqAndRes to obtain the request parameter data type and response value data type.
5

Encode

Encode request parameters and call get, post, and put.
6

Decode

Decode response value.