Skip to content

Commit

Permalink
add: description of json-rpc and extrinsic methods (#635)
Browse files Browse the repository at this point in the history
Co-authored-by: AndrePanin <ap@gear-tech.io>
  • Loading branch information
osipov-mit and AndrePanin committed Mar 15, 2024
1 parent 89a5b12 commit 701a27d
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 1 deletion.
76 changes: 76 additions & 0 deletions docs/api/extrinsics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
sidebar_position: 13
sidebar_label: Extrinsics
---

# Extrinsics

Gear provides a set of extrinsics to interact with the Gear pallets.

The extrinsics of other pallets used in the chain are also available and can be found in the [Substrate Extrinsics documentation](https://polkadot.js.org/docs/substrate/extrinsics).

`author_submitExtrinsic` method is used to submit an extrinsic to the chain.

## Gear pallets methods

### Save program's `code` in storage

- summary: The method saves the program's `code` in storage, which can later be used to initialize the program from it.
- struct: `uploadCode(code: Bytes)`
- gear-js/api method: `api.code.upload`

### Program init in the same block

- summary: Creates program initialization request (message), that is scheduled to be run in the same block.
- struct: `uploadProgram(code: Bytes, salt: Bytes, init_payload: Bytes, gas_limit: u64, value: u128, keep_alive: bool)`
- gear-js/api method: `api.program.upload`

### Create program from `code`

- summary: Creates program via `code_id` from storage.
- struct: `createProgram(code_id: H256, salt: Bytes, init_payload: Bytes, gas_limit: u64, value: u128, keep_alive: bool)`
- gear-js/api method: `api.program.create`

### Send message

- struct: `sendMessage(destination: H256, payload: Bytes, gas_limit: u64, value: u128, keep_alive: bool)`
- summary: Sends a message to a program or to another account.
- gear-js/api method: `api.message.send`

### Send reply

- struct: `sendReply(reply_to_id: H256, payload: Bytes, gas_limit: u64, value: u128, keep_alive: bool)`
- summary: Sends a reply to a message in the `Mailbox`.
- gear-js/api method: `api.message.sendReply`

### Claim value from message

- struct: `claim_value(message_id: H256)`
- summary: Claims value from a message in the `Mailbox`.
- gear-js/api method: `api.mailbox.claimValue.submit`

## Gear Voucher

### Issue a new voucher

- struct: `issue(spender: H256, balance: u128, programs: Option<BTreeSet<ProgramId>>, code_uploading: bool, duration: BlockNumber)`
- summary: Issues a new voucher at the spender's expense to be used in a specific program.
- gear-js/api method: `api.voucher.issue`

### Execute prepaid call with given voucher

- struct: `call(voucher_id: H256, call: PrepaidCall<BalanceOf>)`
- summary: Execute prepaid call with given voucher id.
- gear-js/api method: `api.voucher.call`

### Revoke voucher

- struct: `revoke(spender: H256, voucher_id: H256)`
- summary: Revokes an existing voucher.
- gear-js/api method: `api.voucher.revoke`

### Update voucher

- struct: `update(spender: AccountId, voucher_id: VoucherId, move_ownership: Option<AccountId>, balance_top_up: Option<BalanceOf>, append_programs: Option<Option<BTreeSet<ProgramId>>>, code_uploading: Option<bool>, prolong_duration: Option<BlockNumber>)`
- summary: Updates an existing voucher.
- gear-js/api method: `api.voucher.update`
61 changes: 61 additions & 0 deletions docs/api/json-rpc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
sidebar_position: 12
sidebar_label: JSON-RPC methods
---

# JSON-RPC methods

Gear provides a set of JSON-RPC methods to interact with Gear pallets.

The JSON-RPC methods of other pallets used in the chain are also available and can be found in the [Substrate JSON-RPC documentation](https://polkadot.js.org/docs/substrate/rpc).

## Gear pallets

### Calculate gas for Init message (upload_program extrinsic)

- summary: The method allows to calculate gas for Init message (upload_program extrinsic)
- method name: `gear_calculateGasForUpload`
- structure: `calculateGasForUpload(source: H256, code: Vec<u8>, payload: Vec<u8>, value: u128, allow_other_panics: bool): GasInfo`
- gear-js/api method: `api.program.calculateGas.initUpload`

### Calculate gas for Init message (create_program extrinsic)

- summary: The method allows to calculate gas for Init message (create_program extrinsic)
- method name: `gear_calculateGasForCreate`
- structure: `calculateGasForCreate(source: H256, codeId: H256, payload: Vec<u8>, value: u128, allow_other_panics: bool): GasInfo`
- gear-js/api method: `api.program.calculateGas.initCreate`

### Calculate gas for Handle message (send_message extrinsic)

- summary: The method allows to calculate gas for Handle message (send_message extrinsic)
- method name: `gear_calculateGasForHandle`
- structure: `calculateGasForHandle(source: H256, destination: H256, payload: Vec<u8>, value: u128, allow_other_panics: bool): GasInfo`
- gear-js/api method: `api.program.calculateGas.handle`

### Calculate gas for Reply message (send_reply extrinsic)

- summary: The method allows to calculate gas for Reply message (send_reply extrinsic)
- method name: `gear_calculateGasForReply`
- structure: `calculateGasForReply(source: H256, message_id: H256, payload: Vec<u8>, value: u128, allow_other_panics: bool): GasInfo`
- gear-js/api method: `api.program.calculateGas.reply`

### Read the metahash of a program metadata

- summary: The method allows to read the metahash of a program metadata
- method name: `gear_readMetahash`
- structure: `readMetahash(program_id: H256, at: Option<BlockHash>): H256`
- gear-js/api method: `api.program.metaHash`

### Read the state of a program

- summary: The method allows to read the state of a program
- method name: `gear_readState`
- structure: `readState(program_id: H256, payload: Vec<u8>, at: Option<BlockHash>): Bytes`
- gear-js/api method: `api.program.readState`

### Сollect reply details

- summary: The method allows to run queue with the message to collect reply details: payload, value and reply code.
- method name: `gear_calculateReplyForHandle`
- structure: `calculateReplyForHandle(origin: H256, destination: H256, payload: Vec<u8>, gas_limit: u64, value: u128, at: Option<BlockHash>): ReplyInfo`
- gear-js/api method: `api.message.calculateReply`
2 changes: 1 addition & 1 deletion docs/api/tooling/_category_.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"label": "Gear-JS tools",
"position": 12
"position": 14
}

0 comments on commit 701a27d

Please sign in to comment.