near_self_update/
lib.rs

1use near_workspaces::types::NearToken;
2use nitka::{json, ContractCall};
3
4pub trait HasContract {
5    fn contract(&self) -> &near_workspaces::Contract;
6}
7
8pub trait UpdateApiIntegration: HasContract {
9    fn update_contract(&self, code: Vec<u8>, callback: Option<String>) -> ContractCall<()> {
10        ContractCall::new("update_contract", self.contract().clone())
11            .args_json(json!({
12                "code": code,
13                "callback": callback
14            }))
15            .unwrap()
16            .deposit(NearToken::from_yoctonear(1))
17    }
18
19    fn contract_version(&self) -> ContractCall<String> {
20        ContractCall::new("contract_version", self.contract().clone())
21    }
22}
23
24impl<T: HasContract> UpdateApiIntegration for T {}