Skip to content

Commit 2a7e970

Browse files
committed
Adapt to C API changes
1 parent 777675f commit 2a7e970

12 files changed

+78
-73
lines changed

Makefile

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,25 @@ test:
3030
clean:
3131
rm -rf depend/bitcoin/build
3232
go clean ./...
33+
go clean -testcache
3334

3435
lint:
3536
golangci-lint run ./...
3637

3738
deps:
3839
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
3940

41+
update-kernel:
42+
git subtree pull --prefix=depend/bitcoin https://github.com/TheCharlatan/bitcoin.git kernelApi --squash
43+
4044
help:
4145
@echo "Available targets:"
42-
@echo " all - Build kernel library and run tests (default)"
43-
@echo " build-kernel - Build Bitcoin kernel library"
44-
@echo " build - Compile Go code"
45-
@echo " test - Run Go tests"
46-
@echo " clean - Clean build artifacts"
47-
@echo " lint - Lint Go code"
48-
@echo " deps - Install development dependencies"
49-
@echo " help - Show this help message"
46+
@echo " all - Build kernel library and run tests (default)"
47+
@echo " build-kernel - Build Bitcoin kernel library"
48+
@echo " build - Compile Go code"
49+
@echo " test - Run Go tests"
50+
@echo " clean - Clean build artifacts"
51+
@echo " lint - Lint Go code"
52+
@echo " deps - Install development dependencies"
53+
@echo " update-kernel - Update Bitcoin dependency using git subtree"
54+
@echo " help - Show this help message"

