Skip to content

Commit

Permalink
Add wasm for upgrade write-bytes contract
Browse files Browse the repository at this point in the history
  • Loading branch information
sisuresh committed Aug 3, 2023
1 parent 69ef9de commit 39f23fd
Show file tree
Hide file tree
Showing 22 changed files with 59 additions and 17 deletions.
2 changes: 2 additions & 0 deletions soroban-test-wasms/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ pub const UPDATEABLE_CONTRACT: &[u8] =
pub const DELEGATED_ACCOUNT_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/test_delegated_account.wasm").as_slice();
pub const ERR: &[u8] = include_bytes!("../wasm-workspace/opt/example_err.wasm").as_slice();
pub const WRITE_BYTES: &[u8] =
include_bytes!("../wasm-workspace/opt/soroban_write_upgrade_bytes_contract.wasm").as_slice();
28 changes: 12 additions & 16 deletions soroban-test-wasms/wasm-workspace/Cargo.lock

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

3 changes: 2 additions & 1 deletion soroban-test-wasms/wasm-workspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ members = [
"simple_account",
"update",
"delegated_account",
"err"
"err",
"write_upgrade_bytes"
]
[profile.release]
opt-level = "z"
Expand Down
Binary file modified soroban-test-wasms/wasm-workspace/opt/auth_test_contract.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_add_f32.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_add_i32.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_complex.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_contract_data.wasm
Binary file not shown.
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_err.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_fannkuch.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_fib.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_hostile.wasm
Binary file not shown.
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_linear_memory.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/example_vec.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions soroban-test-wasms/wasm-workspace/write_upgrade_bytes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "soroban-write-upgrade-bytes-contract"
version = "0.0.0"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
publish = false
rust-version = "1.65"

[lib]
crate-type = ["cdylib", "rlib"]
doctest = false

[dependencies]
soroban-sdk = { workspace = true }
28 changes: 28 additions & 0 deletions soroban-test-wasms/wasm-workspace/write_upgrade_bytes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![no_std]
use soroban_sdk::{contract, contractimpl, Env, Bytes, BytesN};

pub(crate) const BUMP_AMOUNT: u32 = 518400; // 30 days

#[contract]
pub struct WriteBytesContract;

/*
This contract is used by a stellar core test case to do a Soroban ConfigSetting upgrade.
A copy of this contract also exists in the scripts directory of stellar-core, which is used
by a python script to execute the upgrade. If there's an easy way for the python script to use
this contract in env, the one in stellar-core should be deleted.
*/
#[contractimpl]
impl WriteBytesContract {
pub fn write(env: Env, xdr_bytes: Bytes) -> BytesN<32> {
let hash = env.crypto().sha256(&xdr_bytes);
env.storage().temporary().set(&hash, &xdr_bytes);
env.storage().temporary().bump(&hash, BUMP_AMOUNT);

env.storage().instance().bump(BUMP_AMOUNT);

hash
}
}

mod test;

0 comments on commit 39f23fd

Please sign in to comment.