Skip to content

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

@0xOutOfGas

Description

@0xOutOfGas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions