Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] [starcoin console] Add comparison for dev call and execute-function #195

Open
0xOutOfGas opened this issue Sep 13, 2022 · 1 comment

Comments

@0xOutOfGas
Copy link

Document Suggestion

Add comparison for dev call and execute-function in the console user guide part.

Describe the Suggestion

I noticed there has two console commands, [dev call] and [account execute-function] can call public functions, but no examples found. I wrote the below move test code, and has a summary, maybe we can add some guide in cookbook.

my starcoin version is 1.11.11.

Test move code:

address A1 {
module M1{
    use StarcoinFramework::Debug;
    //use StarcoinFramework::Account;
    use StarcoinFramework::Signer;

    // a resource
    struct Counter has key {
        value: u64,
    }

    // no operation on global storage
    public fun init_counter(a: u64): Counter {
        return Counter{value: a}
    }

    // no operation on global storage
    public(script) fun init_script_counter(a: u64) {
        let c = Counter{value: a};
        Debug::print<u64>(&c.value);
        let Counter{value: _} = c;
    }

    // read global storage
    public fun read_counter(account: signer): u64 acquires Counter {
        let counter = borrow_global<Counter>(Signer::address_of(&account));
        let Counter{value: value} = counter;
        return *value
    }

    // write global storage
    public fun create_counter_from_u64(account: signer, a: u64) {
        move_to(&account, init_counter(a));
    }

    // write global storage
    public fun create_counter(account: signer, c: Counter) {
        move_to(&account, c);
    }

    // read global storage
    public(script) fun read_script_counter(account: signer) acquires Counter {
        let c = read_counter(account);
        Debug::print<u64>(&(c));
    }

    // write global storage
    public(script) fun create_script_counter(account: signer, a: u64){
        create_counter(account, init_counter(a));
    }
}
}

Summary:
public functions:
1 no operation on global storage, dev call init_counter ok
2 read on global storage, dev call read_counter ok
3 write on global storage, dev call set_counter failed with error "Server returned rpc error Invalid params: status REJECTED_WRITE_SET of type Validation"
4 execute-function init_counter failed with error below

	account unlock -p 123 0xe2ecbfb4694a8e73fc794d9b5c037ec0
	account execute-function --function 0xe2ecbfb4694a8e73fc794d9b5c037ec0::M1::init_counter --arg 56u64 -s 0xe2ecbfb4694a8e73fc794d9b5c037ec0 -b
	txn dry run failed
	{
	  "ok": {
		"dry_run_output": {
		  "events": [],
		  "explained_status": {
			"Error": "EXECUTE_SCRIPT_FUNCTION_CALLED_ON_NON_SCRIPT_VISIBLE"

public(script) functions:
1 no operation on global storage, dev call init_script_counter ok
2 execute-function always succeed with a tx, regardless of nop/read/write on global storage

compliled move script(.mv):
1 successed, called via execute-script.

@geometryolife
Copy link
Collaborator

Thank you for your summary contribution. Could you create a file in this directory and organize the content here?

https://github.com/starcoinorg/starcoin-cookbook/tree/main/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples

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

No branches or pull requests

2 participants