Skip to content

Commit

Permalink
Merge pull request #455 from iotaledger/chore/update-modules
Browse files Browse the repository at this point in the history
Update iota.go and inx modules and adapt to changes
  • Loading branch information
muXxer authored Oct 23, 2023
2 parents 1f0f14a + 0541bdd commit a4a953b
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 341 deletions.
10 changes: 5 additions & 5 deletions components/inx/server_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ func getINXBlockMetadata(blockID iotago.BlockID) (*inx.BlockMetadata, error) {
}

return &inx.BlockMetadata{
BlockId: inx.NewBlockId(blockID),
BlockState: inx.WrapBlockState(blockMetadata.BlockState),
BlockFailureReason: inx.WrapBlockFailureReason(blockMetadata.BlockFailureReason),
TxState: inx.WrapTransactionState(blockMetadata.TxState),
TxFailureReason: inx.WrapTransactionFailureReason(blockMetadata.TxFailureReason),
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
}
2 changes: 1 addition & 1 deletion components/restapi/core/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func selectedCommittee(c echo.Context) *apimodels.CommitteeResponse {
})

return &apimodels.CommitteeResponse{
EpochIndex: epoch,
Epoch: epoch,
Committee: committee,
TotalStake: seatedAccounts.Accounts().TotalStake(),
TotalValidatorStake: seatedAccounts.Accounts().TotalValidatorStake(),
Expand Down
35 changes: 2 additions & 33 deletions components/restapi/core/blocks.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package core

import (
"io"

"github.com/labstack/echo/v4"

"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/serializer/v2/serix"
"github.com/iotaledger/inx-app/pkg/httpserver"
"github.com/iotaledger/iota-core/pkg/blockhandler"
"github.com/iotaledger/iota-core/pkg/model"
Expand Down Expand Up @@ -78,37 +75,9 @@ func blockIssuanceBySlot(slotIndex iotago.SlotIndex) (*apimodels.IssuanceBlockHe
}

func sendBlock(c echo.Context) (*apimodels.BlockCreatedResponse, error) {
mimeType, err := httpserver.GetRequestContentType(c, httpserver.MIMEApplicationVendorIOTASerializerV2, echo.MIMEApplicationJSON)
if err != nil {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "invalid block, error: %w", err)
}

var iotaBlock *iotago.ProtocolBlock

if c.Request().Body == nil {
// bad request
return nil, ierrors.Wrap(httpserver.ErrInvalidParameter, "invalid block, error: request body missing")
}

bytes, err := io.ReadAll(c.Request().Body)
iotaBlock, err := httpserver.ParseRequestByHeader(c, deps.Protocol.CommittedAPI(), iotago.ProtocolBlockFromBytes(deps.Protocol))
if err != nil {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "invalid block, error: %w", err)
}

switch mimeType {
case echo.MIMEApplicationJSON:
if err := deps.Protocol.CommittedAPI().JSONDecode(bytes, iotaBlock, serix.WithValidation()); err != nil {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "invalid block, error: %w", err)
}

case httpserver.MIMEApplicationVendorIOTASerializerV2:
iotaBlock, _, err = iotago.ProtocolBlockFromBytes(deps.Protocol)(bytes)
if err != nil {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "invalid block, error: %w", err)
}

default:
return nil, echo.ErrUnsupportedMediaType
return nil, err
}

blockID, err := deps.BlockHandler.AttachBlock(c.Request().Context(), iotaBlock)
Expand Down
8 changes: 4 additions & 4 deletions components/restapi/core/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ func getCommitmentDetails(index iotago.SlotIndex) (*iotago.Commitment, error) {
return commitment.Commitment(), nil
}

func getUTXOChanges(index iotago.SlotIndex) (*apimodels.UTXOChangesResponse, error) {
diffs, err := deps.Protocol.MainEngineInstance().Ledger.SlotDiffs(index)
func getUTXOChanges(slot iotago.SlotIndex) (*apimodels.UTXOChangesResponse, error) {
diffs, err := deps.Protocol.MainEngineInstance().Ledger.SlotDiffs(slot)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to get slot diffs: %d", index)
return nil, ierrors.Wrapf(err, "failed to get slot diffs: %d", slot)
}

createdOutputs := make(iotago.OutputIDs, len(diffs.Outputs))
Expand All @@ -46,7 +46,7 @@ func getUTXOChanges(index iotago.SlotIndex) (*apimodels.UTXOChangesResponse, err
}

return &apimodels.UTXOChangesResponse{
Index: index,
Slot: slot,
CreatedOutputs: createdOutputs,
ConsumedOutputs: consumedOutputs,
}, nil
Expand Down
27 changes: 2 additions & 25 deletions components/restapi/core/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,29 +383,6 @@ func checkNodeSynced() echo.MiddlewareFunc {
}

func responseByHeader(c echo.Context, obj any) error {
mimeType, err := httpserver.GetAcceptHeaderContentType(c, httpserver.MIMEApplicationVendorIOTASerializerV2, echo.MIMEApplicationJSON)
if err != nil && err != httpserver.ErrNotAcceptable {
return err
}

switch mimeType {
case httpserver.MIMEApplicationVendorIOTASerializerV2:
// TODO: that should take the API that belongs to the object
b, err := deps.Protocol.CommittedAPI().Encode(obj)
if err != nil {
return err
}

return c.Blob(http.StatusOK, httpserver.MIMEApplicationVendorIOTASerializerV2, b)

// default to echo.MIMEApplicationJSON
default:
// TODO: that should take the API that belongs to the object
j, err := deps.Protocol.CommittedAPI().JSONEncode(obj)
if err != nil {
return err
}

return c.Blob(http.StatusOK, echo.MIMEApplicationJSON, j)
}
// TODO: that should take the API that belongs to the object
return httpserver.SendResponseByHeader(c, deps.Protocol.CommittedAPI(), obj)
}
18 changes: 9 additions & 9 deletions components/restapi/management/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ func pruneDatabase(c echo.Context) (*apimodels.PruneDatabaseResponse, error) {
}

// only allow one type of pruning at a time
if (request.Index == 0 && request.Depth == 0 && request.TargetDatabaseSize == "") ||
(request.Index != 0 && request.Depth != 0) ||
(request.Index != 0 && request.TargetDatabaseSize != "") ||
if (request.Epoch == 0 && request.Depth == 0 && request.TargetDatabaseSize == "") ||
(request.Epoch != 0 && request.Depth != 0) ||
(request.Epoch != 0 && request.TargetDatabaseSize != "") ||
(request.Depth != 0 && request.TargetDatabaseSize != "") {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "either index, depth or size has to be specified")
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "either epoch, depth or size has to be specified")
}

