Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion types/src/v26/get_prioritised_transactions.rs

This file was deleted.

51 changes: 0 additions & 51 deletions types/src/v29/mining/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,9 @@

use core::fmt;

use bitcoin::amount::ParseAmountError;
use bitcoin::error::UnprefixedHexError;
use bitcoin::{consensus, hex};

use crate::error::write_err;
use crate::NumericError;

/// Error when converting a `BlockTemplateTransaction` type into the model type.
#[derive(Debug)]
pub enum BlockTemplateTransactionError {
/// Conversion of numeric type to expected type failed.
Numeric(NumericError),
/// Conversion of the `data` field failed.
Data(consensus::encode::FromHexError),
/// Conversion of the `txid` field failed.
Txid(hex::HexToArrayError),
/// Conversion of the `hash` field failed.
Hash(hex::HexToArrayError),
/// Conversion of the `fee` field failed.
Fee(ParseAmountError),
}

impl fmt::Display for BlockTemplateTransactionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use BlockTemplateTransactionError as E;

match *self {
E::Numeric(ref e) => write_err!(f, "numeric"; e),
E::Data(ref e) => write_err!(f, "conversion of the `data` field failed"; e),
E::Txid(ref e) => write_err!(f, "conversion of the `txid` field failed"; e),
E::Hash(ref e) => write_err!(f, "conversion of the `hash` field failed"; e),
E::Fee(ref e) => write_err!(f, "conversion of the `fee` field failed"; e),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for BlockTemplateTransactionError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use BlockTemplateTransactionError as E;

match *self {
E::Numeric(ref e) => Some(e),
E::Data(ref e) => Some(e),
E::Txid(ref e) => Some(e),
E::Hash(ref e) => Some(e),
E::Fee(ref e) => Some(e),
}
}
}

impl From<NumericError> for BlockTemplateTransactionError {
fn from(e: NumericError) -> Self { Self::Numeric(e) }
}

/// Error when converting a `GetMiningInfo` type into the model type.
#[derive(Debug)]
Expand Down
31 changes: 2 additions & 29 deletions types/src/v29/mining/into.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
// SPDX-License-Identifier: CC0-1.0

use bitcoin::{consensus, CompactTarget, SignedAmount, Target, Transaction, Txid, Weight, Wtxid};
use bitcoin::{CompactTarget, Target, Weight};

use super::{
BlockTemplateTransaction, BlockTemplateTransactionError, GetMiningInfo, GetMiningInfoError,
NextBlockInfo, NextBlockInfoError,
};
use super::{GetMiningInfo, GetMiningInfoError, NextBlockInfo, NextBlockInfoError};
use crate::model;

impl BlockTemplateTransaction {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(
self,
) -> Result<model::BlockTemplateTransaction, BlockTemplateTransactionError> {
use BlockTemplateTransactionError as E;

let data =
consensus::encode::deserialize_hex::<Transaction>(&self.data).map_err(E::Data)?;
let txid = self.txid.parse::<Txid>().map_err(E::Txid)?;
let wtxid = self.hash.parse::<Wtxid>().map_err(E::Hash)?;
let depends = self
.depends
.iter()
.map(|x| crate::to_u32(*x, "depend"))
.collect::<Result<Vec<_>, _>>()?;
let fee = SignedAmount::from_sat(self.fee);
let sigops = crate::to_u32(self.sigops, "sigops")?;
let weight = Weight::from_wu(self.weight); // FIXME: Is this the correct unit?

Ok(model::BlockTemplateTransaction { data, txid, wtxid, depends, fee, sigops, weight })
}
}

impl GetMiningInfo {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetMiningInfo, GetMiningInfoError> {
Expand Down
30 changes: 1 addition & 29 deletions types/src/v29/mining/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,7 @@ mod into;

use serde::{Deserialize, Serialize};

pub use self::error::{BlockTemplateTransactionError, GetMiningInfoError, NextBlockInfoError};

/// Contents of non-coinbase transactions that should be included in the next block.
///
/// Returned as part of `getblocktemplate`.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct BlockTemplateTransaction {
/// Transaction data encoded in hexadecimal (byte-for-byte).
pub data: String,
/// Transaction id encoded in little-endian hexadecimal.
pub txid: String,
/// Hash encoded in little-endian hexadecimal (including witness data).
pub hash: String,
/// Array of numbers.
///
/// Transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is.
pub depends: Vec<i64>,
/// Difference in value between transaction inputs and outputs (in satoshis); for coinbase
/// transactions, this is a negative Number of the total collected block fees (ie, not including
/// the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there
/// isn't one.
pub fee: i64,
/// Total SigOps cost, as counted for purposes of block limits; if key is not present, sigop
/// cost is unknown and clients MUST NOT assume it is zero.
pub sigops: i64,
/// Total transaction weight, as counted for purposes of block limits.
pub weight: u64,
}
pub use self::error::{GetMiningInfoError, NextBlockInfoError};

/// Result of the JSON-RPC method `getmininginfo`.
///
Expand Down
5 changes: 1 addition & 4 deletions types/src/v29/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,7 @@ pub use self::{
GetBlockchainInfoError, GetChainStates, GetChainStatesError, GetDescriptorActivity,
GetDescriptorActivityError, ReceiveActivity, SpendActivity,
},
mining::{
BlockTemplateTransaction, GetMiningInfo, GetMiningInfoError, NextBlockInfo,
NextBlockInfoError,
},
mining::{GetMiningInfo, GetMiningInfoError, NextBlockInfo, NextBlockInfoError},
raw_transactions::{MempoolAcceptance, TestMempoolAccept},
util::{DeriveAddressesMultipath, GetDescriptorInfo},
};
Expand Down