Skip to content

Commit d5114cb

Browse files
committed
Adapt to C API size_t usages
1 parent 58084a0 commit d5114cb

File tree

9 files changed

+20
-28
lines changed

9 files changed

+20
-28
lines changed

kernel/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (b *Block) CountTransactions() (uint64, error) {
8181
func (b *Block) GetTransactionAt(index uint64) (*Transaction, error) {
8282
checkReady(b)
8383

84-
ptr := C.btck_block_get_transaction_at(b.ptr, C.uint64_t(index))
84+
ptr := C.btck_block_get_transaction_at(b.ptr, C.size_t(index))
8585
if ptr == nil {
8686
return nil, ErrKernelBlockGetTransaction
8787
}

kernel/block_spent_outputs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ type BlockSpentOutputs struct {
1515
ptr *C.btck_BlockSpentOutputs
1616
}
1717

18-
// Size returns the number of transaction spent outputs contained in block spent outputs
19-
func (bso *BlockSpentOutputs) Size() uint64 {
18+
// Count returns the number of transaction spent outputs contained in block spent outputs
19+
func (bso *BlockSpentOutputs) Count() uint64 {
2020
checkReady(bso)
21-
return uint64(C.btck_block_spent_outputs_size(bso.ptr))
21+
return uint64(C.btck_block_spent_outputs_count(bso.ptr))
2222
}
2323

2424
// GetTransactionSpentOutputsAt returns the transaction spent outputs at the specified index
2525
func (bso *BlockSpentOutputs) GetTransactionSpentOutputsAt(index uint64) (*TransactionSpentOutputs, error) {
2626
checkReady(bso)
27-
ptr := C.btck_block_spent_outputs_get_transaction_spent_outputs_at(bso.ptr, C.uint64_t(index))
27+
ptr := C.btck_block_spent_outputs_get_transaction_spent_outputs_at(bso.ptr, C.size_t(index))
2828
if ptr == nil {
2929
return nil, ErrKernelBlockSpentOutputsGetTransactionSpentOutputsAt
3030
}

kernel/block_tree_entry_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ func TestBlockTreeEntryGetPrevious(t *testing.T) {
1717
defer chain.Destroy()
1818

1919
// Get block at height 1
20-
entry, err := chain.GetByHeight(1)
21-
if err != nil {
22-
t.Fatalf("GetByHeight(1) error = %v", err)
23-
}
20+
entry := chain.GetByHeight(1)
2421
defer entry.Destroy()
2522

2623
// Test getting previous block (should be genesis)

kernel/chain.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ func (c *Chain) GetGenesis() (*BlockTreeEntry, error) {
4141
return entry, nil
4242
}
4343

44-
// GetByHeight returns the block tree entry at the specified height or nil if no block at this height
45-
func (c *Chain) GetByHeight(height int) (*BlockTreeEntry, error) {
44+
// GetByHeight returns the block tree entry at the specified height
45+
func (c *Chain) GetByHeight(height int) *BlockTreeEntry {
4646
checkReady(c)
4747
ptr := C.btck_chain_get_by_height(c.ptr, C.int(height))
4848
if ptr == nil {
49-
return nil, nil
49+
panic(ErrKernelChainGetByHeight)
5050
}
5151

5252
entry := &BlockTreeEntry{ptr: ptr}
5353
runtime.SetFinalizer(entry, (*BlockTreeEntry).destroy)
54-
return entry, nil
54+
return entry
5555
}
5656

5757
// GetNextBlockTreeEntry returns the next block tree entry in the active chain, or nil if block tree entry is the chain tip or not in the chain

kernel/chain_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ func TestChain(t *testing.T) {
6969
}
7070

7171
// Test GetByHeight
72-
block1, err := chain.GetByHeight(1)
73-
if err != nil {
74-
t.Fatalf("GetByHeight(1) error = %v", err)
75-
}
72+
block1 := chain.GetByHeight(1)
7673
defer block1.Destroy()
7774

7875
if block1.Height() != 1 {

kernel/chainstate_manager_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ func (s *ChainstateManagerTestSuite) TestBlockSpentOutputs(t *testing.T) {
2828
}
2929
defer chain.Destroy()
3030

31-
blockIndex, err := chain.GetByHeight(202)
32-
if err != nil {
33-
t.Fatalf("GetByHeight(202) error = %v", err)
34-
}
31+
blockIndex := chain.GetByHeight(202)
3532
defer blockIndex.Destroy()
3633

3734
blockSpentOutputs, err := s.Manager.ReadBlockSpentOutputs(blockIndex)
@@ -41,7 +38,7 @@ func (s *ChainstateManagerTestSuite) TestBlockSpentOutputs(t *testing.T) {
4138
defer blockSpentOutputs.Destroy()
4239

4340
// Test transaction spent outputs count
44-
txCount := blockSpentOutputs.Size()
41+
txCount := blockSpentOutputs.Count()
4542
if txCount != 20 {
4643
t.Errorf("Expected 20 transactions, got %d", txCount)
4744
}
@@ -54,7 +51,7 @@ func (s *ChainstateManagerTestSuite) TestBlockSpentOutputs(t *testing.T) {
5451
}
5552
defer txSpentOutputs.Destroy()
5653

57-
spentOutputSize := txSpentOutputs.Size()
54+
spentOutputSize := txSpentOutputs.Count()
5855
if spentOutputSize != 1 {
5956
t.Errorf("Expected transaction spent output size 1, got %d", spentOutputSize)
6057
}

kernel/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ var (
6565

6666
ErrChainParametersUninitialized = &UninitializedError{ObjectName: "chainParameters"}
6767
ErrKernelChainParametersCreate = &KernelError{Operation: "btck_chain_parameters_create"}
68+
ErrKernelChainGetByHeight = &KernelError{Operation: "btck_chain_get_by_height"}
6869

6970
ErrChainUninitialized = &UninitializedError{ObjectName: "chain"}
7071

kernel/transaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (t *Transaction) CountOutputs() (uint64, error) {
6666
func (t *Transaction) GetOutputAt(index uint64) (*TransactionOutput, error) {
6767
checkReady(t)
6868

69-
ptr := C.btck_transaction_get_output_at(t.ptr, C.uint64_t(index))
69+
ptr := C.btck_transaction_get_output_at(t.ptr, C.size_t(index))
7070
if ptr == nil {
7171
return nil, ErrKernelTransactionGetOutput
7272
}

kernel/transaction_spent_outputs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ type TransactionSpentOutputs struct {
1515
ptr *C.btck_TransactionSpentOutputs
1616
}
1717

18-
// Size returns the number of spent transaction outputs for the transaction
19-
func (tso *TransactionSpentOutputs) Size() uint64 {
18+
// Count returns the number of spent transaction outputs for the transaction
19+
func (tso *TransactionSpentOutputs) Count() uint64 {
2020
checkReady(tso)
21-
return uint64(C.btck_transaction_spent_outputs_size(tso.ptr))
21+
return uint64(C.btck_transaction_spent_outputs_count(tso.ptr))
2222
}
2323

2424
// GetCoinAt returns a coin contained in the transaction spent outputs at the specified index
2525
func (tso *TransactionSpentOutputs) GetCoinAt(index uint64) (*Coin, error) {
2626
checkReady(tso)
27-
ptr := C.btck_transaction_spent_outputs_get_coin_at(tso.ptr, C.uint64_t(index))
27+
ptr := C.btck_transaction_spent_outputs_get_coin_at(tso.ptr, C.size_t(index))
2828
if ptr == nil {
2929
return nil, ErrKernelTransactionSpentOutputsGetCoinAt
3030
}

0 commit comments

Comments
 (0)