forked from hyperledger-iroha/iroha
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] hyperledger-iroha#3982: Clear live queries after smart con…
…tract end (hyperledger-iroha#4024) Signed-off-by: Daniil Polyakov <arjentix@gmail.com>
- Loading branch information
Showing
20 changed files
with
575 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
client/tests/integration/smartcontracts/query_assets_and_save_cursor/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "query_assets_and_save_cursor" | ||
|
||
edition.workspace = true | ||
version.workspace = true | ||
authors.workspace = true | ||
|
||
license.workspace = true | ||
|
||
[lib] | ||
crate-type = ['cdylib'] | ||
|
||
[dependencies] | ||
iroha_smart_contract.workspace = true | ||
|
||
panic-halt.workspace = true | ||
lol_alloc.workspace = true | ||
serde_json = { version = "1.0.108", default-features = false } |
38 changes: 38 additions & 0 deletions
38
client/tests/integration/smartcontracts/query_assets_and_save_cursor/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! Smart contract which executes [`FindAllAssets`] and saves cursor to the owner's metadata. | ||
|
||
#![no_std] | ||
|
||
#[cfg(not(test))] | ||
extern crate panic_halt; | ||
|
||
extern crate alloc; | ||
|
||
use alloc::string::ToString as _; | ||
use core::num::NonZeroU32; | ||
|
||
use iroha_smart_contract::{parse, prelude::*}; | ||
use lol_alloc::{FreeListAllocator, LockedAllocator}; | ||
|
||
#[global_allocator] | ||
static ALLOC: LockedAllocator<FreeListAllocator> = LockedAllocator::new(FreeListAllocator::new()); | ||
|
||
/// Execute [`FindAllAssets`] and save cursor to the owner's metadata. | ||
#[iroha_smart_contract::main] | ||
fn main(owner: AccountId) { | ||
let asset_cursor = FindAllAssets | ||
.fetch_size(FetchSize::new(Some(NonZeroU32::try_from(1).dbg_unwrap()))) | ||
.execute() | ||
.dbg_unwrap(); | ||
|
||
let (_batch, cursor) = asset_cursor.into_raw_parts(); | ||
|
||
SetKeyValueExpr::new( | ||
owner, | ||
parse!("cursor" as Name), | ||
serde_json::to_value(cursor) | ||
.dbg_expect("Failed to convert cursor to JSON") | ||
.to_string(), | ||
) | ||
.execute() | ||
.dbg_expect("Failed to save cursor to the owner's metadata"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.