Skip to content

Commit

Permalink
Add TransactionMetadata to INX server
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Dec 1, 2023
1 parent 4b243d0 commit 7faaf8b
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 31 deletions.
23 changes: 15 additions & 8 deletions components/inx/server_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/iotaledger/iota-core/pkg/model"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
)

func (s *Server) ReadActiveRootBlocks(_ context.Context, _ *inx.NoParams) (*inx.RootBlocksResponse, error) {
Expand Down Expand Up @@ -202,16 +203,22 @@ func (s *Server) attachBlock(ctx context.Context, block *iotago.Block) (*inx.Blo
}

func getINXBlockMetadata(blockID iotago.BlockID) (*inx.BlockMetadata, error) {
blockMetadata, err := deps.Protocol.MainEngineInstance().Retainer.BlockMetadata(blockID)
retainerBlockMetadata, err := deps.Protocol.MainEngineInstance().Retainer.BlockMetadata(blockID)
if err != nil {
return nil, ierrors.Errorf("failed to get BlockMetadata: %v", err)
}

return &inx.BlockMetadata{
BlockId: inx.NewBlockId(blockID),
BlockState: inx.WrapBlockState(blockMetadata.BlockState),
BlockFailureReason: inx.WrapBlockFailureReason(blockMetadata.BlockFailureReason),
TransactionState: inx.WrapTransactionState(blockMetadata.TransactionState),
TransactionFailureReason: inx.WrapTransactionFailureReason(blockMetadata.TransactionFailureReason),
}, nil
// TODO: the retainer should store the blockMetadataResponse directly
blockMetadata := &api.BlockMetadataResponse{
BlockID: retainerBlockMetadata.BlockID,
BlockState: retainerBlockMetadata.BlockState,
BlockFailureReason: retainerBlockMetadata.BlockFailureReason,
TransactionMetadata: &api.TransactionMetadataResponse{
TransactionID: iotago.EmptyTransactionID, // TODO: change the retainer to store the transaction ID
TransactionState: retainerBlockMetadata.TransactionState,
TransactionFailureReason: retainerBlockMetadata.TransactionFailureReason,
},
}

return inx.WrapBlockMetadata(blockMetadata)
}
58 changes: 58 additions & 0 deletions components/inx/server_transactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package inx

import (
"context"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

inx "github.com/iotaledger/inx/go"
iotago "github.com/iotaledger/iota.go/v4"
)

func (s *Server) ReadTransactionMetadata(_ context.Context, transactionID *inx.TransactionId) (*inx.TransactionMetadata, error) {
return getINXTransactionMetadata(transactionID.Unwrap())
}

func getINXTransactionMetadata(transactionID iotago.TransactionID) (*inx.TransactionMetadata, error) {

blockIDFromTransactionID := func(transactionID iotago.TransactionID) (iotago.BlockID, error) {
// Get the first output of that transaction (using index 0)
outputID := iotago.OutputIDFromTransactionIDAndIndex(transactionID, 0)

output, spent, err := deps.Protocol.MainEngineInstance().Ledger.OutputOrSpent(outputID)
if err != nil {
return iotago.EmptyBlockID, status.Errorf(codes.Internal, "failed to get output %s: %s", outputID.ToHex(), err)
}

if output != nil {
return output.BlockID(), nil
}

return spent.BlockID(), nil
}

blockID, err := blockIDFromTransactionID(transactionID)
if err != nil {
return nil, err
}

blockMetadata, err := deps.Protocol.MainEngineInstance().Retainer.BlockMetadata(blockID)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get block metadata %s: %s", blockID.ToHex(), err)
}

transactionMetadata := blockMetadata.TransactionMetadataResponse()
if transactionMetadata == nil {
return nil, status.Errorf(codes.NotFound, "transaction not found")
}

/*
// TODO: change the retainer to store the transaction metadata
transactionMetadata, err := deps.Protocol.MainEngineInstance().Retainer.TransactionMetadata(transactionID)
if err != nil {
return nil, ierrors.Errorf("failed to get transaction metadata: %v", err)
}
*/
return inx.WrapTransactionMetadata(transactionMetadata), nil
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ require (
github.com/iotaledger/hive.go/runtime v0.0.0-20231128121006-331a9e522dfe
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231127134220-90b88e35bdb2
github.com/iotaledger/hive.go/stringify v0.0.0-20231128121006-331a9e522dfe
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231128163614-c82e1fa40733
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231128162307-cc6b309e93ef
github.com/iotaledger/iota.go/v4 v4.0.0-20231201103607-03a45ba3707f
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201120059-2d8a08100744
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22
github.com/labstack/echo/v4 v4.11.3
github.com/labstack/gommon v0.4.1
github.com/libp2p/go-libp2p v0.32.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231127134220-90b88e3
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231127134220-90b88e35bdb2/go.mod h1:FoH3T6yKlZJp8xm8K+zsQiibSynp32v21CpWx8xkek8=
github.com/iotaledger/hive.go/stringify v0.0.0-20231128121006-331a9e522dfe h1:RcFUqhnJ+86+sA0XMrZ0q+086ULrdWQkWrjUt2OnJK4=
github.com/iotaledger/hive.go/stringify v0.0.0-20231128121006-331a9e522dfe/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231128163614-c82e1fa40733 h1:jdjFTuMum+fctCq+UdEGk0pRi+JLqLm3cDMC9kUEPAs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231128163614-c82e1fa40733/go.mod h1:3ae5TFi3uaECV+F4d5ekKz+xcJQmVtCICcs/Rhvgn3w=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231128162307-cc6b309e93ef h1:RImO23W0kL3U9egdLoi5OTmOIhE5rHfR/dKM/6XhZeE=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231128162307-cc6b309e93ef/go.mod h1:bi0zndM3irf8FHYUg6MzG/Zk/t0fV8IwGXAdoT7wn98=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201103607-03a45ba3707f h1:uT4ZKAyr/wk6lHcTQifAeEPb6WfBA5tdG7kEuyW7tDU=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201103607-03a45ba3707f/go.mod h1:aO+5iL0vTNwNfE4QMGHVIufGziSI1wTvwJY1ipSMgCk=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201120059-2d8a08100744 h1:nMrp2+ydM/Zp4m08Q/0Ss9yaY7FpZYh3Hxenhb02RiA=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201120059-2d8a08100744/go.mod h1:6cLX3gnhP0WL+Q+mf3/rIqfACe5fWKVR8luPXWh2xiY=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665 h1:XdhojOpZ0t0pJFyNO0zlBogSAUrhEI67eCpTC9H6sGM=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665/go.mod h1:obK1N42oafGA7EH6zC4VX2fKh7jTa3WnIa9h1azfxq0=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22 h1:awGSiqmM1pYF+e+uILNQAiiNXrirU/mTYmUf4f/wVac=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22/go.mod h1:aO+5iL0vTNwNfE4QMGHVIufGziSI1wTvwJY1ipSMgCk=
github.com/ipfs/boxo v0.13.1 h1:nQ5oQzcMZR3oL41REJDcTbrvDvuZh3J9ckc9+ILeRQI=
github.com/ipfs/boxo v0.13.1/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
4 changes: 2 additions & 2 deletions pkg/retainer/block_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type BlockMetadata struct {
func (m *BlockMetadata) BlockMetadataResponse() *api.BlockMetadataResponse {
return &api.BlockMetadataResponse{
BlockID: m.BlockID,
BlockState: m.BlockState.String(),
BlockState: m.BlockState,
BlockFailureReason: m.BlockFailureReason,
TransactionMetadata: m.TransactionMetadataResponse(),
}
Expand All @@ -31,7 +31,7 @@ func (m *BlockMetadata) TransactionMetadataResponse() *api.TransactionMetadataRe

return &api.TransactionMetadataResponse{
TransactionID: m.TransactionID,
TransactionState: m.TransactionState.String(),
TransactionState: m.TransactionState,
TransactionFailureReason: m.TransactionFailureReason,
}
}
6 changes: 3 additions & 3 deletions tools/gendoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ require (
github.com/iotaledger/hive.go/runtime v0.0.0-20231128121006-331a9e522dfe // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231127134220-90b88e35bdb2 // indirect
github.com/iotaledger/hive.go/stringify v0.0.0-20231128121006-331a9e522dfe // indirect
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231128163614-c82e1fa40733 // indirect
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231128162307-cc6b309e93ef // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20231201103607-03a45ba3707f // indirect
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201120059-2d8a08100744 // indirect
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665 // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22 // indirect
github.com/ipfs/boxo v0.13.1 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions tools/gendoc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,12 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231127134220-90b88e3
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231127134220-90b88e35bdb2/go.mod h1:FoH3T6yKlZJp8xm8K+zsQiibSynp32v21CpWx8xkek8=
github.com/iotaledger/hive.go/stringify v0.0.0-20231128121006-331a9e522dfe h1:RcFUqhnJ+86+sA0XMrZ0q+086ULrdWQkWrjUt2OnJK4=
github.com/iotaledger/hive.go/stringify v0.0.0-20231128121006-331a9e522dfe/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231128163614-c82e1fa40733 h1:jdjFTuMum+fctCq+UdEGk0pRi+JLqLm3cDMC9kUEPAs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231128163614-c82e1fa40733/go.mod h1:3ae5TFi3uaECV+F4d5ekKz+xcJQmVtCICcs/Rhvgn3w=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231128162307-cc6b309e93ef h1:RImO23W0kL3U9egdLoi5OTmOIhE5rHfR/dKM/6XhZeE=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231128162307-cc6b309e93ef/go.mod h1:bi0zndM3irf8FHYUg6MzG/Zk/t0fV8IwGXAdoT7wn98=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201103607-03a45ba3707f h1:uT4ZKAyr/wk6lHcTQifAeEPb6WfBA5tdG7kEuyW7tDU=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201103607-03a45ba3707f/go.mod h1:aO+5iL0vTNwNfE4QMGHVIufGziSI1wTvwJY1ipSMgCk=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201120059-2d8a08100744 h1:nMrp2+ydM/Zp4m08Q/0Ss9yaY7FpZYh3Hxenhb02RiA=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201120059-2d8a08100744/go.mod h1:6cLX3gnhP0WL+Q+mf3/rIqfACe5fWKVR8luPXWh2xiY=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665 h1:XdhojOpZ0t0pJFyNO0zlBogSAUrhEI67eCpTC9H6sGM=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665/go.mod h1:obK1N42oafGA7EH6zC4VX2fKh7jTa3WnIa9h1azfxq0=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22 h1:awGSiqmM1pYF+e+uILNQAiiNXrirU/mTYmUf4f/wVac=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22/go.mod h1:aO+5iL0vTNwNfE4QMGHVIufGziSI1wTvwJY1ipSMgCk=
github.com/ipfs/boxo v0.13.1 h1:nQ5oQzcMZR3oL41REJDcTbrvDvuZh3J9ckc9+ILeRQI=
github.com/ipfs/boxo v0.13.1/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
2 changes: 1 addition & 1 deletion tools/genesis-snapshot/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/iotaledger/hive.go/lo v0.0.0-20231128121006-331a9e522dfe
github.com/iotaledger/hive.go/runtime v0.0.0-20231128121006-331a9e522dfe
github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000
github.com/iotaledger/iota.go/v4 v4.0.0-20231201103607-03a45ba3707f
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22
github.com/mr-tron/base58 v1.2.0
github.com/spf13/pflag v1.0.5
golang.org/x/crypto v0.16.0
Expand Down
4 changes: 2 additions & 2 deletions tools/genesis-snapshot/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231127134220-90b88e3
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231127134220-90b88e35bdb2/go.mod h1:FoH3T6yKlZJp8xm8K+zsQiibSynp32v21CpWx8xkek8=
github.com/iotaledger/hive.go/stringify v0.0.0-20231128121006-331a9e522dfe h1:RcFUqhnJ+86+sA0XMrZ0q+086ULrdWQkWrjUt2OnJK4=
github.com/iotaledger/hive.go/stringify v0.0.0-20231128121006-331a9e522dfe/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201103607-03a45ba3707f h1:uT4ZKAyr/wk6lHcTQifAeEPb6WfBA5tdG7kEuyW7tDU=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201103607-03a45ba3707f/go.mod h1:aO+5iL0vTNwNfE4QMGHVIufGziSI1wTvwJY1ipSMgCk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22 h1:awGSiqmM1pYF+e+uILNQAiiNXrirU/mTYmUf4f/wVac=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22/go.mod h1:aO+5iL0vTNwNfE4QMGHVIufGziSI1wTvwJY1ipSMgCk=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
Expand Down

0 comments on commit 7faaf8b

Please sign in to comment.