Skip to content

Commit 46c8c7b

Browse files
committed
Merge branch 'move'
2 parents 49fa5ce + 2318826 commit 46c8c7b

33 files changed

+94
-76
lines changed

src/rust/bitbox02-rust-c/src/workflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ extern crate alloc;
2424

2525
use alloc::boxed::Box;
2626
use alloc::string::String;
27-
use bitbox02_rust::bb02_async::{Task, spin};
2827
use bitbox02_rust::workflow::confirm;
2928
use core::task::Poll;
29+
use util::bb02_async::{Task, spin};
3030

3131
enum TaskState<'a, O> {
3232
Nothing,

src/rust/bitbox02-rust/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ app-cardano = [
101101
]
102102

103103
testing = [
104-
"bitbox02/testing"
104+
"bitbox02/testing",
105+
"util/testing"
105106
]
106107

107108
c-unit-testing = []

src/rust/bitbox02-rust/src/async_usb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
//! This module provides the executor for tasks that are spawned with an API request and deliver a
1616
//! USB response. Terminology: host = computer, device = BitBox02.
1717
18-
use crate::bb02_async::{Task, option, spin as spin_task};
1918
use alloc::boxed::Box;
2019
use alloc::vec::Vec;
2120
use core::cell::RefCell;
2221
use core::task::Poll;
22+
use util::bb02_async::{Task, option, spin as spin_task};
2323

2424
type UsbOut = Vec<u8>;
2525
type UsbIn = Vec<u8>;

src/rust/bitbox02-rust/src/bb02_async.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use alloc::boxed::Box;
1615
use core::cell::RefCell;
17-
use core::pin::Pin;
18-
use core::task::{Context, Poll};
19-
20-
/// Task is the top-level future which can be polled by an executor.
21-
/// Note that other futures awaited inside do not have to be pinned.
22-
/// The 'a lifetime allows to spin a boxed/pinned future that is not
23-
/// 'static, or a future with non-'static input param references.
24-
pub type Task<'a, O> = Pin<Box<dyn core::future::Future<Output = O> + 'a>>;
25-
26-
/// A primitive poll invocation for a task, with no waking functionality.
27-
pub fn spin<O>(task: &mut Task<O>) -> Poll<O> {
28-
// TODO: statically allocate the context.
29-
let waker = crate::waker_fn::waker_fn(|| {});
30-
let context = &mut Context::from_waker(&waker);
31-
task.as_mut().poll(context)
32-
}
33-
34-
/// Implements the Option future, see `option()`.
35-
pub struct AsyncOption<'a, O>(&'a RefCell<Option<O>>);
36-
37-
impl<O> core::future::Future for AsyncOption<'_, O> {
38-
type Output = O;
39-
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
40-
match self.0.borrow_mut().take() {
41-
None => Poll::Pending,
42-
Some(output) => Poll::Ready(output),
43-
}
44-
}
45-
}
4616

4717
/// Disables the screensaver while waiting for an option to contain a value. Afterwards, it returns that value
4818
pub async fn option_no_screensaver<O>(opt: &RefCell<Option<O>>) -> O {
4919
bitbox02::screen_saver::screen_saver_disable();
50-
let result = option(opt).await;
20+
let result = util::bb02_async::option(opt).await;
5121
bitbox02::screen_saver::screen_saver_enable();
5222
result
5323
}
54-
55-
/// Waits for an option to contain a value and returns that value, leaving `None` in its place.
56-
/// E.g. `assert_eq!(option(&Some(42)).await, 42)`.
57-
pub fn option<O>(option: &RefCell<Option<O>>) -> AsyncOption<'_, O> {
58-
AsyncOption(option)
59-
}
60-
61-
/// Polls a future until the result is available.
62-
pub fn block_on<O>(task: impl core::future::Future<Output = O>) -> O {
63-
let mut task: crate::bb02_async::Task<O> = alloc::boxed::Box::pin(task);
64-
loop {
65-
bitbox02::ui::screen_process();
66-
if let Poll::Ready(result) = spin(&mut task) {
67-
return result;
68-
}
69-
}
70-
}

src/rust/bitbox02-rust/src/hww.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ mod tests {
136136
use super::*;
137137
extern crate std;
138138

139-
use crate::bb02_async::block_on;
140139
use crate::hal::testing::TestingHal;
141140
use crate::workflow::testing::Screen;
142141
use bitbox02::testing::mock_memory;
142+
use util::bb02_async::block_on;
143143

144144
use prost::Message;
145145

src/rust/bitbox02-rust/src/hww/api/backup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ pub fn list(hal: &mut impl crate::hal::Hal) -> Result<Response, Error> {
162162
mod tests {
163163
use super::*;
164164

165-
use crate::bb02_async::block_on;
166165
use crate::hal::testing::TestingHal;
167166
use crate::workflow::testing::Screen;
168167
use alloc::boxed::Box;
169168
use bitbox02::testing::{mock_memory, mock_unlocked, mock_unlocked_using_mnemonic};
169+
use util::bb02_async::block_on;
170170

171171
/// Test backup creation on a uninitialized keystore.
172172
#[test]

src/rust/bitbox02-rust/src/hww/api/bitcoin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ pub async fn process_api(
331331
mod tests {
332332
use super::*;
333333

334-
use crate::bb02_async::block_on;
335334
use crate::bip32::parse_xpub;
336335
use crate::hal::testing::TestingHal;
337336
use crate::workflow::testing::Screen;
@@ -341,6 +340,7 @@ mod tests {
341340
TEST_MNEMONIC, mock_memory, mock_unlocked, mock_unlocked_using_mnemonic,
342341
};
343342
use pb::btc_script_config::multisig::ScriptType as MultisigScriptType;
343+
use util::bb02_async::block_on;
344344
use util::bip32::HARDENED;
345345

346346
#[test]

src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ pub async fn process(
140140
mod tests {
141141
use super::*;
142142

143-
use crate::bb02_async::block_on;
144143
use crate::hal::testing::TestingHal;
145144
use crate::workflow::testing::Screen;
146145
use alloc::boxed::Box;
147146
use bitbox02::testing::mock_unlocked;
147+
use util::bb02_async::block_on;
148148
use util::bip32::HARDENED;
149149

150150
const MESSAGE: &str = "message";

src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,13 +1273,13 @@ pub async fn process(
12731273
#[cfg(test)]
12741274
mod tests {
12751275
use super::*;
1276-
use crate::bb02_async::block_on;
12771276
use crate::bip32::parse_xpub;
12781277
use crate::hal::testing::TestingHal;
12791278
use crate::workflow::testing::Screen;
12801279
use alloc::boxed::Box;
12811280
use bitbox02::testing::{mock_memory, mock_unlocked, mock_unlocked_using_mnemonic};
12821281
use pb::btc_payment_request_request::{Memo, memo};
1282+
use util::bb02_async::block_on;
12831283
use util::bip32::HARDENED;
12841284

12851285
fn extract_next(response: &Response) -> &pb::BtcSignNextResponse {

src/rust/bitbox02-rust/src/hww/api/bitcoin/xpubs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pub async fn process_xpubs(request: &pb::BtcXpubsRequest) -> Result<Response, Er
6868
mod tests {
6969
use super::*;
7070

71-
use crate::bb02_async::block_on;
7271
use bitbox02::testing::{mock_memory, mock_unlocked, mock_unlocked_using_mnemonic};
72+
use util::bb02_async::block_on;
7373
use util::bip32::HARDENED;
7474

7575
#[test]

0 commit comments

Comments
 (0)