Skip to content

Conversation

@dcousens
Copy link
Contributor

As the title says.

The script is very simple to build, so I'm not 100% whether this is necessary.

Example 1 (new method):

    var tx = new bitcoin.TransactionBuilder()

    var data = new Buffer('cafedeadbeef', 'hex')
    var dataScript = bitcoin.scripts.dataOutput(data)

    tx.addInput("aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31", 0)
    tx.addOutput(dataScript, 1000)
    // ...

Example 2 (without this PR):

    var tx = new bitcoin.TransactionBuilder()

    var data = new Buffer('cafedeadbeef', 'hex')
    var dataScript = bitcoin.Script.fromChunks([bitcoin.opcodes.OP_RETURN, data])

    tx.addInput("aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31", 0)
    tx.addOutput(dataScript, 1000)
    // ...

Personally, the second is as clear, but, I feel like the complexity surrounding this functionality is already high enough that perhaps this PR helps?
Thoughts?

@dcousens
Copy link
Contributor Author

ping @williamcotton

@dcousens dcousens modified the milestones: 2.0.0, 1.3.0 Oct 19, 2014
@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) when pulling ea66ede on datascript into 27e69ba on master.

@weilu
Copy link
Contributor

weilu commented Oct 19, 2014

IMHO an example on the REAME would be sufficient, but I haven't used OP_RETURN in any prod code. I'm curious to hear from those who actually use OP_RETURN.

@dcousens
Copy link
Contributor Author

@weilu understandably. But, at what point do you do the same for pubKeyInput (which is simply just Script.fromChunks([signature]) etc), the point is this might relinquish some of the burden of knowing how the implementation actually works by making a very simple, but none the less abstracting ... abstraction.

weilu added a commit that referenced this pull request Oct 24, 2014
scripts: add dataOutput convenience function
@weilu weilu merged commit 41da79c into master Oct 24, 2014
@weilu weilu deleted the datascript branch October 24, 2014 05:36
@williamcotton
Copy link
Contributor

👍

@williamcotton
Copy link
Contributor

Reading from OP_RETURN is useful as well:

var outputs = transaction.outputs;
for (var j = outputs.length - 1; j >= 0; j--) {
  var output = outputs[j];
  var scriptPubKey = otuput.scriptPubKey;
  var scriptPubKeyBuffer = new Buffer(scriptPubKey, 'hex')
  if (scriptPubKeyBuffer[0] == 106) { // OP_RETURN code is 106
    var messageBuffer = scriptPubKeyBuffer.slice(2,scriptPubKeyBuffer.length);
    var message = messageBuffer.toString();
  }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants