MCPcopy Index your code
hub / github.com/btcsuite/btcd / AddData

Method AddData

txscript/scriptbuilder.go:224–252  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

222// modified if pushing the data would cause the script to exceed the maximum
223// allowed script engine size.
224func (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

Callers 15

finalizeNonWitnessInputFunction · 0.95
finalizeWitnessInputFunction · 0.95
pushDataScriptFunction · 0.95
mergeScriptsFunction · 0.95
SignTxOutputFunction · 0.95
TestScriptBuilderAllocFunction · 0.95
TestExceedMaxScriptSizeFunction · 0.95
TestErroredScriptFunction · 0.95
genComplexScriptFunction · 0.95
TestDebugEngineFunction · 0.95
TestHasCanonicalPushFunction · 0.95

Calls 3

addDataMethod · 0.95
canonicalDataSizeFunction · 0.85
ErrScriptNotCanonicalTypeAlias · 0.85

Tested by 13

TestScriptBuilderAllocFunction · 0.76
TestExceedMaxScriptSizeFunction · 0.76
TestErroredScriptFunction · 0.76
genComplexScriptFunction · 0.76
TestDebugEngineFunction · 0.76
TestHasCanonicalPushFunction · 0.76
spendCSVOutputFunction · 0.64
TestUseBlockHashFunction · 0.64
TestScriptBuilderAddDataFunction · 0.64