Skip to content

Commit

Permalink
Adapt to new iota.go api package
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Nov 23, 2023
1 parent d6c9478 commit 8d01adb
Show file tree
Hide file tree
Showing 34 changed files with 361 additions and 402 deletions.
25 changes: 12 additions & 13 deletions components/dashboard/explorer_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (
"github.com/iotaledger/inx-app/pkg/httpserver"
"github.com/iotaledger/iota-core/pkg/model"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
restapipkg "github.com/iotaledger/iota-core/pkg/restapi"
"github.com/iotaledger/iota-core/pkg/retainer"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
"github.com/iotaledger/iota.go/v4/hexutil"
"github.com/iotaledger/iota.go/v4/nodeclient/apimodels"
)

// SearchResult defines the struct of the SearchResult.
Expand All @@ -27,8 +26,8 @@ type SearchResult struct {
}

func setupExplorerRoutes(routeGroup *echo.Group) {
routeGroup.GET("/block/:"+restapipkg.ParameterBlockID, func(c echo.Context) (err error) {
blockID, err := httpserver.ParseBlockIDParam(c, restapipkg.ParameterBlockID)
routeGroup.GET("/block/:"+api.ParameterBlockID, func(c echo.Context) (err error) {
blockID, err := httpserver.ParseBlockIDParam(c, api.ParameterBlockID)
if err != nil {
return ierrors.Errorf("parse block ID error: %w", err)
}
Expand All @@ -41,17 +40,17 @@ func setupExplorerRoutes(routeGroup *echo.Group) {
return c.JSON(http.StatusOK, t)
})

routeGroup.GET("/transaction/:"+restapipkg.ParameterTransactionID, getTransaction)
routeGroup.GET("/transaction/:"+api.ParameterTransactionID, getTransaction)
routeGroup.GET("/transaction/:transactionID/metadata", getTransactionMetadata)
// routeGroup.GET("/transaction/:transactionID/attachments", ledgerstateAPI.GetTransactionAttachments)
routeGroup.GET("/output/:"+restapipkg.ParameterOutputID, getOutput)
routeGroup.GET("/output/:"+api.ParameterOutputID, getOutput)
// routeGroup.GET("/output/:outputID/metadata", ledgerstateAPI.GetOutputMetadata)
// routeGroup.GET("/output/:outputID/consumers", ledgerstateAPI.GetOutputConsumers)
// routeGroup.GET("/conflict/:conflictID", ledgerstateAPI.GetConflict)
// routeGroup.GET("/conflict/:conflictID/children", ledgerstateAPI.GetConflictChildren)
// routeGroup.GET("/conflict/:conflictID/conflicts", ledgerstateAPI.GetConflictConflicts)
// routeGroup.GET("/conflict/:conflictID/voters", ledgerstateAPI.GetConflictVoters)
routeGroup.GET("/slot/commitment/:"+restapipkg.ParameterCommitmentID, getSlotDetailsByID)
routeGroup.GET("/slot/commitment/:"+api.ParameterCommitmentID, getSlotDetailsByID)

routeGroup.GET("/search/:search", func(c echo.Context) error {
search := c.Param("search")
Expand Down Expand Up @@ -177,13 +176,13 @@ func createExplorerBlock(block *model.Block, cachedBlock *blocks.Block, metadata
})
} else {
switch metadata.BlockState {
case apimodels.BlockStateConfirmed, apimodels.BlockStateFinalized:
case api.BlockStateConfirmed, api.BlockStateFinalized:
t.Solid = true
t.Booked = true
t.Acceptance = true
t.Scheduled = true
t.Confirmation = true
case apimodels.BlockStateFailed, apimodels.BlockStateRejected:
case api.BlockStateFailed, api.BlockStateRejected:
t.ObjectivelyInvalid = true
}
}
Expand All @@ -192,7 +191,7 @@ func createExplorerBlock(block *model.Block, cachedBlock *blocks.Block, metadata
}

func getTransaction(c echo.Context) error {
txID, err := httpserver.ParseTransactionIDParam(c, restapipkg.ParameterTransactionID)
txID, err := httpserver.ParseTransactionIDParam(c, api.ParameterTransactionID)
if err != nil {
return err
}
Expand Down Expand Up @@ -220,7 +219,7 @@ func getTransaction(c echo.Context) error {
}

func getTransactionMetadata(c echo.Context) error {
txID, err := httpserver.ParseTransactionIDParam(c, restapipkg.ParameterTransactionID)
txID, err := httpserver.ParseTransactionIDParam(c, api.ParameterTransactionID)
if err != nil {
return err
}
Expand All @@ -239,7 +238,7 @@ func getTransactionMetadata(c echo.Context) error {
}

func getOutput(c echo.Context) error {
outputID, err := httpserver.ParseOutputIDParam(c, restapipkg.ParameterOutputID)
outputID, err := httpserver.ParseOutputIDParam(c, api.ParameterOutputID)
if err != nil {
return err
}
Expand All @@ -253,7 +252,7 @@ func getOutput(c echo.Context) error {
}

func getSlotDetailsByID(c echo.Context) error {
commitmentID, err := httpserver.ParseCommitmentIDParam(c, restapipkg.ParameterCommitmentID)
commitmentID, err := httpserver.ParseCommitmentIDParam(c, api.ParameterCommitmentID)
if err != nil {
return err
}
Expand Down
17 changes: 9 additions & 8 deletions components/debugapi/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ import (
"github.com/iotaledger/iota-core/pkg/storage/database"
"github.com/iotaledger/iota-core/pkg/storage/prunable"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
)

const (
RouteValidators = "/validators"
RouteBlockMetadata = "/blocks/:" + restapipkg.ParameterBlockID + "/metadata"
RouteBlockMetadata = "/blocks/:" + api.ParameterBlockID + "/metadata"

RouteChainManagerAllChainsDot = "/all-chains"
RouteChainManagerAllChainsRendered = "/all-chains/rendered"

RouteCommitmentByIndexBlockIDs = "/commitments/by-index/:" + restapipkg.ParameterSlotIndex + "/blocks"
RouteCommitmentBySlotBlockIDs = "/commitments/by-slot/:" + api.ParameterSlot + "/blocks"

RouteCommitmentByIndexTransactionIDs = "/commitments/by-index/:" + restapipkg.ParameterSlotIndex + "/transactions"
RouteCommitmentBySlotTransactionIDs = "/commitments/by-slot/:" + api.ParameterSlot + "/transactions"
)

const (
Expand Down Expand Up @@ -148,7 +149,7 @@ func configure() error {
})

routeGroup.GET(RouteBlockMetadata, func(c echo.Context) error {
blockID, err := httpserver.ParseBlockIDParam(c, restapipkg.ParameterBlockID)
blockID, err := httpserver.ParseBlockIDParam(c, api.ParameterBlockID)
if err != nil {
return err
}
Expand Down Expand Up @@ -206,8 +207,8 @@ func configure() error {
return c.Blob(http.StatusOK, "image/png", renderedBytes)
})

routeGroup.GET(RouteCommitmentByIndexBlockIDs, func(c echo.Context) error {
slot, err := httpserver.ParseSlotParam(c, restapipkg.ParameterSlotIndex)
routeGroup.GET(RouteCommitmentBySlotBlockIDs, func(c echo.Context) error {
slot, err := httpserver.ParseSlotParam(c, api.ParameterSlot)
if err != nil {
return err
}
Expand All @@ -220,8 +221,8 @@ func configure() error {
return httpserver.JSONResponse(c, http.StatusOK, resp)
})

routeGroup.GET(RouteCommitmentByIndexTransactionIDs, func(c echo.Context) error {
slot, err := httpserver.ParseSlotParam(c, restapipkg.ParameterSlotIndex)
routeGroup.GET(RouteCommitmentBySlotTransactionIDs, func(c echo.Context) error {
slot, err := httpserver.ParseSlotParam(c, api.ParameterSlot)
if err != nil {
return err
}
Expand Down
50 changes: 25 additions & 25 deletions components/restapi/core/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"github.com/iotaledger/iota-core/pkg/core/account"
restapipkg "github.com/iotaledger/iota-core/pkg/restapi"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/nodeclient/apimodels"
"github.com/iotaledger/iota.go/v4/api"
)

func congestionByAccountAddress(c echo.Context) (*apimodels.CongestionResponse, error) {
commitmentID, err := httpserver.ParseCommitmentIDQueryParam(c, restapipkg.ParameterCommitmentID)
func congestionByAccountAddress(c echo.Context) (*api.CongestionResponse, error) {
commitmentID, err := httpserver.ParseCommitmentIDQueryParam(c, api.ParameterCommitmentID)
if err != nil {
return nil, err
}
Expand All @@ -32,14 +32,14 @@ func congestionByAccountAddress(c echo.Context) (*apimodels.CongestionResponse,
}

hrp := deps.Protocol.CommittedAPI().ProtocolParameters().Bech32HRP()
address, err := httpserver.ParseBech32AddressParam(c, hrp, restapipkg.ParameterBech32Address)
address, err := httpserver.ParseBech32AddressParam(c, hrp, api.ParameterBech32Address)
if err != nil {
return nil, err
}

accountAddress, ok := address.(*iotago.AccountAddress)
if !ok {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "address %s is not an account address", c.Param(restapipkg.ParameterBech32Address))
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "address %s is not an account address", c.Param(api.ParameterBech32Address))
}

accountID := accountAddress.AccountID()
Expand All @@ -51,15 +51,15 @@ func congestionByAccountAddress(c echo.Context) (*apimodels.CongestionResponse,
return nil, ierrors.Wrapf(echo.ErrNotFound, "account not found: %s", accountID.ToHex())
}

return &apimodels.CongestionResponse{
return &api.CongestionResponse{
Slot: commitment.Slot(),
Ready: deps.Protocol.MainEngineInstance().Scheduler.IsBlockIssuerReady(accountID),
ReferenceManaCost: commitment.ReferenceManaCost(),
BlockIssuanceCredits: acc.Credits.Value,
}, nil
}

func validators(c echo.Context) (*apimodels.ValidatorsResponse, error) {
func validators(c echo.Context) (*api.ValidatorsResponse, error) {
var err error
pageSize := restapi.ParamsRestAPI.MaxPageSize
if len(c.QueryParam(restapipkg.QueryParameterPageSize)) > 0 {
Expand Down Expand Up @@ -100,7 +100,7 @@ func validators(c echo.Context) (*apimodels.ValidatorsResponse, error) {
}

page := registeredValidators[cursorIndex:lo.Min(cursorIndex+pageSize, uint32(len(registeredValidators)))]
resp := &apimodels.ValidatorsResponse{
resp := &api.ValidatorsResponse{
Validators: page,
PageSize: pageSize,
}
Expand All @@ -114,16 +114,16 @@ func validators(c echo.Context) (*apimodels.ValidatorsResponse, error) {
return resp, nil
}

func validatorByAccountAddress(c echo.Context) (*apimodels.ValidatorResponse, error) {
func validatorByAccountAddress(c echo.Context) (*api.ValidatorResponse, error) {
hrp := deps.Protocol.CommittedAPI().ProtocolParameters().Bech32HRP()
address, err := httpserver.ParseBech32AddressParam(c, hrp, restapipkg.ParameterBech32Address)
address, err := httpserver.ParseBech32AddressParam(c, hrp, api.ParameterBech32Address)
if err != nil {
return nil, err
}

accountAddress, ok := address.(*iotago.AccountAddress)
if !ok {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "address %s is not an account address", c.Param(restapipkg.ParameterBech32Address))
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "address %s is not an account address", c.Param(api.ParameterBech32Address))
}

latestCommittedSlot := deps.Protocol.MainEngineInstance().SyncManager.LatestCommitment().Slot()
Expand All @@ -144,7 +144,7 @@ func validatorByAccountAddress(c echo.Context) (*apimodels.ValidatorResponse, er
return nil, ierrors.Wrapf(err, "failed to check if account %s is an active candidate", accountID.ToHex())
}

return &apimodels.ValidatorResponse{
return &api.ValidatorResponse{
AddressBech32: accountID.ToAddress().Bech32(deps.Protocol.CommittedAPI().ProtocolParameters().Bech32HRP()),
PoolStake: accountData.ValidatorStake + accountData.DelegationStake,
ValidatorStake: accountData.ValidatorStake,
Expand All @@ -156,18 +156,18 @@ func validatorByAccountAddress(c echo.Context) (*apimodels.ValidatorResponse, er
}, nil
}

func rewardsByOutputID(c echo.Context) (*apimodels.ManaRewardsResponse, error) {
outputID, err := httpserver.ParseOutputIDParam(c, restapipkg.ParameterOutputID)
func rewardsByOutputID(c echo.Context) (*api.ManaRewardsResponse, error) {
outputID, err := httpserver.ParseOutputIDParam(c, api.ParameterOutputID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to parse output ID %s", c.Param(restapipkg.ParameterOutputID))
return nil, ierrors.Wrapf(err, "failed to parse output ID %s", c.Param(api.ParameterOutputID))
}

var slotIndex iotago.SlotIndex
if len(c.QueryParam(restapipkg.ParameterSlotIndex)) > 0 {
if len(c.QueryParam(api.ParameterSlot)) > 0 {
var err error
slotIndex, err = httpserver.ParseSlotQueryParam(c, restapipkg.ParameterSlotIndex)
slotIndex, err = httpserver.ParseSlotQueryParam(c, api.ParameterSlot)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to parse slot index %s", c.Param(restapipkg.ParameterSlotIndex))
return nil, ierrors.Wrapf(err, "failed to parse slot index %s", c.Param(api.ParameterSlot))
}
genesisSlot := deps.Protocol.LatestAPI().ProtocolParameters().GenesisSlot()
if slotIndex < genesisSlot {
Expand Down Expand Up @@ -231,19 +231,19 @@ func rewardsByOutputID(c echo.Context) (*apimodels.ManaRewardsResponse, error) {
return nil, ierrors.Wrapf(echo.ErrInternalServerError, "failed to calculate reward for output %s: %s", outputID.ToHex(), err)
}

return &apimodels.ManaRewardsResponse{
return &api.ManaRewardsResponse{
EpochStart: actualStart,
EpochEnd: actualEnd,
Rewards: reward,
}, nil
}

func selectedCommittee(c echo.Context) (*apimodels.CommitteeResponse, error) {
func selectedCommittee(c echo.Context) (*api.CommitteeResponse, error) {
timeProvider := deps.Protocol.CommittedAPI().TimeProvider()

var slot iotago.SlotIndex

epoch, err := httpserver.ParseEpochQueryParam(c, restapipkg.ParameterEpochIndex)
epoch, err := httpserver.ParseEpochQueryParam(c, api.ParameterEpoch)
if err != nil {
// by default we return current epoch
slot = timeProvider.SlotFromTime(time.Now())
Expand All @@ -254,7 +254,7 @@ func selectedCommittee(c echo.Context) (*apimodels.CommitteeResponse, error) {

seatedAccounts, exists := deps.Protocol.MainEngineInstance().SybilProtection.SeatManager().CommitteeInSlot(slot)
if !exists {
return &apimodels.CommitteeResponse{
return &api.CommitteeResponse{
Epoch: epoch,
}, nil
}
Expand All @@ -264,9 +264,9 @@ func selectedCommittee(c echo.Context) (*apimodels.CommitteeResponse, error) {
return nil, ierrors.Wrapf(err, "failed to get accounts from committee for slot %d", slot)
}

committee := make([]*apimodels.CommitteeMemberResponse, 0, accounts.Size())
committee := make([]*api.CommitteeMemberResponse, 0, accounts.Size())
accounts.ForEach(func(accountID iotago.AccountID, seat *account.Pool) bool {
committee = append(committee, &apimodels.CommitteeMemberResponse{
committee = append(committee, &api.CommitteeMemberResponse{
AddressBech32: accountID.ToAddress().Bech32(deps.Protocol.CommittedAPI().ProtocolParameters().Bech32HRP()),
PoolStake: seat.PoolStake,
ValidatorStake: seat.ValidatorStake,
Expand All @@ -276,7 +276,7 @@ func selectedCommittee(c echo.Context) (*apimodels.CommitteeResponse, error) {
return true
})

return &apimodels.CommitteeResponse{
return &api.CommitteeResponse{
Epoch: epoch,
Committee: committee,
TotalStake: accounts.TotalStake(),
Expand Down
Loading

0 comments on commit 8d01adb

Please sign in to comment.