-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TransactionMetadata to INX server
- Loading branch information
Showing
9 changed files
with
96 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters