payload: drop Network from P2PNotaryRequest
It's not needed now.
This commit is contained in:
parent
8c110a6147
commit
c789431402
8 changed files with 7 additions and 46 deletions
|
@ -12,7 +12,6 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/internal/testchain"
|
"github.com/nspcc-dev/neo-go/internal/testchain"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
||||||
|
@ -199,7 +198,6 @@ func TestNotary(t *testing.T) {
|
||||||
payloads[i] = &payload.P2PNotaryRequest{
|
payloads[i] = &payload.P2PNotaryRequest{
|
||||||
MainTransaction: main,
|
MainTransaction: main,
|
||||||
FallbackTransaction: fallback,
|
FallbackTransaction: fallback,
|
||||||
Network: netmode.UnitTestNet,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return payloads
|
return payloads
|
||||||
|
@ -249,7 +247,6 @@ func TestNotary(t *testing.T) {
|
||||||
payloads[i] = &payload.P2PNotaryRequest{
|
payloads[i] = &payload.P2PNotaryRequest{
|
||||||
MainTransaction: main,
|
MainTransaction: main,
|
||||||
FallbackTransaction: fallback,
|
FallbackTransaction: fallback,
|
||||||
Network: netmode.UnitTestNet,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return payloads
|
return payloads
|
||||||
|
|
|
@ -149,7 +149,7 @@ func (m *Message) decodePayload() error {
|
||||||
case CMDExtensible:
|
case CMDExtensible:
|
||||||
p = payload.NewExtensible()
|
p = payload.NewExtensible()
|
||||||
case CMDP2PNotaryRequest:
|
case CMDP2PNotaryRequest:
|
||||||
p = &payload.P2PNotaryRequest{Network: m.Network}
|
p = &payload.P2PNotaryRequest{}
|
||||||
case CMDGetBlocks:
|
case CMDGetBlocks:
|
||||||
p = &payload.GetBlocks{}
|
p = &payload.GetBlocks{}
|
||||||
case CMDGetHeaders:
|
case CMDGetHeaders:
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
@ -16,17 +15,15 @@ import (
|
||||||
type P2PNotaryRequest struct {
|
type P2PNotaryRequest struct {
|
||||||
MainTransaction *transaction.Transaction
|
MainTransaction *transaction.Transaction
|
||||||
FallbackTransaction *transaction.Transaction
|
FallbackTransaction *transaction.Transaction
|
||||||
Network netmode.Magic
|
|
||||||
|
|
||||||
Witness transaction.Witness
|
Witness transaction.Witness
|
||||||
|
|
||||||
hash util.Uint256
|
hash util.Uint256
|
||||||
signedHash util.Uint256
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewP2PNotaryRequestFromBytes decodes P2PNotaryRequest from the given bytes.
|
// NewP2PNotaryRequestFromBytes decodes P2PNotaryRequest from the given bytes.
|
||||||
func NewP2PNotaryRequestFromBytes(network netmode.Magic, b []byte) (*P2PNotaryRequest, error) {
|
func NewP2PNotaryRequestFromBytes(b []byte) (*P2PNotaryRequest, error) {
|
||||||
req := &P2PNotaryRequest{Network: network}
|
req := &P2PNotaryRequest{}
|
||||||
br := io.NewBinReaderFromBuf(b)
|
br := io.NewBinReaderFromBuf(b)
|
||||||
req.DecodeBinary(br)
|
req.DecodeBinary(br)
|
||||||
if br.Err != nil {
|
if br.Err != nil {
|
||||||
|
@ -59,36 +56,11 @@ func (r *P2PNotaryRequest) Hash() util.Uint256 {
|
||||||
return r.hash
|
return r.hash
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSignedHash returns a hash of the payload used to verify it.
|
|
||||||
func (r *P2PNotaryRequest) GetSignedHash() util.Uint256 {
|
|
||||||
if r.signedHash.Equals(util.Uint256{}) {
|
|
||||||
if r.createHash() != nil {
|
|
||||||
panic("failed to compute hash!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return r.signedHash
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSignedPart returns a part of the payload which must be signed.
|
|
||||||
func (r *P2PNotaryRequest) GetSignedPart() []byte {
|
|
||||||
if r.hash.Equals(util.Uint256{}) {
|
|
||||||
if r.createHash() != nil {
|
|
||||||
panic("failed to compute hash!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buf := io.NewBufBinWriter()
|
|
||||||
buf.WriteU32LE(uint32(r.Network))
|
|
||||||
buf.WriteBytes(r.hash[:])
|
|
||||||
return buf.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
// createHash creates hash of the payload.
|
// createHash creates hash of the payload.
|
||||||
func (r *P2PNotaryRequest) createHash() error {
|
func (r *P2PNotaryRequest) createHash() error {
|
||||||
buf := io.NewBufBinWriter()
|
buf := io.NewBufBinWriter()
|
||||||
r.encodeHashableFields(buf.BinWriter)
|
r.encodeHashableFields(buf.BinWriter)
|
||||||
r.hash = hash.Sha256(buf.Bytes())
|
r.hash = hash.Sha256(buf.Bytes())
|
||||||
signed := r.GetSignedPart()
|
|
||||||
r.signedHash = hash.Sha256(signed)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/internal/random"
|
"github.com/nspcc-dev/neo-go/internal/random"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
|
@ -171,7 +170,6 @@ func TestNotaryRequestBytesFromBytes(t *testing.T) {
|
||||||
_ = fallbackTx.Hash()
|
_ = fallbackTx.Hash()
|
||||||
_ = fallbackTx.Size()
|
_ = fallbackTx.Size()
|
||||||
p := &P2PNotaryRequest{
|
p := &P2PNotaryRequest{
|
||||||
Network: netmode.UnitTestNet,
|
|
||||||
MainTransaction: mainTx,
|
MainTransaction: mainTx,
|
||||||
FallbackTransaction: fallbackTx,
|
FallbackTransaction: fallbackTx,
|
||||||
Witness: transaction.Witness{
|
Witness: transaction.Witness{
|
||||||
|
@ -183,7 +181,7 @@ func TestNotaryRequestBytesFromBytes(t *testing.T) {
|
||||||
_ = p.Hash() // initialize hash caches
|
_ = p.Hash() // initialize hash caches
|
||||||
bytes, err := p.Bytes()
|
bytes, err := p.Bytes()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
actual, err := NewP2PNotaryRequestFromBytes(netmode.UnitTestNet, bytes)
|
actual, err := NewP2PNotaryRequestFromBytes(bytes)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, p, actual)
|
require.Equal(t, p, actual)
|
||||||
}
|
}
|
||||||
|
|
|
@ -542,7 +542,6 @@ func TestGetData(t *testing.T) {
|
||||||
r := &payload.P2PNotaryRequest{
|
r := &payload.P2PNotaryRequest{
|
||||||
MainTransaction: mainTx,
|
MainTransaction: mainTx,
|
||||||
FallbackTransaction: fallbackTx,
|
FallbackTransaction: fallbackTx,
|
||||||
Network: netmode.UnitTestNet,
|
|
||||||
Witness: transaction.Witness{
|
Witness: transaction.Witness{
|
||||||
InvocationScript: []byte{1, 2, 3},
|
InvocationScript: []byte{1, 2, 3},
|
||||||
VerificationScript: []byte{1, 2, 3},
|
VerificationScript: []byte{1, 2, 3},
|
||||||
|
@ -725,7 +724,6 @@ func TestInv(t *testing.T) {
|
||||||
r := &payload.P2PNotaryRequest{
|
r := &payload.P2PNotaryRequest{
|
||||||
MainTransaction: newDummyTx(),
|
MainTransaction: newDummyTx(),
|
||||||
FallbackTransaction: fallbackTx,
|
FallbackTransaction: fallbackTx,
|
||||||
Network: netmode.UnitTestNet,
|
|
||||||
}
|
}
|
||||||
require.NoError(t, s.notaryRequestPool.Add(r.FallbackTransaction, s.chain, r))
|
require.NoError(t, s.notaryRequestPool.Add(r.FallbackTransaction, s.chain, r))
|
||||||
hs := []util.Uint256{random.Uint256(), r.FallbackTransaction.Hash(), random.Uint256()}
|
hs := []util.Uint256{random.Uint256(), r.FallbackTransaction.Hash(), random.Uint256()}
|
||||||
|
|
|
@ -659,10 +659,9 @@ func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fa
|
||||||
req := &payload.P2PNotaryRequest{
|
req := &payload.P2PNotaryRequest{
|
||||||
MainTransaction: mainTx,
|
MainTransaction: mainTx,
|
||||||
FallbackTransaction: fallbackTx,
|
FallbackTransaction: fallbackTx,
|
||||||
Network: c.GetNetwork(),
|
|
||||||
}
|
}
|
||||||
req.Witness = transaction.Witness{
|
req.Witness = transaction.Witness{
|
||||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, acc.PrivateKey().Sign(req.GetSignedPart())...),
|
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, acc.PrivateKey().SignHashable(uint32(c.GetNetwork()), req)...),
|
||||||
VerificationScript: acc.GetVerificationScript(),
|
VerificationScript: acc.GetVerificationScript(),
|
||||||
}
|
}
|
||||||
actualHash, err := c.SubmitP2PNotaryRequest(req)
|
actualHash, err := c.SubmitP2PNotaryRequest(req)
|
||||||
|
|
|
@ -1279,7 +1279,7 @@ func (s *Server) submitNotaryRequest(ps request.Params) (interface{}, *response.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, response.ErrInvalidParams
|
return nil, response.ErrInvalidParams
|
||||||
}
|
}
|
||||||
r, err := payload.NewP2PNotaryRequestFromBytes(s.network, bytePayload)
|
r, err := payload.NewP2PNotaryRequestFromBytes(bytePayload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, response.ErrInvalidParams
|
return nil, response.ErrInvalidParams
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/nspcc-dev/neo-go/internal/testchain"
|
"github.com/nspcc-dev/neo-go/internal/testchain"
|
||||||
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
||||||
|
@ -1099,7 +1098,6 @@ func TestSubmitNotaryRequest(t *testing.T) {
|
||||||
{InvocationScript: []byte{1, 2, 3}, VerificationScript: []byte{1, 2, 3}}},
|
{InvocationScript: []byte{1, 2, 3}, VerificationScript: []byte{1, 2, 3}}},
|
||||||
}
|
}
|
||||||
p := &payload.P2PNotaryRequest{
|
p := &payload.P2PNotaryRequest{
|
||||||
Network: netmode.UnitTestNet,
|
|
||||||
MainTransaction: mainTx,
|
MainTransaction: mainTx,
|
||||||
FallbackTransaction: fallbackTx,
|
FallbackTransaction: fallbackTx,
|
||||||
Witness: transaction.Witness{
|
Witness: transaction.Witness{
|
||||||
|
@ -1143,7 +1141,6 @@ func TestSubmitNotaryRequest(t *testing.T) {
|
||||||
VerificationScript: sender.PublicKey().GetVerificationScript(),
|
VerificationScript: sender.PublicKey().GetVerificationScript(),
|
||||||
})
|
})
|
||||||
p := &payload.P2PNotaryRequest{
|
p := &payload.P2PNotaryRequest{
|
||||||
Network: netmode.UnitTestNet,
|
|
||||||
MainTransaction: mainTx,
|
MainTransaction: mainTx,
|
||||||
FallbackTransaction: fallbackTx,
|
FallbackTransaction: fallbackTx,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue