Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
Merge #82
Browse files Browse the repository at this point in the history
82: Replace `usize` with `bitcoin::Amount` in the primed transaction interfaces r=mergify[bot] a=D4nte



Co-authored-by: Franck Royer <[email protected]>
  • Loading branch information
bors[bot] and Franck Royer authored Sep 29, 2020
2 parents aa13d2a + 67de8bd commit 48d00a1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ Cargo.lock
**/*.rs.bk

.idea

/rust-toolchain
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed
- Replace `usize` with `bitcoin::Amount` in the primed transaction interfaces.

## [0.4.0] - 2020-09-15

### Changed
Expand Down
9 changes: 4 additions & 5 deletions lib/src/bitcoin/witness/primed_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,14 @@ impl PrimedTransaction {
pub fn sign_with_rate<C: secp256k1::Signing>(
self,
secp: &Secp256k1<C>,
fee_per_byte: usize,
fee_per_byte: Amount,
) -> Result<Transaction, Error> {
let mut transaction = self._transaction_without_signatures_or_output_values();

let weight = transaction.get_weight();
let fee = weight
.checked_mul(fee_per_byte)
let fee = fee_per_byte
.checked_mul(weight as u64)
.ok_or(Error::OverflowingFee)?;
let fee = Amount::from_sat(fee as u64);

if self.total_input_value() < fee {
return Err(Error::FeeHigherThanInputValue);
Expand Down Expand Up @@ -218,7 +217,7 @@ mod test {
};
let total_input_value = primed_txn.total_input_value();

let rate = 42;
let rate = Amount::from_sat(42);

let estimated_weight = primed_txn.estimate_weight();
let transaction = primed_txn.sign_with_rate(&secp, rate).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/bitcoin_witness_sign_with_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn sign_with_rate() {

let alice_addr: Address = client.get_new_address().unwrap();

let rate = 42;
let rate = Amount::from_sat(42);

let primed_tx = PrimedTransaction {
inputs: vec![PrimedInput::new(
Expand Down

0 comments on commit 48d00a1

Please sign in to comment.