Returns the minimal bytecode required to push the provided data to the
stack.
Remarks
This method conservatively encodes a Uint8Array as a data push. For VM
Numbers that can be pushed using a single opcode (-1 through 16), the
equivalent bytecode value is returned. Other data values will be prefixed
with the proper opcode and push length bytes (if necessary) to create the
minimal push instruction.
Note, while some single-byte VM Number pushes will be minimally-encoded by
this method, all larger inputs will be encoded as-is (it cannot be assumed
that inputs are intended to be used as VM Numbers). To encode the push of a
VM Number, minimally-encode the number before passing it to this
method, e.g.:
encodeDataPush(bigIntToVmNumber(decodeVmNumber(nonMinimalNumber))).
The maximum bytecode length that can be encoded for a push in the Bitcoin
system is 4294967295 (~4GB). This method assumes a smaller input – if
bytecode has the potential to be longer, it should be checked (and the
error handled) prior to calling this method.
Returns the minimal bytecode required to push the provided
data
to the stack.Remarks
This method conservatively encodes a
Uint8Array
as a data push. For VM Numbers that can be pushed using a single opcode (-1 through 16), the equivalent bytecode value is returned. Otherdata
values will be prefixed with the proper opcode and push length bytes (if necessary) to create the minimal push instruction.Note, while some single-byte VM Number pushes will be minimally-encoded by this method, all larger inputs will be encoded as-is (it cannot be assumed that inputs are intended to be used as VM Numbers). To encode the push of a VM Number, minimally-encode the number before passing it to this method, e.g.:
encodeDataPush(bigIntToVmNumber(decodeVmNumber(nonMinimalNumber)))
.The maximum
bytecode
length that can be encoded for a push in the Bitcoin system is4294967295
(~4GB). This method assumes a smaller input – ifbytecode
has the potential to be longer, it should be checked (and the error handled) prior to calling this method.