-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support perpetual-contract branch of circuit (#46)
* support perpetual-contract branch of circuit * use TOKEN_MAX_PRECISION * small fix * cargo fmt * update ZkLinkTxType, and fix validator comment * add builder for contract transaction * add ContractBuilder * update params * remove op_codes of ZkLinkTxType, fix params * resolve Todo * fix test rescue_hash_orders and cargo fmt * fix function order in GetBytes trait --------- Co-authored-by: RequiemOfSouls <[email protected]>
- Loading branch information
1 parent
ed7a506
commit 31cad4f
Showing
37 changed files
with
2,030 additions
and
354 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
pub struct BitConvert; | ||
|
||
impl BitConvert { | ||
/// Сonverts a set of bits to a set of bytes in direct order. | ||
pub fn into_bytes(bits: Vec<bool>) -> Vec<u8> { | ||
assert_eq!(bits.len() % 8, 0); | ||
let mut message_bytes: Vec<u8> = vec![]; | ||
|
||
let byte_chunks = bits.chunks(8); | ||
for byte_chunk in byte_chunks { | ||
let mut byte = 0u8; | ||
for (i, bit) in byte_chunk.iter().enumerate() { | ||
if *bit { | ||
byte |= 1 << i; | ||
} | ||
} | ||
message_bytes.push(byte); | ||
} | ||
|
||
message_bytes | ||
} | ||
|
||
/// Сonverts a set of bits to a set of bytes in reverse order for each byte. | ||
pub fn into_bytes_ordered(bits: Vec<bool>) -> Vec<u8> { | ||
assert_eq!(bits.len() % 8, 0); | ||
let mut message_bytes: Vec<u8> = vec![]; | ||
|
||
let byte_chunks = bits.chunks(8); | ||
for byte_chunk in byte_chunks { | ||
let mut byte = 0u8; | ||
for (i, bit) in byte_chunk.iter().rev().enumerate() { | ||
if *bit { | ||
byte |= 1 << i; | ||
} | ||
} | ||
message_bytes.push(byte); | ||
} | ||
|
||
message_bytes | ||
} | ||
|
||
/// Сonverts a set of Big Endian bytes to a set of bits. | ||
pub fn from_be_bytes(bytes: &[u8]) -> Vec<bool> { | ||
let mut bits = vec![]; | ||
for byte in bytes { | ||
let mut temp = *byte; | ||
for _ in 0..8 { | ||
bits.push(temp & 0x80 == 0x80); | ||
temp <<= 1; | ||
} | ||
} | ||
bits | ||
} | ||
} |
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.