Skip to content

Commit

Permalink
Merge branch 'master' into todo-list
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky authored Mar 25, 2021
2 parents 12cb786 + c181be9 commit 6677dfe
Show file tree
Hide file tree
Showing 21 changed files with 1,416 additions and 671 deletions.
13 changes: 6 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ lazy_static = "~1.4.0"
deflate = "~0.8.6"
inflate = "~0.4.5"
chrono = "~0.4.19"
regex = "~1.4.3"
# Temporary-needed dependencies:
# ------------------------------
# 1. We are of no control of what's happening in Grin and would like to prevent
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sudo apt-get install cargo libssl-dev libzmq3-dev pkg-config g++ cmake

On Mac OS, run
```shell script
brew cargo pkg-config zmq
brew install rust pkg-config zmq
```

### Clone and compile library
Expand Down
89 changes: 66 additions & 23 deletions rgb20/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::collections::BTreeMap;
use std::convert::{TryFrom, TryInto};

use amplify::Wrapper;
use bitcoin::OutPoint;
use bitcoin::{OutPoint, Txid};
use lnpbp::Chain;
use rgb::prelude::*;
use rgb::seal::WitnessVoutError;
Expand All @@ -43,6 +43,16 @@ pub enum Error {
/// can't be a witness transaction for genesis
#[from(WitnessVoutError)]
GenesisSeal,

/// Epoch seal definition for node {0} contains confidential data
EpochSealConfidential(NodeId),

/// Burn & replace seal definition for node {0} contains confidential data
BurnSealConfidential(NodeId),

/// Inflation assignment (seal or state) for node {0} contains confidential
/// data
InflationAssignmentConfidential(NodeId),
}

// TODO #31: Add support for renominations, burn & replacements
Expand Down Expand Up @@ -92,8 +102,12 @@ pub struct Asset {
/// arbitrary order
known_issues: Vec<Issue>,

/// Burn & replacement epochs, organized according to the epoch order
epochs: Vec<Epoch>,
/// Burn & replacement epochs, organized according to the witness txid.
///
/// Witness transaction must be mined for the epoch to be real.
/// One of the inputs of this transaction MUST spend UTXO defined as a
/// seal closed by this epoch ([`Epoch::closes`])
epochs: BTreeMap<Txid, Epoch>,

/// Detailed information about the asset supply (aggregated from the issue
/// and burning information kept inside the epochs data)
Expand Down Expand Up @@ -217,12 +231,7 @@ impl Asset {

impl Asset {
#[inline]
pub fn add_issue(&self, _issue: Transition) -> Supply {
unimplemented!()
}

#[inline]
pub fn allocations(&self, outpoint: bitcoin::OutPoint) -> Vec<Allocation> {
pub fn allocations(&self, outpoint: OutPoint) -> Vec<Allocation> {
self.known_allocations
.iter()
.filter(|a| *a.outpoint() == outpoint)
Expand All @@ -232,7 +241,7 @@ impl Asset {

pub fn add_allocation(
&mut self,
outpoint: bitcoin::OutPoint,
outpoint: OutPoint,
node_id: NodeId,
index: u16,
value: value::Revealed,
Expand All @@ -248,7 +257,7 @@ impl Asset {

pub fn remove_allocation(
&mut self,
outpoint: bitcoin::OutPoint,
outpoint: OutPoint,
node_id: NodeId,
index: u16,
value: value::Revealed,
Expand Down Expand Up @@ -289,9 +298,9 @@ impl TryFrom<Genesis> for Asset {
for assignment in
genesis.owned_rights_by_type(*OwnedRightsType::Inflation)
{
for state in assignment.to_custom_state() {
for state in assignment.to_data_assignment_vec() {
match state {
OwnedState::Revealed {
Assignment::Revealed {
seal_definition,
assigned_state,
} => {
Expand All @@ -302,7 +311,7 @@ impl TryFrom<Genesis> for Asset {
.ok_or(schema::Error::NotAllFieldsPresent)?,
);
}
OwnedState::ConfidentialSeal { assigned_state, .. } => {
Assignment::ConfidentialSeal { assigned_state, .. } => {
if issue_limit < core::u64::MAX {
issue_limit += assigned_state
.u64()
Expand All @@ -316,23 +325,17 @@ impl TryFrom<Genesis> for Asset {
}
}

let issue = Issue::try_from(&genesis)?;
let node_id = NodeId::from_inner(genesis.contract_id().into_inner());
let issue = Issue::with(
genesis.node_id(),
genesis.contract_id(),
supply.clone(),
empty!(), // This is a primary issue, so no origin here
known_inflation.clone(),
);
let mut known_allocations = Vec::<Allocation>::new();
for assignment in genesis.owned_rights_by_type(*OwnedRightsType::Assets)
{
assignment
.to_discrete_state()
.to_value_assignment_vec()
.into_iter()
.enumerate()
.for_each(|(index, assign)| {
if let OwnedState::Revealed {
if let Assignment::Revealed {
seal_definition:
seal::Revealed::TxOutpoint(outpoint_reveal),
assigned_state,
Expand Down Expand Up @@ -386,3 +389,43 @@ impl TryFrom<Genesis> for Asset {
})
}
}

impl TryFrom<Consignment> for Asset {
type Error = Error;

fn try_from(consignment: Consignment) -> Result<Self, Self::Error> {
// 1. Parse genesis
let asset: Asset = consignment.genesis.try_into()?;

// 2. Parse secondary issues

// 3. Parse epochs & burn/replace operations

// 4. Parse renominations

unimplemented!()
}
}

impl Asset {
#[allow(dead_code)]
fn append_epoch(
&mut self,
consignment: &Consignment,
epoch_id: NodeId,
) -> Result<(), Error> {
// 1. It must correctly extend known state, i.e. close UTXO for a seal
// defined by a state transition already belonging to the asset
unimplemented!()
}

#[allow(dead_code)]
fn append_burn_or_replace(
&mut self,
consignment: &Consignment,
epoch_id: NodeId,
bor_id: NodeId,
) -> Result<(), Error> {
unimplemented!()
}
}
7 changes: 7 additions & 0 deletions rgb20/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ pub fn schema() -> Schema {
FieldType::RicardianContract => NoneOrOnce,
FieldType::Precision => Once,
FieldType::Timestamp => Once,
// We need this field in order to be able to verify pedersen
// commitments
FieldType::IssuedSupply => Once
},
owned_rights: type_map! {
Expand All @@ -162,6 +164,8 @@ pub fn schema() -> Schema {
transitions: type_map! {
TransitionType::Issue => TransitionSchema {
metadata: type_map! {
// We need this field in order to be able to verify pedersen
// commitments
FieldType::IssuedSupply => Once
},
closes: type_map! {
Expand Down Expand Up @@ -231,6 +235,9 @@ pub fn schema() -> Schema {
// mistake this will be impossible, so we allow to have
// multiple burned UTXOs as a part of a single operation
FieldType::BurnUtxo => OnceOrMore,
// We need this field in order to be able to verify pedersen
// commitments
FieldType::IssuedSupply => Once,
FieldType::HistoryProofFormat => Once,
FieldType::HistoryProof => NoneOrMore
},
Expand Down
Loading

0 comments on commit 6677dfe

Please sign in to comment.