List all deployed contracts/tokens?
Is there a way to get/search/track all deployed custom tokens/smart contracts in a private blockchain ? Is it possible to do it through an RPC command?
I see that there is a ListContracts method in ContractManagement class, but I was not able to find a way to use/call it from a remote client.
get/search
NeoGo allows to iterate over contract IDs with getcontractstate (https://github.com/nspcc-dev/neo-go/blob/41613cd631e662dab1791adc306f53faddb17b89/docs/rpc.md#getcontractstate), but you don't reliably know where to stop. Still, it's possible and then you can look into manifested standards (but neo-project/neo#1883, so additional checks are needed).
findstates can probably be used as well, though that'd be a bit more involved.
track
Deploy notifications are emitted from ContractManagement contract for every deployment (see Update and Destroy also).
Is there a problem to add a ListContracts method to RpcServer, which uses the one that is already available in ContractManagement?
findstatescan probably be used as well, though that'd be a bit more involved.
To elaborate a bit on the steps, as I recently needed this myself, and is probably going to take some time to get accepted (if at all).
- Get the chain height using the getblockcount RPC method
- Get the stateroot using the height from
1.using the getstateroot RPC method - Call the findstates RPC method with
{
"jsonrpc": "2.0",
"method": "findstates",
"params": ["<your_state_root_here>","0xfffdc93764dbaddd97c48f252a53ea4643faa3fd","CA=="],
"id": 1
}
- iterate over results
a. base64decode the
valuefield b. deserialize the result using binaryserializer to get a stackitem c. feed the stackitem fromb.into this method to get the contract state from which you can access the manifest and NEF. - check if
truncatedistrue, if so take the lastkeyfrom the results and append it as the 4th argument to theparamsfield to get the next page of results
As I mentioned in my question, there is already a native method ListContracts. It can be just exposed as a RPC method. It returns all registered contracts (including native ones) and could also have some filter options.
If i were to implement "FindContractLog" in RPC for #807 you would be able to do a search for "Deploy" event on the ContractManagement (0xfffdc93764dbaddd97c48f252a53ea4643faa3fd), than page through looking for a contract. But who knows when that will come out.
The ContractManagement returns an iterator for all hashes that are non-native with GetContractHashes.
However, I think that there could be other methods more directed to this on the RPC calls themself.
This would require you to get all contracts and on the blockchain. Check for Nep-17, Nep-11 in the supportedStandards property of the contract manifest. Then you can invoke the virtual machine to get it's standards. Like symbol decimals balanceOf for example. This last step isn't necessary, but it also depends on how confident you want to be that the contract does indeed follow the specification.