Skip to content

Commit 411bd0b

Browse files
authoredMar 19, 2024··
[Feature] Add address getter to Program
2 parents a08416f + 7477077 commit 411bd0b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
 

‎wasm/src/account/address.rs

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ impl FromStr for Address {
7777
}
7878
}
7979

80+
impl From<AddressNative> for Address {
81+
fn from(value: AddressNative) -> Self {
82+
Self(value)
83+
}
84+
}
85+
8086
impl fmt::Display for Address {
8187
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8288
write!(f, "{}", self.0)

‎wasm/src/programs/program.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with the Aleo SDK library. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use crate::types::native::{CurrentNetwork, EntryType, IdentifierNative, PlaintextType, ProgramNative, ValueType};
17+
use crate::{
18+
account::Address,
19+
types::native::{CurrentNetwork, EntryType, IdentifierNative, PlaintextType, ProgramNative, ValueType},
20+
};
1821

1922
use js_sys::{Array, Object, Reflect};
2023
use std::{ops::Deref, str::FromStr};
@@ -418,6 +421,14 @@ impl Program {
418421
self.0.id().to_string()
419422
}
420423

424+
/// Get a unique address of the program
425+
///
426+
/// @returns {Address} The address of the program
427+
#[wasm_bindgen]
428+
pub fn address(&self) -> Result<Address, String> {
429+
Ok(Address::from(self.0.id().to_address().map_err(|e| e.to_string())?))
430+
}
431+
421432
/// Determine equality with another program
422433
///
423434
/// @param {Program} other The other program to compare

0 commit comments

Comments
 (0)
Please sign in to comment.