Skip to content

Commit 15c8d61

Browse files
committed
Adapt to C API and remove BlockPointer
1 parent 02e2e49 commit 15c8d61

File tree

3 files changed

+5
-37
lines changed

3 files changed

+5
-37
lines changed

kernel/context_options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern void go_notify_warning_set_bridge(void* user_data, btck_Warning warning,
1414
extern void go_notify_warning_unset_bridge(void* user_data, btck_Warning warning);
1515
extern void go_notify_flush_error_bridge(void* user_data, const char* message, size_t message_len);
1616
extern void go_notify_fatal_error_bridge(void* user_data, const char* message, size_t message_len);
17-
extern void go_validation_interface_block_checked_bridge(void* user_data, const btck_BlockPointer* block, const btck_BlockValidationState* state);
17+
extern void go_validation_interface_block_checked_bridge(void* user_data, btck_Block* block, const btck_BlockValidationState* state);
1818
*/
1919
import "C"
2020
import (

kernel/validation_interface_callbacks.go

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,17 @@ import (
1111

1212
// ValidationInterfaceCallbacks contains all the Go callback function types for validation interface.
1313
type ValidationInterfaceCallbacks struct {
14-
OnBlockChecked func(block *BlockPointer, state *BlockValidationState)
14+
OnBlockChecked func(block *Block, state *BlockValidationState)
1515
}
1616

1717
//export go_validation_interface_block_checked_bridge
18-
func go_validation_interface_block_checked_bridge(user_data unsafe.Pointer, block *C.btck_BlockPointer, state *C.btck_BlockValidationState) {
18+
func go_validation_interface_block_checked_bridge(user_data unsafe.Pointer, block *C.btck_Block, state *C.btck_BlockValidationState) {
1919
// Convert void* back to Handle - user_data contains Handle ID
2020
handle := cgo.Handle(user_data)
2121
// Retrieve original Go callback struct
2222
callbacks := handle.Value().(*ValidationInterfaceCallbacks)
2323

2424
if callbacks.OnBlockChecked != nil {
25-
goBlock := &BlockPointer{ptr: (*C.btck_BlockPointer)(unsafe.Pointer(block))}
26-
goState := &BlockValidationState{ptr: (*C.btck_BlockValidationState)(unsafe.Pointer(state))}
27-
callbacks.OnBlockChecked(goBlock, goState)
25+
callbacks.OnBlockChecked(newBlockFromPtr(block), &BlockValidationState{ptr: state})
2826
}
2927
}
30-
31-
// BlockPointer wraps the C kernel_BlockPointer for validation interface callbacks
32-
type BlockPointer struct {
33-
ptr *C.btck_BlockPointer
34-
}
35-
36-
// GetHash returns the block hash
37-
func (bp *BlockPointer) GetHash() (*BlockHash, error) {
38-
if bp.ptr == nil {
39-
return nil, ErrBlockUninitialized
40-
}
41-
42-
hashPtr := C.btck_block_pointer_get_hash(bp.ptr)
43-
if hashPtr == nil {
44-
return nil, ErrKernelBlockGetHash
45-
}
46-
47-
return &BlockHash{ptr: hashPtr}, nil
48-
}
49-
50-
// Bytes returns the serialized block
51-
func (bp *BlockPointer) Bytes() ([]byte, error) {
52-
if bp.ptr == nil {
53-
return nil, ErrBlockUninitialized
54-
}
55-
56-
return writeToBytes(func(writer C.btck_WriteBytes, user_data unsafe.Pointer) C.int {
57-
return C.btck_block_pointer_to_bytes(bp.ptr, writer, user_data)
58-
})
59-
}

kernel/validation_interface_callbacks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func TestValidationInterfaceCallbacks(t *testing.T) {
1111
var lastBlockData []byte
1212

1313
callbacks := &ValidationInterfaceCallbacks{
14-
OnBlockChecked: func(block *BlockPointer, state *BlockValidationState) {
14+
OnBlockChecked: func(block *Block, state *BlockValidationState) {
1515
blockCheckedCalled = true
1616
lastValidationMode = state.ValidationMode()
1717
var err error

0 commit comments

Comments
 (0)