Skip to content

Commit

Permalink
default should be safe
Browse files Browse the repository at this point in the history
  • Loading branch information
unwriter committed Feb 12, 2020
1 parent 85aec6d commit 69e46fb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ var _script = function(options) {
if (options.data) {
if (Array.isArray(options.data)) {
s = new bitcoin.Script();
if (!options.hasOwnProperty("safe")) {
options.safe = true;
}
if (options.safe) {
s.add(bitcoin.Opcode.OP_FALSE);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datapay",
"version": "0.0.20",
"version": "0.0.22",
"description": "post data over bitcoin sv",
"main": "index.js",
"scripts": {
Expand Down
37 changes: 37 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,43 @@ describe('datapay', function() {
})
})
describe('build', function() {
describe('safe as default', function() {
it('safe as default', function(done) {
const options = {
data: [{op: 78}, "hello world"]
}
datapay.build(options, function(err, tx) {
let generated = tx.toObject()
let s = new bitcoin.Script(generated.outputs[0].script).toString()
assert(s.startsWith("OP_0 OP_RETURN OP_PUSHDATA4 1818585099"))
done()
});
})
it('set safe true', function(done) {
const options = {
safe: true,
data: [{op: 78}, "hello world"]
}
datapay.build(options, function(err, tx) {
let generated = tx.toObject()
let s = new bitcoin.Script(generated.outputs[0].script).toString()
assert(s.startsWith("OP_0 OP_RETURN OP_PUSHDATA4 1818585099"))
done()
});
})
it('set safe false', function(done) {
const options = {
safe: false,
data: [{op: 78}, "hello world"]
}
datapay.build(options, function(err, tx) {
let generated = tx.toObject()
let s = new bitcoin.Script(generated.outputs[0].script).toString()
assert(s.startsWith("OP_RETURN OP_PUSHDATA4 1818585099"))
done()
});
})
})
describe('data only', function() {
it('opcode', function(done) {
const options = {
Expand Down

0 comments on commit 69e46fb

Please sign in to comment.