Skip to content

Commit

Permalink
rust: get_unspent_outputs: serialize commitments for liquid
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoComandini committed Apr 14, 2022
1 parent 061f6b1 commit 65272a8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions subprojects/gdk_rust/gdk_common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::be::{BEOutPoint, BEScript, BETransaction, BETransactionEntry, BETxid}
use crate::util::{is_confidential_txoutsecrets, weight_to_vsize, StringSerialized};
use crate::NetworkId;
use bitcoin::Network;
use elements::confidential;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

Expand Down Expand Up @@ -751,6 +752,8 @@ pub struct Txo {

/// The Liquid commitment preimages (asset, satoshi and blinders)
pub txoutsecrets: Option<elements::TxOutSecrets>,
/// The Liquid commitments
pub txoutcommitments: Option<(confidential::Asset, confidential::Value, confidential::Nonce)>,
}

impl Txo {
Expand Down Expand Up @@ -803,6 +806,14 @@ pub struct UnspentOutput {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "amountblinder")]
pub amount_blinder: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "asset_tag")]
pub asset_commitment: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "commitment")]
pub value_commitment: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub nonce_commitment: Option<String>,
}

impl TryFrom<Txo> for UnspentOutput {
Expand All @@ -814,6 +825,14 @@ impl TryFrom<Txo> for UnspentOutput {
let confidential = txo.confidential();
let asset_blinder = txo.txoutsecrets.as_ref().map(|s| s.asset_bf.to_hex());
let amount_blinder = txo.txoutsecrets.as_ref().map(|s| s.value_bf.to_hex());
let (asset_commitment, value_commitment, nonce_commitment) = match &txo.txoutcommitments {
None => (None, None, None),
Some((a, v, n)) => (
Some(elements::encode::serialize_hex(a)),
Some(elements::encode::serialize_hex(v)),
Some(elements::encode::serialize_hex(n)),
),
};
Ok(Self {
txhash: txo.outpoint.txid().to_hex(),
pt_idx: txo.outpoint.vout(),
Expand All @@ -833,6 +852,9 @@ impl TryFrom<Txo> for UnspentOutput {
asset_id,
asset_blinder,
amount_blinder,
asset_commitment,
value_commitment,
nonce_commitment,
})
}
}
Expand Down
9 changes: 9 additions & 0 deletions subprojects/gdk_rust/gdk_electrum/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,14 @@ impl Account {
BEOutPoint::Elements(o) => acc_store.unblinded.get(&o).cloned(),
};

let txoutcommitments = match tx {
BETransaction::Bitcoin(_) => None,
BETransaction::Elements(tx) => {
let txout = &tx.output[vout as usize];
Some((txout.asset, txout.value, txout.nonce))
}
};

Ok(Txo {
outpoint: outpoint.clone(),
height,
Expand All @@ -409,6 +417,7 @@ impl Account {
satoshi,
sequence: None,
txoutsecrets,
txoutcommitments,
})
}

Expand Down

0 comments on commit 65272a8

Please sign in to comment.