diff --git a/components/inx/server_blocks.go b/components/inx/server_blocks.go index 6f95a99ee..0bd9fefd1 100644 --- a/components/inx/server_blocks.go +++ b/components/inx/server_blocks.go @@ -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) { @@ -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) } diff --git a/components/inx/server_transactions.go b/components/inx/server_transactions.go new file mode 100644 index 000000000..6705bbf71 --- /dev/null +++ b/components/inx/server_transactions.go @@ -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 +} diff --git a/go.mod b/go.mod index 8afa0b707..f24b5f54c 100644 --- a/go.mod +++ b/go.mod @@ -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.20231201123347-1c44b3f24221 + 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 diff --git a/go.sum b/go.sum index 8748b7e4a..d65c68ff1 100644 --- a/go.sum +++ b/go.sum @@ -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.20231201123347-1c44b3f24221 h1:+ozrau44uPy2kYv2fuj2Wks8+VkXR62WB9zONOJgzdE= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201123347-1c44b3f24221/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= diff --git a/pkg/retainer/block_metadata.go b/pkg/retainer/block_metadata.go index a7eaabc8c..913c9284c 100644 --- a/pkg/retainer/block_metadata.go +++ b/pkg/retainer/block_metadata.go @@ -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(), } @@ -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, } } diff --git a/tools/gendoc/go.mod b/tools/gendoc/go.mod index 874fe97f1..d93bf4c5e 100644 --- a/tools/gendoc/go.mod +++ b/tools/gendoc/go.mod @@ -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.20231201123347-1c44b3f24221 // 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 diff --git a/tools/gendoc/go.sum b/tools/gendoc/go.sum index 3d4892dc3..1208a30b0 100644 --- a/tools/gendoc/go.sum +++ b/tools/gendoc/go.sum @@ -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.20231201123347-1c44b3f24221 h1:+ozrau44uPy2kYv2fuj2Wks8+VkXR62WB9zONOJgzdE= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201123347-1c44b3f24221/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= diff --git a/tools/genesis-snapshot/go.mod b/tools/genesis-snapshot/go.mod index b910a2cbe..aa2165797 100644 --- a/tools/genesis-snapshot/go.mod +++ b/tools/genesis-snapshot/go.mod @@ -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 diff --git a/tools/genesis-snapshot/go.sum b/tools/genesis-snapshot/go.sum index 1a30bb675..138a2d62f 100644 --- a/tools/genesis-snapshot/go.sum +++ b/tools/genesis-snapshot/go.sum @@ -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=