Return all transactions in a block
This commit is contained in:
parent
5e9343a662
commit
9fa814a74a
4 changed files with 78 additions and 49 deletions
|
@ -7,7 +7,7 @@
|
||||||
"http_timeout": 300,
|
"http_timeout": 300,
|
||||||
"max_retries": 5,
|
"max_retries": 5,
|
||||||
"retry_elapsed_time": 0,
|
"retry_elapsed_time": 0,
|
||||||
"max_online_connections": 0,
|
"max_online_connections": 1000,
|
||||||
"max_sync_concurrency": 0,
|
"max_sync_concurrency": 0,
|
||||||
"tip_delay": 1800,
|
"tip_delay": 1800,
|
||||||
"log_configuration": false,
|
"log_configuration": false,
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"http_timeout": 300,
|
"http_timeout": 300,
|
||||||
"max_retries": 5,
|
"max_retries": 5,
|
||||||
"retry_elapsed_time": 0,
|
"retry_elapsed_time": 0,
|
||||||
"max_online_connections": 0,
|
"max_online_connections": 1000,
|
||||||
"max_sync_concurrency": 0,
|
"max_sync_concurrency": 0,
|
||||||
"tip_delay": 1800,
|
"tip_delay": 1800,
|
||||||
"log_configuration": false,
|
"log_configuration": false,
|
||||||
|
|
|
@ -54,6 +54,22 @@ func (s *BlockAPIService) Block(
|
||||||
return nil, wrapErr(ErrBlockNotFound, err)
|
return nil, wrapErr(ErrBlockNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
txs := make([]*types.Transaction, len(blockResponse.OtherTransactions))
|
||||||
|
for i, otherTx := range blockResponse.OtherTransactions {
|
||||||
|
transaction, err := s.i.GetBlockTransaction(
|
||||||
|
ctx,
|
||||||
|
blockResponse.Block.BlockIdentifier,
|
||||||
|
otherTx,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, wrapErr(ErrTransactionNotFound, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
txs[i] = transaction
|
||||||
|
}
|
||||||
|
blockResponse.Block.Transactions = txs
|
||||||
|
|
||||||
|
blockResponse.OtherTransactions = nil
|
||||||
return blockResponse, nil
|
return blockResponse, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,20 +78,5 @@ func (s *BlockAPIService) BlockTransaction(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *types.BlockTransactionRequest,
|
request *types.BlockTransactionRequest,
|
||||||
) (*types.BlockTransactionResponse, *types.Error) {
|
) (*types.BlockTransactionResponse, *types.Error) {
|
||||||
if s.config.Mode != configuration.Online {
|
return nil, ErrUnimplemented
|
||||||
return nil, wrapErr(ErrUnavailableOffline, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
transaction, err := s.i.GetBlockTransaction(
|
|
||||||
ctx,
|
|
||||||
request.BlockIdentifier,
|
|
||||||
request.TransactionIdentifier,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, wrapErr(ErrTransactionNotFound, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.BlockTransactionResponse{
|
|
||||||
Transaction: transaction,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,8 @@ func TestBlockService_Offline(t *testing.T) {
|
||||||
|
|
||||||
blockTransaction, err := servicer.BlockTransaction(ctx, &types.BlockTransactionRequest{})
|
blockTransaction, err := servicer.BlockTransaction(ctx, &types.BlockTransactionRequest{})
|
||||||
assert.Nil(t, blockTransaction)
|
assert.Nil(t, blockTransaction)
|
||||||
assert.Equal(t, ErrUnavailableOffline.Code, err.Code)
|
assert.Equal(t, ErrUnimplemented.Code, err.Code)
|
||||||
assert.Equal(t, ErrUnavailableOffline.Message, err.Message)
|
assert.Equal(t, ErrUnimplemented.Message, err.Message)
|
||||||
|
|
||||||
mockIndexer.AssertExpectations(t)
|
mockIndexer.AssertExpectations(t)
|
||||||
}
|
}
|
||||||
|
@ -54,51 +54,49 @@ func TestBlockService_Online(t *testing.T) {
|
||||||
servicer := NewBlockAPIService(cfg, mockIndexer)
|
servicer := NewBlockAPIService(cfg, mockIndexer)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
block := &types.Block{
|
rawBlock := &types.Block{
|
||||||
BlockIdentifier: &types.BlockIdentifier{
|
BlockIdentifier: &types.BlockIdentifier{
|
||||||
Index: 100,
|
Index: 100,
|
||||||
Hash: "block 100",
|
Hash: "block 100",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
blockResponse := &types.BlockResponse{
|
|
||||||
Block: block,
|
|
||||||
OtherTransactions: []*types.TransactionIdentifier{
|
|
||||||
{
|
|
||||||
Hash: "tx1",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
transaction := &types.Transaction{
|
transaction := &types.Transaction{
|
||||||
TransactionIdentifier: &types.TransactionIdentifier{
|
TransactionIdentifier: &types.TransactionIdentifier{
|
||||||
Hash: "tx1",
|
Hash: "tx1",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
block := &types.Block{
|
||||||
|
BlockIdentifier: &types.BlockIdentifier{
|
||||||
|
Index: 100,
|
||||||
|
Hash: "block 100",
|
||||||
|
},
|
||||||
|
Transactions: []*types.Transaction{
|
||||||
|
transaction,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
blockResponse := &types.BlockResponse{
|
||||||
|
Block: block,
|
||||||
|
}
|
||||||
|
|
||||||
t.Run("nil identifier", func(t *testing.T) {
|
t.Run("nil identifier", func(t *testing.T) {
|
||||||
mockIndexer.On(
|
mockIndexer.On(
|
||||||
"GetBlockLazy",
|
"GetBlockLazy",
|
||||||
ctx,
|
ctx,
|
||||||
(*types.PartialBlockIdentifier)(nil),
|
(*types.PartialBlockIdentifier)(nil),
|
||||||
).Return(
|
).Return(
|
||||||
blockResponse,
|
&types.BlockResponse{
|
||||||
|
Block: rawBlock,
|
||||||
|
OtherTransactions: []*types.TransactionIdentifier{
|
||||||
|
{
|
||||||
|
Hash: "tx1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
nil,
|
nil,
|
||||||
).Once()
|
).Once()
|
||||||
b, err := servicer.Block(ctx, &types.BlockRequest{})
|
|
||||||
assert.Nil(t, err)
|
|
||||||
assert.Equal(t, blockResponse, b)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("populated identifier", func(t *testing.T) {
|
|
||||||
pbIdentifier := types.ConstructPartialBlockIdentifier(block.BlockIdentifier)
|
|
||||||
mockIndexer.On("GetBlockLazy", ctx, pbIdentifier).Return(blockResponse, nil).Once()
|
|
||||||
b, err := servicer.Block(ctx, &types.BlockRequest{
|
|
||||||
BlockIdentifier: pbIdentifier,
|
|
||||||
})
|
|
||||||
assert.Nil(t, err)
|
|
||||||
assert.Equal(t, blockResponse, b)
|
|
||||||
|
|
||||||
mockIndexer.On(
|
mockIndexer.On(
|
||||||
"GetBlockTransaction",
|
"GetBlockTransaction",
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -108,12 +106,42 @@ func TestBlockService_Online(t *testing.T) {
|
||||||
transaction,
|
transaction,
|
||||||
nil,
|
nil,
|
||||||
).Once()
|
).Once()
|
||||||
blockTransaction, err := servicer.BlockTransaction(ctx, &types.BlockTransactionRequest{
|
b, err := servicer.Block(ctx, &types.BlockRequest{})
|
||||||
BlockIdentifier: blockResponse.Block.BlockIdentifier,
|
assert.Nil(t, err)
|
||||||
TransactionIdentifier: transaction.TransactionIdentifier,
|
assert.Equal(t, blockResponse, b)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("populated identifier", func(t *testing.T) {
|
||||||
|
pbIdentifier := types.ConstructPartialBlockIdentifier(block.BlockIdentifier)
|
||||||
|
mockIndexer.On(
|
||||||
|
"GetBlockLazy",
|
||||||
|
ctx,
|
||||||
|
pbIdentifier,
|
||||||
|
).Return(
|
||||||
|
&types.BlockResponse{
|
||||||
|
Block: rawBlock,
|
||||||
|
OtherTransactions: []*types.TransactionIdentifier{
|
||||||
|
{
|
||||||
|
Hash: "tx1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
nil,
|
||||||
|
).Once()
|
||||||
|
mockIndexer.On(
|
||||||
|
"GetBlockTransaction",
|
||||||
|
ctx,
|
||||||
|
blockResponse.Block.BlockIdentifier,
|
||||||
|
transaction.TransactionIdentifier,
|
||||||
|
).Return(
|
||||||
|
transaction,
|
||||||
|
nil,
|
||||||
|
).Once()
|
||||||
|
b, err := servicer.Block(ctx, &types.BlockRequest{
|
||||||
|
BlockIdentifier: pbIdentifier,
|
||||||
})
|
})
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, transaction, blockTransaction.Transaction)
|
assert.Equal(t, blockResponse, b)
|
||||||
})
|
})
|
||||||
|
|
||||||
mockIndexer.AssertExpectations(t)
|
mockIndexer.AssertExpectations(t)
|
||||||
|
|
Loading…
Reference in a new issue