Skip to content

Commit

Permalink
feat: Added a new command to manage BOS profile in SocialDB (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
FroVolod authored Oct 7, 2023
1 parent ac0e629 commit c2c6f1a
Show file tree
Hide file tree
Showing 29 changed files with 1,431 additions and 169 deletions.
26 changes: 22 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ near-gas = { version = "0.2.3", features = [
"interactive-clap",
] }

interactive-clap = "0.2.4"
interactive-clap-derive = "0.2.4"
keyring = "2.0.5"
interactive-clap = "0.2.6"
interactive-clap-derive = "0.2.6"

near-socialdb-client = "0.1.0"

[features]
default = ["ledger", "self-update"]
Expand Down
95 changes: 95 additions & 0 deletions docs/GUIDE.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ View account details ([View properties for an account](#view-account-summary---v
- [view-account-summary](#view-account-summary---View-properties-for-an-account)
- [import-account](#import-account---import-existing-account-aka-sign-in)
- [create-account](#create-account---Create-a-new-account)
- [update-social-profile](#update-social-profile---Update-NEAR-Social-profile)
- [delete-account](#delete-account---Delete-an-account)
- [list-keys](#list-keys---View-a-list-of-access-keys-of-an-account)
- [add-key](#add-key---Add-an-access-key-to-an-account)
Expand Down Expand Up @@ -763,6 +764,100 @@ The file "/Users/frovolod/.near-credentials/implicit/eca9e1a6e0fa9a6af6d046bcffa
</a>
</details>

#### update-social-profile - Update NEAR Social profile

- [json-args](#json-args---Valid-JSON-arguments-eg-token_id-42)
- base64-args
- [file-args](#file-args---Read-from-file-eg-reusable-JSON-or-binary-data)
- [manually](#manually---Interactive-input-of-arguments)

##### json-args - Valid JSON arguments (e.g. {"token_id": "42"})

To update the contract account profile using JSON arguments, enter the following at the terminal command line:

```txt
near account \
update-social-profile fro_volod.testnet \
json-args '{"name":"frovolod","image":{"ipfs_cid":"bafkreifdzusz6hp3j4njdtqqxr3tlvx4agedgh7znyac4wbuiao3gtppde"},"linktree":{"github":"FroVolod","telegram":"frovolod"},"tags": {"rust":"","near":"","developer":""}}' \
sign-as fro_volod.testnet \
network-config testnet \
sign-with-keychain \
send
```

<details><summary><i>The result of this command will be as follows:</i></summary>

```txt
Profile for fro_volod.testnet updated successfully
```
</details>

<details><summary><i>Demonstration of the command in interactive mode</i></summary>
<a href="https://asciinema.org/a/bF7AQuj012xVk4Xt5kMfOWAq1?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/bF7AQuj012xVk4Xt5kMfOWAq1.png" width="836"/>
</a>
</details>

##### file-args - Read from file (e.g. reusable JSON or binary data)

To update the account profile on the contract using the prepared file, you must enter in the terminal command line:

```txt
near account \
update-social-profile fro_volod.testnet \
file-args profile.txt \
sign-as fro_volod.testnet \
network-config testnet \
sign-with-keychain \
send
```

<details><summary><i>The result of this command will be as follows:</i></summary>

```txt
Profile for fro_volod.testnet updated successfully
```
</details>

<details><summary><i>Demonstration of the command in interactive mode</i></summary>
<a href="https://asciinema.org/a/lbyMQp94TqvbNjBGmjQ49PEpJ?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/lbyMQp94TqvbNjBGmjQ49PEpJ.png" width="836"/>
</a>
</details>

##### manually - Interactive input of arguments

To update the account profile on the contract in interactive mode, you must use the prompts of the dialog or enter in the terminal command line:

```txt
near account \
update-social-profile fro_volod.testnet \
manually \
--name fro_volod.testnet \
--image-ipfs-cid bafkreifdzusz6hp3j4njdtqqxr3tlvx4agedgh7znyac4wbuiao3gtppde \
--description 'This is my profile' \
--github FroVolod \
--website https://example.com/ \
--tags dev,rust \
sign-as fro_volod.testnet \
network-config testnet \
sign-with-keychain \
send
```

<details><summary><i>The result of this command will be as follows:</i></summary>

```txt
Profile for fro_volod.testnet updated successfully
```
</details>

<details><summary><i>Demonstration of the command in interactive mode</i></summary>
<a href="https://asciinema.org/a/sJxaZKOkjGu75yvMGOqkQxi34?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/sJxaZKOkjGu75yvMGOqkQxi34.png" width="836"/>
</a>
</details>

#### delete-account - Delete an account

This command is designed to delete the current account. It is important to remember that all tokens of the deleted account will be transferred to the "_beneficiary_" account.
Expand Down
95 changes: 95 additions & 0 deletions docs/GUIDE.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ near --offline tokens \
- [import-account](#import-account---Import-existing-account-aka-sign-in)
- [export-account](#export-account---Export-existing-account)
- [create-account](#create-account---Create-a-new-account)
- [update-social-profile](#update-social-profile---Update-NEAR-Social-profile)
- [delete-account](#delete-account---Delete-an-account)
- [list-keys](#list-keys---View-a-list-of-access-keys-of-an-account)
- [add-key](#add-key---Add-an-access-key-to-an-account)
Expand Down Expand Up @@ -763,6 +764,100 @@ The file "/Users/frovolod/.near-credentials/implicit/eca9e1a6e0fa9a6af6d046bcffa
</a>
</details>

#### update-social-profile - Update NEAR Social profile

- [json-args](#json-args---Valid-JSON-arguments-eg-token_id-42)
- base64-args
- [file-args](#file-args---Read-from-file-eg-reusable-JSON-or-binary-data)
- [manually](#manually---Interactive-input-of-arguments)

##### json-args - Valid JSON arguments (e.g. {"token_id": "42"})

Для изменения профиля аккаунта на контракте с использованием аргументов в формате JSON необходимо ввести в командной строке терминала:

```txt
near account \
update-social-profile fro_volod.testnet \
json-args '{"name":"frovolod","image":{"ipfs_cid":"bafkreifdzusz6hp3j4njdtqqxr3tlvx4agedgh7znyac4wbuiao3gtppde"},"linktree":{"github":"FroVolod","telegram":"frovolod"},"tags": {"rust":"","near":"","developer":""}}' \
sign-as fro_volod.testnet \
network-config testnet \
sign-with-keychain \
send
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
Profile for fro_volod.testnet updated successfully
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/bF7AQuj012xVk4Xt5kMfOWAq1?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/bF7AQuj012xVk4Xt5kMfOWAq1.png" width="836"/>
</a>
</details>

##### file-args - Read from file (e.g. reusable JSON or binary data)

Для изменения профиля аккаунта на контракте с использованием подготовленного файла необходимо ввести в командной строке терминала:

```txt
near account \
update-social-profile fro_volod.testnet \
file-args profile.txt \
sign-as fro_volod.testnet \
network-config testnet \
sign-with-keychain \
send
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
Profile for fro_volod.testnet updated successfully
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/lbyMQp94TqvbNjBGmjQ49PEpJ?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/lbyMQp94TqvbNjBGmjQ49PEpJ.png" width="836"/>
</a>
</details>

##### manually - Interactive input of arguments

Для изменения профиля аккаунта на контракте с использованием интерактивного режима необходимо воспользоваться диалоговыми подсказками либо ввести в командной строке терминала:

```txt
near account \
update-social-profile fro_volod.testnet \
manually \
--name fro_volod.testnet \
--image-ipfs-cid bafkreifdzusz6hp3j4njdtqqxr3tlvx4agedgh7znyac4wbuiao3gtppde \
--description 'This is my profile' \
--github FroVolod \
--website https://auto-rti.com/ \
--tags dev,rust \
sign-as fro_volod.testnet \
network-config testnet \
sign-with-keychain \
send
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
Profile for fro_volod.testnet updated successfully
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/sJxaZKOkjGu75yvMGOqkQxi34?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/sJxaZKOkjGu75yvMGOqkQxi34.png" width="836"/>
</a>
</details>

#### delete-account - Delete an account

Данная команда предназначена для удаления текущего аккаунта. Важно помнить, что все средства удаляемого аккаунта перейдут на счет "_beneficiary_".
Expand Down
6 changes: 6 additions & 0 deletions src/commands/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod export_account;
mod import_account;
mod list_keys;
pub mod storage_management;
pub mod update_social_profile;
mod view_account_summary;

pub const MIN_ALLOWED_TOP_LEVEL_ACCOUNT_LENGTH: usize = 32;
Expand Down Expand Up @@ -41,6 +42,11 @@ pub enum AccountActions {
#[strum_discriminants(strum(message = "create-account - Create a new account"))]
/// Create a new account
CreateAccount(self::create_account::CreateAccount),
#[strum_discriminants(strum(
message = "update-social-profile - Update NEAR Social profile"
))]
/// Update NEAR Social profile
UpdateSocialProfile(self::update_social_profile::UpdateSocialProfile),
#[strum_discriminants(strum(message = "delete-account - Delete an account"))]
/// Delete an account
DeleteAccount(self::delete_account::DeleteAccount),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl AccountContext {
.wrap_err_with(|| {
"Failed to fetch query for view method: 'storage_balance_of'"
})?
.parse_result_from_json::<crate::common::StorageBalance>()
.parse_result_from_json::<near_socialdb_client::StorageBalance>()
.wrap_err_with(|| {
"Failed to parse return value of view function call for StorageBalance."
})?;
Expand Down
46 changes: 46 additions & 0 deletions src/commands/account/update_social_profile/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
mod profile_args_type;
mod sign_as;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct TransactionFunctionArgs {
pub data: near_socialdb_client::types::socialdb_types::SocialDb,
}

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = crate::GlobalContext)]
#[interactive_clap(output_context = UpdateSocialProfileContext)]
pub struct UpdateSocialProfile {
#[interactive_clap(skip_default_input_arg)]
account_id: crate::types::account_id::AccountId,
#[interactive_clap(subcommand)]
profile_args_type: self::profile_args_type::ProfileArgsType,
}

#[derive(Clone)]
pub struct UpdateSocialProfileContext {
pub global_context: crate::GlobalContext,
pub account_id: near_primitives::types::AccountId,
}

impl UpdateSocialProfileContext {
pub fn from_previous_context(
previous_context: crate::GlobalContext,
scope: &<UpdateSocialProfile as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
Ok(Self {
global_context: previous_context,
account_id: scope.account_id.clone().into(),
})
}
}

impl UpdateSocialProfile {
pub fn input_account_id(
context: &crate::GlobalContext,
) -> color_eyre::eyre::Result<Option<crate::types::account_id::AccountId>> {
crate::common::input_non_signer_account_id_from_used_account_list(
&context.config.credentials_home_dir,
"Which account do you want to update the profile for?",
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = super::super::UpdateSocialProfileContext)]
#[interactive_clap(output_context = Base64ArgsContext)]
pub struct Base64Args {
/// Enter valid Base64-encoded string (e.g. e30=):
data: crate::types::base64_bytes::Base64Bytes,
#[interactive_clap(named_arg)]
/// Specify signer account ID
sign_as: super::super::sign_as::Signer,
}

#[derive(Clone)]
pub struct Base64ArgsContext(super::ArgsContext);

impl Base64ArgsContext {
pub fn from_previous_context(
previous_context: super::super::UpdateSocialProfileContext,
scope: &<Base64Args as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
Ok(Self(super::ArgsContext {
global_context: previous_context.global_context,
account_id: previous_context.account_id,
data: scope.data.clone().into_bytes(),
}))
}
}

impl From<Base64ArgsContext> for super::ArgsContext {
fn from(item: Base64ArgsContext) -> Self {
item.0
}
}
Loading

0 comments on commit c2c6f1a

Please sign in to comment.