Skip to content

Commit

Permalink
Merge branch 'develop' into fix/conflicting-tx-reason
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed Nov 27, 2023
2 parents 07d4330 + bacf3dd commit bd8b14c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-network-health.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
pull_request:
paths:
- '*'
- '**'
- '!documentation/**'
- '!scripts/**'
- '!tools/**'
Expand Down
16 changes: 15 additions & 1 deletion components/restapi/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ func blockMetadataByBlockID(blockID iotago.BlockID) (*api.BlockMetadataResponse,
return blockMetadata.BlockMetadataResponse(), nil
}

func transactionMetadataByBlockID(blockID iotago.BlockID) (*api.TransactionMetadataResponse, error) {
blockMetadata, err := deps.Protocol.MainEngineInstance().Retainer.BlockMetadata(blockID)
if err != nil {
return nil, ierrors.Wrapf(echo.ErrInternalServerError, "failed to get block metadata %s: %s", blockID.ToHex(), err)
}

metadata := blockMetadata.TransactionMetadataResponse()
if metadata == nil {
return nil, ierrors.Wrapf(echo.ErrNotFound, "transaction not found")
}

return metadata, nil
}

func blockMetadataByID(c echo.Context) (*api.BlockMetadataResponse, error) {
blockID, err := httpserver.ParseBlockIDParam(c, api.ParameterBlockID)
if err != nil {
Expand All @@ -50,7 +64,7 @@ func blockWithMetadataByID(c echo.Context) (*api.BlockWithMetadataResponse, erro

block, exists := deps.Protocol.MainEngineInstance().Block(blockID)
if !exists {
return nil, ierrors.Wrapf(echo.ErrNotFound, "block not found: %s", blockID.ToHex())
return nil, ierrors.Wrapf(echo.ErrNotFound, "no transaction found for block ID %s", blockID.ToHex())
}

blockMetadata, err := blockMetadataByBlockID(blockID)
Expand Down
9 changes: 9 additions & 0 deletions components/restapi/core/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ func configure() error {
return responseByHeader(c, resp)
}, checkNodeSynced())

routeGroup.GET(api.EndpointWithEchoParameters(api.CoreEndpointTransactionsMetadata), func(c echo.Context) error {
resp, err := transactionMetadataFromTransactionID(c)
if err != nil {
return err
}

return responseByHeader(c, resp)
}, checkNodeSynced())

routeGroup.GET(api.EndpointWithEchoParameters(api.CoreEndpointCongestion), func(c echo.Context) error {
resp, err := congestionByAccountAddress(c)
if err != nil {
Expand Down
21 changes: 21 additions & 0 deletions components/restapi/core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,24 @@ func blockMetadataFromTransactionID(c echo.Context) (*api.BlockMetadataResponse,

return blockMetadataByBlockID(blockID)
}

func transactionMetadataFromTransactionID(c echo.Context) (*api.TransactionMetadataResponse, error) {
txID, err := httpserver.ParseTransactionIDParam(c, api.ParameterTransactionID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to parse transaction ID %s", c.Param(api.ParameterTransactionID))
}

blockID, err := blockIDFromTransactionID(txID)
if err != nil {
return nil, ierrors.Wrapf(echo.ErrNotFound, "failed to get block ID from transaction ID: %v", err)
}

metadata, err := transactionMetadataByBlockID(blockID)
if err != nil {
return nil, err
}

metadata.TransactionID = txID

return metadata, nil
}
13 changes: 13 additions & 0 deletions pkg/retainer/block_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,16 @@ func (b *BlockMetadata) BlockMetadataResponse() *api.BlockMetadataResponse {

return response
}

func (b *BlockMetadata) TransactionMetadataResponse() *api.TransactionMetadataResponse {
if b.TransactionState == api.TransactionStateNoTransaction {
return nil
}

response := &api.TransactionMetadataResponse{
TransactionState: b.TransactionState.String(),
TransactionFailureReason: b.TransactionFailureReason,
}

return response
}

0 comments on commit bd8b14c

Please sign in to comment.