payload: drop Network from Extensible
It's only used to sign/verify it and is not a part of the structure. It's still neded in consensus.Payload though because that's the way dbft library is.
This commit is contained in:
parent
95c279325a
commit
f91ff78918
10 changed files with 18 additions and 76 deletions
|
@ -201,12 +201,12 @@ var (
|
|||
func NewPayload(m netmode.Magic, stateRootEnabled bool) *Payload {
|
||||
return &Payload{
|
||||
Extensible: npayload.Extensible{
|
||||
Network: m,
|
||||
Category: Category,
|
||||
},
|
||||
message: message{
|
||||
stateRootEnabled: stateRootEnabled,
|
||||
},
|
||||
network: m,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/dbft/payload"
|
||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
npayload "github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
|
@ -28,6 +29,7 @@ type (
|
|||
Payload struct {
|
||||
npayload.Extensible
|
||||
message
|
||||
network netmode.Magic
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -128,7 +130,7 @@ func (p *Payload) EncodeBinary(w *io.BinWriter) {
|
|||
// It also sets corresponding verification and invocation scripts.
|
||||
func (p *Payload) Sign(key *privateKey) error {
|
||||
p.encodeData()
|
||||
sig := key.SignHash(p.GetSignedHash())
|
||||
sig := key.PrivateKey.SignHashable(uint32(p.network), &p.Extensible)
|
||||
|
||||
buf := io.NewBufBinWriter()
|
||||
emit.Bytes(buf.BinWriter, sig)
|
||||
|
@ -138,22 +140,6 @@ func (p *Payload) Sign(key *privateKey) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetSignedPart implements crypto.Verifiable interface.
|
||||
func (p *Payload) GetSignedPart() []byte {
|
||||
if p.Extensible.Data == nil {
|
||||
p.encodeData()
|
||||
}
|
||||
return p.Extensible.GetSignedPart()
|
||||
}
|
||||
|
||||
// GetSignedHash returns a hash of the payload used to verify it.
|
||||
func (p *Payload) GetSignedHash() util.Uint256 {
|
||||
if p.Extensible.Data == nil {
|
||||
p.encodeData()
|
||||
}
|
||||
return p.Extensible.GetSignedHash()
|
||||
}
|
||||
|
||||
// Hash implements payload.ConsensusPayload interface.
|
||||
func (p *Payload) Hash() util.Uint256 {
|
||||
if p.Extensible.Data == nil {
|
||||
|
|
|
@ -79,7 +79,7 @@ func TestConsensusPayload_Setters(t *testing.T) {
|
|||
func TestConsensusPayload_Serializable(t *testing.T) {
|
||||
for _, mt := range messageTypes {
|
||||
p := randomPayload(t, mt)
|
||||
actual := &Payload{Extensible: npayload.Extensible{Network: netmode.UnitTestNet}}
|
||||
actual := &Payload{Extensible: npayload.Extensible{}, network: netmode.UnitTestNet}
|
||||
data, err := testserdes.EncodeBinary(p)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, testserdes.DecodeBinary(data, &actual.Extensible))
|
||||
|
@ -158,12 +158,12 @@ func randomPayload(t *testing.T, mt messageType) *Payload {
|
|||
payload: randomMessage(t, mt),
|
||||
},
|
||||
Extensible: npayload.Extensible{
|
||||
Network: netmode.UnitTestNet,
|
||||
Witness: transaction.Witness{
|
||||
InvocationScript: random.Bytes(3),
|
||||
VerificationScript: []byte{byte(opcode.PUSH0)},
|
||||
},
|
||||
},
|
||||
network: netmode.UnitTestNet,
|
||||
}
|
||||
|
||||
if mt == changeViewType {
|
||||
|
|
|
@ -298,7 +298,6 @@ func fromPayload(t messageType, recovery *Payload, p io.Serializable) *Payload {
|
|||
return &Payload{
|
||||
Extensible: npayload.Extensible{
|
||||
Category: Category,
|
||||
Network: recovery.Network,
|
||||
ValidBlockEnd: recovery.BlockIndex,
|
||||
},
|
||||
message: message{
|
||||
|
@ -308,5 +307,6 @@ func fromPayload(t messageType, recovery *Payload, p io.Serializable) *Payload {
|
|||
payload: p,
|
||||
stateRootEnabled: recovery.stateRootEnabled,
|
||||
},
|
||||
network: recovery.network,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue