Skip to content

Commit

Permalink
Merge pull request #106 from RGB-WG/v0.10
Browse files Browse the repository at this point in the history
Release v0.10.9
  • Loading branch information
dr-orlovsky authored Oct 14, 2023
2 parents 47ff297 + 52854b4 commit af2af95
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 72 deletions.
47 changes: 26 additions & 21 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,38 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install latest nightly
- name: Set up toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
toolchain: stable
override: true
- name: Build & test
components: rustfmt, llvm-tools-preview
- name: Build
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --all-features --no-fail-fast
command: build
args: --release
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off'
- id: coverage
name: Generate coverage
uses: actions-rs/[email protected]
CARGO_INCREMENTAL: "0"
RUSTFLAGS: "-Cinstrument-coverage"
RUSTDOCFLAGS: "-Cinstrument-coverage"
- name: Test
uses: actions-rs/cargo@v1
with:
args: >
-t lcov
--llvm
--ignore-not-existing
--ignore "/*"
-o ./target/lcov.info
./target/debug/
command: test
args: --all-features --no-fail-fast
env:
CARGO_INCREMENTAL: "0"
RUSTFLAGS: "-Cinstrument-coverage"
RUSTDOCFLAGS: "-Cinstrument-coverage"
- name: Install grcov
run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi
- name: Generate coverage
run: grcov . --binary-path target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
file: ${{ steps.coverage.outputs.report }}
directory: ./coverage/reports/
files: ./coverage.lcov
flags: rust
fail_ci_if_error: true
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
name: Clippy
with:
command: clippy
args: --workspace --all-features --all-targets
args: --workspace --all-features --all-targets -- -D warnings
doc:
runs-on: ubuntu-latest
steps:
Expand Down
15 changes: 8 additions & 7 deletions Cargo.lock

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

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rgb-core = { version = "0.10.8", features = ["stl"] }

[package]
name = "rgb-wallet"
version = "0.10.8"
version = "0.10.9"
description = "RGB wallet library for smart contracts on Bitcoin & Lightning network"
keywords = ["bitcoin", "lightning", "rgb", "smart-contracts", "lnp-bp"]
categories = ["cryptography::cryptocurrencies"]
Expand Down Expand Up @@ -76,6 +76,3 @@ wasm-bindgen-test = "0.3"

[package.metadata.docs.rs]
features = [ "all" ]

[patch.crates-io]
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "v0.10" }
6 changes: 6 additions & 0 deletions src/invoice/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use super::{Beneficiary, RgbInvoice, RgbTransport, TransportParseError};
#[derive(Clone, Eq, PartialEq, Debug)]
pub struct RgbInvoiceBuilder(RgbInvoice);

