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

[cli] Extract abstract account provider for support remote RPC with local account provider #3215

Closed
jolestar opened this issue Feb 15, 2022 · 0 comments · Fixed by #3259
Closed
Assignees
Labels
enhancement Enhancement feature New feature help wanted Extra attention is needed

Comments

@jolestar
Copy link
Member

Now if the user wants to deploy a module or execute a script function, need to sync a full node at local.

if the user connects to the remote node, such as:

starcoin --connect ws://main.seed.starcoin.org:9870 console

The user cannot use account-related commands as the remote node does not public the account API.

So, if we extract an abstract account provider, users can combine a local account database with a remote API node.

trait AccountProvider{

    fn create_account(&self, password: String) -> Result<AccountInfo>;

    fn get_default_account(&self) -> Result<Option<AccountInfo>>;
   
    fn get_accounts(&self) -> Result<Vec<AccountInfo>>;

    async fn get_account(&self, address: AccountAddress) -> Result<Option<AccountInfo>>;

    /// Signs the hash of data with given address.
    fn sign_message(
        &self,
        address: AccountAddress,
        message: SigningMessage,
    ) -> Result<SignedMessage>;

    fn sign_txn(
        &self,
        raw_txn: RawUserTransaction,
        signer_address: AccountAddress,
    ) -> Result<SignedUserTransaction>;

     ....
}

Now, we can implement several account provider

  1. Remote API Account provider: the default account provider, provider account by JSONRPC API.
  2. Local Database Account provider: provider account by a local database.
  3. Private key account provider: provider account by the private key, this provider maybe doesn't support the create or import account command.

Usage:

starcoin --connect ws://main.seed.starcoin.org:9870 --account-provider ~/.starcoin/main/account_vaults/ console

The dir .starcoin/main/account_vaults/ is a local account database.

starcoin --connect ws://main.seed.starcoin.org:9870 --account-provider address=$private_key console

The user just needs to provide an address to the private_key pair, then can use most of the account commands, this feature is especially useful for automated testing/ci scenarios.

@jolestar jolestar added enhancement Enhancement help wanted Extra attention is needed feature New feature labels Feb 15, 2022
@sanlee42 sanlee42 self-assigned this Feb 18, 2022
@jolestar jolestar linked a pull request Mar 3, 2022 that will close this issue
7 tasks
@jolestar jolestar closed this as completed Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement feature New feature help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants