Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions blockproducer/interfaces/mixins.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@

package interfaces

import "time"

//go:generate hsp

// TransactionTypeMixin provide type heuristic features to transaction wrapper.
type TransactionTypeMixin struct {
TxType TransactionType
TxType TransactionType
Timestamp time.Time
}

// NewTransactionTypeMixin returns new instance.
func NewTransactionTypeMixin(txType TransactionType) *TransactionTypeMixin {
return &TransactionTypeMixin{
TxType: txType,
Timestamp: time.Now(),
}
}

// ContainsTransactionTypeMixin interface defines interface to detect transaction type mixin.
Expand All @@ -38,9 +49,12 @@ func (m *TransactionTypeMixin) SetTransactionType(t TransactionType) {
m.TxType = t
}

// NewTransactionTypeMixin returns new instance.
func NewTransactionTypeMixin(txType TransactionType) *TransactionTypeMixin {
return &TransactionTypeMixin{
TxType: txType,
}
// GetTimestamp implements Transaciton.GetTimestamp()
func (m *TransactionTypeMixin) GetTimestamp() time.Time {
return m.Timestamp
}

// SetTimestamp is a helper function for derived types.
func (m *TransactionTypeMixin) SetTimestamp(t time.Time) {
m.Timestamp = t
}
8 changes: 5 additions & 3 deletions blockproducer/interfaces/mixins_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions blockproducer/interfaces/mixins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package interfaces

import (
"testing"
"time"

. "github.com/smartystreets/goconvey/convey"
)
Expand All @@ -28,5 +29,9 @@ func TestTransactionTypeMixin(t *testing.T) {
So(m.GetTransactionType(), ShouldEqual, TransactionTypeBaseAccount)
m.SetTransactionType(TransactionTypeTransfer)
So(m.GetTransactionType(), ShouldEqual, TransactionTypeTransfer)
now := time.Now()
So(now.Sub(m.GetTimestamp()).Seconds(), ShouldBeLessThan, 0.1)
m.SetTimestamp(now)
So(m.GetTimestamp(), ShouldEqual, now)
})
}
4 changes: 3 additions & 1 deletion blockproducer/interfaces/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package interfaces

import (
"encoding/binary"
"time"

"github.com/CovenantSQL/CovenantSQL/crypto/asymmetric"
"github.com/CovenantSQL/CovenantSQL/crypto/hash"
Expand Down Expand Up @@ -111,10 +112,11 @@ func (t TransactionType) String() string {
// Transaction is the interface implemented by an object that can be verified and processed by
// block producers.
type Transaction interface {
GetTransactionType() TransactionType
GetAccountAddress() proto.AccountAddress
GetAccountNonce() AccountNonce
GetTimestamp() time.Time
Hash() hash.Hash
GetTransactionType() TransactionType
Sign(signer *asymmetric.PrivateKey) error
Verify() error
MarshalHash() ([]byte, error)
Expand Down
21 changes: 3 additions & 18 deletions types/init_service_type_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 5 additions & 18 deletions types/request_type_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.