AddData pushes the passed data to the end of the script. It automatically chooses canonical opcodes depending on the length of the data. A zero length buffer will lead to a push of empty data onto the stack (OP_0) and any push of data greater than MaxScriptElementSize will not modify the script si
(data []byte)
| 222 | // modified if pushing the data would cause the script to exceed the maximum |
| 223 | // allowed script engine size. |
| 224 | func (b *ScriptBuilder) AddData(data []byte) *ScriptBuilder { |
| 225 | if b.err != nil { |
| 226 | return b |
| 227 | } |
| 228 | |
| 229 | // Pushes that would cause the script to exceed the largest allowed |
| 230 | // script size would result in a non-canonical script. |
| 231 | dataSize := canonicalDataSize(data) |
| 232 | if len(b.script)+dataSize > MaxScriptSize { |
| 233 | str := fmt.Sprintf("adding %d bytes of data would exceed the "+ |
| 234 | "maximum allowed canonical script length of %d", |
| 235 | dataSize, MaxScriptSize) |
| 236 | b.err = ErrScriptNotCanonical(str) |
| 237 | return b |
| 238 | } |
| 239 | |
| 240 | // Pushes larger than the max script element size would result in a |
| 241 | // script that is not canonical. |
| 242 | dataLen := len(data) |
| 243 | if dataLen > MaxScriptElementSize { |
| 244 | str := fmt.Sprintf("adding a data element of %d bytes would "+ |
| 245 | "exceed the maximum allowed script element size of %d", |
| 246 | dataLen, MaxScriptElementSize) |
| 247 | b.err = ErrScriptNotCanonical(str) |
| 248 | return b |
| 249 | } |
| 250 | |
| 251 | return b.addData(data) |
| 252 | } |
| 253 | |
| 254 | // AddInt64 pushes the passed integer to the end of the script. The script will |
| 255 | // not be modified if pushing the data would cause the script to exceed the |