Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Update invokefunction.md #1102

Merged
merged 3 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 48 additions & 41 deletions docs/en-us/reference/rpc/latest-version/api/invokefunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,31 @@ Invokes a smart contract with its scripthash based on the specified operation an
## Parameter Description

* scripthash: Smart contract scripthash. You need to use the proper byte order of the address passed according to its data type. If the data type is Hash160, use the big endian scripthash; if the data type is ByteArray, use the little endian scripthash.

* operation: The operation name (string)

* params: The parameters to be passed into the smart contract operation
* cosigners: Add signatures when required.

> [!Note]
>
> You need to use the proper byte order of the address passed according to its data type. If the data type is Hash160, use the big endian script hash; if the data type is ByteArray, use the little endian scripthash.

* checkWitnessHashes: list of contract signature accounts

For example:
You need to use the proper byte order of the address passed according to its data type. If the data type is Hash160, use the big endian script hash; if the data type is ByteArray, use the little endian scripthash.

```json
{
"type": "String",
"value": "Hello"
}
```
For example:

```json
{
"type": "Hash160",
"value": "39e7394d6231aa09c097d02391d5d149f873f12b"
}
```
```json
{
"type": "String",
"value": "Hello"
}

{
"type": "Hash160",
"value": "0xf621168b1fce3a89c33a5f6bcf7e774b4657031c"
}

{
"type": "ByteArray",
"value": "7472616e73666572"
}
```

## Example

