-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into win-installer
- Loading branch information
Showing
13 changed files
with
118 additions
and
65 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,49 @@ | ||
use std::collections::HashMap; | ||
use std::{collections::HashMap, convert::Infallible, str::FromStr}; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::locator; | ||
|
||
#[derive(Serialize, Deserialize, Default)] | ||
pub struct Data { | ||
pub ids: HashMap<String, String>, | ||
} | ||
|
||
/// Address can be either a contract address, C.. or eventually an alias of a contract address. | ||
#[derive(Clone, Debug)] | ||
pub enum ContractAddress { | ||
ContractId(stellar_strkey::Contract), | ||
Alias(String), | ||
} | ||
|
||
impl Default for ContractAddress { | ||
fn default() -> Self { | ||
ContractAddress::Alias(String::default()) | ||
} | ||
} | ||
|
||
impl FromStr for ContractAddress { | ||
type Err = Infallible; | ||
|
||
fn from_str(value: &str) -> Result<Self, Self::Err> { | ||
Ok(stellar_strkey::Contract::from_str(value).map_or_else( | ||
|_| ContractAddress::Alias(value.to_string()), | ||
ContractAddress::ContractId, | ||
)) | ||
} | ||
} | ||
|
||
impl ContractAddress { | ||
pub fn resolve_contract_id( | ||
&self, | ||
locator: &locator::Args, | ||
network_passphrase: &str, | ||
) -> Result<stellar_strkey::Contract, locator::Error> { | ||
match self { | ||
ContractAddress::ContractId(muxed_account) => Ok(*muxed_account), | ||
ContractAddress::Alias(alias) => locator | ||
.get_contract_id(alias, network_passphrase)? | ||
.ok_or_else(|| locator::Error::ContractNotFound(alias.to_owned())), | ||
} | ||
} | ||
} |
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.