Skip to content

Commit

Permalink
Merge pull request #1258 from multiversx/upgrade-attribute
Browse files Browse the repository at this point in the history
upgrade attribute (basics)
  • Loading branch information
andrei-marinica authored Nov 21, 2023
2 parents 9b2f741 + 0b2d94e commit 4acaa25
Show file tree
Hide file tree
Showing 24 changed files with 450 additions and 36 deletions.
5 changes: 5 additions & 0 deletions contracts/examples/adder/src/adder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ pub trait Adder {
self.sum().set(initial_value);
}

#[upgrade]
fn upgrade(&self, initial_value: BigUint) {
self.init(initial_value);
}

/// Add desired amount to the storage variable.
#[endpoint]
fn add(&self, value: BigUint) {
Expand Down
5 changes: 3 additions & 2 deletions contracts/examples/adder/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 2
// Endpoints: 3
// Async Callback (empty): 1
// Total number of exported functions: 4
// Total number of exported functions: 5

#![no_std]

Expand All @@ -23,6 +23,7 @@ multiversx_sc_wasm_adapter::endpoints! {
(
init => init
getSum => sum
upgrade => upgrade
add => add
)
}
Expand Down
5 changes: 5 additions & 0 deletions contracts/examples/multisig/src/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ pub trait Multisig:
self.quorum().set(quorum);
}

#[upgrade]
fn upgrade(&self, quorum: usize, board: MultiValueEncoded<ManagedAddress>) {
self.init(quorum, board)
}

/// Allows the contract to receive funds even if it is marked as unpayable in the protocol.
#[payable("*")]
#[endpoint]
Expand Down
5 changes: 3 additions & 2 deletions contracts/examples/multisig/wasm-multisig-full/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 28
// Endpoints: 29
// Async Callback: 1
// Total number of exported functions: 30
// Total number of exported functions: 31

#![no_std]

Expand All @@ -22,6 +22,7 @@ multiversx_sc_wasm_adapter::endpoints! {
multisig
(
init => init
upgrade => upgrade
deposit => deposit
signed => signed
sign => sign
Expand Down
5 changes: 3 additions & 2 deletions contracts/examples/multisig/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 20
// Endpoints: 21
// Async Callback: 1
// Total number of exported functions: 22
// Total number of exported functions: 23

#![no_std]

Expand All @@ -22,6 +22,7 @@ multiversx_sc_wasm_adapter::endpoints! {
multisig
(
init => init
upgrade => upgrade
deposit => deposit
signed => signed
sign => sign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub trait ProxyTestFirst {

self.message_me_proxy()
.contract(other_contract)
.init(456)
.init(456) // TODO: upgrade proxy
.with_egld_transfer(payment.clone_value())
.upgrade_contract(&code, CodeMetadata::DEFAULT);
}
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ pub trait ProxyTestSecond {
init_arg + 1
}

#[upgrade]
#[payable("EGLD")]
fn upgrade(&self, init_arg: i32) -> i32 {
self.init(init_arg)
}

#[payable("EGLD")]
#[endpoint(payMe)]
fn pay_me(&self, arg1: i64) {
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 3
// Endpoints: 4
// Async Callback (empty): 1
// Total number of exported functions: 5
// Total number of exported functions: 6

#![no_std]

Expand All @@ -22,6 +22,7 @@ multiversx_sc_wasm_adapter::endpoints! {
proxy_test_second
(
init => init
upgrade => upgrade
payMe => pay_me
payMeWithResult => pay_me_with_result_endpoint
messageMe => message_me
Expand Down
8 changes: 7 additions & 1 deletion contracts/feature-tests/composability/vault/sc-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ main = "main"
[contracts.main]
name = "vault"
add-unlabelled = true
add-labels = ["upgrade"]

[contracts.promises]
name = "vault-promises"
add-unlabelled = true
add-labels = ["promises-endpoint"]
add-labels = ["promises-endpoint"]

[contracts.upgrade]
name = "vault-upgrade"
add-unlabelled = false
add-labels = ["upgrade"]
13 changes: 13 additions & 0 deletions contracts/feature-tests/composability/vault/src/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ pub trait Vault {
opt_arg_to_echo
}

#[upgrade]
#[label("upgrade")]
fn upgrade(
&self,
opt_arg_to_echo: OptionalValue<ManagedBuffer>,
) -> MultiValue2<&'static str, OptionalValue<ManagedBuffer>> {
self.upgraded_event();
("upgraded", opt_arg_to_echo).into()
}

#[event("upgraded")]
fn upgraded_event(&self);

#[endpoint]
fn echo_arguments(
&self,
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ publish = false

[lib]
crate-type = ["cdylib"]

[profile.release]
codegen-units = 1
opt-level = "z"
lto = true
debug = false
panic = "abort"

[dependencies.vault]
path = ".."

Expand Down
Loading

0 comments on commit 4acaa25

Please sign in to comment.