|
1 | 1 | import pathlib |
2 | 2 | from typing import Literal |
3 | 3 |
|
4 | | -from pydantic import model_validator, HttpUrl |
| 4 | +from pydantic import BaseModel, ConfigDict, model_validator, HttpUrl |
5 | 5 | from pydantic_settings import BaseSettings, SettingsConfigDict |
6 | | -from stellar_sdk import Keypair, Network |
| 6 | +from stellar_sdk import xdr |
| 7 | +from stellar_sdk import Keypair, Network, scval |
7 | 8 |
|
8 | | -__all__ = ["Identity", "NetworkConfig"] |
| 9 | +__all__ = ["Identity", "NetworkConfig", "Parameter", "Parameters"] |
9 | 10 |
|
10 | 11 |
|
11 | 12 | def _load_configuration(id: str | pathlib.Path, kind: Literal["identity", "network"]): |
@@ -72,3 +73,21 @@ def from_network(cls, network: str | pathlib.Path | None = None) -> "NetworkConf |
72 | 73 | fname = _load_configuration(network, "network") |
73 | 74 | network = NetworkConfig(_env_file=fname) |
74 | 75 | return network |
| 76 | + |
| 77 | + |
| 78 | +class Parameter(BaseModel): |
| 79 | + model_config = ConfigDict(arbitrary_types_allowed=True) |
| 80 | + |
| 81 | + name: str |
| 82 | + type: str |
| 83 | + value: int | float | str | xdr.SCVal |
| 84 | + |
| 85 | + @model_validator(mode="after") |
| 86 | + def value_to_scval(self) -> "Parameter": |
| 87 | + if not isinstance(self.value, xdr.SCVal): |
| 88 | + self.value = getattr(scval, f"to_{self.type}")(self.value) |
| 89 | + return self |
| 90 | + |
| 91 | + |
| 92 | +class Parameters(BaseModel): |
| 93 | + args: list[Parameter] |
0 commit comments