|
@@ -19,18 +19,18 @@
|
|
|
use darkfi_serial::{serialize, SerialDecodable, SerialEncodable};
|
|
use darkfi_serial::{serialize, SerialDecodable, SerialEncodable};
|
|
|
use pasta_curves::{group::ff::PrimeField, pallas};
|
|
use pasta_curves::{group::ff::PrimeField, pallas};
|
|
|
|
|
|
|
|
|
|
+/// ContractId represents an on-chain identifier for a certain
|
|
|
|
|
+/// smart contract.
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, SerialEncodable, SerialDecodable)]
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, SerialEncodable, SerialDecodable)]
|
|
|
pub struct ContractId(pallas::Base);
|
|
pub struct ContractId(pallas::Base);
|
|
|
|
|
|
|
|
impl ContractId {
|
|
impl ContractId {
|
|
|
- pub fn new(contract_id: pallas::Base) -> Self {
|
|
|
|
|
- Self(contract_id)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /// Get the inner `pallas::Base` element.
|
|
|
pub fn inner(&self) -> pallas::Base {
|
|
pub fn inner(&self) -> pallas::Base {
|
|
|
self.0
|
|
self.0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// Create a `ContractId` object from given bytes.
|
|
|
pub fn from_bytes(x: [u8; 32]) -> Self {
|
|
pub fn from_bytes(x: [u8; 32]) -> Self {
|
|
|
// FIXME: Handle Option
|
|
// FIXME: Handle Option
|
|
|
Self(pallas::Base::from_repr(x).unwrap())
|
|
Self(pallas::Base::from_repr(x).unwrap())
|
|
@@ -47,6 +47,12 @@ impl ContractId {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+impl From<pallas::Base> for ContractId {
|
|
|
|
|
+ fn from(x: pallas::Base) -> Self {
|
|
|
|
|
+ Self(x)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
impl std::fmt::Display for ContractId {
|
|
impl std::fmt::Display for ContractId {
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
// base58 encoding
|
|
// base58 encoding
|