#[allow(clippy::result_large_err)]
impl RgbInvoiceBuilder {
pub fn new(beneficiary: impl Into<Beneficiary>) -> Self {
Self(RgbInvoice {
Expand Down Expand Up @@ -106,6 +107,11 @@ impl RgbInvoiceBuilder {
Ok(self.set_amount_raw(amount))
}

/// # Safety
///
/// The function may cause the loss of the information about the precise
/// amout of the asset, since f64 type doesn't provide full precision
/// required for that.
pub unsafe fn set_amount_approx(self, amount: f64, precision: Precision) -> Result<Self, Self> {
if amount <= 0.0 {
return Err(self);
Expand Down
1 change: 1 addition & 0 deletions src/invoice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[allow(clippy::module_inception)]
mod invoice;
mod parse;
mod builder;
Expand Down
4 changes: 2 additions & 2 deletions src/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::collections::{BTreeMap, HashMap};
use std::error::Error;
use std::iter;

use amplify::RawArray;
use amplify::ByteArray;
use bitcoin::hashes::Hash;
use bitcoin::psbt::Psbt;
use bp::seals::txout::CloseMethod;
Expand Down Expand Up @@ -291,7 +291,7 @@ pub trait InventoryWallet: Inventory {
}
let beneficiary = match beneficiary {
BuilderSeal::Revealed(seal) => BuilderSeal::Revealed(
seal.resolve(Txid::from_raw_array(witness_txid.to_byte_array())),
seal.resolve(Txid::from_byte_array(witness_txid.to_byte_array())),
),
BuilderSeal::Concealed(seal) => BuilderSeal::Concealed(seal),
};
Expand Down
4 changes: 2 additions & 2 deletions src/psbt/dbc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// limitations under the License.

use amplify::num::u5;
use amplify::RawArray;
use amplify::ByteArray;
use bitcoin::hashes::Hash;
use bitcoin::psbt::Psbt;
use bitcoin::secp256k1::SECP256K1;
Expand Down Expand Up @@ -152,7 +152,7 @@ impl PsbtDbc for Psbt {
Proof::TapretFirst(tapret_proof)
} else if method == CloseMethod::OpretFirst {
output.set_opret_commitment(commitment)?;
txout.script_pubkey = ScriptBuf::new_op_return(&commitment.to_raw_array());
txout.script_pubkey = ScriptBuf::new_op_return(&commitment.to_byte_array());
Proof::OpretFirst
} else {
return Err(DbcPsbtError::MethodUnsupported(method));
Expand Down
15 changes: 8 additions & 7 deletions src/psbt/lnpbp4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

use std::collections::BTreeMap;

use amplify::confinement;
use amplify::confinement::Confined;
use amplify::confinement::{self, Confined};
use amplify::FromSliceError;
use bitcoin::psbt::raw::ProprietaryKey;
use bitcoin::psbt::Output;
use commit_verify::mpc::{self, Message, ProtocolId};
Expand Down Expand Up @@ -84,6 +84,10 @@ pub enum Lnpbp4PsbtError {
#[from(bitcoin::hashes::Error)]
InvalidKeyValue,

/// the length of the commitment data doesn't match 32 byte hash.
#[from(FromSliceError)]
InvalidHashValue,

/// message map produced from PSBT inputs exceeds maximum size bounds.
#[from]
MessageMapTooLarge(confinement::Error),
Expand Down Expand Up @@ -120,10 +124,7 @@ impl OutputLnpbp4 for Output {
key.prefix == PSBT_LNPBP4_PREFIX && key.subtype == PSBT_OUT_LNPBP4_MESSAGE
})
.map(|(key, val)| {
Ok((
ProtocolId::from_slice(&key.key).ok_or(Lnpbp4PsbtError::InvalidKeyValue)?,
Message::from_slice(val).ok_or(Lnpbp4PsbtError::InvalidKeyValue)?,
))
Ok((ProtocolId::copy_from_slice(&key.key)?, Message::copy_from_slice(val)?))
})
.collect::<Result<BTreeMap<_, _>, Lnpbp4PsbtError>>()?;
Confined::try_from(map).map_err(Lnpbp4PsbtError::from)
Expand All @@ -139,7 +140,7 @@ impl OutputLnpbp4 for Output {
fn lnpbp4_message(&self, protocol_id: ProtocolId) -> Option<Message> {
let key = ProprietaryKey::lnpbp4_message(protocol_id);
let data = self.proprietary.get(&key)?;
Message::from_slice(data)
Message::copy_from_slice(data).ok()
}

/// Returns a valid LNPBP-4 entropy value, if present.
Expand Down
2 changes: 1 addition & 1 deletion src/psbt/opret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl OutputOpret for Output {
return Err(OpretKeyError::NonOpReturnOutput);
}*/
let data = self.proprietary.get(&ProprietaryKey::opret_commitment())?;
mpc::Commitment::from_slice(data)
mpc::Commitment::copy_from_slice(data).ok()
}

/// Assigns value of the opreturn commitment to this PSBT output, by
Expand Down
2 changes: 1 addition & 1 deletion src/psbt/tapret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl OutputTapret for Output {
/// only in situations when the commitment is absent.
fn tapret_commitment(&self) -> Option<mpc::Commitment> {
let data = self.proprietary.get(&ProprietaryKey::tapret_commitment())?;
mpc::Commitment::from_slice(data)
mpc::Commitment::copy_from_slice(data).ok()
}

/// Assigns value of the tapreturn commitment to this PSBT output, by
Expand Down
4 changes: 2 additions & 2 deletions std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rgb-std"
version = "0.10.8"
version = "0.10.9"
description = "RGB standard library for working with smart contracts on Bitcoin & Lightning"
keywords = ["bitcoin", "lightning", "rgb", "smart-contracts", "lnp-bp"]
categories = ["cryptography::cryptocurrencies"]
Expand Down Expand Up @@ -28,7 +28,7 @@ bp-core = { workspace = true }
rgb-core = { workspace = true }
baid58 = { workspace = true }
base85 = "=2.0.0"
chrono = "0.4.31"
chrono = "0.4.26"
serde_crate = { package = "serde", version = "1", features = ["derive"] }

[features]
Expand Down
5 changes: 3 additions & 2 deletions std/src/containers/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::io;
use std::str::FromStr;

use amplify::confinement::SmallOrdSet;
use amplify::{Bytes32, RawArray};
use amplify::{ByteArray, Bytes32};
use baid58::{Baid58ParseError, Chunking, FromBaid58, ToBaid58, CHUNKING_32};
use commit_verify::{CommitEncode, CommitmentId, Conceal};
use strict_encoding::{StrictEncode, StrictWriter};
Expand Down Expand Up @@ -51,14 +51,15 @@ pub struct TransferId(
impl ToBaid58<32> for TransferId {
const HRI: &'static str = "consign";
const CHUNKING: Option<Chunking> = CHUNKING_32;
fn to_baid58_payload(&self) -> [u8; 32] { self.to_raw_array() }
fn to_baid58_payload(&self) -> [u8; 32] { self.to_byte_array() }
fn to_baid58_string(&self) -> String { self.to_string() }
}
impl FromBaid58<32> for TransferId {}
impl FromStr for TransferId {
type Err = Baid58ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> { Self::from_baid58_chunked_str(s, ':', '#') }
}
#[allow(clippy::wrong_self_convention)] // We need the method that takes self by ref in order to have simplier APIs in iterators
impl TransferId {
pub fn to_baid58_string(&self) -> String { format!("{::<#.2}", self.to_baid58()) }
pub fn to_mnemonic(&self) -> String { self.to_baid58().mnemonic() }
Expand Down
4 changes: 2 additions & 2 deletions std/src/interface/iface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::fmt::{self, Display, Formatter};
use std::str::FromStr;

use amplify::confinement::{TinyOrdMap, TinyOrdSet};
use amplify::{Bytes32, RawArray};
use amplify::{ByteArray, Bytes32};
use baid58::{Baid58ParseError, Chunking, FromBaid58, ToBaid58, CHUNKING_32};
use commit_verify::{CommitStrategy, CommitmentId};
use rgb::Occurrences;
Expand Down Expand Up @@ -58,7 +58,7 @@ pub struct IfaceId(
impl ToBaid58<32> for IfaceId {
const HRI: &'static str = "if";
const CHUNKING: Option<Chunking> = CHUNKING_32;
fn to_baid58_payload(&self) -> [u8; 32] { self.to_raw_array() }
fn to_baid58_payload(&self) -> [u8; 32] { self.to_byte_array() }
fn to_baid58_string(&self) -> String { self.to_string() }
}
impl FromBaid58<32> for IfaceId {}
Expand Down
4 changes: 2 additions & 2 deletions std/src/interface/iimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::fmt::{self, Display, Formatter};
use std::str::FromStr;

use amplify::confinement::{TinyOrdMap, TinyOrdSet};
use amplify::{Bytes32, RawArray};
use amplify::{ByteArray, Bytes32};
use baid58::{Baid58ParseError, Chunking, FromBaid58, ToBaid58, CHUNKING_32};
use commit_verify::{CommitStrategy, CommitmentId};
use rgb::{
Expand Down Expand Up @@ -60,7 +60,7 @@ pub struct ImplId(
impl ToBaid58<32> for ImplId {
const HRI: &'static str = "im";
const CHUNKING: Option<Chunking> = CHUNKING_32;
fn to_baid58_payload(&self) -> [u8; 32] { self.to_raw_array() }
fn to_baid58_payload(&self) -> [u8; 32] { self.to_byte_array() }
fn to_baid58_string(&self) -> String { self.to_string() }
}
impl FromBaid58<32> for ImplId {}
Expand Down
4 changes: 2 additions & 2 deletions std/src/interface/rgb20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// limitations under the License.

use amplify::confinement::LargeVec;
use bp::bc::stl::bitcoin_stl;
use bp::bc::stl::bp_tx_stl;
use strict_types::{CompileError, LibBuilder, TypeLib};

use super::{
Expand Down Expand Up @@ -59,7 +59,7 @@ pub enum Error {

fn _rgb20_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_RGB20), tiny_bset! {
bitcoin_stl().to_dependency(),
bp_tx_stl().to_dependency(),
rgb_contract_stl().to_dependency()
})
.transpile::<Error>()
Expand Down
4 changes: 2 additions & 2 deletions std/src/interface/rgb21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::str::FromStr;

use amplify::ascii::AsciiString;
use amplify::confinement::{Confined, NonEmptyVec, SmallBlob};
use bp::bc::stl::bitcoin_stl;
use bp::bc::stl::bp_tx_stl;
use strict_encoding::stl::AsciiPrintable;
use strict_encoding::{
InvalidIdent, StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize, TypedWrite,
Expand Down Expand Up @@ -262,7 +262,7 @@ pub enum Error {
fn _rgb21_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_RGB21), tiny_bset! {
std_stl().to_dependency(),
bitcoin_stl().to_dependency(),
bp_tx_stl().to_dependency(),
rgb_contract_stl().to_dependency()
})
.transpile::<TokenData>()
Expand Down
4 changes: 2 additions & 2 deletions std/src/interface/rgb25.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

use std::fmt::Debug;

use bp::bc::stl::bitcoin_stl;
use bp::bc::stl::bp_tx_stl;
use strict_encoding::{StrictDumb, StrictEncode};
use strict_types::stl::std_stl;
use strict_types::{CompileError, LibBuilder, TypeLib};
Expand Down Expand Up @@ -61,7 +61,7 @@ pub enum Error {
fn _rgb25_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_RGB25), tiny_bset! {
std_stl().to_dependency(),
bitcoin_stl().to_dependency(),
bp_tx_stl().to_dependency(),
rgb_contract_stl().to_dependency(),
})
.transpile::<Error>()
Expand Down
Loading

0 comments on commit af2af95

Please sign in to comment.