Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Record contract id into abi and manifest files. #540

Closed
superboyiii opened this issue Feb 10, 2020 · 9 comments
Closed

Record contract id into abi and manifest files. #540

superboyiii opened this issue Feb 10, 2020 · 9 comments

Comments

@superboyiii
Copy link
Member

superboyiii commented Feb 10, 2020

Now contract id is used to be storage key for smart contract. However if someone wants to get storage content, he has to invoke RPC method [getcontractstate] to get id. This is very inconvenient for developers to test contracts. My advice is to write id as a parameter into abi and manifest files whenever it's successfully deployed. This is much more conveninet.

@shargon
Copy link
Member

shargon commented Feb 10, 2020

It's required only if we want to know it inside the smart contract

@Tommo-L
Copy link
Contributor

Tommo-L commented Feb 10, 2020

It's required only if we want to know it inside the smart contract

Agree, we can convert from scripthash to id in RPC method.

        private JObject GetStorage(JArray _params)
        {
            UInt160 script_hash = UInt160.Parse(_params[0].AsString());
            Int id = GetContractIdByScriptHash(script_hash); // <----   add this line
            byte[] key = _params[1].AsString().HexToBytes();
            StorageItem item = Blockchain.Singleton.View.Storages.TryGet(new StorageKey
            {
                Id = id,
                Key = key
            }) ?? new StorageItem();
            return item.Value?.ToHexString();
         }

@superboyiii
Copy link
Member Author

superboyiii commented Feb 10, 2020

@shargon One example:
I'm a nep5 owner. I have some coin A. One day I want to make transaction on cli. I remember my asset_id was A_xxxx, then I found the old contract was updated and destroyed. Then I ask many people. Some one told me the new asset_id is B_xxxx. Then I make transaction again. I finally find I don't have B on my address. And I ask NGD for help. Finally I found the new asset_id for updated A is C_xxxx. However, if I record the id of coin A's sc at first, I will always know which is my asset. Whatever how many times you update nep5 sc, id is always the unique symbol for contract to help people find where it is.
That's why I think id must be recorded somewhere.

@shargon
Copy link
Member

shargon commented Feb 10, 2020

We can add a new RPC command for get this information

@superboyiii
Copy link
Member Author

getcontractstate can do this.

@shargon
Copy link
Member

shargon commented Feb 10, 2020

getcontractstate can do this.

Then we don't need to change the core, right?

@superboyiii
Copy link
Member Author

I just worry about if a contract was updated and the id was not recorded, how to find the new one.

@doubiliu
Copy link

I think @Tommo-L 's code is enough, it has no impact on the user's use, just adjust the implementation logic of RPC

@superboyiii
Copy link
Member Author

OK, I'll close this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants