-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swap and Ics 20 Withdrawal effect hash (#9)
* Add ics20 parser * add swap parser * add swap effect hash * update snapshots
- Loading branch information
Showing
67 changed files
with
1,290 additions
and
199 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::parser::commitment::Commitment; | ||
use crate::parser::id::Id; | ||
use crate::parser::value::Sign; | ||
use crate::parser::value::{Value, ValueC}; | ||
use crate::ParserError; | ||
use decaf377::Fq; | ||
use decaf377::Fr; | ||
use crate::constants::{AMOUNT_LEN_BYTES, ID_LEN_BYTES}; | ||
// The staking token asset ID (upenumbra) | ||
// Bech32m: passet1984fctenw8m2fpl8a9wzguzp7j34d7vravryuhft808nyt9fdggqxmanqm | ||
pub const STAKING_TOKEN_ASSET_ID_BYTES: [u8; 32] = [ | ||
0x29, 0xea, 0x9c, 0x2f, 0x33, 0x71, 0xf6, 0xa4, 0x87, 0xe7, 0xe9, 0x5c, 0x24, 0x70, 0x41, 0xf4, | ||
0xa3, 0x56, 0xf9, 0x83, 0xeb, 0x06, 0x4e, 0x5d, 0x2b, 0x3b, 0xcf, 0x32, 0x2c, 0xa9, 0x6a, 0x10, | ||
]; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Fee(pub Value); | ||
|
||
#[repr(C)] | ||
#[derive(Clone)] | ||
#[cfg_attr(any(feature = "derive-debug", test), derive(Debug))] | ||
pub struct FeeC(pub ValueC); | ||
|
||
impl TryFrom<FeeC> for Fee { | ||
type Error = ParserError; | ||
|
||
fn try_from(value: FeeC) -> Result<Self, Self::Error> { | ||
if value.0.has_asset_id { | ||
Ok(Fee(Value::try_from(value.0)?)) | ||
} else { | ||
// If conversion fails, create a new Value with the amount and staking token asset ID | ||
Ok(Fee(Value { | ||
amount: value.0.amount.try_into()?, | ||
asset_id: Id { | ||
0: Fq::from_le_bytes_mod_order(&STAKING_TOKEN_ASSET_ID_BYTES), | ||
}, | ||
})) | ||
} | ||
} | ||
} | ||
|
||
impl FeeC { | ||
pub fn to_value_c(&self) -> ValueC { | ||
self.0.clone() | ||
} | ||
} | ||
|
||
impl Fee { | ||
pub const LEN: usize = AMOUNT_LEN_BYTES + ID_LEN_BYTES; | ||
|
||
pub fn commit(&self, blinding: Fr) -> Result<Commitment, ParserError> { | ||
let value = Value::try_from(self.0.clone()); | ||
if let Ok(value) = value { | ||
Ok(value.commit(blinding, Sign::Required)?) | ||
} else { | ||
Err(ParserError::ClueCreationFailed) | ||
} | ||
} | ||
|
||
pub fn to_bytes(&self) -> Result<[u8; Self::LEN], ParserError> { | ||
self.0.to_bytes() | ||
} | ||
} |
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
Oops, something went wrong.