Skip to content

Commit

Permalink
wire: add flag bits to PR message
Browse files Browse the repository at this point in the history
Two new flag fields are introduced to the pair request message, both of which
are application specific and have no meaning to the wire package.  The first
is a Flags field which will be used to describe capabilities that do not
affect the pairing type.  This will be used in the initial release to allow
wallets to advertise support for solving and publishing the factored
polynomial.  While here, a second flags field which affects the pairing
compatibility is also added, as this will aid in any future incompatibility in
the client behavior without disturbing clients who have not upgraded.
  • Loading branch information
jrick committed May 8, 2024
1 parent a8f4243 commit da62575
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions wire/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestMessage(t *testing.T) {
msgReject := NewMsgReject("block", RejectDuplicate, "duplicate block")
msgGetInitState := NewMsgGetInitState()
msgInitState := NewMsgInitState()
msgMixPR, err := NewMsgMixPairReq([33]byte{}, 1, 1, "", 1, 1, 1, 1, []MixPairReqUTXO{}, NewTxOut(0, []byte{}))
msgMixPR, err := NewMsgMixPairReq([33]byte{}, 1, 1, "", 1, 1, 1, 1, []MixPairReqUTXO{}, NewTxOut(0, []byte{}), 1, 1)
if err != nil {
t.Errorf("NewMsgMixPairReq: %v", err)
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestMessage(t *testing.T) {
{msgCFTypes, msgCFTypes, pver, MainNet, 26},
{msgGetInitState, msgGetInitState, pver, MainNet, 25},
{msgInitState, msgInitState, pver, MainNet, 27},
{msgMixPR, msgMixPR, pver, MainNet, 165},
{msgMixPR, msgMixPR, pver, MainNet, 167},
{msgMixKE, msgMixKE, pver, MainNet, 1449},
{msgMixCT, msgMixCT, pver, MainNet, 158},
{msgMixSR, msgMixSR, pver, MainNet, 161},
Expand Down
25 changes: 22 additions & 3 deletions wire/msgmixpairreq.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type MsgMixPairReq struct {
InputValue int64
UTXOs []MixPairReqUTXO
Change *TxOut
Flags byte
PairingFlags byte

// hash records the hash of the message. It is a member of the
// message for convenience and performance, but is never automatically
Expand All @@ -83,7 +85,8 @@ func (msg *MsgMixPairReq) Pairing() ([]byte, error) {
VarIntSerializeSize(uint64(len(msg.ScriptClass))) + // Script class
len(msg.ScriptClass) +
2 + // Tx version
4 // Locktime
4 + // Locktime
1 // Pairing flags
w := bytes.NewBuffer(make([]byte, 0, bufLen))

err := writeElement(w, msg.MixAmount)
Expand All @@ -96,7 +99,7 @@ func (msg *MsgMixPairReq) Pairing() ([]byte, error) {
return nil, err
}

err = writeElements(w, msg.TxVersion, msg.LockTime)
err = writeElements(w, msg.TxVersion, msg.LockTime, msg.PairingFlags)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -209,6 +212,14 @@ func (msg *MsgMixPairReq) BtcDecode(r io.Reader, pver uint32) error {
return messageError(op, ErrInvalidMsg, msg)
}

var flags, pairingFlags byte
err = readElements(r, &flags, &pairingFlags)
if err != nil {
return err
}
msg.Flags = flags
msg.PairingFlags = pairingFlags

return nil
}

Expand Down Expand Up @@ -370,6 +381,11 @@ func (msg *MsgMixPairReq) writeMessageNoSignature(op string, w io.Writer, pver u
}
}

err = writeElements(w, msg.Flags, msg.PairingFlags)
if err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -433,7 +449,8 @@ func (msg *MsgMixPairReq) GetRun() uint32 {
// remaining fields.
func NewMsgMixPairReq(identity [33]byte, expiry uint32, mixAmount int64,
scriptClass string, txVersion uint16, lockTime, messageCount uint32,
inputValue int64, utxos []MixPairReqUTXO, change *TxOut) (*MsgMixPairReq, error) {
inputValue int64, utxos []MixPairReqUTXO, change *TxOut,
flags, pairingFlags byte) (*MsgMixPairReq, error) {

const op = "NewMsgMixPairReq"
lenScriptClass := len(scriptClass)
Expand Down Expand Up @@ -466,6 +483,8 @@ func NewMsgMixPairReq(identity [33]byte, expiry uint32, mixAmount int64,
InputValue: inputValue,
UTXOs: utxos,
Change: change,
Flags: flags,
PairingFlags: pairingFlags,
}
return msg, nil
}
11 changes: 10 additions & 1 deletion wire/msgmixpairreq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ type mixPairReqArgs struct {
inputValue int64
utxos []MixPairReqUTXO
change *TxOut
flags byte
pairingFlags byte
}

func (a *mixPairReqArgs) msg() (*MsgMixPairReq, error) {
return NewMsgMixPairReq(a.identity, a.expiry, a.mixAmount, a.scriptClass,
a.txVersion, a.lockTime, a.messageCount, a.inputValue, a.utxos, a.change)
a.txVersion, a.lockTime, a.messageCount, a.inputValue, a.utxos,
a.change, a.flags, a.pairingFlags)
}

func newMixPairReqArgs() *mixPairReqArgs {
Expand Down Expand Up @@ -74,6 +77,8 @@ func newMixPairReqArgs() *mixPairReqArgs {
const changeValue = int64(0x1393939393939393)
pkScript := repeat(0x94, 25)
change := NewTxOut(changeValue, pkScript)
flags := byte(0x95)
pairingFlags := byte(0x96)

return &mixPairReqArgs{
identity: id,
Expand All @@ -87,6 +92,8 @@ func newMixPairReqArgs() *mixPairReqArgs {
inputValue: inputValue,
utxos: utxos,
change: change,
flags: flags,
pairingFlags: pairingFlags,
}
}

Expand Down Expand Up @@ -154,6 +161,8 @@ func TestMsgMixPairReqWire(t *testing.T) {
0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94,
0x94,
}...)
expected = append(expected, 0x95) // Flags
expected = append(expected, 0x96) // Pairing flags

expectedSerializationEqual(t, buf.Bytes(), expected)

Expand Down

0 comments on commit da62575

Please sign in to comment.