Skip to content

Commit

Permalink
Updated consignment creation & validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 9, 2020
1 parent 69090a5 commit 4a32887
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 126 deletions.
2 changes: 1 addition & 1 deletion src/rgb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub mod prelude {
};
pub use stash::{
Anchor, AnchorId, Consignment, ConsignmentEndpoints, Disclosure, Stash,
TransitionData, PSBT_FEE_KEY, PSBT_PUBKEY_KEY,
TransitionData,
};
pub use validation::{Validator, Validity};
pub use vm::VirtualMachine;
Expand Down
24 changes: 13 additions & 11 deletions src/rgb/stash/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use std::collections::{BTreeMap, HashMap};

use amplify::Wrapper;
use bitcoin::secp256k1;
use bitcoin::util::psbt::{raw::Key, PartiallySignedTransaction as Psbt};
use bitcoin::util::psbt::{
raw::ProprietaryKey, PartiallySignedTransaction as Psbt,
};
use bitcoin::util::uint::Uint256;
use bitcoin::{Transaction, Txid};
use bitcoin_hashes::{sha256, sha256t, Hash, HashEngine};
Expand All @@ -31,8 +33,6 @@ use crate::commit_verify::{CommitVerify, EmbedCommitVerify, TryCommitVerify};
use crate::lnpbp4::{MultimsgCommitment, TooManyMessagesError};
use crate::rgb::{ContractId, NodeId};

