Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
platform: linux_amd64

env:
TEST_VERSION: '0.0.3-alpha.4'
TEST_VERSION: '0.0.4-alpha.pr14.5'
TEST_REPO: 'stringintech/kernel-bindings-tests'
TEST_DIR: '.conformance-tests'

Expand Down
Binary file modified native/osx-x64/libbitcoinkernel.dylib
Binary file not shown.
31 changes: 31 additions & 0 deletions src/BitcoinKernel.Interop/Enums/BlockCheckFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace BitcoinKernel.Interop.Enums;

/// <summary>
/// Flags controlling optional context-free block checks performed by
/// btck_block_check. The base checks (size limits, coinbase structure,
/// transaction checks, sigop limits) always run; these flags toggle the
/// optional proof-of-work and merkle-root checks.
/// </summary>
[Flags]
public enum BlockCheckFlags : uint
{
/// <summary>
/// Run the base context-free block checks only.
/// </summary>
Base = 0,

/// <summary>
/// Run CheckProofOfWork via CheckBlockHeader.
/// </summary>
Pow = 1U << 0,

/// <summary>
/// Verify merkle root (and mutation detection).
/// </summary>
Merkle = 1U << 1,

/// <summary>
/// Enable all optional context-free block checks.
/// </summary>
All = Pow | Merkle
}
72 changes: 72 additions & 0 deletions src/BitcoinKernel.Interop/Enums/TxValidationResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
namespace BitcoinKernel.Interop.Enums;

/// <summary>
/// A granular "reason" why a transaction was invalid.
/// </summary>
public enum TxValidationResult : uint
{
/// <summary>
/// Initial value. Tx has not yet been rejected.
/// </summary>
UNSET = 0,

/// <summary>
/// Invalid by consensus rules.
/// </summary>
CONSENSUS = 1,

/// <summary>
/// Inputs (covered by txid) failed policy rules.
/// </summary>
INPUTS_NOT_STANDARD = 2,

/// <summary>
/// Otherwise didn't meet local policy rules.
/// </summary>
NOT_STANDARD = 3,

/// <summary>
/// Transaction was missing some of its inputs.
/// </summary>
MISSING_INPUTS = 4,

/// <summary>
/// Transaction spends a coinbase too early, or violates locktime/sequence locks.
/// </summary>
PREMATURE_SPEND = 5,

/// <summary>
/// Witness may have been malleated or is prior to SegWit activation.
/// </summary>
WITNESS_MUTATED = 6,

/// <summary>
/// Transaction is missing a witness.
/// </summary>
WITNESS_STRIPPED = 7,

/// <summary>
/// Tx already in mempool or conflicts with a tx in the chain.
/// </summary>
CONFLICT = 8,

/// <summary>
/// Violated mempool's fee/size/descendant/RBF/etc limits.
/// </summary>
MEMPOOL_POLICY = 9,

/// <summary>
/// This node does not have a mempool so can't validate the transaction.
/// </summary>
NO_MEMPOOL = 10,

/// <summary>
/// Fails some policy, but might be acceptable if submitted in a (different) package.
/// </summary>
RECONSIDERABLE = 11,

/// <summary>
/// Transaction was not validated because package failed.
/// </summary>
UNKNOWN = 12
}
85 changes: 85 additions & 0 deletions src/BitcoinKernel.Interop/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ static NativeMethods()
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chain_parameters_destroy")]
public static extern void ChainParametersDestroy(IntPtr chain_params);

/// <summary>
/// Gets the consensus parameters from chain parameters. The returned pointer
/// is unowned and only valid for the lifetime of the chain parameters.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chain_parameters_get_consensus_params")]
public static extern IntPtr ChainParametersGetConsensusParams(IntPtr chain_parameters);

#endregion

#region Chainstate Manager
Expand Down Expand Up @@ -320,6 +327,26 @@ public static extern int BlockToBytes(
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_get_transaction_at")]
public static extern IntPtr BlockGetTransactionAt(IntPtr block, nuint index);

/// <summary>
/// Returns the ancestor of a block tree entry at the given height.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_tree_entry_get_ancestor")]
public static extern IntPtr BlockTreeEntryGetAncestor(IntPtr block_tree_entry, int height);

/// <summary>
/// Performs context-free validation checks on a block.
/// Runs base checks (size, coinbase, tx, sigops) plus optional POW and
/// merkle-root checks controlled by <paramref name="flags"/>. The
/// validation_state is updated in-place.
/// Returns 1 if the block passed the checks, 0 otherwise.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_check")]
public static extern int BlockCheck(
IntPtr block,
IntPtr consensus_params,
BlockCheckFlags flags,
IntPtr validation_state);

#endregion

#region BlockHash Operations
Expand Down Expand Up @@ -409,6 +436,15 @@ public static extern IntPtr BlockHeaderCreate(
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_header_destroy")]
public static extern void BlockHeaderDestroy(IntPtr header);

/// <summary>
/// Serializes a block header to 80 bytes.
/// Returns 0 on success.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_header_to_bytes")]
public static extern int BlockHeaderToBytes(
IntPtr header,
[MarshalAs(UnmanagedType.LPArray, SizeConst = 80)] byte[] output);

#endregion

#region Chain Operations
Expand Down Expand Up @@ -519,6 +555,20 @@ public static extern int TransactionToBytes(
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_output_destroy")]
public static extern void TransactionOutputDestroy(IntPtr output);

/// <summary>
/// Gets the nLockTime value of a transaction.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_get_locktime")]
public static extern uint TransactionGetLocktime(IntPtr transaction);

/// <summary>
/// Runs context-free consensus validation on a transaction.
/// The validation_state is reset on entry and updated in-place.
/// Returns 1 if valid, 0 if invalid.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_check")]
public static extern int TransactionCheck(IntPtr tx, IntPtr validation_state);

#endregion

#region PrecomputedTransactionData Operations
Expand Down Expand Up @@ -867,6 +917,12 @@ public static extern IntPtr TransactionSpentOutputsGetCoinAt(
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_input_destroy")]
public static extern void TransactionInputDestroy(IntPtr transaction_input);

/// <summary>
/// Gets the nSequence value of a transaction input.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_input_get_sequence")]
public static extern uint TransactionInputGetSequence(IntPtr transaction_input);

#endregion

#region TransactionOutPoint Operations
Expand Down Expand Up @@ -897,4 +953,33 @@ public static extern IntPtr TransactionSpentOutputsGetCoinAt(

#endregion

#region Tx Validation State

/// <summary>
/// Creates a new transaction validation state.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_tx_validation_state_create")]
public static extern IntPtr TxValidationStateCreate();

/// <summary>
/// Gets the validation mode from a transaction validation state.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_tx_validation_state_get_validation_mode")]
public static extern ValidationMode TxValidationStateGetValidationMode(IntPtr validation_state);

/// <summary>
/// Gets the transaction validation result from a transaction validation state.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_tx_validation_state_get_tx_validation_result")]
public static extern TxValidationResult TxValidationStateGetTxValidationResult(IntPtr validation_state);

/// <summary>
/// Destroys a transaction validation state.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_tx_validation_state_destroy")]
public static extern void TxValidationStateDestroy(IntPtr validation_state);

#endregion


}
2 changes: 1 addition & 1 deletion tools/kernel-bindings-test-handler/Protocol/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BitcoinKernel.TestHandler.Protocol;
/// </summary>
public class Response
{
[JsonPropertyName("id")]
[JsonIgnore]
public string Id { get; set; } = string.Empty;

[JsonPropertyName("result")]
Expand Down
Loading