Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.add_op_return_data = (tx, data) => {
let script = new bch.Script();
script.add(bch.Opcode.OP_RETURN);
for (let m of data) {
if (m['type'] == 'hex') {
script.add(Buffer.from(m['v'], 'hex'));
} else if(m['type'] == 'str') {
script.add(Buffer.from(m['v']));
} else {
throw new Error('unknown data type');
}
}
tx.addOutput(new bch.Transaction.Output({
script: script,
satoshis: 0
}));