Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Commit

Permalink
Finalizing updates to consignment creation
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 9, 2020
1 parent 97ad1ce commit 7e9e7c9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 33 deletions.
37 changes: 32 additions & 5 deletions Cargo.lock

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

23 changes: 13 additions & 10 deletions src/cli/fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ use std::fs;
use std::path::PathBuf;

use bitcoin::consensus::{Decodable, Encodable};
use bitcoin::util::psbt::{raw::Key, PartiallySignedTransaction};
use bitcoin::util::psbt::{raw::ProprietaryKey, PartiallySignedTransaction};
use bitcoin::OutPoint;

use crate::DataFormat;
use lnpbp::bitcoin;
use lnpbp::bp::blind::OutpointReveal;
use lnpbp::client_side_validation::Conceal;
Expand All @@ -31,6 +30,7 @@ use crate::api::fungible::{AcceptApi, Issue, TransferApi};
use crate::api::{reply, Reply};
use crate::fungible::{Asset, Invoice, Outcoincealed, Outcoins, Outpoint};
use crate::util::file::ReadWrite;
use crate::DataFormat;

#[derive(Clap, Clone, Debug, Display)]
#[display(Debug)]
Expand Down Expand Up @@ -94,6 +94,7 @@ pub enum Command {
#[display(Debug)]
pub struct InvoiceCli {
/// Assets
#[clap(parse(try_from_str = ContractId::from_bech32_str))]
pub asset: ContractId,

/// Amount
Expand Down Expand Up @@ -416,13 +417,15 @@ impl TransferCli {
}
};

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![],
};

debug!(
Expand All @@ -437,10 +440,10 @@ impl TransferCli {
})?;

psbt.global
.unknown
.proprietary
.insert(fee_key, self.fee.to_be_bytes().to_vec());
for output in &mut psbt.outputs {
output.unknown.insert(
output.proprietary.insert(
pubkey_key.clone(),
output.bip32_derivation.keys().next().unwrap().to_bytes(),
);
Expand Down
9 changes: 5 additions & 4 deletions src/contracts/fungible/data/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use url::Url;
use lnpbp::bitcoin;
use lnpbp::bitcoin::Address;
use lnpbp::bp::blind::OutpointHash;
use lnpbp::rgb::{Bech32, ContractId, ToBech32};
use lnpbp::rgb::{Bech32, ContractId, FromBech32, ToBech32};

#[derive(Clone, PartialEq, Eq, Debug, Display, Error, From)]
#[display(Debug)]
Expand Down Expand Up @@ -88,7 +88,7 @@ impl FromStr for Outpoint {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match (Address::from_str(s), Bech32::from_str(s)) {
(Ok(addr), _) => Ok(Self::Address(addr)),
(_, Ok(Bech32::Outpoint(outpoint))) => Ok(Self::BlindedUtxo(outpoint)),
(_, Ok(Bech32::BlindedUtxo(outpoint))) => Ok(Self::BlindedUtxo(outpoint)),
_ => Err(Error::WrongOutpoint),
}
}
Expand All @@ -115,7 +115,8 @@ impl FromStr for Invoice {
.query_pairs()
.find(|(x, _)| x == "asset")
.ok_or(Error::NoAsset)?;
let contract_id = contract_id.parse().map_err(|_| Error::WrongAssetEncoding)?;
let contract_id =
ContractId::from_bech32_str(&contract_id).map_err(|_| Error::WrongAssetEncoding)?;
Ok(Invoice {
contract_id,
outpoint,
Expand All @@ -136,7 +137,7 @@ impl Display for OutpointDescriptor {
impl Display for Outpoint {
fn fmt(&self, f: &mut Formatter<'_>) -> ::core::fmt::Result {
match self {
Self::BlindedUtxo(outpoint) => write!(f, "{}", Bech32::Outpoint(outpoint.clone())),
Self::BlindedUtxo(outpoint) => write!(f, "{}", Bech32::BlindedUtxo(outpoint.clone())),
Self::Address(addr) => write!(f, "{}", addr),
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/contracts/fungible/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ impl Runtime {

async fn rpc_process(&mut self, raw: Vec<u8>) -> Result<Reply, Reply> {
trace!("Got {} bytes over ZMQ RPC: {:?}", raw.len(), raw);
let message = &*self
.unmarshaller
.unmarshall(&raw)
.map_err(|err| ServiceError::from_rpc(ServiceErrorSource::Stash, err))?;
let message = &*self.unmarshaller.unmarshall(&raw).map_err(|err| {
error!("Error unmarshalling the data: {}", err);
ServiceError::from_rpc(ServiceErrorSource::Contract(s!("fungible")), err)
})?;
debug!("Received ZMQ RPC request: {:?}", message);
Ok(match message {
Request::Issue(issue) => self.rpc_issue(issue).await,
Expand Down
22 changes: 12 additions & 10 deletions src/i9n/fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use std::fs::File;
use std::path::PathBuf;

use lnpbp::bitcoin::consensus::encode::{deserialize, Encodable};
use lnpbp::bitcoin::util::psbt::{raw::Key, PartiallySignedTransaction};
use lnpbp::bitcoin::util::psbt::{raw::ProprietaryKey, PartiallySignedTransaction};
use lnpbp::bitcoin::OutPoint;

use lnpbp::bp;
use lnpbp::lnp::presentation::Encode;
use lnpbp::lnp::Unmarshall;
use lnpbp::rgb::{Amount, PSBT_FEE_KEY, PSBT_PUBKEY_KEY};
use lnpbp::rgb::Amount;

use super::{Error, Runtime};
use crate::api::{fungible::Issue, fungible::Request, fungible::TransferApi, reply, Reply};
Expand Down Expand Up @@ -92,23 +92,25 @@ impl Runtime {
Outpoint::Address(_address) => unimplemented!(),
};

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 psbt_bytes = base64::decode(&prototype_psbt)?;
let mut psbt: PartiallySignedTransaction = deserialize(&psbt_bytes)?;

psbt.global
.unknown
.proprietary
.insert(fee_key, fee.to_be_bytes().to_vec());
for output in &mut psbt.outputs {
output.unknown.insert(
output.proprietary.insert(
pubkey_key.clone(),
output.bip32_derivation.keys().next().unwrap().to_bytes(),
);
Expand Down
Binary file modified test/consignment.rgb
Binary file not shown.
Binary file modified test/dest_tx.psbt
Binary file not shown.

0 comments on commit 7e9e7c9

Please sign in to comment.