pub const PSBT_FEE_KEY: &[u8] = b"\x03rgb\x01";
pub const PSBT_PUBKEY_KEY: &[u8] = b"\x03rgb\x02";
lazy_static! {
static ref LNPBP4_TAG: bitcoin::hashes::sha256::Hash =
sha256::Hash::hash(b"LNPBP4");
Expand Down Expand Up @@ -84,18 +84,20 @@ impl Anchor {
let tx = &mut psbt.global.unsigned_tx;
let num_outs = tx.output.len() as u64;

let pubkey_key = Key {
type_value: 0xFC,
key: PSBT_PUBKEY_KEY.to_vec(),
let pubkey_key = ProprietaryKey {
prefix: b"RGB".to_vec(),
subtype: 2u8,
key: vec![],
};
let fee_key = Key {
type_value: 0xFC,
key: PSBT_FEE_KEY.to_vec(),
let fee_key = ProprietaryKey {
prefix: b"RGB".to_vec(),
subtype: 1u8,
key: vec![],
};

let fee = psbt
.global
.unknown
.proprietary
.get(&fee_key)
.ok_or(Error::NoFeeInformation)?;
let mut fee_slice = [0u8; 8];
Expand Down Expand Up @@ -132,7 +134,7 @@ impl Anchor {
let tx_out = &tx.output[vout];

let pubkey = psbt_out
.unknown
.proprietary
.get(&pubkey_key)
.ok_or(Error::NoRequiredPubkey(vout))?;
let pubkey = secp256k1::PublicKey::from_slice(pubkey)?;
Expand Down
216 changes: 103 additions & 113 deletions src/rgb/stash/consignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,118 +120,109 @@ pub(crate) mod test {

pub(crate) fn consignment() -> Consignment {
let data: Vec<u8> = vec![
// ** Version: 0 (2 bytes)
0, 0, //
// ** Genesis
// * Schema Id (32 bytes)
// 32, 0, // Length
211, 66, 50, 8, 132, 162, 132, 224, //
141, 136, 241, 106, 62, 52, 132, 32, //
85, 122, 53, 167, 151, 135, 178, 70, //
187, 68, 10, 209, 232, 38, 153, 97, //
//
// * Chain
0x6f, 0xe2, 0x8c, 0xa, 0xb6, 0xf1, 0xb3, 0x72, 0xc1, 0xa6, 0xa2,
0x46, 0xae, 0x63, 0xf7, 0x4f, 0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a,
0x8, 0x9c, 0x68, 0xd6, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x0,
0x62, 0x69, 0x74, 0x63, 0x6f, 0x69, 0x6e, 0xf9, 0xbe, 0xb4, 0xd9,
0x4, 0x0, 0x6d, 0x61, 0x69, 0x6e, 0x2, 0x0, 0x62, 0x63, 0x8d, 0x20,
0x8c, 0x20, 0xb4, 0xb2, 0x7, 0x0, 0x10, 0xeb, 0x9, 0x0, 0x0, 0x22,
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x42, 0x54, 0x43, 0x7,
0x0, 0x42, 0x69, 0x74, 0x63, 0x6f, 0x69, 0x6e, 0x7, 0x0, 0x73,
0x61, 0x74, 0x6f, 0x73, 0x68, 0x69, 0x0, 0xe1, 0xf5, 0x5, 0x0, 0x0,
0x0, 0x0, 0x6f, 0xe2, 0x8c, 0xa, 0xb6, 0xf1, 0xb3, 0x72, 0xc1,
0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f, 0x93, 0x1e, 0x83, 0x65,
0xe1, 0x5a, 0x8, 0x9c, 0x68, 0xd6, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x1, // Bitcoin mainnet
//
// * Network - replaced with Chain
// 0x43, 0x49, 0x7f, 0xd7, 0xf8, 0x26, 0x95, 0x71, 0x08, 0xf4,
// 0xa3, 0x0f, 0xd9, 0xce, 0xc3, 0xae, 0xba, 0x79,
// 0x97, 0x20, 0x84, 0xe9, 0x0e, 0xad, 0x01, 0xea, 0x33, 0x09,
// 0x00, 0x00, 0x00, 0x00, // testnet
// * Metadata
7, 0, // No of fields: 7
// Field 1
0, 0, // Field type: Ticker
1, 0, // No of values
33, // Value type: string
4, 0, // Value length: 4
85, 83, 68, 84, // Value: USDT
// Field 2
1, 0, // Field type: Name
1, 0, // No of values
33, // Value type: string
10, 0, // Value length: 16
85, 83, 68, 32, 84, 101, 116, 104, 101,
114, // Value: USD Tether
// Field 3
3, 0, // Field type: total supply
1, 0, // No of values
3, // Value type: U64
160, 134, 1, 0, 0, 0, 0, 0, // Value
// Field 4
4, 0, // Field type: Issued supply
1, 0, // No of values
3, // Value type: U64
160, 134, 1, 0, 0, 0, 0, 0, // Value
// Field 5
5, 0, // Field type: dust limit
1, 0, // No of values
3, // Value type: U64
0, 0, 0, 0, 0, 0, 0, 0, // Value
// Field 6
6, 0, // Field type: precision
1, 0, // No of values
0, // Value type: U8
0, // Value
// Field 7
8, 0, // Field type: timestamp
1, 0, // No of values
11, // Value type: I64
129, 58, 36, 95, 0, 0, 0, 0, // Value
//
// * Assignments
2, 0, // No of assignments
1, 0, 1, 3, 1, 0, 1, 0, 172, 198, 241, 181, 165, 20, 213, 54, 40,
73, 173, 36, 33, 53, 221, 119, 251, 0, 189, 217, 213, 41, 198, 175,
58, 121, 140, 28, 146, 37, 87, 64, 38, 143, 99, 202, 152, 114, 142,
39, 0, 0, 0, 0, 3, 160, 134, 1, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 1, 0, 119, 31, 120, 181,
213, 239, 72, 20, 181, 14, 218, 85, 151, 249, 249, 0, 34, 112, 87,
248, 175, 199, 165, 38, 102, 156, 251, 196, 1, 155, 240, 11, 89,
186, 209, 42, 101, 37, 228, 34, 242, 78, 181, 53, 50, 131, 104, 49,
210, 154, 160, 244, 233, 215, 118, 60, 109, 208, 57, 250, 158, 106,
0, 250, 1, 0, 40, 60, 217, 167, 244, 2, 37, 149, 49, 155, 251, 143,
97, 38, 157, 145, 70, 26, 1, 55, 226, 254, 248, 79, 245, 146, 206,
78, 133, 169, 41, 40, 3, 0, 0, 84, 58, 167, 47, 84, 222, 139, 254,
20, 54, 254, 23, 40, 20, 240, 121, 252, 19, 90, 52, 55, 246, 119,
163, 115, 68, 213, 191, 221, 242, 223, 85, 0, 236, 157, 125, 216,
45, 29, 21, 128, 28, 221, 79, 169, 116, 83, 179, 83, 228, 196, 75,
217, 96, 20, 17, 13, 55, 81, 51, 28, 151, 83, 41, 135, 1, 44, 67,
210, 154, 72, 87, 82, 60, 148, 202, 96, 0, 34, 227, 220, 39, 91,
26, 55, 190, 155, 201, 78, 248, 246, 29, 193, 42, 235, 69, 155,
195, 119, 31, 120, 181, 213, 239, 72, 20, 181, 14, 218, 85, 151,
249, 249, 0, 34, 112, 87, 248, 175, 199, 165, 38, 102, 156, 251,
196, 1, 155, 240, 11, 1, 126, 204, 108, 187, 10, 227, 183, 4, 3,
158, 255, 31, 84, 122, 29, 95, 146, 223, 162, 186, 122, 246, 172,
151, 26, 75, 208, 59, 164, 167, 52, 176, 49, 86, 162, 86, 184, 173,
58, 30, 249, 0, 1, 0, 0, 0, 1, 0, 44, 67, 210, 154, 72, 87, 82, 60,
148, 202, 96, 0, 34, 227, 220, 39, 91, 26, 55, 190, 155, 201, 78,
248, 246, 29, 193, 42, 235, 69, 155, 195, 1, 0, 1, 0, 1, 0, 0, 0,
1, 0, 1, 0, 1, 3, 2, 0, 2, 89, 186, 209, 42, 101, 37, 228, 34, 242,
78, 181, 53, 50, 131, 104, 49, 210, 154, 160, 244, 233, 215, 118,
60, 109, 208, 57, 250, 158, 106, 0, 250, 3, 100, 0, 0, 0, 0, 0, 0,
0, 32, 0, 94, 225, 8, 249, 174, 126, 227, 191, 87, 70, 139, 92,
167, 220, 218, 31, 21, 6, 130, 248, 84, 18, 137, 87, 242, 81, 220,
82, 184, 99, 93, 135, 1, 0, 50, 112, 155, 170, 111, 145, 181, 32,
190, 173, 32, 142, 81, 240, 183, 249, 253, 225, 241, 208, 43, 50,
220, 113, 160, 83, 117, 66, 39, 54, 213, 157, 241, 15, 215, 23,
180, 230, 84, 244, 1, 0, 0, 0, 3, 60, 134, 1, 0, 0, 0, 0, 0, 32, 0,
161, 30, 247, 6, 81, 129, 28, 64, 168, 185, 116, 163, 88, 35, 37,
223, 165, 168, 89, 238, 91, 54, 22, 227, 205, 128, 130, 58, 23,
210, 227, 187, 0, 0,
0, 0, 81, 189, 152, 202, 208, 73, 28, 146, 80, 53, 236, 43, 105,
76, 225, 179, 161, 203, 253, 49, 8, 205, 244, 160, 80, 216, 216,
251, 188, 226, 52, 13, 1, 0, 153, 0, 67, 73, 127, 215, 248, 38,
149, 113, 8, 244, 163, 15, 217, 206, 195, 174, 186, 121, 151, 32,
132, 233, 14, 173, 1, 234, 51, 9, 0, 0, 0, 0, 7, 0, 116, 101, 115,
116, 110, 101, 116, 11, 17, 9, 7, 4, 0, 116, 101, 115, 116, 2, 0,
116, 98, 157, 71, 156, 71, 1, 0, 0, 0, 236, 1, 28, 0, 0, 34, 2, 0,
0, 0, 0, 0, 0, 4, 0, 116, 66, 84, 67, 12, 0, 84, 101, 115, 116, 32,
66, 105, 116, 99, 111, 105, 110, 12, 0, 84, 101, 115, 116, 32, 115,
97, 116, 111, 115, 104, 105, 0, 225, 245, 5, 0, 0, 0, 0, 67, 73,
127, 215, 248, 38, 149, 113, 8, 244, 163, 15, 217, 206, 195, 174,
186, 121, 151, 32, 132, 233, 14, 173, 1, 234, 51, 9, 0, 0, 0, 0, 0,
1, 1, 7, 0, 0, 0, 1, 0, 33, 4, 0, 85, 83, 68, 84, 1, 0, 1, 0, 33,
10, 0, 85, 83, 68, 32, 84, 101, 116, 104, 101, 114, 3, 0, 1, 0, 3,
160, 134, 1, 0, 0, 0, 0, 0, 4, 0, 1, 0, 3, 160, 134, 1, 0, 0, 0, 0,
0, 5, 0, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 1, 0, 0, 0, 8, 0,
1, 0, 11, 98, 7, 127, 95, 0, 0, 0, 0, 2, 0, 1, 0, 1, 3, 1, 0, 1, 0,
178, 33, 37, 44, 27, 178, 4, 3, 40, 73, 173, 36, 33, 53, 221, 119,
251, 0, 189, 217, 213, 41, 198, 175, 58, 121, 140, 28, 146, 37, 87,
64, 38, 143, 99, 202, 152, 114, 142, 39, 0, 0, 0, 0, 3, 160, 134,
1, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 92, 166, 163, 138, 199, 202, 164, 245, 113,
122, 18, 103, 23, 163, 19, 162, 163, 76, 87, 249, 108, 157, 128,
35, 167, 241, 108, 90, 119, 62, 221, 25, 13, 89, 171, 84, 193, 91,
149, 210, 253, 90, 73, 209, 95, 67, 176, 176, 241, 245, 106, 115,
168, 19, 65, 93, 243, 55, 106, 242, 165, 8, 73, 84, 1, 0, 168, 170,
15, 228, 35, 104, 92, 41, 63, 185, 164, 121, 156, 162, 131, 12, 47,
6, 164, 26, 196, 153, 222, 217, 64, 160, 41, 209, 233, 153, 122,
12, 3, 0, 1, 99, 9, 176, 91, 232, 64, 240, 92, 218, 231, 109, 250,
143, 250, 176, 91, 23, 191, 14, 131, 20, 25, 114, 222, 246, 150,
230, 15, 107, 177, 120, 169, 92, 166, 163, 138, 199, 202, 164, 245,
113, 122, 18, 103, 23, 163, 19, 162, 163, 76, 87, 249, 108, 157,
128, 35, 167, 241, 108, 90, 119, 62, 221, 25, 0, 195, 21, 162, 3,
239, 233, 201, 237, 18, 236, 101, 93, 131, 155, 149, 138, 74, 215,
139, 198, 25, 200, 138, 206, 173, 165, 44, 179, 145, 229, 87, 33,
0, 100, 123, 211, 136, 254, 136, 113, 24, 177, 157, 79, 243, 71,
248, 33, 143, 160, 201, 21, 73, 103, 215, 72, 106, 243, 186, 141,
61, 139, 200, 9, 68, 1, 69, 24, 189, 99, 171, 32, 233, 39, 3, 158,
255, 31, 84, 122, 29, 95, 146, 223, 162, 186, 122, 246, 172, 151,
26, 75, 208, 59, 164, 167, 52, 176, 49, 86, 162, 86, 184, 173, 58,
30, 249, 0, 1, 0, 0, 0, 1, 0, 99, 9, 176, 91, 232, 64, 240, 92,
218, 231, 109, 250, 143, 250, 176, 91, 23, 191, 14, 131, 20, 25,
114, 222, 246, 150, 230, 15, 107, 177, 120, 169, 1, 0, 1, 0, 1, 0,
0, 0, 1, 0, 1, 0, 1, 3, 2, 0, 2, 13, 89, 171, 84, 193, 91, 149,
210, 253, 90, 73, 209, 95, 67, 176, 176, 241, 245, 106, 115, 168,
19, 65, 93, 243, 55, 106, 242, 165, 8, 73, 84, 3, 100, 0, 0, 0, 0,
0, 0, 0, 32, 0, 163, 255, 181, 52, 214, 207, 164, 188, 164, 62,
206, 51, 148, 21, 55, 20, 219, 87, 167, 93, 37, 93, 220, 174, 85,
114, 39, 10, 129, 149, 142, 205, 3, 0, 29, 168, 83, 31, 208, 67,
243, 121, 190, 173, 32, 142, 81, 240, 183, 249, 253, 225, 241, 208,
43, 50, 220, 113, 160, 83, 117, 66, 39, 54, 213, 157, 241, 15, 215,
23, 180, 230, 84, 244, 1, 0, 0, 0, 33, 0, 8, 51, 208, 63, 29, 66,
223, 18, 233, 176, 231, 97, 133, 123, 94, 138, 167, 67, 249, 121,
198, 119, 104, 110, 244, 210, 160, 32, 50, 229, 234, 213, 247, 163,
2, 80, 167, 74, 173, 71, 114, 240, 90, 198, 161, 11, 196, 138, 22,
251, 17, 118, 223, 43, 233, 180, 69, 93, 26, 50, 211, 38, 66, 218,
207, 135, 95, 102, 240, 157, 211, 197, 152, 172, 141, 203, 255, 91,
167, 227, 63, 121, 238, 202, 205, 162, 113, 232, 26, 200, 160, 249,
72, 35, 41, 84, 162, 219, 234, 14, 171, 22, 87, 37, 133, 199, 33,
100, 238, 228, 194, 63, 189, 223, 251, 234, 251, 72, 86, 205, 194,
119, 144, 187, 48, 167, 189, 142, 6, 97, 181, 165, 165, 12, 93, 80,
225, 87, 26, 182, 106, 177, 201, 169, 122, 10, 106, 238, 67, 209,
103, 180, 129, 223, 15, 76, 127, 129, 105, 153, 37, 192, 128, 201,
59, 239, 226, 124, 211, 198, 255, 199, 89, 250, 82, 179, 199, 170,
37, 79, 28, 18, 171, 37, 124, 213, 153, 43, 1, 20, 30, 121, 123,
20, 46, 158, 187, 184, 86, 155, 230, 49, 131, 65, 142, 176, 138,
98, 135, 225, 192, 164, 112, 117, 246, 11, 56, 178, 183, 48, 30,
189, 160, 12, 240, 160, 58, 220, 31, 104, 93, 17, 116, 167, 162,
10, 115, 38, 90, 118, 209, 57, 200, 87, 204, 18, 113, 139, 33, 34,
58, 41, 240, 44, 240, 17, 168, 2, 101, 139, 176, 220, 59, 52, 163,
116, 179, 237, 35, 167, 202, 9, 53, 168, 12, 206, 239, 238, 37, 36,
226, 148, 200, 150, 67, 44, 14, 84, 248, 155, 229, 229, 131, 137,
171, 156, 87, 55, 136, 196, 240, 114, 166, 202, 79, 60, 107, 113,
3, 120, 145, 10, 238, 210, 216, 197, 23, 4, 48, 225, 74, 80, 249,
204, 211, 175, 197, 14, 90, 222, 58, 206, 208, 70, 249, 223, 34,
112, 175, 246, 53, 53, 29, 40, 155, 183, 193, 19, 178, 160, 162,
195, 197, 108, 35, 141, 93, 79, 32, 83, 76, 37, 139, 53, 177, 155,
33, 129, 32, 231, 37, 207, 243, 223, 172, 72, 230, 20, 233, 121,
175, 182, 186, 103, 49, 232, 49, 124, 7, 1, 246, 154, 70, 205, 72,
137, 138, 13, 9, 112, 100, 34, 95, 14, 125, 184, 196, 241, 191, 85,
83, 199, 84, 121, 52, 180, 123, 223, 99, 254, 82, 11, 209, 165,
211, 143, 44, 86, 12, 84, 103, 13, 89, 167, 164, 107, 214, 46, 139,
143, 252, 204, 167, 220, 134, 249, 27, 180, 82, 116, 111, 184, 235,
127, 170, 181, 197, 22, 182, 72, 52, 4, 88, 155, 204, 242, 213, 31,
128, 151, 53, 148, 202, 141, 251, 23, 45, 245, 232, 197, 81, 48,
67, 206, 64, 58, 130, 168, 228, 244, 117, 115, 20, 61, 219, 148,
200, 253, 44, 19, 168, 238, 15, 165, 205, 97, 243, 0, 185, 50, 231,
27, 81, 174, 252, 232, 12, 237, 89, 56, 190, 63, 67, 87, 64, 79,
136, 214, 182, 119, 105, 227, 51, 63, 93, 64, 9, 79, 38, 96, 247,
84, 176, 176, 205, 28, 239, 101, 12, 245, 113, 200, 102, 0, 158,
153, 222, 164, 243, 143, 205, 125, 192, 88, 99, 172, 46, 233, 84,
139, 227, 179, 4, 98, 135, 182, 41, 225, 63, 161, 216, 188, 189,
169, 38, 98, 193, 22, 128, 190, 36, 211, 1, 199, 30, 55, 185, 172,
149, 136, 82, 218, 124, 47, 98, 206, 135, 55, 211, 66, 12, 158,
202, 114, 153, 151, 113, 182, 6, 55, 34, 174, 166, 119, 187, 144,
87, 181, 137, 241, 30, 183, 117, 124, 141, 86, 215, 241, 183, 101,
87, 94, 25, 71, 200, 2, 17, 46, 42, 57, 87, 227, 183, 155, 118,
136, 95, 162, 169, 102, 197, 8, 138, 61, 128, 231, 202, 17, 103,
238, 8, 58, 17, 255, 77, 115, 33, 240, 230, 50, 73, 229, 170, 127,
242, 192, 210, 192, 239, 205, 87, 228, 71, 214, 21, 120, 80, 143,
125, 203, 213, 131, 78, 231, 61, 117, 55, 145, 98, 144, 0, 0, 0, 0,
0, 0,
];

Consignment::strict_decode(&data[..]).unwrap()
Expand All @@ -253,7 +244,6 @@ pub(crate) mod test {
}

#[test]
#[ignore]
fn test_consignment_validation() {
let consignment = consignment();
let schema = schema();
Expand Down
2 changes: 1 addition & 1 deletion src/rgb/stash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod consignment;
mod disclosure;
mod stash;

pub use anchor::{Anchor, AnchorId, PSBT_FEE_KEY, PSBT_PUBKEY_KEY};
pub use anchor::{Anchor, AnchorId};
pub use consignment::{Consignment, ConsignmentEndpoints, TransitionData};
pub use disclosure::Disclosure;
pub use stash::Stash;

0 comments on commit 4a32887

Please sign in to comment.