Expand All @@ -47,23 +46,28 @@ Request body:
"id": 1,
"method": "invokefunction",
"params": [
"0x806b7fa0db3b46d6c42e1e1b0a7fd50db9d4a9b0",
"0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc",
"transfer",
[
{
"type": "Hash160",
"value": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"
},
"type":"Hash160",
"value":"0xf621168b1fce3a89c33a5f6bcf7e774b4657031c"
},
{
"type": "Hash160",
"value": "0x2916eba24e652fa006f3e5eb8f9892d2c3b00399"
},
"type":"Hash160",
"value":"0x1f177332c467db9ba734d3ca85645fbadd7e13e3"
},
{
"type": "Integer",
"value": "1000"
}
"type":"Integer",
"value":"8"
}
],
["0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"]
[
{
"account": "0xf621168b1fce3a89c33a5f6bcf7e774b4657031c",
"scopes": "CalledByEntry"
}
]
]
}
```
Expand All @@ -75,15 +79,16 @@ Response body:
"jsonrpc": "2.0",
"id": 1,
"result": {
"script": "1a0c149903b0c3d292988febe5f306a02f654ea2eb16290c146925aa554712439a9c613ba114efa3fac23ddbca13c00c087472616e736665720c14b0a9d4b90dd57f0a1b1e2ec4d6463bdba07f6b8041627d5b52",
"script": "180c14e3137eddba5f6485cad334a79bdb67c43273171f0c141c0357464b777ecf6b5f3ac3893ace1f8b1621f613c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b52",
"state": "HALT",
"gas_consumed": "9413130",
"gasconsumed": "9007960",
"stack": [
{
"type": "Integer",
"value": "1"
"type": "Boolean",
"value": true
}
]
],
"tx": "0005d16e331c0357464b777ecf6b5f3ac3893ace1f8b1621f658738900000000001e47130000000000a81f200001011c0357464b777ecf6b5f3ac3893ace1f8b1621f60154180c14e3137eddba5f6485cad334a79bdb67c43273171f0c141c0357464b777ecf6b5f3ac3893ace1f8b1621f613c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b5201420c40de4c406084b738675c42519643018748215cf9de3ef9c6ec40eecf70b403250a2dddca6045e020bf713503c649ba4df0ff6cfc39459fb26929c0699aebcb0a0c290c210222d8515184c7d62ffa99b829aeb4938c4704ecb0dd7e340e842e9df1218263430b4195440d78"
}
}
```
Expand All @@ -93,11 +98,11 @@ Response description:
- script: the invocation script of the contract. By reference to [OpCodeConverter](https://github.com/chenzhitong/OpCodeConverter) you can convert the script to the following OpCode (NeoVM is a stack-based virtual machine that executes from bottom to top when executing):

```
PUSHINT16 1000
PUSHDATA1 0x2916eba24e652fa006f3e5eb8f9892d2c3b00399
PUSHDATA1 0xcadb3dc2faa3ef14a13b619c9a43124755aa2569
PUSHINT16 8
PUSHDATA1 0x1f177332c467db9ba734d3ca85645fbadd7e13e3
PUSHDATA1 0xf621168b1fce3a89c33a5f6bcf7e774b4657031c
PUSHDATA1 transfer
PUSHDATA1 0x806b7fa0db3b46d6c42e1e1b0a7fd50db9d4a9b0
PUSHDATA1 0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc
SYSCALL System.Contract.Call
```

Expand All @@ -107,7 +112,9 @@ Response description:

- stack: the contract execution result. If the value is String or ByteArray, it is encoded by Base64.

- tx: It defaults to null and returns the constructed transaction (i.e. the hexadecimal string of the contract invocation transaction) when the proper signature is passed to the wallet. The transaction can be sent to the blockchain with [sendrawtransaction](sendrawtransaction.md).

> [!Note]
>
> After entering the `invokefunction` command, the node invokes the `main` method of the contract rather than directly invokes the `operation` method, and pass `operation` and `params` as arguments. If `operation` and `params` are not processed in the `main` method, the expected result cannot be returned.
> The `invokefunction` command invokes the `operation` method and pass `params` as arguments. If `operation` is not found in the contract abi file, the expected result cannot be returned.

31 changes: 21 additions & 10 deletions docs/en-us/reference/rpc/latest-version/api/invokescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Returns the result after passing a script through the VM.

### Parameter Description

- script: A script runnable in the VM. This is the same script that is carried in InvocationTransaction
- checkWitnessHashes: List of contact signature accounts.
- script: A script runnable in the VM. Refer to the script in the [invokefunction](invokefunction.md) response body.
- cosigners: Add signatures when required.

## Example

Expand All @@ -19,9 +19,20 @@ Request body:
```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "invokescript",
"params": ["0c142bf173f849d1d59123d097c009aa31624d39e73911c00c0962616c616e63654f660c14897720d8cd76f4f00abfa37c0edd889c208fde9b41627d5b52",["0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"]],
"id": 3
"params": [ "180c14e3137eddba5f6485cad334a79bdb67c43273171f0c141c0357464b777ecf6b5f3ac3893ace1f8b1621f613c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b52",
[
{
"account": "0xf621168b1fce3a89c33a5f6bcf7e774b4657031c",
"scopes": "CalledByEntry"
},
{
"account": "0xb120f50f804d3a203c43475212894ab1c911ce18",
"scopes": "CalledByEntry"
}
]
]
}
```

Expand All @@ -30,18 +41,18 @@ Response body:
```json
{
"jsonrpc": "2.0",
"id": 3,
"id": 1,
"result": {
"script": "0c142bf173f849d1d59123d097c009aa31624d39e73911c00c0962616c616e63654f660c14897720d8cd76f4f00abfa37c0edd889c208fde9b41627d5b52",
"script": "180c14e3137eddba5f6485cad334a79bdb67c43273171f0c141c0357464b777ecf6b5f3ac3893ace1f8b1621f613c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b52",
"state": "HALT",
"gas_consumed": "2007570",
"gasconsumed": "9007960",
"stack": [
{
"type": "Integer",
"value": "9999885"
"type": "Boolean",
"value": true
}
],
"tx": "004473771e2bf173f849d1d59123d097c009aa31624d39e73900e1f50500000000269f120000000000eae1200000003e0c142bf173f849d1d59123d097c009aa31624d39e73911c00c0962616c616e63654f660c14897720d8cd76f4f00abfa37c0edd889c208fde9b41627d5b5201420c40abc3a8055c64dcfd70a922cf1a09df19f2d6ccb0b4dacf24612cd40ebab3ab0bf591dd159783c06f187088fb277cde15e8baee0ebc8c3953df22f435215c3421290c2103b9c46c6d5c671ef5c21bc7aa7c30468aeb081a2e3895269adf947718d650ce1e0b410a906ad4"
"tx": "0044381e331c0357464b777ecf6b5f3ac3893ace1f8b1621f658738900000000009c8a2400000000000020200002011c0357464b777ecf6b5f3ac3893ace1f8b1621f6010118ce11c9b14a89125247433c203a4d800ff520b10154180c14e3137eddba5f6485cad334a79bdb67c43273171f0c141c0357464b777ecf6b5f3ac3893ace1f8b1621f613c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b5202420c40d26e1bd8588a54b1537b058a1bd0dfc7580662ab277edba02bbcca2aaa70d1a6fce23d6c5140a23d2fdb5d4a35b0cb26c1ea4f01c87b6dc896f15e2b241b2ec7290c21028bd1902c4d1419f002b821e6de653ddfd5358063208e426756398be6ffa3aac80b4195440d78420c40aa0cba50fc14584ed81ef6bb24b2e78f1fa1aff4bdc2825b4392d3d0f5bf9ec4d0a34361e3463eed25d0ab888de00a538d938769df53ca5993fcbed4aa2df793290c210222d8515184c7d62ffa99b829aeb4938c4704ecb0dd7e340e842e9df1218263430b4195440d78"
}
}
```
78 changes: 43 additions & 35 deletions docs/zh-cn/reference/rpc/latest-version/api/invokefunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

> [!Note]
>
> - 此方法用于测试你的虚拟机脚本,如同在区块链上运行一样。这个RPC调用对区块链没有任何影响
> - 此方法用于测试你的虚拟机脚本,调用时只是在 RPC 对应的节点试运行脚本并返回结果,不会对区块链数据产生影响
> - 此方法由插件提供,需要安装 [RpcServer](https://github.com/neo-project/neo-modules/releases) 插件才可以调用

## 参数说明
Expand All @@ -15,25 +15,26 @@

- params:传递给智能合约操作的参数。

> [!Note]
>
> 注意你需要根据传入地址的数据类型,使用正确的字节序格式。如果数据类型为 Hash160,输入大端序 scripthash;如果数据类型为 ByteArray,则输入小端序 scripthash。
- cosigners:需要添加的签名列表,如不需要签名,无需传递此参数。

- checkWitnessHashes: 合约签名账户列表
注意你需要根据传入地址的数据类型,使用正确的字节序格式。如果数据类型为 Hash160,输入大端序 scripthash;如果数据类型为 ByteArray,则输入小端序 scripthash

例如:
例如:

```json
{
"type": "String",
"value": "Hello"
}
```

```json
{
"type": "Hash160",
"value": "39e7394d6231aa09c097d02391d5d149f873f12b
"value": "0xf621168b1fce3a89c33a5f6bcf7e774b4657031c"
}

{
"type": "ByteArray",
"value": "7472616e73666572"
}
```

Expand All @@ -47,23 +48,28 @@
"id": 1,
"method": "invokefunction",
"params": [
"0x806b7fa0db3b46d6c42e1e1b0a7fd50db9d4a9b0",
"0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc",
"transfer",
[
{
"type": "Hash160",
"value": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"
},
"type":"Hash160",
"value":"0xf621168b1fce3a89c33a5f6bcf7e774b4657031c"
},
{
"type": "Hash160",
"value": "0x2916eba24e652fa006f3e5eb8f9892d2c3b00399"
},
"type":"Hash160",
"value":"0x1f177332c467db9ba734d3ca85645fbadd7e13e3"
},
{
"type": "Integer",
"value": "1000"
}
"type":"Integer",
"value":"8"
}
],
["0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"]
[
{
"account": "0xf621168b1fce3a89c33a5f6bcf7e774b4657031c",
"scopes": "CalledByEntry"
}
]
]
}
```
Expand All @@ -75,15 +81,16 @@
"jsonrpc": "2.0",
"id": 1,
"result": {
"script": "1a0c149903b0c3d292988febe5f306a02f654ea2eb16290c146925aa554712439a9c613ba114efa3fac23ddbca13c00c087472616e736665720c14b0a9d4b90dd57f0a1b1e2ec4d6463bdba07f6b8041627d5b52",
"script": "180c14e3137eddba5f6485cad334a79bdb67c43273171f0c141c0357464b777ecf6b5f3ac3893ace1f8b1621f613c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b52",
"state": "HALT",
"gas_consumed": "9413130",
"gasconsumed": "9007960",
"stack": [
{
"type": "Integer",
"value": "1"
"type": "Boolean",
"value": true
}
]
],
"tx": "0005d16e331c0357464b777ecf6b5f3ac3893ace1f8b1621f658738900000000001e47130000000000a81f200001011c0357464b777ecf6b5f3ac3893ace1f8b1621f60154180c14e3137eddba5f6485cad334a79bdb67c43273171f0c141c0357464b777ecf6b5f3ac3893ace1f8b1621f613c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b5201420c40de4c406084b738675c42519643018748215cf9de3ef9c6ec40eecf70b403250a2dddca6045e020bf713503c649ba4df0ff6cfc39459fb26929c0699aebcb0a0c290c210222d8515184c7d62ffa99b829aeb4938c4704ecb0dd7e340e842e9df1218263430b4195440d78"
}
}
```
Expand All @@ -92,19 +99,20 @@

