Remove dependency to tx.transaction in transactionpool.
@@ -3,8 +3,6 @@ package tx
import (
"log"
- "github.com/icon-project/goloop/common/codec"
-
"github.com/icon-project/goloop/module"
)
@@ -20,15 +18,14 @@ const (
)
var (
- sReactorCodec = codec.MP
subProtocols = []module.ProtocolInfo{ProtocolPropagateTransaction}
)
func (r *TransactionReactor) OnReceive(subProtocol module.ProtocolInfo, buf []byte, peerId module.PeerID) (bool, error) {
switch subProtocol {
case ProtocolPropagateTransaction:
- var tx transaction
- if _, err := sReactorCodec.UnmarshalFromBytes(buf, &tx); err != nil {
+ tx, err := NewTransaction(buf)
+ if err != nil {
log.Printf("Failed to unmarshal transaction. buf=%x, err=%+v\n", buf, err)
return false, err
}
@@ -38,11 +35,11 @@ func (r *TransactionReactor) OnReceive(subProtocol module.ProtocolInfo, buf []by
return false, err
}
if tx.Group() == module.TransactionGroupPatch {
- if err := r.patchPool.Add(&tx); err != nil {
+ if err := r.patchPool.Add(tx); err != nil {
return false, err
}
} else {
- if err := r.normalPool.Add(&tx); err != nil {
+ if err := r.normalPool.Add(tx); err != nil {
return false, err
}
}
@@ -52,13 +49,8 @@ func (r *TransactionReactor) OnReceive(subProtocol module.ProtocolInfo, buf []by
}
func (r *TransactionReactor) PropagateTransaction(pi module.ProtocolInfo, tx Transaction) error {
- buf, err := sReactorCodec.MarshalToBytes(tx)
- if err != nil {
- log.Printf("Failed to marshal transaction. tx=%v, err=%+v\n", tx, err)
- }
-
if r != nil {
- r.membership.Multicast(ProtocolPropagateTransaction, buf, module.ROLE_VALIDATOR)
+ r.membership.Multicast(ProtocolPropagateTransaction, tx.Bytes(), module.ROLE_VALIDATOR)
}
return nil
}
