Skip to content
Snippets Groups Projects
Unverified Commit f4a382dc authored by Acha Bill's avatar Acha Bill Committed by GitHub
Browse files

validate tx signature before issueing tx (#630)


* validate tx signature before issueing tx

* Fix typo

Co-authored-by: default avatarAngelo Capossele <angelocapossele@gmail.com>

* refactor

Co-authored-by: default avatarAngelo Capossele <angelocapossele@gmail.com>

Co-authored-by: default avatarAngelo Capossele <angelocapossele@gmail.com>
parent f7e23d7d
No related branches found
No related tags found
No related merge requests found
......@@ -14,4 +14,9 @@ var (
// ErrDoubleSpendForbidden represents an error that is triggered when a user tries to issue a double spend.
ErrDoubleSpendForbidden = errors.New("it is not allowed to issue a double spend")
// ErrTransactionDoesNotSpendAllFunds is returned if a transaction does not spend all of its inputs.
ErrTransactionDoesNotSpendAllFunds = errors.New("transaction does not spend all funds from inputs")
// ErrInvalidTransactionSignature is returned if the signature of a transaction is invalid.
ErrInvalidTransactionSignature = errors.New("missing or invalid transaction signature")
)
......@@ -30,6 +30,12 @@ func NewValueObjectFactory(tangle *Tangle, tipManager *tipmanager.TipManager) *V
func (v *ValueObjectFactory) IssueTransaction(tx *transaction.Transaction) (valueObject *payload.Payload, err error) {
parent1, parent2 := v.tipManager.Tips()
// validate the transaction signature
if !tx.SignaturesValid() {
err = ErrInvalidTransactionSignature
return
}
// check if the tx that is supposed to be issued is a double spend
tx.Inputs().ForEach(func(outputId transaction.OutputID) bool {
v.tangle.TransactionOutput(outputId).Consume(func(output *Output) {
......
......@@ -21,13 +21,6 @@ import (
"github.com/iotaledger/goshimmer/packages/binary/storageprefix"
)
var (
// ErrTransactionDoesNotSpendAllFunds is returned if a transaction does not spend all of its inputs.
ErrTransactionDoesNotSpendAllFunds = errors.New("transaction does not spend all funds from inputs")
// ErrInvalidTransactionSignature is returned if the signature of a transaction is invalid.
ErrInvalidTransactionSignature = errors.New("invalid transaction signatures")
)
// Tangle represents the value tangle that consists out of value payloads.
// It is an independent ontology, that lives inside the tangle.
type Tangle struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment