Skip to content

Commit d96e67a

Browse files
committed
fmt
1 parent cd51531 commit d96e67a

17 files changed

+1588
-1351
lines changed

src/channel_handler/game_handler.rs

+146-115
Large diffs are not rendered by default.

src/channel_handler/handler.rs

+490-427
Large diffs are not rendered by default.

src/channel_handler/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1+
pub mod game_handler;
12
pub mod handler;
23
pub mod types;
3-
pub mod game_handler;

src/channel_handler/types.rs

+38-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
use rand::prelude::*;
2-
use rand::distributions::Standard;
3-
use clvmr::allocator::NodePtr;
4-
use clvm_traits::{ToClvm, ClvmEncoder, ToClvmError, clvm_curried_args};
1+
use clvm_traits::{clvm_curried_args, ClvmEncoder, ToClvm, ToClvmError};
52
use clvm_utils::CurriedProgram;
3+
use clvmr::allocator::NodePtr;
4+
use rand::distributions::Standard;
5+
use rand::prelude::*;
66

7-
use crate::common::types::{Amount, CoinString, PrivateKey, PublicKey, Aggsig, GameID, Puzzle, PuzzleHash, Error, Timeout, Hash, CoinID, AllocEncoder, IntoErr, SpecificTransactionBundle, Sha256tree};
87
use crate::channel_handler::game_handler::GameHandler;
98
use crate::common::standard_coin::read_hex_puzzle;
9+
use crate::common::types::{
10+
Aggsig, AllocEncoder, Amount, CoinID, CoinString, Error, GameID, Hash, IntoErr, PrivateKey,
11+
PublicKey, Puzzle, PuzzleHash, Sha256tree, SpecificTransactionBundle, Timeout,
12+
};
1013
use crate::referee::RefereeMaker;
1114

