Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store proofs per output that the outputID corresponds to its content #423

Merged
merged 10 commits into from
Oct 11, 2023

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion components/dashboard/frontend/src/app/misc/Payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class TransactionPayload {
networkId: number;
creationSlot: number;
inputs: Array<Input>;
inputsCommitment: string;
outputs: Array<Output>;
payload: any;
unlocks: Array<UnlockBlock>;
Expand Down
15 changes: 7 additions & 8 deletions components/dashboard/jsonresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,13 @@ func NewOutputID(outputID iotago.OutputID) *OutputID {

// Transaction represents the JSON model of a iotago.SignedTransaction.
type Transaction struct {
TransactionID string `json:"txId"`
NetworkID iotago.NetworkID `json:"networkId"`
CreationSlot iotago.SlotIndex `json:"creationSlot"`
Inputs []*Input `json:"inputs"`
InputsCommitment iotago.InputsCommitment `json:"inputsCommitment"`
Outputs []*Output `json:"outputs"`
Unlocks []*UnlockBlock `json:"unlocks"`
Payload []byte `json:"payload"`
TransactionID string `json:"txId"`
NetworkID iotago.NetworkID `json:"networkId"`
CreationSlot iotago.SlotIndex `json:"creationSlot"`
Inputs []*Input `json:"inputs"`
Outputs []*Output `json:"outputs"`
Unlocks []*UnlockBlock `json:"unlocks"`
Payload []byte `json:"payload"`
}

// NewTransaction returns a Transaction from the given iotago.SignedTransaction.
Expand Down
59 changes: 43 additions & 16 deletions components/restapi/core/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,100 +21,118 @@ import (
const (
// RouteInfo is the route for getting the node info.
// GET returns the node info.
// MIMEApplicationJSON => json.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteInfo = "/info"

// RouteBlockIssuance is the route for getting all needed information for block creation.
// GET returns the data needed toa attach block.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteBlockIssuance = "/blocks/issuance"

// RouteBlock is the route for getting a block by its blockID.
// GET returns the block based on the given type in the request "Accept" header.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteBlock = "/blocks/:" + restapipkg.ParameterBlockID

// RouteBlockMetadata is the route for getting block metadata by its blockID.
// GET returns block metadata.
// MIMEApplicationJSON => json.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteBlockMetadata = "/blocks/:" + restapipkg.ParameterBlockID + "/metadata"

// RouteBlocks is the route for sending new blocks.
// POST creates a single new block and returns the new block ID.
// The block is parsed based on the given type in the request "Content-Type" header.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteBlocks = "/blocks"

// RouteOutput is the route for getting an output by its outputID (transactionHash + outputIndex).
// RouteOutput is the route for getting an output by its outputID (transactionHash + outputIndex). This includes the proof, that the output corresponds to the requested outputID.
// GET returns the output based on the given type in the request "Accept" header.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteOutput = "/outputs/:" + restapipkg.ParameterOutputID

// RouteOutputMetadata is the route for getting output metadata by its outputID (transactionHash + outputIndex) without getting the data again.
// RouteOutputMetadata is the route for getting output metadata by its outputID (transactionHash + outputIndex) without getting the output itself again.
// GET returns the output metadata.
// MIMEApplicationJSON => json.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteOutputMetadata = "/outputs/:" + restapipkg.ParameterOutputID + "/metadata"

// RouteOutputWithMetadata is the route for getting output, together with its metadata by its outputID (transactionHash + outputIndex).
// GET returns the output metadata.
// MIMEApplicationJSON => json.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteOutputWithMetadata = "/outputs/:" + restapipkg.ParameterOutputID + "/full"

// RouteTransactionsIncludedBlock is the route for getting the block that was first confirmed for a given transaction ID.
// GET returns the block based on the given type in the request "Accept" header.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteTransactionsIncludedBlock = "/transactions/:" + restapipkg.ParameterTransactionID + "/included-block"

// RouteTransactionsIncludedBlockMetadata is the route for getting the block metadata that was first confirmed in the ledger for a given transaction ID.
// GET returns block metadata (including info about "promotion/reattachment needed").
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteTransactionsIncludedBlockMetadata = "/transactions/:" + restapipkg.ParameterTransactionID + "/included-block/metadata"

// RouteCommitmentByID is the route for getting a slot commitment by its ID.
// GET returns the commitment.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteCommitmentByID = "/commitments/:" + restapipkg.ParameterCommitmentID

// RouteCommitmentByIDUTXOChanges is the route for getting all UTXO changes of a commitment by its ID.
// GET returns the output IDs of all UTXO changes.
// MIMEApplicationJSON => json.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteCommitmentByIDUTXOChanges = "/commitments/:" + restapipkg.ParameterCommitmentID + "/utxo-changes"

// RouteCommitmentByIndex is the route for getting a commitment by its Slot.
// GET returns the commitment.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteCommitmentByIndex = "/commitments/by-index/:" + restapipkg.ParameterSlotIndex

// RouteCommitmentByIndexUTXOChanges is the route for getting all UTXO changes of a commitment by its Slot.
// GET returns the output IDs of all UTXO changes.
// MIMEApplicationJSON => json.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteCommitmentByIndexUTXOChanges = "/commitments/by-index/:" + restapipkg.ParameterSlotIndex + "/utxo-changes"

// RouteCongestion is the route for getting the current congestion state and all account related useful details as block issuance credits.
// GET returns the congestion state related to the specified account.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteCongestion = "/accounts/:" + restapipkg.ParameterAccountID + "/congestion"

// RouteValidators is the route for getting informations about the current validators.
// GET returns the paginated response with the list of validators.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteValidators = "/validators"

// RouteValidatorsAccount is the route for getting details about the validator by its accountID.
// GET returns the validator details.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteValidatorsAccount = "/validators/:" + restapipkg.ParameterAccountID

// RouteRewards is the route for getting the rewards for staking or delegation based on staking account or delegation output.
// Rewards are decayed up to returned epochEnd index.
// GET returns the rewards.
// MIMEApplicationJSON => json.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteRewards = "/rewards/:" + restapipkg.ParameterOutputID

// RouteCommittee is the route for getting the current committee.
// GET returns the committee.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteCommittee = "/committee"
)

Expand Down Expand Up @@ -255,12 +273,12 @@ func configure() error {
})

routeGroup.GET(RouteOutput, func(c echo.Context) error {
output, err := getOutput(c)
resp, err := getOutput(c)
if err != nil {
return err
}

return responseByHeader(c, output.Output())
return responseByHeader(c, resp)
})

routeGroup.GET(RouteOutputMetadata, func(c echo.Context) error {
Expand All @@ -272,6 +290,15 @@ func configure() error {
return responseByHeader(c, resp)
})

routeGroup.GET(RouteOutputWithMetadata, func(c echo.Context) error {
resp, err := getOutputWithMetadata(c)
if err != nil {
return err
}

return responseByHeader(c, resp)
})

routeGroup.GET(RouteTransactionsIncludedBlock, func(c echo.Context) error {
block, err := blockByTransactionID(c)
if err != nil {
Expand Down
53 changes: 46 additions & 7 deletions components/restapi/core/utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/iotaledger/iota.go/v4/nodeclient/apimodels"
)

func getOutput(c echo.Context) (*utxoledger.Output, error) {
func getOutput(c echo.Context) (*apimodels.OutputResponse, error) {
outputID, err := httpserver.ParseOutputIDParam(c, restapipkg.ParameterOutputID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to parse output ID param: %s", c.Param(restapipkg.ParameterOutputID))
Expand All @@ -21,10 +21,13 @@ func getOutput(c echo.Context) (*utxoledger.Output, error) {
return nil, ierrors.Wrapf(err, "failed to get output: %s from the Ledger", outputID.String())
}

return output, nil
return &apimodels.OutputResponse{
Output: output.Output(),
OutputIDProof: output.OutputIDProof(),
}, nil
}

func getOutputMetadata(c echo.Context) (*apimodels.OutputMetadataResponse, error) {
func getOutputMetadata(c echo.Context) (*apimodels.OutputMetadata, error) {
outputID, err := httpserver.ParseOutputIDParam(c, restapipkg.ParameterOutputID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to parse output ID param: %s", c.Param(restapipkg.ParameterOutputID))
Expand All @@ -42,10 +45,46 @@ func getOutputMetadata(c echo.Context) (*apimodels.OutputMetadataResponse, error
return newOutputMetadataResponse(output)
}

func newOutputMetadataResponse(output *utxoledger.Output) (*apimodels.OutputMetadataResponse, error) {
func getOutputWithMetadata(c echo.Context) (*apimodels.OutputWithMetadataResponse, error) {
outputID, err := httpserver.ParseOutputIDParam(c, restapipkg.ParameterOutputID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to parse output ID param: %s", c.Param(restapipkg.ParameterOutputID))
}

output, spent, err := deps.Protocol.MainEngineInstance().Ledger.OutputOrSpent(outputID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to get output: %s from the Ledger", outputID.String())
}

if spent != nil {
metadata, err := newSpentMetadataResponse(spent)
if err != nil {
return nil, err
}

return &apimodels.OutputWithMetadataResponse{
Output: spent.Output().Output(),
OutputIDProof: spent.Output().OutputIDProof(),
Metadata: metadata,
}, nil
}

metadata, err := newOutputMetadataResponse(output)
if err != nil {
return nil, err
}

return &apimodels.OutputWithMetadataResponse{
Output: output.Output(),
OutputIDProof: output.OutputIDProof(),
Metadata: metadata,
}, nil
}

func newOutputMetadataResponse(output *utxoledger.Output) (*apimodels.OutputMetadata, error) {
latestCommitment := deps.Protocol.MainEngineInstance().SyncManager.LatestCommitment()

resp := &apimodels.OutputMetadataResponse{
resp := &apimodels.OutputMetadata{
BlockID: output.BlockID(),
TransactionID: output.OutputID().TransactionID(),
OutputIndex: output.OutputID().Index(),
Expand All @@ -65,10 +104,10 @@ func newOutputMetadataResponse(output *utxoledger.Output) (*apimodels.OutputMeta
return resp, nil
}

func newSpentMetadataResponse(spent *utxoledger.Spent) (*apimodels.OutputMetadataResponse, error) {
func newSpentMetadataResponse(spent *utxoledger.Spent) (*apimodels.OutputMetadata, error) {
latestCommitment := deps.Protocol.MainEngineInstance().SyncManager.LatestCommitment()

resp := &apimodels.OutputMetadataResponse{
resp := &apimodels.OutputMetadata{
BlockID: spent.BlockID(),
TransactionID: spent.OutputID().TransactionID(),
OutputIndex: spent.OutputID().Index(),
Expand Down
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/iotaledger/iota-core

go 1.21

replace github.com/goccy/go-graphviz => github.com/mranney-dd/go-graphviz v0.0.0-20230707134512-55e1cb640211
replace github.com/goccy/go-graphviz => github.com/alexsporn/go-graphviz v0.0.0-20231011102718-04f10f0a9b59

require (
github.com/goccy/go-graphviz v0.1.1
Expand All @@ -24,25 +24,25 @@ require (
github.com/iotaledger/hive.go/runtime v0.0.0-20231010133617-cdbd5387e2af
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231010133617-cdbd5387e2af
github.com/iotaledger/hive.go/stringify v0.0.0-20231010133617-cdbd5387e2af
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231005192108-08a985c2e217
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231005191759-16a3636128c4
github.com/iotaledger/iota.go/v4 v4.0.0-20231005184534-62e6761a7b7c
github.com/labstack/echo/v4 v4.11.1
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231011100725-88b57a507aea
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231011100123-28cd2b2657a3
github.com/iotaledger/iota.go/v4 v4.0.0-20231011095639-a11b6691ddab
github.com/labstack/echo/v4 v4.11.2
github.com/labstack/gommon v0.4.0
github.com/libp2p/go-libp2p v0.30.0
github.com/libp2p/go-libp2p-kad-dht v0.25.1
github.com/multiformats/go-multiaddr v0.11.0
github.com/multiformats/go-varint v0.0.7
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e
github.com/otiai10/copy v1.12.0
github.com/prometheus/client_golang v1.16.0
github.com/otiai10/copy v1.14.0
github.com/prometheus/client_golang v1.17.0
github.com/stretchr/testify v1.8.4
github.com/wollac/iota-crypto-demo v0.0.0-20221117162917-b10619eccb98
github.com/zyedidia/generic v1.2.1
go.uber.org/atomic v1.11.0
go.uber.org/dig v1.17.0
golang.org/x/crypto v0.14.0
google.golang.org/grpc v1.58.2
google.golang.org/grpc v1.58.3
google.golang.org/protobuf v1.31.0
)

Expand Down Expand Up @@ -147,7 +147,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pokt-network/smt v0.6.1 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
Expand All @@ -173,14 +173,14 @@ require (
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
gonum.org/v1/gonum v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231009173412-8bfb1ae86b6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
Expand Down
Loading
Loading