var err error

if request.Index != 0 {
err = deps.Protocol.MainEngineInstance().Storage.PruneByEpochIndex(request.Index)
if request.Epoch != 0 {
err = deps.Protocol.MainEngineInstance().Storage.PruneByEpochIndex(request.Epoch)
if err != nil {
return nil, ierrors.Wrapf(echo.ErrInternalServerError, "pruning database failed: %s", err)
}
Expand All @@ -55,12 +55,12 @@ func pruneDatabase(c echo.Context) (*apimodels.PruneDatabaseResponse, error) {
}
}

targetIndex, hasPruned := deps.Protocol.MainEngineInstance().Storage.LastPrunedEpoch()
targetEpoch, hasPruned := deps.Protocol.MainEngineInstance().Storage.LastPrunedEpoch()
if hasPruned {
targetIndex++
targetEpoch++
}

return &apimodels.PruneDatabaseResponse{
Index: targetIndex,
Epoch: targetEpoch,
}, nil
}
58 changes: 29 additions & 29 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ require (
github.com/iotaledger/hive.go/runtime v0.0.0-20231020115340-13da292c580b
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231020115340-13da292c580b
github.com/iotaledger/hive.go/stringify v0.0.0-20231020115340-13da292c580b
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231020152103-b6ea7ff7a4af
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231020151337-569450d5bf7d
github.com/iotaledger/iota.go/v4 v4.0.0-20231019174124-aa2290512bcd
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023074100-348fe7fe4ec3
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231021205014-392b75609cc2
github.com/iotaledger/iota.go/v4 v4.0.0-20231023073721-97f39c627159
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 v0.31.0
github.com/libp2p/go-libp2p-kad-dht v0.25.1
github.com/multiformats/go-multiaddr v0.11.0
github.com/multiformats/go-multiaddr v0.12.0
github.com/multiformats/go-varint v0.0.7
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e
github.com/otiai10/copy v1.14.0
Expand Down Expand Up @@ -79,26 +79,26 @@ require (
github.com/google/go-github v17.0.0+incompatible // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f // indirect
github.com/google/pprof v0.0.0-20230926050212-f7f687d19a98 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 // indirect
github.com/iotaledger/hive.go/log v0.0.0-20231019113503-7986872a7a38 // indirect
github.com/ipfs/boxo v0.10.0 // indirect
github.com/iotaledger/hive.go/log v0.0.0-20231020115340-13da292c580b // 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
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/ipld/go-ipld-prime v0.20.0 // indirect
github.com/ipld/go-ipld-prime v0.21.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/compress v1.17.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/koron/go-ssdp v0.0.4 // indirect
Expand All @@ -109,17 +109,17 @@ require (
github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect
github.com/libp2p/go-libp2p-kbucket v0.6.3 // indirect
github.com/libp2p/go-libp2p-record v0.2.0 // indirect
github.com/libp2p/go-libp2p-routing-helpers v0.7.2 // indirect
github.com/libp2p/go-libp2p-routing-helpers v0.7.3 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/libp2p/go-nat v0.2.0 // indirect
github.com/libp2p/go-netroute v0.2.1 // indirect
github.com/libp2p/go-reuseport v0.4.0 // indirect
github.com/libp2p/go-yamux/v4 v4.0.1 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.55 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/miekg/dns v1.1.56 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
Expand All @@ -135,7 +135,7 @@ require (
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/onsi/ginkgo/v2 v2.12.0 // indirect
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c // indirect
Expand All @@ -146,11 +146,11 @@ 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.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.3.3 // indirect
github.com/quic-go/qtls-go1-20 v0.3.4 // indirect
github.com/quic-go/quic-go v0.38.1 // indirect
github.com/quic-go/webtransport-go v0.5.3 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
Expand All @@ -163,22 +163,22 @@ require (
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.uber.org/fx v1.20.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.uber.org/fx v1.20.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/image v0.13.0 // indirect
golang.org/x/mod v0.13.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.13.0 // indirect
gonum.org/v1/gonum v0.13.0 // indirect
golang.org/x/tools v0.14.0 // indirect
gonum.org/v1/gonum v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit a4a953b

Please sign in to comment.