Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:iotaledger/iota-core into feat/r…
Browse files Browse the repository at this point in the history
…eactive-chainmanager
  • Loading branch information
hmoog committed Sep 29, 2023
2 parents 7bb755f + 9c6afcc commit 55665a2
Show file tree
Hide file tree
Showing 61 changed files with 2,080 additions and 1,563 deletions.
12 changes: 6 additions & 6 deletions components/dashboard/explorer_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ func createExplorerBlock(block *model.Block, cachedBlock *blocks.Block, metadata
return iotago.PayloadType(0)
}(),
Payload: func() json.RawMessage {
if isBasic && basicBlock.Payload != nil && basicBlock.Payload.PayloadType() == iotago.PayloadTransaction {
tx, _ := basicBlock.Payload.(*iotago.Transaction)
if isBasic && basicBlock.Payload != nil && basicBlock.Payload.PayloadType() == iotago.PayloadSignedTransaction {
tx, _ := basicBlock.Payload.(*iotago.SignedTransaction)
txResponse := NewTransaction(tx)
bytes, _ := json.Marshal(txResponse)

Expand All @@ -143,8 +143,8 @@ func createExplorerBlock(block *model.Block, cachedBlock *blocks.Block, metadata
return payloadJSON
}(),
TransactionID: func() string {
if isBasic && basicBlock.Payload != nil && basicBlock.Payload.PayloadType() == iotago.PayloadTransaction {
tx, _ := basicBlock.Payload.(*iotago.Transaction)
if isBasic && basicBlock.Payload != nil && basicBlock.Payload.PayloadType() == iotago.PayloadSignedTransaction {
tx, _ := basicBlock.Payload.(*iotago.SignedTransaction)
id, _ := tx.ID()

return id.ToHex()
Expand Down Expand Up @@ -211,9 +211,9 @@ func getTransaction(c echo.Context) error {
return ierrors.Errorf("block not found: %s", output.BlockID().ToHex())
}

iotaTX, isTX := block.Transaction()
iotaTX, isTX := block.SignedTransaction()
if !isTX {
return ierrors.Errorf("payload is not a transaction: %s", output.BlockID().ToHex())
return ierrors.Errorf("payload is not a signed transaction: %s", output.BlockID().ToHex())
}

return httpserver.JSONResponse(c, http.StatusOK, NewTransaction(iotaTX))
Expand Down
36 changes: 18 additions & 18 deletions components/dashboard/jsonresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func NewOutputID(outputID iotago.OutputID) *OutputID {

// region Transaction //////////////////////////////////////////////////////////////////////////////////////////////////

// Transaction represents the JSON model of a ledgerstate.Transaction.
// Transaction represents the JSON model of a iotago.SignedTransaction.
type Transaction struct {
TransactionID string `json:"txId"`
NetworkID iotago.NetworkID `json:"networkId"`
Expand All @@ -128,20 +128,20 @@ type Transaction struct {
Payload []byte `json:"payload"`
}

// NewTransaction returns a Transaction from the given ledgerstate.Transaction.
func NewTransaction(iotaTx *iotago.Transaction) *Transaction {
txID, err := iotaTx.ID()
// NewTransaction returns a Transaction from the given iotago.SignedTransaction.
func NewTransaction(signedTx *iotago.SignedTransaction) *Transaction {
txID, err := signedTx.ID()
if err != nil {
return nil
}

inputs := make([]*Input, len(iotaTx.Essence.Inputs))
for i, input := range iotaTx.Essence.Inputs {
inputs := make([]*Input, len(signedTx.Transaction.Inputs))
for i, input := range signedTx.Transaction.Inputs {
inputs[i] = NewInput(input)
}

outputs := make([]*Output, len(iotaTx.Essence.Outputs))
for i, output := range iotaTx.Essence.Outputs {
outputs := make([]*Output, len(signedTx.Transaction.Outputs))
for i, output := range signedTx.Transaction.Outputs {
outputs[i] = NewOutput(output)
outputs[i].OutputID = &OutputID{
Hex: iotago.OutputIDFromTransactionIDAndIndex(txID, uint16(i)).ToHex(),
Expand All @@ -150,19 +150,19 @@ func NewTransaction(iotaTx *iotago.Transaction) *Transaction {
}
}

unlockBlocks := make([]*UnlockBlock, len(iotaTx.Unlocks))
for i, unlockBlock := range iotaTx.Unlocks {
unlockBlocks := make([]*UnlockBlock, len(signedTx.Unlocks))
for i, unlockBlock := range signedTx.Unlocks {
unlockBlocks[i] = NewUnlockBlock(unlockBlock)
}

dataPayload := make([]byte, 0)
if iotaTx.Essence.Payload != nil {
dataPayload, _ = deps.Protocol.CurrentAPI().Encode(iotaTx.Essence.Payload)
if signedTx.Transaction.Payload != nil {
dataPayload, _ = deps.Protocol.CurrentAPI().Encode(signedTx.Transaction.Payload)
}

return &Transaction{
NetworkID: iotaTx.Essence.NetworkID,
CreationSlot: iotaTx.Essence.CreationSlot,
NetworkID: signedTx.Transaction.NetworkID,
CreationSlot: signedTx.Transaction.CreationSlot,
Inputs: inputs,
Outputs: outputs,
Unlocks: unlockBlocks,
Expand All @@ -174,15 +174,15 @@ func NewTransaction(iotaTx *iotago.Transaction) *Transaction {

// region Input ////////////////////////////////////////////////////////////////////////////////////////////////////////

// Input represents the JSON model of a ledgerstate.Input.
// Input represents the JSON model of a iotago.Input.
type Input struct {
Type string `json:"type"`
ReferencedOutputID *OutputID `json:"referencedOutputID,omitempty"`
// the referenced output object, omit if not specified
Output *Output `json:"output,omitempty"`
}

// NewInput returns an Input from the given ledgerstate.Input.
// NewInput returns an Input from the given iotago.Input.
func NewInput(input iotago.Input) *Input {
utxoInput, isUtxoInput := input.(*iotago.UTXOInput)
if !isUtxoInput {
Expand All @@ -199,14 +199,14 @@ func NewInput(input iotago.Input) *Input {

// region UnlockBlock //////////////////////////////////////////////////////////////////////////////////////////////////

// UnlockBlock represents the JSON model of a ledgerstate.UnlockBlock.
// UnlockBlock represents the JSON model of a iotago.UnlockBlock.
type UnlockBlock struct {
Type string `json:"type"`
SignatureType iotago.SignatureType `json:"signatureType,omitempty"`
Signature json.RawMessage `json:"signature,omitempty"`
}

// NewUnlockBlock returns an UnlockBlock from the given ledgerstate.UnlockBlock.
// NewUnlockBlock returns an UnlockBlock from the given UnlockBlock.
func NewUnlockBlock(unlockBlock iotago.Unlock) *UnlockBlock {
result := &UnlockBlock{
Type: unlockBlock.Type().String(),
Expand Down
4 changes: 2 additions & 2 deletions components/dashboard/visualizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type tipinfo struct {

func sendVertex(blk *blocks.Block, confirmed bool) {
modelBlk, _ := model.BlockFromBlock(blk.ProtocolBlock())
tx, isTx := modelBlk.Transaction()
tx, isTx := modelBlk.SignedTransaction()

broadcastWsBlock(&wsblk{MsgTypeVertex, &vertex{
ID: blk.ID().ToHex(),
Expand Down Expand Up @@ -85,7 +85,7 @@ func runVisualizer(component *app.Component) {
deps.Protocol.Events.Engine.BlockDAG.BlockAttached.Hook(func(block *blocks.Block) {
sendVertex(block, false)

tx, hasTx := block.Transaction()
tx, hasTx := block.SignedTransaction()
if hasTx {
txMetadata, exists := deps.Protocol.MainEngineInstance().Ledger.MemPool().TransactionMetadata(lo.PanicOnErr(tx.ID()))
if exists {
Expand Down
30 changes: 1 addition & 29 deletions components/inx/server_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/iotaledger/hive.go/runtime/contextutils"
"github.com/iotaledger/hive.go/runtime/event"
"github.com/iotaledger/hive.go/runtime/workerpool"
"github.com/iotaledger/hive.go/serializer/v2/serix"
inx "github.com/iotaledger/inx/go"
"github.com/iotaledger/iota-core/pkg/blockfactory"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
Expand Down Expand Up @@ -119,41 +118,14 @@ func (s *Server) ListenToConfirmedBlocks(_ *inx.NoParams, srv inx.INX_ListenToCo
}

func (s *Server) SubmitBlock(ctx context.Context, rawBlock *inx.RawBlock) (*inx.BlockId, error) {
version, _, err := iotago.VersionFromBytes(rawBlock.GetData())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to parse block version: %s", err.Error())
}

apiForVersion, err := deps.Protocol.APIForVersion(version)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid block version: %s", err.Error())
}

block, err := rawBlock.UnwrapBlock(apiForVersion, serix.WithValidation())
block, err := rawBlock.UnwrapBlock(deps.Protocol)
if err != nil {
return nil, err
}

return s.attachBlock(ctx, block)
}

func (s *Server) SubmitPayload(ctx context.Context, rawPayload *inx.RawPayload) (*inx.BlockId, error) {
payload, err := rawPayload.Unwrap(deps.Protocol.CurrentAPI(), serix.WithValidation())
if err != nil {
return nil, err
}

mergedCtx, mergedCtxCancel := contextutils.MergeContexts(ctx, Component.Daemon().ContextStopped())
defer mergedCtxCancel()

block, err := deps.BlockIssuer.CreateBlock(mergedCtx, blockIssuerAccount, blockfactory.WithPayload(payload))
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to create block: %s", err.Error())
}

return s.attachBlock(ctx, block.ProtocolBlock())
}

func (s *Server) attachBlock(ctx context.Context, block *iotago.ProtocolBlock) (*inx.BlockId, error) {
mergedCtx, mergedCtxCancel := contextutils.MergeContexts(ctx, Component.Daemon().ContextStopped())
defer mergedCtxCancel()
Expand Down
18 changes: 18 additions & 0 deletions components/inx/server_tips.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package inx

import (
"context"

inx "github.com/iotaledger/inx/go"
iotago "github.com/iotaledger/iota.go/v4"
)

func (s *Server) RequestTips(_ context.Context, req *inx.TipsRequest) (*inx.TipsResponse, error) {
references := deps.Protocol.MainEngineInstance().TipSelection.SelectTips(int(req.GetCount()))

return &inx.TipsResponse{
StrongTips: inx.NewBlockIds(references[iotago.StrongParentType]),
WeakTips: inx.NewBlockIds(references[iotago.WeakParentType]),
ShallowLikeTips: inx.NewBlockIds(references[iotago.ShallowLikeParentType]),
}, nil
}
33 changes: 16 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@ require (
github.com/google/uuid v1.3.1
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/iotaledger/hive.go/ads v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/app v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/constraints v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/crypto v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/ds v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/ierrors v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/kvstore v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/lo v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/log v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/logger v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/runtime v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230927122328-da2eaee8d805
github.com/iotaledger/hive.go/stringify v0.0.0-20230927122328-da2eaee8d805
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927112840-e982cb6707c9
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132
github.com/iotaledger/iota.go/v4 v4.0.0-20230927112835-2dc846c6153f
github.com/iotaledger/hive.go/ads v0.0.0-20230928074706-d58e32f86729
github.com/iotaledger/hive.go/app v0.0.0-20230928074706-d58e32f86729
github.com/iotaledger/hive.go/constraints v0.0.0-20230928074706-d58e32f86729
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20230928074706-d58e32f86729
github.com/iotaledger/hive.go/crypto v0.0.0-20230928074706-d58e32f86729
github.com/iotaledger/hive.go/ds v0.0.0-20230928074706-d58e32f86729
github.com/iotaledger/hive.go/ierrors v0.0.0-20230928074706-d58e32f86729
github.com/iotaledger/hive.go/kvstore v0.0.0-20230928074706-d58e32f86729
github.com/iotaledger/hive.go/lo v0.0.0-20230928074706-d58e32f86729
github.com/iotaledger/hive.go/logger v0.0.0-20230928074706-d58e32f86729
github.com/iotaledger/hive.go/runtime v0.0.0-20230928074706-d58e32f86729
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230928074706-d58e32f86729
github.com/iotaledger/hive.go/stringify v0.0.0-20230928074706-d58e32f86729
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd
github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c
github.com/labstack/echo/v4 v4.11.1
github.com/labstack/gommon v0.4.0
github.com/libp2p/go-libp2p v0.30.0
Expand Down
Loading

0 comments on commit 55665a2

Please sign in to comment.