@@ -106,7 +106,8 @@ func Deserialize(script bitcoin.Script, isTest bool) (actions.Action, error) {
106106 return nil , ErrNotTokenized
107107 }
108108
109- if msg .PayloadCount () != 3 {
109+ payloadCount := msg .PayloadCount ()
110+ if payloadCount != 2 && payloadCount != 3 {
110111 return nil , errors .Wrapf (ErrNotTokenized , "wrong payload count: %d" ,
111112 msg .PayloadCount ())
112113 }
@@ -119,6 +120,17 @@ func Deserialize(script bitcoin.Script, isTest bool) (actions.Action, error) {
119120 return nil , ErrUnknownVersion
120121 }
121122
123+ if payloadCount == 2 {
124+ // Action payload is not provided because it was empty.
125+ result := actions .NewActionFromCode (string (msg .PayloadAt (1 )))
126+ if result == nil {
127+ return nil , errors .Wrapf (ErrNotTokenized , "unknown action code: %s" ,
128+ string (msg .PayloadAt (1 )))
129+ }
130+
131+ return result , nil
132+ }
133+
122134 return actions .Deserialize (msg .PayloadAt (1 ), msg .PayloadAt (2 ))
123135 }
124136}
@@ -154,9 +166,9 @@ func ActionCodeForScript(script bitcoin.Script, isTest bool) (string, error) {
154166 return "" , ErrNotTokenized
155167 }
156168
157- if msg .PayloadCount () != 3 {
158- return "" , errors . Wrapf ( ErrNotTokenized , "wrong payload count: %d" ,
159- msg . PayloadCount () )
169+ payloadCount := msg .PayloadCount ()
170+ if payloadCount != 2 && payloadCount != 3 {
171+ return "" , errors . Wrapf ( ErrNotTokenized , "wrong payload count: %d" , payloadCount )
160172 }
161173
162174 version , _ , err := bitcoin .ParsePushNumberScript (msg .PayloadAt (0 ))
@@ -179,7 +191,12 @@ func WrapAction(action actions.Action, isTest bool) (envelope.BaseMessage, error
179191 }
180192
181193 message := envelopeV1 .NewMessage ([][]byte {GetProtocolID (isTest )},
182- [][]byte {bitcoin .PushNumberScript (int64 (Version )), []byte (action .Code ()), payload })
194+ [][]byte {bitcoin .PushNumberScript (int64 (Version )), []byte (action .Code ())})
195+
196+ if len (payload ) > 0 {
197+ // Only add action payload if it isn't empty.
198+ message .AddPayload (payload )
199+ }
183200
184201 return message , nil
185202}
0 commit comments