Skip to content

Commit

Permalink
RGB: new TxOutPoint data type for metadata & state
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 1, 2020
1 parent afac539 commit 4906736
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/rgb/contract/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use core::cmp::Ordering;

use bitcoin::hashes::{hash160, sha256, sha256d, sha512, Hash};
use bitcoin::secp256k1;
use bitcoin::OutPoint;

use super::{ConfidentialState, RevealedState};
use crate::client_side_validation::{commit_strategy, CommitEncodeWithStrategy, Conceal};
Expand Down Expand Up @@ -78,6 +79,7 @@ pub enum Revealed {
Ed25519Signature(ed25519_dalek::Signature),
// TODO: Add support for Schnorr's signatures once they will be implemented
// in rust-secp256k1
TxOutPoint(OutPoint),
}

impl RevealedState for Revealed {}
Expand Down Expand Up @@ -195,6 +197,8 @@ pub(super) mod strict_encoding {

Ed25519Pubkey = 0b_1000_1001_u8,
Ed25519Signature = 0b_1000_1010_u8,

TxOutPoint = 0b_0101_0001_u8,
}
impl_enum_strict_encoding!(EncodingTag);

Expand Down Expand Up @@ -243,6 +247,7 @@ pub(super) mod strict_encoding {
}
Revealed::Ed25519Pubkey(_) => unimplemented!(),
Revealed::Ed25519Signature(_) => unimplemented!(),
Revealed::TxOutPoint(val) => strict_encode_list!(e; EncodingTag::TxOutPoint, val),
})
}
}
Expand Down Expand Up @@ -283,6 +288,7 @@ pub(super) mod strict_encoding {
}
EncodingTag::Ed25519Pubkey => unimplemented!(),
EncodingTag::Ed25519Signature => unimplemented!(),
EncodingTag::TxOutPoint => Revealed::TxOutPoint(OutPoint::strict_decode(&mut d)?),
})
}
}
Expand Down Expand Up @@ -317,7 +323,9 @@ pub(super) mod strict_encoding {
EncodingTag::Secp256k1Signature => 0b_1000_0010_u8,

EncodingTag::Ed25519Pubkey => 0b_1000_1001_u8,
EncodingTag::Ed25519Signature => 0b_1000_1010_u8
EncodingTag::Ed25519Signature => 0b_1000_1010_u8,

EncodingTag::TxOutPoint => 0b_0101_0001_u8
);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/rgb/schema/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,7 @@ pub(crate) mod test {
FIELD_DUST_LIMIT => DataFormat::Unsigned(Bits::Bit64, 0, core::u64::MAX as u128),
FIELD_PRUNE_PROOF => DataFormat::Bytes(core::u16::MAX),
FIELD_TIMESTAMP => DataFormat::Unsigned(Bits::Bit64, 0, core::u64::MAX as u128),
// TODO: (new) Fix this with introduction of new data type
FIELD_PROOF_OF_BURN => DataFormat::String(0)
FIELD_PROOF_OF_BURN => DataFormat::TxOutPoint
},
assignment_types: bmap! {
ASSIGNMENT_ISSUE => StateSchema {
Expand Down
13 changes: 10 additions & 3 deletions src/rgb/schema/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub enum DataFormat {
String(u16),
Bytes(u16),
Digest(DigestAlgorithm),
TxOutPoint,
PublicKey(EllipticCurve, elliptic_curve::PointSerialization),
Signature(elliptic_curve::SignatureAlgorithm),
}
Expand Down Expand Up @@ -190,15 +191,19 @@ mod strict_encoding {
#[display(Debug)]
#[repr(u8)]
enum EncodingTag {
// Primitive types
Unsigned = 0,
Integer = 1,
Float = 2,
Enum = 3,
String = 4,
Bytes = 5,
Digest = 6,
PublicKey = 7,
Signature = 8,
// Cryptographic tyles
Digest = 0x10,
PublicKey = 0x11,
Signature = 0x12,
// Composed types
TxOutPoint = 0x20,
}
impl_enum_strict_encoding!(EncodingTag);

Expand Down Expand Up @@ -479,6 +484,7 @@ mod strict_encoding {
strict_encode_list!(e; EncodingTag::PublicKey, curve, ser)
}
DataFormat::Signature(algo) => strict_encode_list!(e; EncodingTag::Signature, algo),
DataFormat::TxOutPoint => EncodingTag::TxOutPoint.strict_encode(&mut e)?,
})
}
}
Expand Down Expand Up @@ -634,6 +640,7 @@ mod strict_encoding {
EncodingTag::Signature => DataFormat::Signature(
elliptic_curve::SignatureAlgorithm::strict_decode(&mut d)?,
),
EncodingTag::TxOutPoint => DataFormat::TxOutPoint,
})
}
}
Expand Down

0 comments on commit 4906736

Please sign in to comment.