|
| 1 | +#![cfg_attr(any(target_arch = "riscv32", target_arch = "riscv64"), no_std)] |
| 2 | + |
| 3 | +extern crate alloc; |
| 4 | +use alloc::format; |
| 5 | +use jam_pvm_common::*; |
| 6 | +use jam_types::*; |
| 7 | + |
| 8 | +#[allow(dead_code)] |
| 9 | +struct Service; |
| 10 | +declare_service!(Service); |
| 11 | + |
| 12 | +impl jam_pvm_common::Service for Service { |
| 13 | + fn refine( |
| 14 | + id: ServiceId, |
| 15 | + payload: WorkPayload, |
| 16 | + _package_hash: WorkPackageHash, |
| 17 | + _context: RefineContext, |
| 18 | + _auth_code_hash: CodeHash, |
| 19 | + ) -> WorkOutput { |
| 20 | + info!("This is Refine in the Test Service {id:x}h with payload len {}", payload.len()); |
| 21 | + [&b"Hello "[..], payload.take().as_slice()].concat().into() |
| 22 | + } |
| 23 | + fn accumulate(_slot: Slot, id: ServiceId, items: Vec<AccumulateItem>) -> Option<Hash> { |
| 24 | + info!("This is Accumulate in the Test Service {id:x}h with {} items", items.len()); |
| 25 | + for out in items.into_iter().filter_map(|x| x.result.ok()) { |
| 26 | + accumulate::set_storage(b"last", &out).expect("balance low"); |
| 27 | + } |
| 28 | + None |
| 29 | + } |
| 30 | + fn on_transfer(slot: Slot, id: ServiceId, items: Vec<TransferRecord>) { |
| 31 | + items.into_iter().for_each(|i| { |
| 32 | + info!( |
| 33 | + "Transfer at {slot} from {:x}h to {id:x}h of {} memo {}", |
| 34 | + i.source, i.amount, i.memo |
| 35 | + ); |
| 36 | + let msg = format!( |
| 37 | + "Transfer at {slot} from {:x}h to {id:x}h of {} memo {}", |
| 38 | + i.source, i.amount, i.memo, |
| 39 | + ); |
| 40 | + accumulate::set_storage(b"lasttx", msg.as_bytes()).expect("balance low"); |
| 41 | + }); |
| 42 | + } |
| 43 | +} |
0 commit comments