Skip to content
Open
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
Binary file modified res/tonic-dex.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions tonic-dex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod settlement;
mod storage;
mod storage_manager;
mod swap_order;
mod upgrade;
mod views;

pub use crate::account::*;
Expand Down
34 changes: 34 additions & 0 deletions tonic-dex/src/upgrade.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use near_sdk::{Gas, Promise};

use crate::*;

#[near_bindgen]
impl Contract {
pub fn version(&self) -> String {
format!("{}:{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
}

#[private]
#[init(ignore_state)]
pub fn migrate() -> Self {
let contract: Contract = env::state_read().expect("Contract is not initialized");
contract
}

pub fn upgrade(&self) -> Promise {
self.assert_is_owner();

const CALL_GAS: Gas = Gas(200_000_000_000_000); // 200 TGAS
const NO_ARGS: Vec<u8> = vec![];

// Receive the code directly from the input to avoid the
// GAS overhead of deserializing parameters
let code = env::input().expect("Error: No input").to_vec();

// Deploy the contract on self
Promise::new(env::current_account_id())
.deploy_contract(code)
.function_call("migrate".to_string(), NO_ARGS, 0, CALL_GAS)
.as_return()
}
}