Optimizations
This commit is contained in:
@@ -14,11 +14,11 @@ type transaction struct {
|
||||
Src string
|
||||
Dst string
|
||||
Amount int
|
||||
Timestamp time.Time
|
||||
Timestamp int64
|
||||
}
|
||||
|
||||
func NewTransaction(source string, dst string, amount int) transaction {
|
||||
return transaction{Src: source, Dst: dst, Amount: amount, Timestamp: time.Now()}
|
||||
return transaction{Src: source, Dst: dst, Amount: amount, Timestamp: time.Now().Unix()}
|
||||
}
|
||||
|
||||
func (ta transaction) SignTransaction(privKey *rsa.PrivateKey, d int) ([]byte, error) {
|
||||
@@ -36,8 +36,13 @@ func (ta transaction) HashTransaction() []byte {
|
||||
func (ta transaction) ToBytes() []byte {
|
||||
bytes := []byte(ta.Src)
|
||||
bytes = append(bytes, []byte(ta.Dst)...)
|
||||
//fmt.Printf("%s", ta.Dst)
|
||||
bytes = append(bytes, byte(ta.Amount))
|
||||
bytes = append(bytes, []byte(ta.Timestamp.String())...)
|
||||
//bytes = append(bytes, []byte(ta.Timestamp))
|
||||
return bytes
|
||||
}
|
||||
|
||||
func (ta transaction) ToBytesSerialize() []byte {
|
||||
var buf bytes.Buffer
|
||||
gob.NewEncoder(&buf).Encode(ta)
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user