- script:合约的调用脚本,参考 [OpCodeConverter](https://github.com/chenzhitong/OpCodeConverter) 项目,可以将脚本转为如下OpCode(NeoVM 是基于栈的虚拟机,执行时从下向上执行):

```
PUSHINT16 1000
PUSHDATA1 0x2916eba24e652fa006f3e5eb8f9892d2c3b00399
PUSHDATA1 0xcadb3dc2faa3ef14a13b619c9a43124755aa2569
PUSHDATA1 transfer
PUSHDATA1 0x806b7fa0db3b46d6c42e1e1b0a7fd50db9d4a9b0
SYSCALL System.Contract.Call
```

```
PUSHINT16 8
PUSHDATA1 0x1f177332c467db9ba734d3ca85645fbadd7e13e3
PUSHDATA1 0xf621168b1fce3a89c33a5f6bcf7e774b4657031c
PUSHDATA1 transfer
PUSHDATA1 0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc
SYSCALL System.Contract.Call
```
- state:虚拟机状态, `HALT` 表示虚拟机执行成功,`FAULT` 表示虚拟机执行时遇到异常退出。
- gas_consumed:调用智能合约时消耗的系统手续费。
- stack:合约执行结果,其中 value 如果是字符串或 ByteArray,则是 Base64 编码后的结果。
- tx:默认为 null,当打开钱包并传入正确的签名时会返回构造好的交易,即本次调用合约交易的 16 进制字符串,该交易可以直接使用 [sendrawtransaction](sendrawtransaction.md) 接口发送至链上。

> [!Note]
>
> 当输入 invokefunction 命令后,节点并不是直接调用合约中的 `operation` 方法。而是调用该合约的 `main` 方法,并将 `operation` 和 `params` 作为实参传入。如果 main 方法里没有对 `operation` 和 `params` 做处理,将不能返回预期的结果。
> invokefunction 命令执行的时候是调用合约的 `operation` 方法,`params` 将作为实参传入。如果合约 abi 里没有对应的 `operation` 方法,将不能返回预期的结果。
Loading