From 4b0cdbc03c0dc3b643c01875607b0ede0787785e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Fri, 29 Mar 2024 18:08:41 +0800 Subject: [PATCH 1/3] Create GetContractById.md --- .../ContractManagement/GetContractById.md | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md diff --git a/docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md b/docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md new file mode 100644 index 000000000..4a8469d74 --- /dev/null +++ b/docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md @@ -0,0 +1,77 @@ +# ContractManagement.GetContractById Method + +Maps specified ID to deployed contract. + +Namespace: [Neo.SmartContract.Framework.Native](../../native.md) + +Assembly: Neo.SmartContract.Framework + +## Syntax + +```c# +public ContractState GetContractById(int id); +``` + +Parameters: + +- id: Contract ID. Negative numbers represent native contracts, positive numbers represent normal contracts. + +## Example + +Contract: + +```c# +public class Contract1 : SmartContract +{ + public static string MyMethod(int id) + { + var contract = ContractManagement.GetContractById(id); + return contract.Manifest.Name; + } +} +``` + +Invoke from neo-cli + +``` +invoke 0x425d355a8a62eebf961884c91c6567d3ff1ab0dc myMethod [{"type":"Integer","value":"-1"}] +``` + +Invoke from RPC + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "method": "invokefunction", + "params": [ + "0x425d355a8a62eebf961884c91c6567d3ff1ab0dc", + "myMethod", + [ + { + "type": "Integer", + "value": "-1" + } + ] + ] +} +``` + +Response body: + +```json +[ + { + "type":"ByteString", + "value":"Q29udHJhY3RNYW5hZ2VtZW50" + } +] +``` + +Response description: + +According to the contract code, the name of the contract corresponding to the requested contract ID is returned here. + +The string `Q29udHJhY3RNYW5hZ2VtZW50`, when decoded with base64, yields `ContractManagement`. + +[Back](../ContractManagement.md) \ No newline at end of file From dbd67944d7c542a4a771f693c6983a3db5acfaab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Mon, 1 Apr 2024 10:26:28 +0800 Subject: [PATCH 2/3] GetContractHashes --- .../ContractManagement/GetContractById.md | 2 +- .../ContractManagement/getContractHashes.md | 157 ++++++++++++++++++ 2 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 docs/en-us/reference/scapi/framework/native/ContractManagement/getContractHashes.md diff --git a/docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md b/docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md index 4a8469d74..03249f270 100644 --- a/docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md +++ b/docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md @@ -14,7 +14,7 @@ public ContractState GetContractById(int id); Parameters: -- id: Contract ID. Negative numbers represent native contracts, positive numbers represent normal contracts. +- id: Contract ID. Negative numbers represent native contracts, positive numbers represent normal contracts (non native deployed contracts). ## Example diff --git a/docs/en-us/reference/scapi/framework/native/ContractManagement/getContractHashes.md b/docs/en-us/reference/scapi/framework/native/ContractManagement/getContractHashes.md new file mode 100644 index 000000000..bd573a30a --- /dev/null +++ b/docs/en-us/reference/scapi/framework/native/ContractManagement/getContractHashes.md @@ -0,0 +1,157 @@ +# ContractManagement.GetContractById Method + +Gets hashes of all non native deployed contracts. + +Namespace: [Neo.SmartContract.Framework.Native](../../native.md) + +Assembly: Neo.SmartContract.Framework + +## Syntax + +```c# +private IIterator GetContractHashes() +``` + +Return: + +Iterator with hashes of all deployed contracts. + +## Example + +Contract: + +```c# +public static Iterator<(int, UInt160)> MyMethod() +{ + return ContractManagement.GetContractHashes(); +} +``` + +Invoke from RPC + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "method": "invokefunction", + "params": [ + "0xc04ff111aa88cc5239cf36360cb298a9a3eae586", + "myMethod", + [] + ] +} +``` + +Response body: + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "script": "wh8MCG15TWV0aG9kDBSG5eqjqZiyDDY2zzlSzIiqEfFPwEFifVtS", + "state": "HALT", + "gasconsumed": "2950200", + "exception": null, + "notifications": [], + "stack": [ + { + "type": "InteropInterface", + "interface": "IIterator", + "id": "0cd0591b-cf5a-4517-a060-779269f3577d" + } + ], + "session": "4829327b-8c1d-439e-becc-1360453839f6" + } +} +``` + +Invoke agaim from RPC to get the specific value of the Iterator. + +For more information on how to get the specific value of iterator, please refer to the command [traverseiterator](../../../../rpc/latest-version/api/traverseiterator.md). + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "method": "traverseiterator", + "params": [ + "4829327b-8c1d-439e-becc-1360453839f6", + "0cd0591b-cf5a-4517-a060-779269f3577d", + 10 + ] +} +``` + +Response body: + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "result": [ + { + "type": "Struct", + "value": [ + { + "type": "ByteString", + "value": "AAAAAQ==" + }, + { + "type": "ByteString", + "value": "3LAa/9NnZRzJhBiWv+5iilo1XUI=" + } + ] + }, + { + "type": "Struct", + "value": [ + { + "type": "ByteString", + "value": "AAAAAg==" + }, + { + "type": "ByteString", + "value": "gwlF8xm/6snmJCfRzDiaIiu40pI=" + } + ] + }, + { + "type": "Struct", + "value": [ + { + "type": "ByteString", + "value": "AAAAAw==" + }, + { + "type": "ByteString", + "value": "oDlHkjZPmX2hcY9E7b0Wdwwoxa8=" + } + ] + }, + { + "type": "Struct", + "value": [ + { + "type": "ByteString", + "value": "AAAABA==" + }, + { + "type": "ByteString", + "value": "huXqo6mYsgw2Ns85UsyIqhHxT8A=" + } + ] + } + ] +} +``` + +Response description: + +Each element of the returned array is a contract message containing the contract's ID and Hash. + +Base64 string `AAAABA==` to hexadecimal string is `00000004`. + +Base64 script hash `huXqo6mYsgw2Ns85UsyIqhHxT8A=` to script hash (little-endian) is `86e5eaa3a998b20c3636cf3952cc88aa11f14fc0`. + +[Back](../ContractManagement.md) \ No newline at end of file From e1e3f3255652fe643a1b966dc4de82254f264f43 Mon Sep 17 00:00:00 2001 From: Celia18305 Date: Mon, 1 Apr 2024 15:19:57 +0800 Subject: [PATCH 3/3] make minor corrects --- .../native/ContractManagement/GetContractById.md | 13 +++++++------ .../native/ContractManagement/getContractHashes.md | 10 ++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md b/docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md index 03249f270..27d5d73ed 100644 --- a/docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md +++ b/docs/en-us/reference/scapi/framework/native/ContractManagement/GetContractById.md @@ -1,6 +1,6 @@ # ContractManagement.GetContractById Method -Maps specified ID to deployed contract. +Maps the specified ID to the deployed contract. Namespace: [Neo.SmartContract.Framework.Native](../../native.md) @@ -14,7 +14,7 @@ public ContractState GetContractById(int id); Parameters: -- id: Contract ID. Negative numbers represent native contracts, positive numbers represent normal contracts (non native deployed contracts). +- id: Contract ID. Negative numbers represent native contracts, while positive numbers represent normal contracts (non-native deployed contracts). ## Example @@ -31,13 +31,13 @@ public class Contract1 : SmartContract } ``` -Invoke from neo-cli +Invoke from neo-cli: ``` invoke 0x425d355a8a62eebf961884c91c6567d3ff1ab0dc myMethod [{"type":"Integer","value":"-1"}] ``` -Invoke from RPC +Invoke from RPC: ```json { @@ -70,8 +70,9 @@ Response body: Response description: -According to the contract code, the name of the contract corresponding to the requested contract ID is returned here. +According to the contract code, the contract name associated with the requested ID is returned here. The string `Q29udHJhY3RNYW5hZ2VtZW50`, when decoded with base64, yields `ContractManagement`. -[Back](../ContractManagement.md) \ No newline at end of file +[Back](../ContractManagement.md) + diff --git a/docs/en-us/reference/scapi/framework/native/ContractManagement/getContractHashes.md b/docs/en-us/reference/scapi/framework/native/ContractManagement/getContractHashes.md index bd573a30a..4229b0311 100644 --- a/docs/en-us/reference/scapi/framework/native/ContractManagement/getContractHashes.md +++ b/docs/en-us/reference/scapi/framework/native/ContractManagement/getContractHashes.md @@ -1,6 +1,6 @@ # ContractManagement.GetContractById Method -Gets hashes of all non native deployed contracts. +Gets the hashes of all non-native deployed contracts. Namespace: [Neo.SmartContract.Framework.Native](../../native.md) @@ -27,7 +27,7 @@ public static Iterator<(int, UInt160)> MyMethod() } ``` -Invoke from RPC +Invoke from RPC: ```json { @@ -66,9 +66,7 @@ Response body: } ``` -Invoke agaim from RPC to get the specific value of the Iterator. - -For more information on how to get the specific value of iterator, please refer to the command [traverseiterator](../../../../rpc/latest-version/api/traverseiterator.md). +Invoke again from RPC to get the specific value of the iterator. For more information, refer to the command [traverseiterator](../../../../rpc/latest-version/api/traverseiterator.md). ```json { @@ -148,7 +146,7 @@ Response body: Response description: -Each element of the returned array is a contract message containing the contract's ID and Hash. +Each element of the returned array is a contract message containing the contract ID and Hash. Base64 string `AAAABA==` to hexadecimal string is `00000004`.