kernel/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (b *Block) Hash() (*BlockHash, error) {
5151
func (b *Block) Data() ([]byte, error) {
5252
checkReady(b)
5353

54-
byteArray := C.kernel_copy_block_data(b.ptr)
54+
byteArray := C.kernel_block_copy_data(b.ptr)
5555
if byteArray == nil {
5656
return nil, ErrKernelCopyBlockData
5757
}

kernel/block_index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (bi *BlockIndex) Hash() (*BlockHash, error) {
3636
func (bi *BlockIndex) Previous() *BlockIndex {
3737
checkReady(bi)
3838

39-
ptr := C.kernel_get_previous_block_index(bi.ptr)
39+
ptr := C.kernel_block_index_get_previous(bi.ptr)
4040
if ptr == nil {
4141
return nil
4242
}

kernel/block_undo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ func (bu *BlockUndo) Size() uint64 {
2525
// contained in the transaction undo data at the specified index
2626
func (bu *BlockUndo) GetTransactionUndoSize(transactionUndoIndex uint64) uint64 {
2727
checkReady(bu)
28-
return uint64(C.kernel_get_transaction_undo_size(bu.ptr, C.uint64_t(transactionUndoIndex)))
28+
return uint64(C.kernel_block_undo_get_transaction_undo_size(bu.ptr, C.uint64_t(transactionUndoIndex)))
2929
}
3030

3131
// GetUndoOutputHeightByIndex returns the block height of the block that contains
3232
// the output at output_index within the transaction undo data at the provided index
3333
func (bu *BlockUndo) GetUndoOutputHeightByIndex(transactionUndoIndex, outputIndex uint64) uint32 {
3434
checkReady(bu)
35-
return uint32(C.kernel_get_undo_output_height_by_index(bu.ptr, C.uint64_t(transactionUndoIndex), C.uint64_t(outputIndex)))
35+
return uint32(C.kernel_block_undo_get_transaction_output_height_by_index(bu.ptr, C.uint64_t(transactionUndoIndex), C.uint64_t(outputIndex)))
3636
}
3737

3838
// GetUndoOutputByIndex returns a transaction output contained in the transaction
3939
// undo data at the specified indices
4040
func (bu *BlockUndo) GetUndoOutputByIndex(transactionUndoIndex, outputIndex uint64) (*TransactionOutput, error) {
4141
checkReady(bu)
4242

43-
ptr := C.kernel_get_undo_output_by_index(bu.ptr, C.uint64_t(transactionUndoIndex), C.uint64_t(outputIndex))
43+
ptr := C.kernel_block_undo_copy_transaction_output_by_index(bu.ptr, C.uint64_t(transactionUndoIndex), C.uint64_t(outputIndex))
4444
if ptr == nil {
4545
return nil, ErrKernelGetUndoOutputByIndex
4646
}

kernel/block_validation_state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ type BlockValidationState struct {
1414

1515
func (bvs *BlockValidationState) ValidationMode() ValidationMode {
1616
checkReady(bvs)
17-
mode := C.kernel_get_validation_mode_from_block_validation_state(bvs.ptr)
17+
mode := C.kernel_block_validation_state_get_validation_mode(bvs.ptr)
1818
return ValidationMode(mode)
1919
}
2020

2121
func (bvs *BlockValidationState) ValidationResult() BlockValidationResult {
2222
checkReady(bvs)
23-
result := C.kernel_get_block_validation_result_from_block_validation_state(bvs.ptr)
23+
result := C.kernel_block_validation_state_get_block_validation_result(bvs.ptr)
2424
return BlockValidationResult(result)
2525
}
2626

kernel/chainstate_manager.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,30 @@ func NewChainstateManager(context *Context, options *ChainstateManagerOptions) (
4343
return manager, nil
4444
}
4545

46-
// ReadBlockFromDisk reads a block from disk using the provided block index
47-
func (cm *ChainstateManager) ReadBlockFromDisk(blockIndex *BlockIndex) (*Block, error) {
46+
// ReadBlock reads a block using the provided block index
47+
func (cm *ChainstateManager) ReadBlock(blockIndex *BlockIndex) (*Block, error) {
4848
checkReady(cm)
4949
if err := validateReady(blockIndex); err != nil {
5050
return nil, err
5151
}
5252

53-
ptr := C.kernel_read_block_from_disk(cm.context.ptr, cm.ptr, blockIndex.ptr)
53+
ptr := C.kernel_block_read(cm.context.ptr, cm.ptr, blockIndex.ptr)
5454
if ptr == nil {
55-
return nil, ErrKernelChainstateManagerReadBlockFromDisk
55+
return nil, ErrKernelChainstateManagerReadBlock
5656
}
5757
return newBlockFromPtr(ptr), nil
5858
}
5959

60-
// ReadBlockUndoFromDisk reads block undo data from disk for a given block index
61-
func (cm *ChainstateManager) ReadBlockUndoFromDisk(blockIndex *BlockIndex) (*BlockUndo, error) {
60+
// ReadBlockUndo reads block undo data for a given block index
61+
func (cm *ChainstateManager) ReadBlockUndo(blockIndex *BlockIndex) (*BlockUndo, error) {
6262
checkReady(cm)
6363
if err := validateReady(blockIndex); err != nil {
6464
return nil, err
6565
}
6666

67-
ptr := C.kernel_read_block_undo_from_disk(cm.context.ptr, cm.ptr, blockIndex.ptr)
67+
ptr := C.kernel_block_undo_read(cm.context.ptr, cm.ptr, blockIndex.ptr)
6868
if ptr == nil {
69-
return nil, ErrKernelChainstateManagerReadBlockUndoFromDisk
69+
return nil, ErrKernelChainstateManagerReadBlockUndo
7070
}
7171

7272
blockUndo := &BlockUndo{ptr: ptr}
@@ -95,11 +95,11 @@ func (cm *ChainstateManager) ProcessBlock(block *Block) (bool, bool, error) {
9595
return bool(success), bool(newBlock), nil
9696
}
9797

98-
// GetBlockIndexFromTip returns the block index of the current chain tip
99-
func (cm *ChainstateManager) GetBlockIndexFromTip() (*BlockIndex, error) {
98+
// GetBlockIndexTip returns the block index of the current chain tip
99+
func (cm *ChainstateManager) GetBlockIndexTip() (*BlockIndex, error) {
100100
checkReady(cm)
101101

102-
ptr := C.kernel_get_block_index_from_tip(cm.context.ptr, cm.ptr)
102+
ptr := C.kernel_block_index_get_tip(cm.context.ptr, cm.ptr)
103103
if ptr == nil {
104104
return nil, ErrBlockIndexUninitialized
105105
}
@@ -109,11 +109,11 @@ func (cm *ChainstateManager) GetBlockIndexFromTip() (*BlockIndex, error) {
109109
return blockIndex, nil
110110
}
111111

112-
// GetBlockIndexFromGenesis returns the block index of the genesis block
113-
func (cm *ChainstateManager) GetBlockIndexFromGenesis() (*BlockIndex, error) {
112+
// GetBlockIndexGenesis returns the block index of the genesis block
113+
func (cm *ChainstateManager) GetBlockIndexGenesis() (*BlockIndex, error) {
114114
checkReady(cm)
115115

116-
ptr := C.kernel_get_block_index_from_genesis(cm.context.ptr, cm.ptr)
116+
ptr := C.kernel_block_index_get_genesis(cm.context.ptr, cm.ptr)
117117
if ptr == nil {
118118
return nil, ErrBlockIndexUninitialized
119119
}
@@ -123,14 +123,14 @@ func (cm *ChainstateManager) GetBlockIndexFromGenesis() (*BlockIndex, error) {
123123
return blockIndex, nil
124124
}
125125

126-
// GetBlockIndexFromHash returns the block index for a given block hash
127-
func (cm *ChainstateManager) GetBlockIndexFromHash(blockHash *BlockHash) (*BlockIndex, error) {
126+
// GetBlockIndexByHash returns the block index for a given block hash
127+
func (cm *ChainstateManager) GetBlockIndexByHash(blockHash *BlockHash) (*BlockIndex, error) {
128128
checkReady(cm)
129129
if blockHash == nil || blockHash.ptr == nil {
130130
return nil, ErrBlockHashUninitialized
131131
}
132132

133-
ptr := C.kernel_get_block_index_from_hash(cm.context.ptr, cm.ptr, blockHash.ptr)
133+
ptr := C.kernel_block_index_get_by_hash(cm.context.ptr, cm.ptr, blockHash.ptr)
134134
if ptr == nil {
135135
return nil, ErrBlockIndexUninitialized
136136
}
@@ -140,11 +140,11 @@ func (cm *ChainstateManager) GetBlockIndexFromHash(blockHash *BlockHash) (*Block
140140
return blockIndex, nil
141141
}
142142

143-
// GetBlockIndexFromHeight returns the block index for a given height in the currently active chain
144-
func (cm *ChainstateManager) GetBlockIndexFromHeight(height int) (*BlockIndex, error) {
143+
// GetBlockIndexByHeight returns the block index for a given height in the currently active chain
144+
func (cm *ChainstateManager) GetBlockIndexByHeight(height int) (*BlockIndex, error) {
145145
checkReady(cm)
146146

147-
ptr := C.kernel_get_block_index_from_height(cm.context.ptr, cm.ptr, C.int(height))
147+
ptr := C.kernel_block_index_get_by_height(cm.context.ptr, cm.ptr, C.int(height))
148148
if ptr == nil {
149149
return nil, ErrBlockIndexUninitialized
150150
}
@@ -161,7 +161,7 @@ func (cm *ChainstateManager) GetNextBlockIndex(blockIndex *BlockIndex) (*BlockIn
161161
return nil, err
162162
}
163163

164-
ptr := C.kernel_get_next_block_index(cm.context.ptr, cm.ptr, blockIndex.ptr)
164+
ptr := C.kernel_block_index_get_next(cm.context.ptr, cm.ptr, blockIndex.ptr)
165165
if ptr == nil {
166166
return nil, nil // No next block (tip or invalid)
167167
}
@@ -177,7 +177,7 @@ func (cm *ChainstateManager) ImportBlocks(blockFilePaths []string) error {
177177

178178
if len(blockFilePaths) == 0 {
179179
// Import with no files triggers reindex if wipe options were set
180-
success := C.kernel_import_blocks(cm.context.ptr, cm.ptr, nil, nil, 0)
180+
success := C.kernel_chainstate_manager_import_blocks(cm.context.ptr, cm.ptr, nil, nil, 0)
181181
if !success {
182182
return ErrKernelImportBlocks
183183
}
@@ -200,7 +200,7 @@ func (cm *ChainstateManager) ImportBlocks(blockFilePaths []string) error {
200200
}
201201
}()
202202

203-
success := C.kernel_import_blocks(
203+
success := C.kernel_chainstate_manager_import_blocks(
204204
cm.context.ptr,
205205
cm.ptr,
206206
(**C.char)(unsafe.Pointer(&cPaths[0])),

kernel/chainstate_manager_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ func TestChainstateManager(t *testing.T) {
2222
}
2323

2424
func (s *ChainstateManagerTestSuite) TestGenesis(t *testing.T) {
25-
genesisIndex, err := s.Manager.GetBlockIndexFromGenesis()
25+
genesisIndex, err := s.Manager.GetBlockIndexGenesis()
2626
if err != nil {
27-
t.Fatalf("GetBlockIndexFromGenesis() error = %v", err)
27+
t.Fatalf("GetBlockIndexGenesis() error = %v", err)
2828
}
2929
defer genesisIndex.Destroy()
3030

@@ -46,9 +46,9 @@ func (s *ChainstateManagerTestSuite) TestGenesis(t *testing.T) {
4646
}
4747

4848
func (s *ChainstateManagerTestSuite) TestTip(t *testing.T) {
49-
tipIndex, err := s.Manager.GetBlockIndexFromTip()
49+
tipIndex, err := s.Manager.GetBlockIndexTip()
5050
if err != nil {
51-
t.Fatalf("GetBlockIndexFromTip() error = %v", err)
51+
t.Fatalf("GetBlockIndexTip() error = %v", err)
5252
}
5353
defer tipIndex.Destroy()
5454

@@ -74,15 +74,15 @@ func (s *ChainstateManagerTestSuite) TestTip(t *testing.T) {
7474
}
7575

7676
func (s *ChainstateManagerTestSuite) TestBlockUndo(t *testing.T) {
77-
blockIndex, err := s.Manager.GetBlockIndexFromHeight(202)
77+
blockIndex, err := s.Manager.GetBlockIndexByHeight(202)
7878
if err != nil {
79-
t.Fatalf("GetBlockIndexFromHeight(202) error = %v", err)
79+
t.Fatalf("GetBlockIndexByHeight(202) error = %v", err)
8080
}
8181
defer blockIndex.Destroy()
8282

83-
blockUndo, err := s.Manager.ReadBlockUndoFromDisk(blockIndex)
83+
blockUndo, err := s.Manager.ReadBlockUndo(blockIndex)
8484
if err != nil {
85-
t.Fatalf("ReadBlockUndoFromDisk() error = %v", err)
85+
t.Fatalf("ReadBlockUndo() error = %v", err)
8686
}
8787
defer blockUndo.Destroy()
8888

kernel/errors.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ var (
2121
ErrTransactionUninitialized = &UninitializedError{ObjectName: "transaction"}
2222
ErrLoggingConnectionUninitialized = &UninitializedError{ObjectName: "loggingConnection"}
2323

24-
ErrKernelBlockCreate = &KernelError{Operation: "kernel_block_create"}
25-
ErrKernelBlockGetHash = &KernelError{Operation: "kernel_block_get_hash"}
26-
ErrKernelCopyBlockData = &KernelError{Operation: "kernel_copy_block_data"}
27-
ErrKernelScriptPubkeyCreate = &KernelError{Operation: "kernel_script_pubkey_create"}
28-
ErrKernelCopyScriptPubkeyData = &KernelError{Operation: "kernel_copy_script_pubkey_data"}
29-
ErrKernelTransactionOutputCreate = &KernelError{Operation: "kernel_transaction_output_create"}
30-
ErrKernelCopyScriptPubkeyFromOutput = &KernelError{Operation: "kernel_copy_script_pubkey_from_output"}
31-
ErrKernelTransactionCreate = &KernelError{Operation: "kernel_transaction_create"}
32-
ErrKernelLoggingConnectionCreate = &KernelError{Operation: "kernel_logging_connection_create"}
33-
ErrKernelGetUndoOutputByIndex = &KernelError{Operation: "kernel_get_undo_output_by_index"}
34-
ErrKernelChainstateManagerCreate = &KernelError{Operation: "kernel_chainstate_manager_create"}
35-
ErrKernelChainstateManagerOptionsCreate = &KernelError{Operation: "kernel_chainstate_manager_options_create"}
36-
ErrKernelContextCreate = &KernelError{Operation: "kernel_context_create"}
37-
ErrKernelChainstateManagerReadBlockFromDisk = &KernelError{Operation: "kernel_read_block_from_disk"}
38-
ErrKernelChainstateManagerReadBlockUndoFromDisk = &KernelError{Operation: "kernel_read_block_undo_from_disk"}
39-
ErrKernelChainstateManagerProcessBlock = &KernelError{Operation: "kernel_chainstate_manager_process_block"}
40-
ErrKernelImportBlocks = &KernelError{Operation: "kernel_import_blocks"}
41-
ErrKernelChainParametersCreate = &KernelError{Operation: "kernel_chain_parameters_create"}
42-
ErrKernelContextOptionsCreate = &KernelError{Operation: "kernel_context_options_create"}
24+
ErrKernelBlockCreate = &KernelError{Operation: "kernel_block_create"}
25+
ErrKernelBlockGetHash = &KernelError{Operation: "kernel_block_get_hash"}
26+
ErrKernelCopyBlockData = &KernelError{Operation: "kernel_block_copy_data"}
27+
ErrKernelScriptPubkeyCreate = &KernelError{Operation: "kernel_script_pubkey_create"}
28+
ErrKernelCopyScriptPubkeyData = &KernelError{Operation: "kernel_script_pubkey_copy_data"}
29+
ErrKernelTransactionOutputCreate = &KernelError{Operation: "kernel_transaction_output_create"}
30+
ErrKernelCopyScriptPubkeyFromOutput = &KernelError{Operation: "kernel_transaction_output_copy_script_pubkey"}
31+
ErrKernelTransactionCreate = &KernelError{Operation: "kernel_transaction_create"}
32+
ErrKernelLoggingConnectionCreate = &KernelError{Operation: "kernel_logging_connection_create"}
33+
ErrKernelGetUndoOutputByIndex = &KernelError{Operation: "kernel_block_undo_copy_transaction_output_by_index"}
34+
ErrKernelChainstateManagerCreate = &KernelError{Operation: "kernel_chainstate_manager_create"}
35+
ErrKernelChainstateManagerOptionsCreate = &KernelError{Operation: "kernel_chainstate_manager_options_create"}
36+
ErrKernelContextCreate = &KernelError{Operation: "kernel_context_create"}
37+
ErrKernelChainstateManagerReadBlock = &KernelError{Operation: "kernel_block_read"}
38+
ErrKernelChainstateManagerReadBlockUndo = &KernelError{Operation: "kernel_block_undo_read"}
39+
ErrKernelChainstateManagerProcessBlock = &KernelError{Operation: "kernel_chainstate_manager_process_block"}
40+
ErrKernelImportBlocks = &KernelError{Operation: "kernel_chainstate_manager_import_blocks"}
41+
ErrKernelChainParametersCreate = &KernelError{Operation: "kernel_chain_parameters_create"}
42+
ErrKernelContextOptionsCreate = &KernelError{Operation: "kernel_context_options_create"}
4343

4444
ErrScriptVerify = &KernelError{Operation: "kernel_verify_script"}
4545
ErrScriptVerifyTxInputIndex = &KernelError{Operation: "kernel_verify_script", Detail: "the provided input index is out of range of the actual number of inputs of the transaction"}

kernel/logging_connection.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (lc *LoggingConnection) uninitializedError() error {
109109
// DisableLogging permanently disables the global internal logger.
110110
// This function should only be called once and is not thread-safe
111111
func DisableLogging() {
112-
C.kernel_disable_logging()
112+
C.kernel_logging_disable()
113113
}
114114

115115
// Global mutex for thread-safe category management
@@ -119,21 +119,21 @@ var loggingMutex = sync.RWMutex{}
119119
func AddLogLevelCategory(category LogCategory, level LogLevel) {
120120
loggingMutex.Lock()
121121
defer loggingMutex.Unlock()
122-
C.kernel_add_log_level_category(category.mustC(), level.mustC())
122+
C.kernel_logging_set_level_category(category.mustC(), level.mustC())
123123
}
124124

125125
// EnableLogCategory enables logging for a specific category or all categories
126126
func EnableLogCategory(category LogCategory) {
127127
loggingMutex.Lock()
128128
defer loggingMutex.Unlock()
129-
C.kernel_enable_log_category(category.mustC())
129+
C.kernel_logging_enable_category(category.mustC())
130130
}
131131

132132
// DisableLogCategory disables logging for a specific category or all categories
133133
func DisableLogCategory(category LogCategory) {
134134
loggingMutex.Lock()
135135
defer loggingMutex.Unlock()
136-
C.kernel_disable_log_category(category.mustC())
136+
C.kernel_logging_disable_category(category.mustC())
137137
}
138138

139139
// LogLevel represents the logging level

kernel/script_pubkey.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewScriptPubkeyFromRaw(rawScriptPubkey []byte) (*ScriptPubkey, error) {
3535
func (s *ScriptPubkey) Data() ([]byte, error) {
3636
checkReady(s)
3737

38-
byteArray := C.kernel_copy_script_pubkey_data(s.ptr)
38+
byteArray := C.kernel_script_pubkey_copy_data(s.ptr)
3939
if byteArray == nil {
4040
return nil, ErrKernelCopyScriptPubkeyData
4141
}

0 commit comments

Comments
 (0)