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

chore: deduplicate Upgradable docs and examples #80

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 6 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,17 @@ Documentation of all methods provided by `Pausable` is available in the [definit

### [Upgradable](/near-plugins/src/upgradable.rs)

Allows a contract to be upgraded by owner with delay and without having a Full Access Key.
Allows a contract to be upgraded by the owner without requiring a full access key. Optionally a staging duration can be set, which defines the minimum duration that must pass before staged code can be deployed. The staging duration is a safety mechanism to protect users that interact with the contract, giving them time to opt-out before an unfavorable update is deployed.

Contract example using _Upgradable_ plugin. Note that it requires the contract to be Ownable.
Using the `Upgradable` plugin requires a contract to be `Ownable`.

```rust
#[near_bindgen]
#[derive(Ownable, Upgradable)]
struct Counter;

#[near_bindgen]
impl Counter {
/// Specify the owner of the contract in the constructor
#[init]
fn new() -> Self {
let mut contract = Self {};
contract.owner_set(Some(near_sdk::env::predecessor_account_id()));
contract.up_init_staging_duration(std::time::Duration::from_secs(60).as_nanos().try_into().unwrap()); // 1 minute
contract
}
}
```
To upgrade the contract first call `up_stage_code` passing the binary as first argument serialized as borsh. Then call `up_deploy_code`. Both functions must be called by the owner of the contract.

To upgrade the contract first call `up_stage_code` passing the binary as first argument serialized as borsh. Then call `up_deploy_code`.
This functions must be called from the owner.
To set a staging duration, call `up_stage_init_staging_duration`. After initialization the staging duration can be updated by calling `up_stage_update_staging_duration` followed by `up_apply_update_staging_duration`. Updating the staging duration is itself subject to a delay: at least the currently set staging duration must pass before a staged update can be applied. The functions mentioned in this paragraph must be called by the owner of the contract.

To update the staging delay first call `up_stage_update_staging_duration` passing the new delay duration. Then call `up_apply_update_staging_duration`.
This functions must be called from the owner.
[This contract](/near-plugins/tests/contracts/upgradable/src/lib.rs) provides an example of using `Upgradable`. It is compiled, deployed on chain and interacted with in [integration tests](/near-plugins/tests/upgradable.rs).

Documentation of all methods provided by the derived implementation of `Upgradable` is available in the [definition of the trait](/near-plugins/src/upgradable.rs). More examples and guidelines for interacting with an `Upgradable` contract can be found [here](/examples/upgradable-examples/README.md).
Documentation of all methods provided by `Upgradable` is available in the [definition of the trait](/near-plugins/src/upgradable.rs).

### [AccessControllable](/near-plugins/src/access_controllable.rs)

Expand Down
2 changes: 0 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
members = [
"full-access-key-fallback-examples/full_access_key_fallback_base",
"near-plugins-test-utils",
"upgradable-examples/upgradable_base",
"upgradable-examples/up_stage_code",
]
223 changes: 0 additions & 223 deletions examples/upgradable-examples/README.md

This file was deleted.

16 changes: 0 additions & 16 deletions examples/upgradable-examples/up_stage_code/Cargo.toml

This file was deleted.

57 changes: 0 additions & 57 deletions examples/upgradable-examples/up_stage_code/src/main.rs

This file was deleted.

24 changes: 0 additions & 24 deletions examples/upgradable-examples/upgradable_base/Cargo.toml

This file was deleted.

10 changes: 0 additions & 10 deletions examples/upgradable-examples/upgradable_base/build.sh

This file was deleted.

Loading