Skip to content

Commit

Permalink
Merge pull request #297 from RGB-WG/payments
Browse files Browse the repository at this point in the history
Improve v0.12 payments workflows
  • Loading branch information
dr-orlovsky authored Jan 25, 2025
2 parents b0b072f + 79e68c1 commit 6327dbf
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
fail-fast: false
matrix:
feature: [ bp, fs, serde ]
feature: [ bitcoin, liquid, prime, uri, fs, serde, stl ]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand Down
30 changes: 15 additions & 15 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ coverage:
status:
project:
default:
target: 75%
# target: 75%
threshold: 1%
branches:
- master
patch:
default:
target: 60%
# target: 60%
threshold: 1%
only_pulls: true
28 changes: 23 additions & 5 deletions invoice/src/bp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub struct WitnessOut {
impl StrictSerialize for WitnessOut {}
impl StrictDeserialize for WitnessOut {}

impl Into<ScriptPubkey> for WitnessOut {
fn into(self) -> ScriptPubkey { self.address.script_pubkey() }
impl From<WitnessOut> for ScriptPubkey {
fn from(val: WitnessOut) -> Self { val.address.script_pubkey() }
}

impl WitnessOut {
Expand All @@ -74,7 +74,7 @@ impl WitnessOut {
pub fn checksum(&self) -> [u8; 4] {
let key = Sha256::digest(WITNESS_OUT_HRI.as_bytes());
let mut sha = Sha256::new_with_prefix(key);
sha.update(&[0]);
sha.update([0]);
sha.update(self.salt.to_le_bytes());
sha.update(self.script_pubkey().as_slice());
let sha = sha.finalize();
Expand Down Expand Up @@ -115,7 +115,8 @@ impl FromStr for WitnessOut {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s
.strip_prefix(WITNESS_OUT_HRI)
.ok_or(ParseWitnessOutError::NoPrefix)?;
.ok_or(ParseWitnessOutError::NoPrefix)?
.replace('-', "");

let alphabet = Alphabet::new(BAID64_ALPHABET).expect("invalid Baid64 alphabet");
let engine = GeneralPurpose::new(
Expand Down Expand Up @@ -151,7 +152,7 @@ pub enum ParseWitnessOutError {
/// checksum of the provided witness output seal definition is invalid.
InvalidChecksum,

/// invalid Base64 encoding in itness output seal definition - {0}.
/// invalid Base64 encoding in witness output seal definition - {0}.
#[from]
Base64(DecodeError),

Expand All @@ -163,3 +164,20 @@ pub enum ParseWitnessOutError {
#[from]
Encoding(DeserializeError),
}

#[cfg(test)]
mod tests {
use bp::OutputPk;
use strict_encoding::StrictDumb;

use super::*;

#[test]
fn display_from_str() {
let wout = WitnessOut::new(AddressPayload::Tr(OutputPk::strict_dumb()), 0xdeadbeaf1badcafe);
let s = wout.to_string();
assert_eq!(s, "wout:AP7KrRuv-vq3eIAEB-AQEBAQEB-AQEBAQEB-AQEBAQEB-AQEBAQEB-AQEBAQEB-zbu7~w");
let wout2 = WitnessOut::from_str(&s).unwrap();
assert_eq!(wout, wout2);
}
}
12 changes: 6 additions & 6 deletions src/mound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ impl<S: Supply, P: Pile, X: Excavate<S, P>> Mound<S, P, X> {
.filter_map(|(id, stockpile)| stockpile.seal(seal).map(|addr| (*id, addr)))
}

pub fn attest(
pub fn include(
&mut self,
contract_id: ContractId,
opid: Opid,
pub_witness: &<P::Seal as SingleUseSeal>::PubWitness,
anchors: impl IntoIterator<Item = (ContractId, Opid, <P::Seal as SingleUseSeal>::CliWitness)>,
anchor: <P::Seal as SingleUseSeal>::CliWitness,
) {
for (contract_id, opid, anchor) in anchors {
self.contract_mut(contract_id)
.attest(opid, anchor, pub_witness);
}
self.contract_mut(contract_id)
.include(opid, anchor, pub_witness)
}

pub fn consign(
Expand Down
5 changes: 4 additions & 1 deletion src/pile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ pub trait Pile {
if self.hoard_mut().has(pubid) {
let mut prev_anchor = self.hoard_mut().read(pubid);
if prev_anchor != anchor {
prev_anchor.merge(anchor).expect("Invalid anchor");
prev_anchor.merge(anchor).expect(
"existing anchor is not compatible with new one; this indicates either bug in \
RGB standard library or a compromised storage",
);
self.hoard_mut().append(pubid, &prev_anchor);
}
} else {
Expand Down
Loading

0 comments on commit 6327dbf

Please sign in to comment.