Skip to content

Commit

Permalink
Add new utility methods on Transaction type
Browse files Browse the repository at this point in the history
This PR adds the txid(), is_coin_base(), is_explicitly_rbf(),
and is_lock_time_enabled() methods.
Fixes #303
  • Loading branch information
thunderbiscuit committed Mar 10, 2023
1 parent 26c1c22 commit 500c560
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

26 changes: 22 additions & 4 deletions api-docs/kotlin/src/main/kotlin/org/bitcoindevkit/bdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,15 @@ class Blockchain(
* @param transactionBytes The transaction bytes, bitcoin consensus encoded.
*/
class Transaction(transactionBytes: List<UByte>) {
/** Return the transaction bytes, bitcoin consensus encoded. */
fun serialize(): List<UByte> {}
/** Computes the txid. */
fun txid(): String {}

/**
* Returns the "weight" of this transaction, as defined by BIP141.
*
* For transactions with an empty witness, this is simply the consensus-serialized size times four. For transactions with a witness, this is the non-witness consensus-serialized size multiplied by three plus the with-witness consensus-serialized size.
* For transactions with an empty witness, this is simply the consensus-serialized size times four.
* For transactions with a witness, this is the non-witness consensus-serialized size multiplied by three
* plus the with-witness consensus-serialized size.
*/
fun weight(): ULong {}

Expand All @@ -304,9 +306,25 @@ class Transaction(transactionBytes: List<UByte>) {
/**
* Returns the "virtual size" (vsize) of this transaction.
*
* Will be ceil(weight / 4.0). Note this implements the virtual size as per BIP141, which is different to what is implemented in Bitcoin Core. The computation should be the same for any remotely sane transaction.
* Will be ceil(weight / 4.0). Note this implements the virtual size as per BIP141, which is different to
* what is implemented in Bitcoin Core. The computation should be the same for any remotely sane transaction.
*/
fun vsize(): ULong {}

/** Return the transaction bytes, bitcoin consensus encoded. */
fun serialize(): List<UByte> {}

/** Is this a coin base transaction? */
fun isCoinBase(): Boolean {}

/**
* Returns true if the transaction itself opted in to be BIP-125-replaceable (RBF).
* This does not cover the case where a transaction becomes replaceable due to ancestors being RBF.
*/
fun isExplicitlyRbf(): Boolean {}

/** Returns true if this transactions nLockTime is enabled (BIP-65). */
fun isLockTimeEnabled(): Boolean {}
}

/**
Expand Down
10 changes: 9 additions & 1 deletion bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,21 @@ interface Transaction {
[Throws=BdkError]
constructor(sequence<u8> transaction_bytes);

sequence<u8> serialize();
string txid();

u64 weight();

u64 size();

u64 vsize();

sequence<u8> serialize();

boolean is_coin_base();

boolean is_explicitly_rbf();

boolean is_lock_time_enabled();
};

interface PartiallySignedTransaction {
Expand Down
20 changes: 18 additions & 2 deletions bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ impl Transaction {
Ok(Transaction { internal: tx })
}

fn serialize(&self) -> Vec<u8> {
self.internal.serialize()
fn txid(&self) -> String {
self.internal.txid().to_string()
}

fn weight(&self) -> u64 {
Expand All @@ -266,6 +266,22 @@ impl Transaction {
fn vsize(&self) -> u64 {
self.internal.vsize() as u64
}

fn serialize(&self) -> Vec<u8> {
self.internal.serialize()
}

fn is_coin_base(&self) -> bool {
self.internal.is_coin_base()
}

fn is_explicitly_rbf(&self) -> bool {
self.internal.is_explicitly_rbf()
}

fn is_lock_time_enabled(&self) -> bool {
self.internal.is_lock_time_enabled()
}
}

/// A Bitcoin address.
Expand Down

0 comments on commit 500c560

Please sign in to comment.