From be58d07d8e8f30bdd4d2214e581954a7f2fac3f1 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Thu, 28 Sep 2023 17:03:32 +0200 Subject: [PATCH] Apply review suggestions. --- components/dashboard/explorer_routes.go | 2 +- components/dashboard/jsonresponse.go | 38 +++++++++---------- .../conflictdagv1/conflict_test.go | 2 +- .../conflictdagv1/conflictdag_test.go | 2 +- .../mempool/conflictdag/tests/framework.go | 2 +- .../engine/mempool/tests/transaction.go | 2 +- pkg/protocol/engine/mempool/transaction.go | 2 +- pkg/testsuite/transactions_framework.go | 4 +- tools/evil-spammer/wallet/options.go | 8 ++-- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/components/dashboard/explorer_routes.go b/components/dashboard/explorer_routes.go index 491c98414..703e8db62 100644 --- a/components/dashboard/explorer_routes.go +++ b/components/dashboard/explorer_routes.go @@ -213,7 +213,7 @@ func getTransaction(c echo.Context) error { 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)) diff --git a/components/dashboard/jsonresponse.go b/components/dashboard/jsonresponse.go index 3f5f737a0..f8b1558ce 100644 --- a/components/dashboard/jsonresponse.go +++ b/components/dashboard/jsonresponse.go @@ -114,9 +114,9 @@ func NewOutputID(outputID iotago.OutputID) *OutputID { // endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////// -// region SignedTransaction ////////////////////////////////////////////////////////////////////////////////////////////////// +// region Transaction ////////////////////////////////////////////////////////////////////////////////////////////////// -// Transaction represents the JSON model of a ledgerstate.SignedTransaction. +// Transaction represents the JSON model of a iotago.SignedTransaction. type Transaction struct { TransactionID string `json:"txId"` NetworkID iotago.NetworkID `json:"networkId"` @@ -128,20 +128,20 @@ type Transaction struct { Payload []byte `json:"payload"` } -// NewTransaction returns a Transaction from the given ledgerstate.SignedTransaction. -func NewTransaction(iotaTx *iotago.SignedTransaction) *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.Transaction.Inputs)) - for i, input := range iotaTx.Transaction.Inputs { + inputs := make([]*Input, len(signedTx.Transaction.Inputs)) + for i, input := range signedTx.Transaction.Inputs { inputs[i] = NewInput(input) } - outputs := make([]*Output, len(iotaTx.Transaction.Outputs)) - for i, output := range iotaTx.Transaction.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(), @@ -150,19 +150,19 @@ func NewTransaction(iotaTx *iotago.SignedTransaction) *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.Transaction.Payload != nil { - dataPayload, _ = deps.Protocol.CurrentAPI().Encode(iotaTx.Transaction.Payload) + if signedTx.Transaction.Payload != nil { + dataPayload, _ = deps.Protocol.CurrentAPI().Encode(signedTx.Transaction.Payload) } return &Transaction{ - NetworkID: iotaTx.Transaction.NetworkID, - CreationSlot: iotaTx.Transaction.CreationSlot, + NetworkID: signedTx.Transaction.NetworkID, + CreationSlot: signedTx.Transaction.CreationSlot, Inputs: inputs, Outputs: outputs, Unlocks: unlockBlocks, @@ -174,7 +174,7 @@ func NewTransaction(iotaTx *iotago.SignedTransaction) *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"` @@ -182,7 +182,7 @@ type Input struct { 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 { @@ -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(), diff --git a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflict_test.go b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflict_test.go index 24607157a..20876b610 100644 --- a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflict_test.go +++ b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflict_test.go @@ -22,7 +22,7 @@ import ( type TestConflict = *Conflict[iotago.TransactionID, iotago.OutputID, vote.MockedRank] -//var NewTestConflict = NewConflict[iotago.SignedTransactionID, iotago.OutputID, vote.MockedRank] +//var NewTestConflict = NewConflict[iotago.TransactionID, iotago.OutputID, vote.MockedRank] func NewTestConflict(id iotago.TransactionID, parentConflicts ds.Set[*Conflict[iotago.TransactionID, iotago.OutputID, vote.MockedRank]], conflictSets ds.Set[*ConflictSet[iotago.TransactionID, iotago.OutputID, vote.MockedRank]], initialWeight *weight.Weight, pendingTasksCounter *syncutils.Counter, acceptanceThresholdProvider func() int64) *Conflict[iotago.TransactionID, iotago.OutputID, vote.MockedRank] { conflict := NewConflict[iotago.TransactionID, iotago.OutputID, vote.MockedRank](id, initialWeight, pendingTasksCounter, acceptanceThresholdProvider) diff --git a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflictdag_test.go b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflictdag_test.go index 6b1d8256e..71f6d4322 100644 --- a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflictdag_test.go +++ b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflictdag_test.go @@ -36,7 +36,7 @@ func newTestFramework(t *testing.T) *tests.Framework { ) } -// transactionID creates a (made up) SignedTransactionID from the given alias. +// transactionID creates a (made up) TransactionID from the given alias. func transactionID(alias string) iotago.TransactionID { result := iotago.TransactionIDFromData(TestTransactionCreationSlot, []byte(alias)) result.RegisterAlias(alias) diff --git a/pkg/protocol/engine/mempool/conflictdag/tests/framework.go b/pkg/protocol/engine/mempool/conflictdag/tests/framework.go index 62ddbd35d..32676fa84 100644 --- a/pkg/protocol/engine/mempool/conflictdag/tests/framework.go +++ b/pkg/protocol/engine/mempool/conflictdag/tests/framework.go @@ -22,7 +22,7 @@ type Framework struct { // Assert provides a set of assertions that can be used to verify the state of the ConflictDAG. Assert *Assertions - // ConflictID is a function that is used to translate a string alias into a (deterministic) iotago.SignedTransactionID. + // ConflictID is a function that is used to translate a string alias into a (deterministic) iotago.TransactionID. ConflictID func(string) iotago.TransactionID // ResourceID is a function that is used to translate a string alias into a (deterministic) iotago.OutputID. diff --git a/pkg/protocol/engine/mempool/tests/transaction.go b/pkg/protocol/engine/mempool/tests/transaction.go index 907a367fb..43e91913c 100644 --- a/pkg/protocol/engine/mempool/tests/transaction.go +++ b/pkg/protocol/engine/mempool/tests/transaction.go @@ -38,7 +38,7 @@ func (t *Transaction) ContextInputs() (iotago.TransactionContextInputs, error) { } func (t *Transaction) String() string { - return "SignedTransaction(" + t.id.String() + ")" + return "Transaction(" + t.id.String() + ")" } var _ mempool.Transaction = new(Transaction) diff --git a/pkg/protocol/engine/mempool/transaction.go b/pkg/protocol/engine/mempool/transaction.go index 346f4a241..ed4ff92a9 100644 --- a/pkg/protocol/engine/mempool/transaction.go +++ b/pkg/protocol/engine/mempool/transaction.go @@ -6,7 +6,7 @@ import ( type Transaction interface { // ID returns the identifier of the Transaction. - ID() (iotago.SignedTransactionID, error) + ID() (iotago.TransactionID, error) // Inputs returns the inputs of the Transaction. Inputs() ([]*iotago.UTXOInput, error) diff --git a/pkg/testsuite/transactions_framework.go b/pkg/testsuite/transactions_framework.go index b4d4ac07d..967ac1065 100644 --- a/pkg/testsuite/transactions_framework.go +++ b/pkg/testsuite/transactions_framework.go @@ -357,7 +357,7 @@ func (t *TransactionFramework) SignedTransaction(alias string) *iotago.SignedTra return transaction } -func (t *TransactionFramework) SignedTransactionID(alias string) iotago.TransactionID { +func (t *TransactionFramework) SignedTransactionID(alias string) iotago.SignedTransactionID { return lo.PanicOnErr(t.SignedTransaction(alias).ID()) } @@ -502,7 +502,7 @@ func WithAccountNativeTokens(nativeTokens iotago.NativeTokens) options.Option[bu } } -// SignedTransaction options +// TransactionBuilder options func WithInputs(inputs utxoledger.Outputs) options.Option[builder.TransactionBuilder] { return func(txBuilder *builder.TransactionBuilder) { diff --git a/tools/evil-spammer/wallet/options.go b/tools/evil-spammer/wallet/options.go index 00fb121d2..a59259d2b 100644 --- a/tools/evil-spammer/wallet/options.go +++ b/tools/evil-spammer/wallet/options.go @@ -117,7 +117,7 @@ func (o *Options) checkInputsAndOutputs() error { return nil } -// WithInputs returns an Option that is used to provide the Inputs of the SignedTransaction. +// WithInputs returns an Option that is used to provide the Inputs of the Transaction. func WithInputs(inputs interface{}) Option { return func(options *Options) { switch in := inputs.(type) { @@ -135,7 +135,7 @@ func WithInputs(inputs interface{}) Option { } } -// WithOutput returns an Option that is used to define a non-colored Output for the SignedTransaction in the Block. +// WithOutput returns an Option that is used to define a non-colored Output for the Transaction in the Block. func WithOutput(output *OutputOption) Option { return func(options *Options) { if output.amount == 0 || output.address == nil { @@ -162,7 +162,7 @@ func WithOutput(output *OutputOption) Option { } } -// WithOutputs returns an Option that is used to define a non-colored Outputs for the SignedTransaction in the Block. +// WithOutputs returns an Option that is used to define a non-colored Outputs for the Transaction in the Block. func WithOutputs(outputs []*OutputOption) Option { return func(options *Options) { for _, output := range outputs { @@ -248,7 +248,7 @@ func NewFaucetRequestOptions(options ...FaucetRequestOption) *FaucetRequestOptio // FaucetRequestOption is an option for faucet request. type FaucetRequestOption func(*FaucetRequestOptions) -// WithOutputAlias returns an Option that is used to provide the Output of the SignedTransaction. +// WithOutputAlias returns an Option that is used to provide the Output of the Transaction. func WithOutputAlias(aliasName string) FaucetRequestOption { return func(options *FaucetRequestOptions) { options.outputAliasName = aliasName