1215
#[derive(Default)]
@@ -38,7 +41,7 @@ pub struct ChannelHandlerInitiationData {
3841

3942
pub struct ChannelHandlerInitiationResult {
4043
pub channel_puzzle_hash_up: PuzzleHash,
41-
pub my_initial_channel_half_signature_peer: Aggsig
44+
pub my_initial_channel_half_signature_peer: Aggsig,
4245
}
4346

4447
pub struct PotatoSignatures {
@@ -59,18 +62,23 @@ pub struct GameStartInfo {
5962
pub initial_state: NodePtr,
6063
pub initial_move: Vec<u8>,
6164
pub initial_max_move_size: usize,
62-
pub initial_mover_share: Amount
65+
pub initial_mover_share: Amount,
6366
}
6467

6568
#[derive(Clone)]
6669
pub struct ReadableMove(NodePtr);
6770

6871
impl ReadableMove {
69-
pub fn from_nodeptr(n: NodePtr) -> Self { ReadableMove(n) }
72+
pub fn from_nodeptr(n: NodePtr) -> Self {
73+
ReadableMove(n)
74+
}
7075
}
7176

7277
impl ToClvm<NodePtr> for ReadableMove {
73-
fn to_clvm(&self, encoder: &mut impl ClvmEncoder<Node = NodePtr>) -> Result<NodePtr, ToClvmError> {
78+
fn to_clvm(
79+
&self,
80+
encoder: &mut impl ClvmEncoder<Node = NodePtr>,
81+
) -> Result<NodePtr, ToClvmError> {
7482
Ok(self.0)
7583
}
7684
}
@@ -83,20 +91,20 @@ pub struct MoveResult {
8391
pub move_peer: Vec<u8>,
8492
pub validation_info_hash_peer: Hash,
8593
pub max_move_size_peer: usize,
86-
pub mover_share_peer: Amount
94+
pub mover_share_peer: Amount,
8795
}
8896

8997
pub struct OnChainGameCoin<'a> {
9098
pub game_id_up: GameID,
9199
pub coin_string_up: Option<CoinString>,
92-
pub referee_up: &'a RefereeMaker
100+
pub referee_up: &'a RefereeMaker,
93101
}
94102

95103
#[derive(Clone)]
96104
pub struct CoinSpentMoveUp {
97105
pub game_id: GameID,
98106
pub spend_before_game_coin: SpecificTransactionBundle,
99-
pub after_update_game_coin: CoinString
107+
pub after_update_game_coin: CoinString,
100108
}
101109

102110
#[derive(Clone)]
@@ -130,15 +138,18 @@ pub struct CoinSpentResult<'a> {
130138

131139
pub struct UnrollCoinSignatures {
132140
pub to_create_unroll_coin: Aggsig,
133-
pub to_spend_unroll_coin: Aggsig
141+
pub to_spend_unroll_coin: Aggsig,
134142
}
135143

136144
pub fn read_unroll_metapuzzle(allocator: &mut AllocEncoder) -> Result<Puzzle, Error> {
137145
read_hex_puzzle(allocator, "resources/unroll_meta_puzzle.hex")
138146
}
139147

140148
pub fn read_unroll_puzzle(allocator: &mut AllocEncoder) -> Result<Puzzle, Error> {
141-
read_hex_puzzle(allocator, "resources/unroll_puzzle_state_channel_unrolling.hex")
149+
read_hex_puzzle(
150+
allocator,
151+
"resources/unroll_puzzle_state_channel_unrolling.hex",
152+
)
142153
}
143154

144155
pub struct ChannelHandlerEnv<'a, R: Rng> {
@@ -160,7 +171,7 @@ impl<'a, R: Rng> ChannelHandlerEnv<'a, R> {
160171
unroll_metapuzzle: Puzzle,
161172
unroll_puzzle: Puzzle,
162173
referee_coin_puzzle: Puzzle,
163-
agg_sig_me_additional_data: Hash
174+
agg_sig_me_additional_data: Hash,
164175
) -> ChannelHandlerEnv<'a, R> {
165176
let referee_coin_puzzle_hash = referee_coin_puzzle.sha256tree(allocator);
166177
ChannelHandlerEnv {
@@ -170,14 +181,22 @@ impl<'a, R: Rng> ChannelHandlerEnv<'a, R> {
170181
referee_coin_puzzle_hash,
171182
unroll_metapuzzle,
172183
unroll_puzzle,
173-
agg_sig_me_additional_data
184+
agg_sig_me_additional_data,
174185
}
175186
}
176187

177-
pub fn curried_unroll_puzzle(&mut self, old_seq_number: u64, default_conditions_hash: PuzzleHash) -> Result<Puzzle, Error> {
188+
pub fn curried_unroll_puzzle(
189+
&mut self,
190+
old_seq_number: u64,
191+
default_conditions_hash: PuzzleHash,
192+
) -> Result<Puzzle, Error> {
178193
let curried_program = CurriedProgram {
179194
program: self.unroll_puzzle.clone(),
180-
args: clvm_curried_args!(self.unroll_metapuzzle.clone(), old_seq_number, default_conditions_hash)
195+
args: clvm_curried_args!(
196+
self.unroll_metapuzzle.clone(),
197+
old_seq_number,
198+
default_conditions_hash
199+
),
181200
};
182201
let nodeptr = curried_program.to_clvm(self.allocator).into_gen()?;
183202
Ok(Puzzle::from_nodeptr(nodeptr))
@@ -206,5 +225,5 @@ pub struct PotatoMoveCachedData {
206225
pub enum CachedPotatoRegenerateLastHop {
207226
PotatoCreatedGame(Vec<GameID>, Amount, Amount),
208227
PotatoAccept(PotatoAcceptCachedData),
209-
PotatoMoveHappening(PotatoMoveCachedData)
228+
PotatoMoveHappening(PotatoMoveCachedData),
210229
}

src/common/constants.rs

+11-134
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
use crate::common::types::{Hash, Sha256Input};
12
use lazy_static::lazy_static;
2-
use crate::common::types::{Sha256Input, Hash};
33

44
lazy_static! {
5-
pub static ref Q_KW_TREEHASH: Hash = Sha256Input::Array(vec![
6-
Sha256Input::Bytes(&[1]),
7-
Sha256Input::Bytes(&[1]),
8-
]).hash();
5+
pub static ref Q_KW_TREEHASH: Hash =
6+
Sha256Input::Array(vec![Sha256Input::Bytes(&[1]), Sha256Input::Bytes(&[1]),]).hash();
97
}
108

119
pub const CREATE_COIN: u32 = 51;
@@ -17,143 +15,23 @@ pub const CREATE_COIN_ATOM: [u8; 1] = [51];
1715
pub const REM_ATOM: [u8; 1] = [1];
1816

1917
pub const GROUP_ORDER: [u8; 32] = [
20-
0x73,
21-
0xED,
22-
0xA7,
23-
0x53,
24-
0x29,
25-
0x9D,
26-
0x7D,
27-
0x48,
28-
0x33,
29-
0x39,
30-
0xD8,
31-
0x08,
32-
0x09,
33-
0xA1,
34-
0xD8,
35-
0x05,
36-
0x53,
37-
0xBD,
38-
0xA4,
39-
0x02,
40-
0xFF,
41-
0xFE,
42-
0x5B,
43-
0xFE,
44-
0xFF,
45-
0xFF,
46-
0xFF,
47-
0xFF,
48-
0x00,
49-
0x00,
50-
0x00,
51-
0x01
18+
0x73, 0xED, 0xA7, 0x53, 0x29, 0x9D, 0x7D, 0x48, 0x33, 0x39, 0xD8, 0x08, 0x09, 0xA1, 0xD8, 0x05,
19+
0x53, 0xBD, 0xA4, 0x02, 0xFF, 0xFE, 0x5B, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01,
5220
];
5321

5422
pub const DEFAULT_HIDDEN_PUZZLE_HASH: [u8; 32] = [
55-
0x71,
56-
0x1d,
57-
0x6c,
58-
0x4e,
59-
0x32,
60-
0xc9,
61-
0x2e,
62-
0x53,
63-
0x17,
64-
0x9b,
65-
0x19,
66-
0x94,
67-
0x84,
68-
0xcf,
69-
0x8c,
70-
0x89,
71-
0x75,
72-
0x42,
73-
0xbc,
74-
0x57,
75-
0xf2,
76-
0xb2,
77-
0x25,
78-
0x82,
79-
0x79,
80-
0x9f,
81-
0x9d,
82-
0x65,
83-
0x7e,
84-
0xec,
85-
0x46,
86-
0x99,
23+
0x71, 0x1d, 0x6c, 0x4e, 0x32, 0xc9, 0x2e, 0x53, 0x17, 0x9b, 0x19, 0x94, 0x84, 0xcf, 0x8c, 0x89,
24+
0x75, 0x42, 0xbc, 0x57, 0xf2, 0xb2, 0x25, 0x82, 0x79, 0x9f, 0x9d, 0x65, 0x7e, 0xec, 0x46, 0x99,
8725
];
8826

8927
pub const DEFAULT_PUZZLE_HASH: [u8; 32] = [
90-
0xe9,
91-
0xaa,
92-
0xa4,
93-
0x9f,
94-
0x45,
95-
0xba,
96-
0xd5,
97-
0xc8,
98-
0x89,
99-
0xb8,
100-
0x6e,
101-
0xe3,
102-
0x34,
103-
0x15,
104-
0x50,
105-
0xc1,
106-
0x55,
107-
0xcf,
108-
0xdd,
109-
0x10,
110-
0xc3,
111-
0xa6,
112-
0x75,
113-
0x7d,
114-
0xe6,
115-
0x18,
116-
0xd2,
117-
0x06,
118-
0x12,
119-
0xff,
120-
0xfd,
121-
0x52,
28+
0xe9, 0xaa, 0xa4, 0x9f, 0x45, 0xba, 0xd5, 0xc8, 0x89, 0xb8, 0x6e, 0xe3, 0x34, 0x15, 0x50, 0xc1,
29+
0x55, 0xcf, 0xdd, 0x10, 0xc3, 0xa6, 0x75, 0x7d, 0xe6, 0x18, 0xd2, 0x06, 0x12, 0xff, 0xfd, 0x52,
12230
];
12331

12432
pub const AGG_SIG_ME_ADDITIONAL_DATA: [u8; 32] = [
125-
0xcc,
126-
0xd5,
127-
0xbb,
128-
0x71,
129-
0x18,
130-
0x35,
131-
0x32,
132-
0xbf,
133-
0xf2,
134-
0x20,
135-
0xba,
136-
0x46,
137-
0xc2,
138-
0x68,
139-
0x99,
140-
0x1a,
141-
0x3f,
142-
0xf0,
143-
0x7e,
144-
0xb3,
145-
0x58,
146-
0xe8,
147-
0x25,
148-
0x5a,
149-
0x65,
150-
0xc3,
151-
0x0a,
152-
0x2d,
153-
0xce,
154-
0x0e,
155-
0x5f,
156-
0xbb
33+
0xcc, 0xd5, 0xbb, 0x71, 0x18, 0x35, 0x32, 0xbf, 0xf2, 0x20, 0xba, 0x46, 0xc2, 0x68, 0x99, 0x1a,
34+
0x3f, 0xf0, 0x7e, 0xb3, 0x58, 0xe8, 0x25, 0x5a, 0x65, 0xc3, 0x0a, 0x2d, 0xce, 0x0e, 0x5f, 0xbb,
15735
];
15836

15937
pub const ONE: [u8; 1] = [1];
@@ -162,4 +40,3 @@ pub const TWO: [u8; 1] = [2];
16240
pub const Q_KW: [u8; 1] = [1];
16341
pub const A_KW: [u8; 1] = [2];
16442
pub const C_KW: [u8; 1] = [4];
165-

src/common/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub mod constants;
2-
pub mod types;
32
pub mod standard_coin;
3+
pub mod types;

0 commit comments

Comments
 (0)