1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#[deny(missing_docs)]
use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::{Hash, HashEngine};
use bitcoin::util::bip32::*;
use sapio_ctv_emulator_trait::Clause;
pub use sapio_ctv_emulator_trait::{CTVEmulator, EmulatorError, NullEmulator};
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::net::SocketAddr;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream, ToSocketAddrs};
use bitcoin::secp256k1::{All, Secp256k1};
use bitcoin::util::psbt::PartiallySignedTransaction;
use rand::Rng;
use sapio_base::CTVHash;
use std::sync::Arc;
const MAX_MSG: usize = 1_000_000;
pub mod connections;
mod msgs;
pub mod servers;
thread_local! {
pub static SECP: Secp256k1<All> = Secp256k1::new();
}
fn input_error<T>(s: &str) -> Result<T, std::io::Error> {
Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, s))
}
fn hash_to_child_vec(h: Sha256) -> Vec<ChildNumber> {
let a: [u8; 32] = h.into_inner();
let b: [[u8; 4]; 8] = unsafe { std::mem::transmute(a) };
let mut c: Vec<ChildNumber> = b
.iter()
.map(|x| (u32::from_be_bytes(*x) << 1) >> 1)
.map(ChildNumber::from)
.collect();
c.push(
b.iter()
.enumerate()
.map(|(i, x)| (u32::from_be_bytes(*x) >> 31) << i)
.sum::<u32>()
.into(),
);
c
}