Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Add TransactionID to retainer
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Nov 28, 2023
1 parent 8d26f8f commit 22dc53b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/retainer/retainer/retainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,13 @@ func (r *Retainer) BlockMetadata(blockID iotago.BlockID) (*retainer.BlockMetadat
blockStatus = api.BlockStatePending
}

txStatus, txFailureReason := r.transactionStatus(blockID)
txID, txStatus, txFailureReason := r.transactionStatus(blockID)

return &retainer.BlockMetadata{
BlockID: blockID,
BlockState: blockStatus,
BlockFailureReason: blockFailureReason,
TransactionID: txID,
TransactionState: txStatus,
TransactionFailureReason: txFailureReason,
}, nil
Expand Down Expand Up @@ -240,16 +241,16 @@ func (r *Retainer) blockStatus(blockID iotago.BlockID) (api.BlockState, api.Bloc
return blockData.State, blockData.FailureReason
}

func (r *Retainer) transactionStatus(blockID iotago.BlockID) (api.TransactionState, api.TransactionFailureReason) {
func (r *Retainer) transactionStatus(blockID iotago.BlockID) (iotago.TransactionID, api.TransactionState, api.TransactionFailureReason) {
store, err := r.store(blockID.Slot())
if err != nil {
r.errorHandler(ierrors.Wrapf(err, "could not get retainer store for slot %d", blockID.Slot()))
return api.TransactionStateNoTransaction, api.TxFailureNone
return iotago.EmptyTransactionID, api.TransactionStateNoTransaction, api.TxFailureNone
}

txData, exists := store.GetTransaction(blockID)
if !exists {
return api.TransactionStateNoTransaction, api.TxFailureNone
return iotago.EmptyTransactionID, api.TransactionStateNoTransaction, api.TxFailureNone
}

// for confirmed and finalized we need to check for the block status
Expand All @@ -258,13 +259,13 @@ func (r *Retainer) transactionStatus(blockID iotago.BlockID) (api.TransactionSta

switch blockState {
case api.BlockStateConfirmed:
return api.TransactionStateConfirmed, api.TxFailureNone
return txData.TransactionID, api.TransactionStateConfirmed, api.TxFailureNone
case api.BlockStateFinalized:
return api.TransactionStateFinalized, api.TxFailureNone
return txData.TransactionID, api.TransactionStateFinalized, api.TxFailureNone
}
}

return txData.State, txData.FailureReason
return txData.TransactionID, txData.State, txData.FailureReason
}

func (r *Retainer) onBlockAttached(blockID iotago.BlockID) error {
Expand Down
20 changes: 20 additions & 0 deletions pkg/retainer/transaction_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package retainer

import (
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
)

type TransactionMetadata struct {
TransactionID iotago.TransactionID
TransactionState api.TransactionState
TransactionFailureReason api.TransactionFailureReason
}

func (m *TransactionMetadata) Response() *api.TransactionMetadataResponse {
return &api.TransactionMetadataResponse{
TransactionID: m.TransactionID,
TransactionState: m.TransactionState.String(),
TransactionFailureReason: m.TransactionFailureReason,
}
}
7 changes: 7 additions & 0 deletions pkg/storage/prunable/slotstore/retainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ func BlockRetainerDataFromBytes(bytes []byte) (*BlockRetainerData, int, error) {
}

type TransactionRetainerData struct {
TransactionID iotago.TransactionID
State api.TransactionState
FailureReason api.TransactionFailureReason
}

func (t *TransactionRetainerData) Bytes() ([]byte, error) {
byteBuffer := stream.NewByteBuffer(2)

if err := stream.Write(byteBuffer, t.TransactionID); err != nil {
return nil, ierrors.Wrap(err, "failed to write transaction ID")
}
if err := stream.Write(byteBuffer, t.State); err != nil {
return nil, ierrors.Wrap(err, "failed to write transaction state")
}
Expand All @@ -72,6 +76,9 @@ func TransactionRetainerDataFromBytes(bytes []byte) (*TransactionRetainerData, i
var err error
t := new(TransactionRetainerData)

if t.TransactionID, err = stream.Read[iotago.TransactionID](byteReader); err != nil {
return nil, 0, ierrors.Wrap(err, "failed to read transaction ID")
}
if t.State, err = stream.Read[api.TransactionState](byteReader); err != nil {
return nil, 0, ierrors.Wrap(err, "failed to read transaction state")
}
Expand Down

0 comments on commit 22dc53b

Please sign in to comment.