pushdata function
Prepend proper varint to a buffer chunk to be included in script.
Implementation
List<int> pushdata(List<int> buf) {
if (buf.isEmpty) {
return [0x4C, 0x00];
} else if (buf.length < 0x4E) {
return [buf.length, ...buf];
} else if (buf.length < 0xFF) {
return [0x4c, buf.length, ...buf];
} else if (buf.length < 0xFFFF) {
final tmp = ByteData(2);
tmp.setUint16(0, buf.length, Endian.little);
return [0x4d, ...tmp.buffer.asUint8List().toList(), ...buf];
} else if (buf.length < 0xFFFFFFFF) {
final tmp = ByteData(4);
tmp.setUint32(0, buf.length, Endian.little);
return [0x4e, ...tmp.buffer.asUint8List().toList(), ...buf];
} else {
throw('does not support bigger pushes yet');
}
}