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

feat: Added a new command to manage BOS profile in SocialDB #231

Merged
merged 49 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8f896e8
added ViewProfile
Aug 14, 2023
5076910
added UpdateProfile (JsonArgs)
Aug 15, 2023
113b085
refactored input_data()
Aug 16, 2023
767a2eb
added UpdateProfile (TextArgs)
Aug 17, 2023
188905a
refactored JsonArgs::input_data()
Aug 17, 2023
e58c9be
added UpdateProfile (Base64Args)
Aug 17, 2023
48d92f9
added UpdateProfile (FileArgs)
Aug 17, 2023
27fcd6c
fixed Profile
Aug 18, 2023
8328da2
added UpdateProfile (Manually)
Aug 18, 2023
64343eb
refactored
Aug 18, 2023
cca0cc1
refactor: Upgrade cargo-dist to 0.1.0 release (#229)
frol Aug 17, 2023
b80c590
chore: release 0.5.2 (#219)
frol Aug 17, 2023
cdb16a5
ci: Fix the release script to Linux binaries after cargo-dist upgrade
frol Aug 17, 2023
3014a8f
Merge branch 'master' into manage-profile
FroVolod Aug 18, 2023
b65c282
added Guide
Aug 22, 2023
757db78
fixed
Aug 22, 2023
d493dc5
refactored
Aug 25, 2023
a6d1bd8
Merge branch 'master' into manage-profile
FroVolod Aug 29, 2023
a3aa9f3
updated to PR #225 (order networks selection ...)
Aug 29, 2023
9624154
clippy
Aug 29, 2023
9aa37df
Merge branch 'master' into manage-profile
FroVolod Sep 3, 2023
ebfb83d
Merge branch 'master' into manage-profile
FroVolod Sep 3, 2023
2ac7afc
Merge branch 'master' into manage-profile
FroVolod Sep 4, 2023
217f317
fmt
Sep 4, 2023
72b2a2c
updated GUIDE to "master"
Sep 9, 2023
ed621c9
Merge branch 'master' into manage-profile
FroVolod Sep 9, 2023
bf1fc43
Merge branch 'master' into manage-profile
FroVolod Sep 26, 2023
8be0e16
updated to "near-gas"
Sep 26, 2023
232bb93
clippy
Sep 26, 2023
9fb6fbc
Merge branch 'master' into manage-profile
FroVolod Sep 29, 2023
d4b6c85
updated: interactive-clap = "0.2.5"
Sep 30, 2023
0c4c6b4
Update src/commands/account/mod.rs
FroVolod Oct 1, 2023
49a258c
renamed ManageProfile to UpdateSocialProfile
Oct 1, 2023
521de91
UpdateSocialProfile moved after CreateAccount
Oct 1, 2023
7db1eef
updated interactive-clap
Oct 3, 2023
4005f3e
updated ViewAccountSummary
Oct 3, 2023
3ec167d
updated crate::types::base64_bytes::Base64Bytes
Oct 4, 2023
ad26d98
refactored
Oct 4, 2023
335b7b5
updated GUIDE
Oct 4, 2023
c89b48e
updated GUIDE
Oct 4, 2023
da7a665
updated interactive-clap to 0.2.6
Oct 5, 2023
80db5d0
updated config
Oct 5, 2023
489a419
added near-socialdb-client-rs to [dependencies]
Oct 6, 2023
23b6d71
Merge branch 'master' into manage-profile
FroVolod Oct 6, 2023
f43c362
Update src/types/base64_bytes.rs
FroVolod Oct 6, 2023
57f97b1
Update src/types/file_bytes.rs
FroVolod Oct 6, 2023
4837560
fixed
Oct 6, 2023
137808e
Merge branch 'manage-profile' of https://github.com/near/near-cli-rs …
Oct 6, 2023
99ea8ad
apdated near-socialdb-client in [dependencies]
Oct 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading