Skip to content

Introduce new TransactionWithSignature interface #2175

@kirugan

Description

@kirugan

Right now all transactions implement Signature() method, but we don't need it for L1Handler and Deploy transactions (right now they return empty slice).
We already faced some issues with it, here is an example:

if txSignature := transaction.Signature(); len(txSignature) > 0 {
   digest.Update(txSignature...)
} else {
   digest.Update(&felt.Zero)
}

it was rewritten as:

switch transaction.(type) {
  case *DeployTransaction, *L1HandlerTransaction:
     digest.Update(&felt.Zero)
  default:
    digest.Update(transaction.Signature()...)
}

but code above may lead to more questions: why we're specifying exactly these transactions? is it specific to this function only or applicable to entire codebase?

It can be solved by introducing new interface type TransactionWithSignature (name only for example, I'm pretty sure there is a better naming):

type TransactionWithSignature interface {
   Signature() []*felt.Felt
}

which can be used in example above as:

switch transaction.(type) {
case TransactionWithSignature:
     digest.Update(transaction.Signature()...)
default:
     digest.Update(&felt.Zero)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions